use of org.apache.hadoop.hbase.TableExistsException in project hbase by apache.
the class TestAsyncTableAdminApi method testCloneTableSchemaWithExistentDestinationTable.
@Test
public void testCloneTableSchemaWithExistentDestinationTable() throws Exception {
final TableName newTableName = TableName.valueOf(tableName.getNameAsString() + "_new");
byte[] FAMILY_0 = Bytes.toBytes("cf0");
TEST_UTIL.createTable(tableName, FAMILY_0);
TEST_UTIL.createTable(newTableName, FAMILY_0);
// test for existent destination table
try {
admin.cloneTableSchema(tableName, newTableName, false).join();
fail("Should have failed when destination table exists.");
} catch (CompletionException e) {
assertTrue(e.getCause() instanceof TableExistsException);
}
}
use of org.apache.hadoop.hbase.TableExistsException in project hbase by apache.
the class TestCloneSnapshotProcedure method testCloneSnapshotToSameTable.
@Test
public void testCloneSnapshotToSameTable() throws Exception {
// take the snapshot
SnapshotProtos.SnapshotDescription snapshotDesc = getSnapshot();
final ProcedureExecutor<MasterProcedureEnv> procExec = getMasterProcedureExecutor();
final TableName clonedTableName = TableName.valueOf(snapshotDesc.getTable());
final TableDescriptor htd = createTableDescriptor(clonedTableName, CF);
long procId = ProcedureTestingUtility.submitAndWait(procExec, new CloneSnapshotProcedure(procExec.getEnvironment(), htd, snapshotDesc));
Procedure<?> result = procExec.getResult(procId);
assertTrue(result.isFailed());
LOG.debug("Clone snapshot failed with exception: " + result.getException());
assertTrue(ProcedureTestingUtility.getExceptionCause(result) instanceof TableExistsException);
}
use of org.apache.hadoop.hbase.TableExistsException in project hbase by apache.
the class TestHRegionServerBulkLoad method setupTable.
/**
* Creates a table with given table name and specified number of column
* families if the table does not already exist.
*/
public void setupTable(TableName table, int cfs) throws IOException {
try {
LOG.info("Creating table " + table);
TableDescriptorBuilder tableDescriptorBuilder = TableDescriptorBuilder.newBuilder(table);
tableDescriptorBuilder.setCoprocessor(MyObserver.class.getName());
MyObserver.sleepDuration = this.sleepDuration;
for (int i = 0; i < 10; i++) {
ColumnFamilyDescriptor columnFamilyDescriptor = ColumnFamilyDescriptorBuilder.newBuilder(Bytes.toBytes(family(i))).build();
tableDescriptorBuilder.setColumnFamily(columnFamilyDescriptor);
}
UTIL.getAdmin().createTable(tableDescriptorBuilder.build());
} catch (TableExistsException tee) {
LOG.info("Table " + table + " already exists");
}
}
use of org.apache.hadoop.hbase.TableExistsException in project hbase by apache.
the class TestAdmin method testCloneTableSchemaWithExistentDestinationTable.
@Test
public void testCloneTableSchemaWithExistentDestinationTable() throws Exception {
final TableName tableName = TableName.valueOf(name.getMethodName());
final TableName newTableName = TableName.valueOf(tableName.getNameAsString() + "_new");
byte[] FAMILY_0 = Bytes.toBytes("cf0");
TEST_UTIL.createTable(tableName, FAMILY_0);
TEST_UTIL.createTable(newTableName, FAMILY_0);
// test for existent destination table
try {
ADMIN.cloneTableSchema(tableName, newTableName, false);
fail("Should have failed to create a existent table.");
} catch (TableExistsException ex) {
// expected
}
}
use of org.apache.hadoop.hbase.TableExistsException in project hbase by apache.
the class TestClusterRestart method test.
@Test
public void test() throws Exception {
UTIL.startMiniCluster(3);
UTIL.waitFor(60000, () -> UTIL.getMiniHBaseCluster().getMaster().isInitialized());
LOG.info("\n\nCreating tables");
for (TableName TABLE : TABLES) {
UTIL.createTable(TABLE, FAMILY);
}
for (TableName TABLE : TABLES) {
UTIL.waitTableEnabled(TABLE);
}
List<RegionInfo> allRegions = MetaTableAccessor.getAllRegions(UTIL.getConnection(), false);
assertEquals(NUM_REGIONS, allRegions.size());
LOG.info("\n\nShutting down cluster");
UTIL.shutdownMiniHBaseCluster();
LOG.info("\n\nSleeping a bit");
Thread.sleep(2000);
LOG.info("\n\nStarting cluster the second time");
UTIL.restartHBaseCluster(3);
// Need to use a new 'Configuration' so we make a new Connection.
// Otherwise we're reusing an Connection that has gone stale because
// the shutdown of the cluster also called shut of the connection.
allRegions = MetaTableAccessor.getAllRegions(UTIL.getConnection(), false);
assertEquals(NUM_REGIONS, allRegions.size());
LOG.info("\n\nWaiting for tables to be available");
for (TableName TABLE : TABLES) {
try {
UTIL.createTable(TABLE, FAMILY);
assertTrue("Able to create table that should already exist", false);
} catch (TableExistsException tee) {
LOG.info("Table already exists as expected");
}
UTIL.waitTableAvailable(TABLE);
}
}
Aggregations