Java 类org.apache.hadoop.hbase.snapshot.SnapshotTestingUtils 实例源码

项目:ditb    文件:TestRestoreSnapshotFromClient.java   
@Test
public void testCloneSnapshotOfCloned() throws IOException, InterruptedException {
  TableName clonedTableName =
      TableName.valueOf("clonedtb-" + System.currentTimeMillis());
  admin.cloneSnapshot(snapshotName0, clonedTableName);
  SnapshotTestingUtils.verifyRowCount(TEST_UTIL, clonedTableName, snapshot0Rows);
  SnapshotTestingUtils.verifyReplicasCameOnline(clonedTableName, admin, getNumReplicas());
  admin.disableTable(clonedTableName);
  admin.snapshot(snapshotName2, clonedTableName);
  TEST_UTIL.deleteTable(clonedTableName);
  waitCleanerRun();

  admin.cloneSnapshot(snapshotName2, clonedTableName);
  SnapshotTestingUtils.verifyRowCount(TEST_UTIL, clonedTableName, snapshot0Rows);
  SnapshotTestingUtils.verifyReplicasCameOnline(clonedTableName, admin, getNumReplicas());
  TEST_UTIL.deleteTable(clonedTableName);
}
项目:ditb    文件:TestRestoreSnapshotFromClient.java   
@Test
public void testCloneAndRestoreSnapshot() throws IOException, InterruptedException {
  TEST_UTIL.deleteTable(tableName);
  waitCleanerRun();

  admin.cloneSnapshot(snapshotName0, tableName);
  SnapshotTestingUtils.verifyRowCount(TEST_UTIL, tableName, snapshot0Rows);
  SnapshotTestingUtils.verifyReplicasCameOnline(tableName, admin, getNumReplicas());
  waitCleanerRun();

  admin.disableTable(tableName);
  admin.restoreSnapshot(snapshotName0);
  admin.enableTable(tableName);
  SnapshotTestingUtils.verifyRowCount(TEST_UTIL, tableName, snapshot0Rows);
  SnapshotTestingUtils.verifyReplicasCameOnline(tableName, admin, getNumReplicas());
}
项目:LCIndex-HBase-0.94.16    文件:TestRestoreSnapshotFromClient.java   
@Test
public void testRestoreSnapshot() throws IOException {
  SnapshotTestingUtils.verifyRowCount(TEST_UTIL, tableName, snapshot1Rows);

  // Restore from snapshot-0
  admin.disableTable(tableName);
  admin.restoreSnapshot(snapshotName0);
  admin.enableTable(tableName);
  SnapshotTestingUtils.verifyRowCount(TEST_UTIL, tableName, snapshot0Rows);

  // Restore from emptySnapshot
  admin.disableTable(tableName);
  admin.restoreSnapshot(emptySnapshot);
  admin.enableTable(tableName);
  SnapshotTestingUtils.verifyRowCount(TEST_UTIL, tableName, 0);

  // Restore from snapshot-1
  admin.disableTable(tableName);
  admin.restoreSnapshot(snapshotName1);
  admin.enableTable(tableName);
  SnapshotTestingUtils.verifyRowCount(TEST_UTIL, tableName, snapshot1Rows);
}
项目:LCIndex-HBase-0.94.16    文件:TestSnapshotFromMaster.java   
/**
 * @return all the HFiles for a given table that have been archived
 * @throws IOException on expected failure
 */
private final Collection<String> getArchivedHFiles(Path archiveDir, Path rootDir,
    FileSystem fs, String tableName) throws IOException {
  Path tableArchive = new Path(archiveDir, tableName);
  Path[] archivedHFiles = SnapshotTestingUtils.listHFiles(fs, tableArchive);
  List<String> files = new ArrayList<String>(archivedHFiles.length);
  LOG.debug("Have archived hfiles: " + tableArchive);
  for (Path file : archivedHFiles) {
    LOG.debug(file);
    files.add(file.getName());
  }
  // sort the archived files

  Collections.sort(files);
  return files;
}
项目:pbase    文件:TestRestoreSnapshotFromClient.java   
@Test
public void testCloneSnapshotOfCloned() throws IOException, InterruptedException {
  TableName clonedTableName =
      TableName.valueOf("clonedtb-" + System.currentTimeMillis());
  admin.cloneSnapshot(snapshotName0, clonedTableName);
  SnapshotTestingUtils.verifyRowCount(TEST_UTIL, clonedTableName, snapshot0Rows);
  SnapshotTestingUtils.verifyReplicasCameOnline(clonedTableName, admin, getNumReplicas());
  admin.disableTable(clonedTableName);
  admin.snapshot(snapshotName2, clonedTableName);
  TEST_UTIL.deleteTable(clonedTableName);
  waitCleanerRun();

  admin.cloneSnapshot(snapshotName2, clonedTableName);
  SnapshotTestingUtils.verifyRowCount(TEST_UTIL, clonedTableName, snapshot0Rows);
  SnapshotTestingUtils.verifyReplicasCameOnline(clonedTableName, admin, getNumReplicas());
  TEST_UTIL.deleteTable(clonedTableName);
}
项目:pbase    文件:TestRestoreSnapshotFromClient.java   
@Test
public void testCloneAndRestoreSnapshot() throws IOException, InterruptedException {
  TEST_UTIL.deleteTable(tableName);
  waitCleanerRun();

  admin.cloneSnapshot(snapshotName0, tableName);
  SnapshotTestingUtils.verifyRowCount(TEST_UTIL, tableName, snapshot0Rows);
  SnapshotTestingUtils.verifyReplicasCameOnline(tableName, admin, getNumReplicas());
  waitCleanerRun();

  admin.disableTable(tableName);
  admin.restoreSnapshot(snapshotName0);
  admin.enableTable(tableName);
  SnapshotTestingUtils.verifyRowCount(TEST_UTIL, tableName, snapshot0Rows);
  SnapshotTestingUtils.verifyReplicasCameOnline(tableName, admin, getNumReplicas());
}
项目:pbase    文件:TestSnapshotFromMaster.java   
/**
 * @return all the HFiles for a given table that have been archived
 * @throws IOException on expected failure
 */
private final Collection<String> getArchivedHFiles(Path archiveDir, Path rootDir,
    FileSystem fs, TableName tableName) throws IOException {
  Path tableArchive = FSUtils.getTableDir(archiveDir, tableName);
  Path[] archivedHFiles = SnapshotTestingUtils.listHFiles(fs, tableArchive);
  List<String> files = new ArrayList<String>(archivedHFiles.length);
  LOG.debug("Have archived hfiles: " + tableArchive);
  for (Path file : archivedHFiles) {
    LOG.debug(file);
    files.add(file.getName());
  }
  // sort the archived files

  Collections.sort(files);
  return files;
}
项目:HIndex    文件:TestSnapshotFromMaster.java   
/**
 * @return all the HFiles for a given table that have been archived
 * @throws IOException on expected failure
 */
private final Collection<String> getArchivedHFiles(Path archiveDir, Path rootDir,
    FileSystem fs, TableName tableName) throws IOException {
  Path tableArchive = FSUtils.getTableDir(archiveDir, tableName);
  Path[] archivedHFiles = SnapshotTestingUtils.listHFiles(fs, tableArchive);
  List<String> files = new ArrayList<String>(archivedHFiles.length);
  LOG.debug("Have archived hfiles: " + tableArchive);
  for (Path file : archivedHFiles) {
    LOG.debug(file);
    files.add(file.getName());
  }
  // sort the archived files

  Collections.sort(files);
  return files;
}
项目:HIndex    文件:TestFlushSnapshotFromClient.java   
@Test(timeout = 300000)
public void testAsyncFlushSnapshot() throws Exception {
  HBaseAdmin admin = UTIL.getHBaseAdmin();
  SnapshotDescription snapshot = SnapshotDescription.newBuilder().setName("asyncSnapshot")
      .setTable(TABLE_NAME.getNameAsString())
      .setType(SnapshotDescription.Type.FLUSH)
      .build();

  // take the snapshot async
  admin.takeSnapshotAsync(snapshot);

  // constantly loop, looking for the snapshot to complete
  HMaster master = UTIL.getMiniHBaseCluster().getMaster();
  SnapshotTestingUtils.waitForSnapshotToComplete(master, snapshot, 200);
  LOG.info(" === Async Snapshot Completed ===");
  FSUtils.logFileSystemState(UTIL.getTestFileSystem(),
    FSUtils.getRootDir(UTIL.getConfiguration()), LOG);
  // make sure we get the snapshot
  SnapshotTestingUtils.assertOneSnapshotThatMatches(admin, snapshot);
}
项目:IRIndex    文件:TestRestoreSnapshotFromClient.java   
@Test
public void testRestoreSnapshot() throws IOException {
  SnapshotTestingUtils.verifyRowCount(TEST_UTIL, tableName, snapshot1Rows);

  // Restore from snapshot-0
  admin.disableTable(tableName);
  admin.restoreSnapshot(snapshotName0);
  admin.enableTable(tableName);
  SnapshotTestingUtils.verifyRowCount(TEST_UTIL, tableName, snapshot0Rows);

  // Restore from emptySnapshot
  admin.disableTable(tableName);
  admin.restoreSnapshot(emptySnapshot);
  admin.enableTable(tableName);
  SnapshotTestingUtils.verifyRowCount(TEST_UTIL, tableName, 0);

  // Restore from snapshot-1
  admin.disableTable(tableName);
  admin.restoreSnapshot(snapshotName1);
  admin.enableTable(tableName);
  SnapshotTestingUtils.verifyRowCount(TEST_UTIL, tableName, snapshot1Rows);
}
项目:IRIndex    文件:TestSnapshotFromMaster.java   
/**
 * @return all the HFiles for a given table that have been archived
 * @throws IOException on expected failure
 */
private final Collection<String> getArchivedHFiles(Path archiveDir, Path rootDir,
    FileSystem fs, String tableName) throws IOException {
  Path tableArchive = new Path(archiveDir, tableName);
  Path[] archivedHFiles = SnapshotTestingUtils.listHFiles(fs, tableArchive);
  List<String> files = new ArrayList<String>(archivedHFiles.length);
  LOG.debug("Have archived hfiles: " + tableArchive);
  for (Path file : archivedHFiles) {
    LOG.debug(file);
    files.add(file.getName());
  }
  // sort the archived files

  Collections.sort(files);
  return files;
}
项目:hbase    文件:TestRestoreSnapshotFromClient.java   
@Test
public void testCloneSnapshotOfCloned() throws IOException, InterruptedException {
  TableName clonedTableName = TableName.valueOf(name.getMethodName() + "-" + System.currentTimeMillis());
  admin.cloneSnapshot(snapshotName0, clonedTableName);
  verifyRowCount(TEST_UTIL, clonedTableName, snapshot0Rows);
  SnapshotTestingUtils.verifyReplicasCameOnline(clonedTableName, admin, getNumReplicas());
  admin.disableTable(clonedTableName);
  admin.snapshot(snapshotName2, clonedTableName);
  TEST_UTIL.deleteTable(clonedTableName);
  waitCleanerRun();

  admin.cloneSnapshot(snapshotName2, clonedTableName);
  verifyRowCount(TEST_UTIL, clonedTableName, snapshot0Rows);
  SnapshotTestingUtils.verifyReplicasCameOnline(clonedTableName, admin, getNumReplicas());
  TEST_UTIL.deleteTable(clonedTableName);
}
项目:hbase    文件:TestRestoreSnapshotFromClient.java   
@Test
public void testCloneAndRestoreSnapshot() throws IOException, InterruptedException {
  TEST_UTIL.deleteTable(tableName);
  waitCleanerRun();

  admin.cloneSnapshot(snapshotName0, tableName);
  verifyRowCount(TEST_UTIL, tableName, snapshot0Rows);
  SnapshotTestingUtils.verifyReplicasCameOnline(tableName, admin, getNumReplicas());
  waitCleanerRun();

  admin.disableTable(tableName);
  admin.restoreSnapshot(snapshotName0);
  admin.enableTable(tableName);
  verifyRowCount(TEST_UTIL, tableName, snapshot0Rows);
  SnapshotTestingUtils.verifyReplicasCameOnline(tableName, admin, getNumReplicas());
}
项目:hbase    文件:TestMobCloneSnapshotFromClient.java   
@Test
@Override
public void testCloneLinksAfterDelete() throws IOException, InterruptedException {
  // delay the flush to make sure
  delayFlush = true;
  SnapshotTestingUtils.loadData(TEST_UTIL, tableName, 20, FAMILY);
  long tid = System.currentTimeMillis();
  byte[] snapshotName3 = Bytes.toBytes("snaptb3-" + tid);
  TableName clonedTableName3 = TableName.valueOf(name.getMethodName() + System.currentTimeMillis());
  admin.snapshot(snapshotName3, tableName);
  delayFlush = false;
  int snapshot3Rows = -1;
  try (Table table = TEST_UTIL.getConnection().getTable(tableName)) {
    snapshot3Rows = TEST_UTIL.countRows(table);
  }
  admin.cloneSnapshot(snapshotName3, clonedTableName3);
  admin.deleteSnapshot(snapshotName3);
  super.testCloneLinksAfterDelete();
  verifyRowCount(TEST_UTIL, clonedTableName3, snapshot3Rows);
  admin.disableTable(clonedTableName3);
  admin.deleteTable(clonedTableName3);
}
项目:hbase    文件:TestMobCloneSnapshotFromClient.java   
private void createMobTable(final HBaseTestingUtility util, final TableName tableName,
  final byte[][] splitKeys, int regionReplication, final byte[]... families) throws IOException,
  InterruptedException {
  HTableDescriptor htd = new HTableDescriptor(tableName);
  htd.setRegionReplication(regionReplication);
  htd.addCoprocessor(DelayFlushCoprocessor.class.getName());
  for (byte[] family : families) {
    HColumnDescriptor hcd = new HColumnDescriptor(family);
    hcd.setMobEnabled(true);
    hcd.setMobThreshold(0L);
    htd.addFamily(hcd);
  }
  util.getAdmin().createTable(htd, splitKeys);
  SnapshotTestingUtils.waitForTableToBeOnline(util, tableName);
  assertEquals((splitKeys.length + 1) * regionReplication,
    util.getAdmin().getTableRegions(tableName).size());
}
项目:hbase    文件:TestCloneSnapshotProcedure.java   
private SnapshotProtos.SnapshotDescription getSnapshot() throws Exception {
  if (snapshot == null) {
    final TableName snapshotTableName = TableName.valueOf("testCloneSnapshot");
    long tid = System.currentTimeMillis();
    final byte[] snapshotName = Bytes.toBytes("snapshot-" + tid);

    Admin admin = UTIL.getAdmin();
    // create Table
    SnapshotTestingUtils.createTable(UTIL, snapshotTableName, getNumReplicas(), CF);
    // Load data
    SnapshotTestingUtils.loadData(UTIL, snapshotTableName, 500, CF);
    admin.disableTable(snapshotTableName);
    // take a snapshot
    admin.snapshot(snapshotName, snapshotTableName);
    admin.enableTable(snapshotTableName);

    List<SnapshotDescription> snapshotList = admin.listSnapshots();
    snapshot = ProtobufUtil.createHBaseProtosSnapshotDesc(snapshotList.get(0));
  }
  return snapshot;
}
项目:hbase    文件:TestSnapshotHFileCleaner.java   
/**
 * If there is a corrupted region manifest, it should throw out CorruptedSnapshotException,
 * instead of an IOException
 */
@Test
public void testCorruptedRegionManifest() throws IOException {
  SnapshotTestingUtils.SnapshotMock
      snapshotMock = new SnapshotTestingUtils.SnapshotMock(TEST_UTIL.getConfiguration(), fs, rootDir);
  SnapshotTestingUtils.SnapshotMock.SnapshotBuilder builder = snapshotMock.createSnapshotV2(
      SNAPSHOT_NAME_STR, TABLE_NAME_STR);
  builder.addRegionV2();
  builder.corruptOneRegionManifest();

  long period = Long.MAX_VALUE;
  SnapshotFileCache cache = new SnapshotFileCache(fs, rootDir, period, 10000000,
      "test-snapshot-file-cache-refresh", new SnapshotFiles());
  try {
    cache.getSnapshotsInProgress(null);
  } catch (CorruptedSnapshotException cse) {
    LOG.info("Expected exception " + cse);
  } finally {
    fs.delete(SnapshotDescriptionUtils.getWorkingSnapshotDir(rootDir), true);
  }
}
项目:hbase    文件:TestSnapshotHFileCleaner.java   
/**
 * If there is a corrupted data manifest, it should throw out CorruptedSnapshotException,
 * instead of an IOException
 */
@Test
public void testCorruptedDataManifest() throws IOException {
  SnapshotTestingUtils.SnapshotMock
      snapshotMock = new SnapshotTestingUtils.SnapshotMock(TEST_UTIL.getConfiguration(), fs, rootDir);
  SnapshotTestingUtils.SnapshotMock.SnapshotBuilder builder = snapshotMock.createSnapshotV2(
      SNAPSHOT_NAME_STR, TABLE_NAME_STR);
  builder.addRegionV2();
  // consolidate to generate a data.manifest file
  builder.consolidate();
  builder.corruptDataManifest();

  long period = Long.MAX_VALUE;
  SnapshotFileCache cache = new SnapshotFileCache(fs, rootDir, period, 10000000,
      "test-snapshot-file-cache-refresh", new SnapshotFiles());
  try {
    cache.getSnapshotsInProgress(null);
  } catch (CorruptedSnapshotException cse) {
    LOG.info("Expected exception " + cse);
  } finally {
    fs.delete(SnapshotDescriptionUtils.getWorkingSnapshotDir(rootDir), true);
  }
}
项目:hbase    文件:TestSnapshotHFileCleaner.java   
/**
* HBASE-16464
*/
@Test
public void testMissedTmpSnapshot() throws IOException {
  SnapshotTestingUtils.SnapshotMock
      snapshotMock = new SnapshotTestingUtils.SnapshotMock(TEST_UTIL.getConfiguration(), fs, rootDir);
  SnapshotTestingUtils.SnapshotMock.SnapshotBuilder builder = snapshotMock.createSnapshotV2(
      SNAPSHOT_NAME_STR, TABLE_NAME_STR);
  builder.addRegionV2();
  builder.missOneRegionSnapshotFile();

    long period = Long.MAX_VALUE;
  SnapshotFileCache cache = new SnapshotFileCache(fs, rootDir, period, 10000000,
      "test-snapshot-file-cache-refresh", new SnapshotFiles());
  cache.getSnapshotsInProgress(null);
  assertFalse(fs.exists(builder.getSnapshotsDir()));
}
项目:hbase    文件:TestCompactSplitThread.java   
@Test(timeout = 60000)
public void testFlushWithTableCompactionDisabled() throws Exception {
  HTableDescriptor htd = new HTableDescriptor(tableName);
  htd.setCompactionEnabled(false);
  TEST_UTIL.createTable(htd, new byte[][] { family }, null);

  // load the table
  for (int i = 0; i < blockingStoreFiles + 1; i ++) {
    TEST_UTIL.loadTable(TEST_UTIL.getConnection().getTable(tableName), family);
    TEST_UTIL.flush(tableName);
  }

  // Make sure that store file number is greater than blockingStoreFiles + 1
  Path tableDir = FSUtils.getTableDir(rootDir, tableName);
  Collection<String> hfiles =  SnapshotTestingUtils.listHFileNames(fs, tableDir);
  assert(hfiles.size() > blockingStoreFiles + 1);
}
项目:PyroDB    文件:TestSnapshotFromMaster.java   
/**
 * @return all the HFiles for a given table that have been archived
 * @throws IOException on expected failure
 */
private final Collection<String> getArchivedHFiles(Path archiveDir, Path rootDir,
    FileSystem fs, TableName tableName) throws IOException {
  Path tableArchive = FSUtils.getTableDir(archiveDir, tableName);
  Path[] archivedHFiles = SnapshotTestingUtils.listHFiles(fs, tableArchive);
  List<String> files = new ArrayList<String>(archivedHFiles.length);
  LOG.debug("Have archived hfiles: " + tableArchive);
  for (Path file : archivedHFiles) {
    LOG.debug(file);
    files.add(file.getName());
  }
  // sort the archived files

  Collections.sort(files);
  return files;
}
项目:PyroDB    文件:TestFlushSnapshotFromClient.java   
/**
 * Basic end-to-end test of simple-flush-based snapshots
 */
@Test (timeout=300000)
public void testFlushCreateListDestroy() throws Exception {
  LOG.debug("------- Starting Snapshot test -------------");
  HBaseAdmin admin = UTIL.getHBaseAdmin();
  // make sure we don't fail on listing snapshots
  SnapshotTestingUtils.assertNoSnapshots(admin);
  // load the table so we have some data
  SnapshotTestingUtils.loadData(UTIL, TABLE_NAME, DEFAULT_NUM_ROWS, TEST_FAM);

  String snapshotName = "flushSnapshotCreateListDestroy";
  FileSystem fs = UTIL.getHBaseCluster().getMaster().getMasterFileSystem().getFileSystem();
  Path rootDir = UTIL.getHBaseCluster().getMaster().getMasterFileSystem().getRootDir();
  SnapshotTestingUtils.createSnapshotAndValidate(admin,
    TableName.valueOf(STRING_TABLE_NAME), Bytes.toString(TEST_FAM),
    snapshotName, rootDir, fs, true);
}
项目:ditb    文件:TestSnapshotMetadata.java   
/**
 * Verify that the describe for a cloned table matches the describe from the original.
 */
@Test (timeout=300000)
public void testDescribeMatchesAfterClone() throws Exception {
  // Clone the original table
  final String clonedTableNameAsString = "clone" + originalTableName;
  final TableName clonedTableName = TableName.valueOf(clonedTableNameAsString);
  final String snapshotNameAsString = "snapshot" + originalTableName
      + System.currentTimeMillis();
  final byte[] snapshotName = Bytes.toBytes(snapshotNameAsString);

  // restore the snapshot into a cloned table and examine the output
  List<byte[]> familiesList = new ArrayList<byte[]>();
  Collections.addAll(familiesList, families);

  // Create a snapshot in which all families are empty
  SnapshotTestingUtils.createSnapshotAndValidate(admin, originalTableName, null,
    familiesList, snapshotNameAsString, rootDir, fs, /* onlineSnapshot= */ false);

  admin.cloneSnapshot(snapshotName, clonedTableName);
  Table clonedTable = new HTable(UTIL.getConfiguration(), clonedTableName);
  HTableDescriptor cloneHtd = admin.getTableDescriptor(clonedTableName);
  assertEquals(
    originalTableDescription.replace(originalTableName.getNameAsString(),clonedTableNameAsString),
    cloneHtd.toStringCustomizedValues());

  // Verify the custom fields
  assertEquals(originalTableDescriptor.getValues().size(),
                      cloneHtd.getValues().size());
  assertEquals(originalTableDescriptor.getConfiguration().size(),
                      cloneHtd.getConfiguration().size());
  assertEquals(cloneHtd.getValue(TEST_CUSTOM_VALUE), TEST_CUSTOM_VALUE);
  assertEquals(cloneHtd.getConfigurationValue(TEST_CONF_CUSTOM_VALUE), TEST_CONF_CUSTOM_VALUE);
  assertEquals(originalTableDescriptor.getValues(), cloneHtd.getValues());
  assertEquals(originalTableDescriptor.getConfiguration(), cloneHtd.getConfiguration());

  admin.enableTable(originalTableName);
  clonedTable.close();
}
项目:ditb    文件:TestRestoreSnapshotFromClient.java   
/**
 * Initialize the tests with a table filled with some data
 * and two snapshots (snapshotName0, snapshotName1) of different states.
 * The tableName, snapshotNames and the number of rows in the snapshot are initialized.
 */
@Before
public void setup() throws Exception {
  this.admin = TEST_UTIL.getHBaseAdmin();

  long tid = System.currentTimeMillis();
  tableName =
      TableName.valueOf("testtb-" + tid);
  emptySnapshot = Bytes.toBytes("emptySnaptb-" + tid);
  snapshotName0 = Bytes.toBytes("snaptb0-" + tid);
  snapshotName1 = Bytes.toBytes("snaptb1-" + tid);
  snapshotName2 = Bytes.toBytes("snaptb2-" + tid);

  // create Table and disable it
  SnapshotTestingUtils.createTable(TEST_UTIL, tableName, getNumReplicas(), FAMILY);
  admin.disableTable(tableName);

  // take an empty snapshot
  admin.snapshot(emptySnapshot, tableName);

  // enable table and insert data
  admin.enableTable(tableName);
  SnapshotTestingUtils.loadData(TEST_UTIL, tableName, 500, FAMILY);
  try (Table table = TEST_UTIL.getConnection().getTable(tableName)) {
    snapshot0Rows = TEST_UTIL.countRows(table);
  }
  admin.disableTable(tableName);

  // take a snapshot
  admin.snapshot(snapshotName0, tableName);

  // enable table and insert more data
  admin.enableTable(tableName);
  SnapshotTestingUtils.loadData(TEST_UTIL, tableName, 500, FAMILY);
  try (Table table = TEST_UTIL.getConnection().getTable(tableName)) {
    snapshot1Rows = TEST_UTIL.countRows(table);
  }
}
项目:ditb    文件:TestRestoreSnapshotFromClient.java   
@Test
public void testRestoreSnapshot() throws IOException {
  SnapshotTestingUtils.verifyRowCount(TEST_UTIL, tableName, snapshot1Rows);
  admin.disableTable(tableName);
  admin.snapshot(snapshotName1, tableName);
  // Restore from snapshot-0
  admin.restoreSnapshot(snapshotName0);
  admin.enableTable(tableName);
  SnapshotTestingUtils.verifyRowCount(TEST_UTIL, tableName, snapshot0Rows);
  SnapshotTestingUtils.verifyReplicasCameOnline(tableName, admin, getNumReplicas());

  // Restore from emptySnapshot
  admin.disableTable(tableName);
  admin.restoreSnapshot(emptySnapshot);
  admin.enableTable(tableName);
  SnapshotTestingUtils.verifyRowCount(TEST_UTIL, tableName, 0);
  SnapshotTestingUtils.verifyReplicasCameOnline(tableName, admin, getNumReplicas());

  // Restore from snapshot-1
  admin.disableTable(tableName);
  admin.restoreSnapshot(snapshotName1);
  admin.enableTable(tableName);
  SnapshotTestingUtils.verifyRowCount(TEST_UTIL, tableName, snapshot1Rows);
  SnapshotTestingUtils.verifyReplicasCameOnline(tableName, admin, getNumReplicas());

  // Restore from snapshot-1
  TEST_UTIL.deleteTable(tableName);
  admin.restoreSnapshot(snapshotName1);
  SnapshotTestingUtils.verifyRowCount(TEST_UTIL, tableName, snapshot1Rows);
  SnapshotTestingUtils.verifyReplicasCameOnline(tableName, admin, getNumReplicas());
}
项目:ditb    文件:TestTableSnapshotScanner.java   
public static void createTableAndSnapshot(HBaseTestingUtility util, TableName tableName,
    String snapshotName, int numRegions)
    throws Exception {
  try {
    util.deleteTable(tableName);
  } catch(Exception ex) {
    // ignore
  }

  if (numRegions > 1) {
    util.createTable(tableName, FAMILIES, 1, bbb, yyy, numRegions);
  } else {
    util.createTable(tableName, FAMILIES);
  }
  Admin admin = util.getHBaseAdmin();

  // put some stuff in the table
  HTable table = new HTable(util.getConfiguration(), tableName);
  util.loadTable(table, FAMILIES);

  Path rootDir = FSUtils.getRootDir(util.getConfiguration());
  FileSystem fs = rootDir.getFileSystem(util.getConfiguration());

  SnapshotTestingUtils.createSnapshotAndValidate(admin, tableName,
      Arrays.asList(FAMILIES), null, snapshotName, rootDir, fs, true);

  // load different values
  byte[] value = Bytes.toBytes("after_snapshot_value");
  util.loadTable(table, FAMILIES, value);

  // cause flush to create new files in the region
  admin.flush(tableName);
  table.close();
}
项目:ditb    文件:TestCloneSnapshotFromClient.java   
@After
public void tearDown() throws Exception {
  if (admin.tableExists(tableName)) {
    TEST_UTIL.deleteTable(tableName);
  }
  SnapshotTestingUtils.deleteAllSnapshots(admin);
  SnapshotTestingUtils.deleteArchiveDirectory(TEST_UTIL);
}
项目:ditb    文件:TestCloneSnapshotFromClient.java   
private void testCloneSnapshot(final TableName tableName, final byte[] snapshotName,
    int snapshotRows) throws IOException, InterruptedException {
  // create a new table from snapshot
  admin.cloneSnapshot(snapshotName, tableName);
  SnapshotTestingUtils.verifyRowCount(TEST_UTIL, tableName, snapshotRows);

  verifyReplicasCameOnline(tableName);
  TEST_UTIL.deleteTable(tableName);
}
项目:ditb    文件:TestSnapshotFromClient.java   
/**
 * Test HBaseAdmin#deleteSnapshots(String) which deletes snapshots whose names match the parameter
 *
 * @throws Exception
 */
@Test (timeout=300000)
public void testSnapshotDeletionWithRegex() throws Exception {
  Admin admin = UTIL.getHBaseAdmin();
  // make sure we don't fail on listing snapshots
  SnapshotTestingUtils.assertNoSnapshots(admin);

  // put some stuff in the table
  HTable table = new HTable(UTIL.getConfiguration(), TABLE_NAME);
  UTIL.loadTable(table, TEST_FAM);
  table.close();

  byte[] snapshot1 = Bytes.toBytes("TableSnapshot1");
  admin.snapshot(snapshot1, TABLE_NAME);
  LOG.debug("Snapshot1 completed.");

  byte[] snapshot2 = Bytes.toBytes("TableSnapshot2");
  admin.snapshot(snapshot2, TABLE_NAME);
  LOG.debug("Snapshot2 completed.");

  String snapshot3 = "3rdTableSnapshot";
  admin.snapshot(Bytes.toBytes(snapshot3), TABLE_NAME);
  LOG.debug(snapshot3 + " completed.");

  // delete the first two snapshots
  admin.deleteSnapshots("TableSnapshot.*");
  List<SnapshotDescription> snapshots = admin.listSnapshots();
  assertEquals(1, snapshots.size());
  assertEquals(snapshots.get(0).getName(), snapshot3);

  admin.deleteSnapshot(snapshot3);
  admin.close();
}
项目:ditb    文件:TestMultiTableSnapshotInputFormat.java   
@BeforeClass
public static void setUpSnapshots() throws Exception {

  TEST_UTIL.enableDebug(MultiTableSnapshotInputFormat.class);
  TEST_UTIL.enableDebug(MultiTableSnapshotInputFormatImpl.class);

  // take a snapshot of every table we have.
  for (String tableName : TABLES) {
    SnapshotTestingUtils
        .createSnapshotAndValidate(TEST_UTIL.getHBaseAdmin(), TableName.valueOf(tableName),
            ImmutableList.of(MultiTableInputFormatTestBase.INPUT_FAMILY), null,
            snapshotNameForTable(tableName), FSUtils.getRootDir(TEST_UTIL.getConfiguration()),
            TEST_UTIL.getTestFileSystem(), true);
  }
}
项目:ditb    文件:TableSnapshotInputFormatTestBase.java   
protected static void createTableAndSnapshot(HBaseTestingUtility util, TableName tableName,
  String snapshotName, byte[] startRow, byte[] endRow, int numRegions)
  throws Exception {
  try {
    util.deleteTable(tableName);
  } catch(Exception ex) {
    // ignore
  }

  if (numRegions > 1) {
    util.createTable(tableName, FAMILIES, 1, startRow, endRow, numRegions);
  } else {
    util.createTable(tableName, FAMILIES);
  }
  Admin admin = util.getHBaseAdmin();

  // put some stuff in the table
  HTable table = new HTable(util.getConfiguration(), tableName);
  util.loadTable(table, FAMILIES);

  Path rootDir = FSUtils.getRootDir(util.getConfiguration());
  FileSystem fs = rootDir.getFileSystem(util.getConfiguration());

  SnapshotTestingUtils.createSnapshotAndValidate(admin, tableName,
    Arrays.asList(FAMILIES), null, snapshotName, rootDir, fs, true);

  // load different values
  byte[] value = Bytes.toBytes("after_snapshot_value");
  util.loadTable(table, FAMILIES, value);

  // cause flush to create new files in the region
  admin.flush(tableName);
  table.close();
}
项目:LCIndex-HBase-0.94.16    文件:TestRestoreSnapshotFromClient.java   
@Test
public void testCloneSnapshotOfCloned() throws IOException, InterruptedException {
  byte[] clonedTableName = Bytes.toBytes("clonedtb-" + System.currentTimeMillis());
  admin.cloneSnapshot(snapshotName0, clonedTableName);
  SnapshotTestingUtils.verifyRowCount(TEST_UTIL, clonedTableName, snapshot0Rows);
  admin.disableTable(clonedTableName);
  admin.snapshot(snapshotName2, clonedTableName);
  admin.deleteTable(clonedTableName);
  waitCleanerRun();

  admin.cloneSnapshot(snapshotName2, clonedTableName);
  SnapshotTestingUtils.verifyRowCount(TEST_UTIL, clonedTableName, snapshot0Rows);
  TEST_UTIL.deleteTable(clonedTableName);
}
项目:LCIndex-HBase-0.94.16    文件:TestRestoreSnapshotFromClient.java   
@Test
public void testCloneAndRestoreSnapshot() throws IOException, InterruptedException {
  TEST_UTIL.deleteTable(tableName);
  waitCleanerRun();

  admin.cloneSnapshot(snapshotName0, tableName);
  SnapshotTestingUtils.verifyRowCount(TEST_UTIL, tableName, snapshot0Rows);
  waitCleanerRun();

  admin.disableTable(tableName);
  admin.restoreSnapshot(snapshotName0);
  admin.enableTable(tableName);
  SnapshotTestingUtils.verifyRowCount(TEST_UTIL, tableName, snapshot0Rows);
}
项目:LCIndex-HBase-0.94.16    文件:TestCloneSnapshotFromClient.java   
@After
public void tearDown() throws Exception {
  if (admin.tableExists(tableName)) {
    TEST_UTIL.deleteTable(tableName);
  }
  SnapshotTestingUtils.deleteAllSnapshots(admin);
  SnapshotTestingUtils.deleteArchiveDirectory(TEST_UTIL);
}
项目:LCIndex-HBase-0.94.16    文件:TestCloneSnapshotFromClient.java   
private void testCloneSnapshot(final byte[] tableName, final byte[] snapshotName,
    int snapshotRows) throws IOException, InterruptedException {
  // create a new table from snapshot
  admin.cloneSnapshot(snapshotName, tableName);
  SnapshotTestingUtils.verifyRowCount(TEST_UTIL, tableName, snapshotRows);

  TEST_UTIL.deleteTable(tableName);
}
项目:pbase    文件:TestSnapshotMetadata.java   
/**
 * Verify that the describe for a cloned table matches the describe from the original.
 */
@Test (timeout=300000)
public void testDescribeMatchesAfterClone() throws Exception {
  // Clone the original table
  final String clonedTableNameAsString = "clone" + originalTableName;
  final TableName clonedTableName = TableName.valueOf(clonedTableNameAsString);
  final String snapshotNameAsString = "snapshot" + originalTableName
      + System.currentTimeMillis();
  final byte[] snapshotName = Bytes.toBytes(snapshotNameAsString);

  // restore the snapshot into a cloned table and examine the output
  List<byte[]> familiesList = new ArrayList<byte[]>();
  Collections.addAll(familiesList, families);

  // Create a snapshot in which all families are empty
  SnapshotTestingUtils.createSnapshotAndValidate(admin, originalTableName, null,
    familiesList, snapshotNameAsString, rootDir, fs, /* onlineSnapshot= */ false);

  admin.cloneSnapshot(snapshotName, clonedTableName);
  Table clonedTable = new HTable(UTIL.getConfiguration(), clonedTableName);
  HTableDescriptor cloneHtd = admin.getTableDescriptor(clonedTableName);
  assertEquals(
    originalTableDescription.replace(originalTableName.getNameAsString(),clonedTableNameAsString),
    cloneHtd.toStringCustomizedValues());

  // Verify the custom fields
  assertEquals(originalTableDescriptor.getValues().size(),
                      cloneHtd.getValues().size());
  assertEquals(originalTableDescriptor.getConfiguration().size(),
                      cloneHtd.getConfiguration().size());
  assertEquals(cloneHtd.getValue(TEST_CUSTOM_VALUE), TEST_CUSTOM_VALUE);
  assertEquals(cloneHtd.getConfigurationValue(TEST_CONF_CUSTOM_VALUE), TEST_CONF_CUSTOM_VALUE);
  assertEquals(originalTableDescriptor.getValues(), cloneHtd.getValues());
  assertEquals(originalTableDescriptor.getConfiguration(), cloneHtd.getConfiguration());

  admin.enableTable(originalTableName);
  clonedTable.close();
}
项目:pbase    文件:TestRestoreSnapshotFromClient.java   
/**
 * Initialize the tests with a table filled with some data
 * and two snapshots (snapshotName0, snapshotName1) of different states.
 * The tableName, snapshotNames and the number of rows in the snapshot are initialized.
 */
@Before
public void setup() throws Exception {
  this.admin = TEST_UTIL.getHBaseAdmin();

  long tid = System.currentTimeMillis();
  tableName =
      TableName.valueOf("testtb-" + tid);
  emptySnapshot = Bytes.toBytes("emptySnaptb-" + tid);
  snapshotName0 = Bytes.toBytes("snaptb0-" + tid);
  snapshotName1 = Bytes.toBytes("snaptb1-" + tid);
  snapshotName2 = Bytes.toBytes("snaptb2-" + tid);

  // create Table and disable it
  SnapshotTestingUtils.createTable(TEST_UTIL, tableName, getNumReplicas(), FAMILY);
  admin.disableTable(tableName);

  // take an empty snapshot
  admin.snapshot(emptySnapshot, tableName);

  // enable table and insert data
  admin.enableTable(tableName);
  SnapshotTestingUtils.loadData(TEST_UTIL, tableName, 500, FAMILY);
  try (Table table = TEST_UTIL.getConnection().getTable(tableName)) {
    snapshot0Rows = TEST_UTIL.countRows(table);
  }
  admin.disableTable(tableName);

  // take a snapshot
  admin.snapshot(snapshotName0, tableName);

  // enable table and insert more data
  admin.enableTable(tableName);
  SnapshotTestingUtils.loadData(TEST_UTIL, tableName, 500, FAMILY);
  try (Table table = TEST_UTIL.getConnection().getTable(tableName)) {
    snapshot1Rows = TEST_UTIL.countRows(table);
  }
}
项目:pbase    文件:TestRestoreSnapshotFromClient.java   
@Test
public void testRestoreSnapshot() throws IOException {
  SnapshotTestingUtils.verifyRowCount(TEST_UTIL, tableName, snapshot1Rows);
  admin.disableTable(tableName);
  admin.snapshot(snapshotName1, tableName);
  // Restore from snapshot-0
  admin.restoreSnapshot(snapshotName0);
  admin.enableTable(tableName);
  SnapshotTestingUtils.verifyRowCount(TEST_UTIL, tableName, snapshot0Rows);
  SnapshotTestingUtils.verifyReplicasCameOnline(tableName, admin, getNumReplicas());

  // Restore from emptySnapshot
  admin.disableTable(tableName);
  admin.restoreSnapshot(emptySnapshot);
  admin.enableTable(tableName);
  SnapshotTestingUtils.verifyRowCount(TEST_UTIL, tableName, 0);
  SnapshotTestingUtils.verifyReplicasCameOnline(tableName, admin, getNumReplicas());

  // Restore from snapshot-1
  admin.disableTable(tableName);
  admin.restoreSnapshot(snapshotName1);
  admin.enableTable(tableName);
  SnapshotTestingUtils.verifyRowCount(TEST_UTIL, tableName, snapshot1Rows);
  SnapshotTestingUtils.verifyReplicasCameOnline(tableName, admin, getNumReplicas());

  // Restore from snapshot-1
  TEST_UTIL.deleteTable(tableName);
  admin.restoreSnapshot(snapshotName1);
  SnapshotTestingUtils.verifyRowCount(TEST_UTIL, tableName, snapshot1Rows);
  SnapshotTestingUtils.verifyReplicasCameOnline(tableName, admin, getNumReplicas());
}
项目:pbase    文件:TestTableSnapshotScanner.java   
public static void createTableAndSnapshot(HBaseTestingUtility util, TableName tableName,
    String snapshotName, int numRegions)
    throws Exception {
  try {
    util.deleteTable(tableName);
  } catch(Exception ex) {
    // ignore
  }

  if (numRegions > 1) {
    util.createTable(tableName, FAMILIES, 1, bbb, yyy, numRegions);
  } else {
    util.createTable(tableName, FAMILIES);
  }
  Admin admin = util.getHBaseAdmin();

  // put some stuff in the table
  HTable table = new HTable(util.getConfiguration(), tableName);
  util.loadTable(table, FAMILIES);

  Path rootDir = FSUtils.getRootDir(util.getConfiguration());
  FileSystem fs = rootDir.getFileSystem(util.getConfiguration());

  SnapshotTestingUtils.createSnapshotAndValidate(admin, tableName,
      Arrays.asList(FAMILIES), null, snapshotName, rootDir, fs, true);

  // load different values
  byte[] value = Bytes.toBytes("after_snapshot_value");
  util.loadTable(table, FAMILIES, value);

  // cause flush to create new files in the region
  admin.flush(tableName);
  table.close();
}
项目:pbase    文件:TestCloneSnapshotFromClient.java   
@After
public void tearDown() throws Exception {
  if (admin.tableExists(tableName)) {
    TEST_UTIL.deleteTable(tableName);
  }
  SnapshotTestingUtils.deleteAllSnapshots(admin);
  SnapshotTestingUtils.deleteArchiveDirectory(TEST_UTIL);
}