use of org.apache.hadoop.hbase.client.TableDescriptorBuilder in project hbase by apache.
the class TestNamespaceAuditor method testDeleteTable.
@Test
public void testDeleteTable() throws Exception {
String namespace = prefix + "_dummy";
NamespaceDescriptor nspDesc = NamespaceDescriptor.create(namespace).addConfiguration(TableNamespaceManager.KEY_MAX_REGIONS, "100").addConfiguration(TableNamespaceManager.KEY_MAX_TABLES, "3").build();
ADMIN.createNamespace(nspDesc);
assertNotNull("Namespace descriptor found null.", ADMIN.getNamespaceDescriptor(namespace));
NamespaceTableAndRegionInfo stateInfo = getNamespaceState(nspDesc.getName());
assertNotNull("Namespace state found null for " + namespace, stateInfo);
ColumnFamilyDescriptor columnFamilyDescriptor = ColumnFamilyDescriptorBuilder.newBuilder(Bytes.toBytes("fam1")).build();
TableDescriptorBuilder tableDescOne = TableDescriptorBuilder.newBuilder(TableName.valueOf(namespace + TableName.NAMESPACE_DELIM + "table1"));
tableDescOne.setColumnFamily(columnFamilyDescriptor);
TableDescriptorBuilder tableDescTwo = TableDescriptorBuilder.newBuilder(TableName.valueOf(namespace + TableName.NAMESPACE_DELIM + "table2"));
tableDescTwo.setColumnFamily(columnFamilyDescriptor);
ADMIN.createTable(tableDescOne.build());
ADMIN.createTable(tableDescTwo.build(), Bytes.toBytes("AAA"), Bytes.toBytes("ZZZ"), 5);
stateInfo = getNamespaceState(nspDesc.getName());
assertNotNull("Namespace state found to be null.", stateInfo);
assertEquals(2, stateInfo.getTables().size());
assertEquals(5, stateInfo.getRegionCountOfTable(tableDescTwo.build().getTableName()));
assertEquals(6, stateInfo.getRegionCount());
ADMIN.disableTable(tableDescOne.build().getTableName());
deleteTable(tableDescOne.build().getTableName());
stateInfo = getNamespaceState(nspDesc.getName());
assertNotNull("Namespace state found to be null.", stateInfo);
assertEquals(5, stateInfo.getRegionCount());
assertEquals(1, stateInfo.getTables().size());
ADMIN.disableTable(tableDescTwo.build().getTableName());
deleteTable(tableDescTwo.build().getTableName());
ADMIN.deleteNamespace(namespace);
stateInfo = getNamespaceState(namespace);
assertNull("Namespace state not found to be null.", stateInfo);
}
use of org.apache.hadoop.hbase.client.TableDescriptorBuilder in project hbase by apache.
the class TestNamespaceAuditor method testRestoreSnapshot.
@Test
public void testRestoreSnapshot() throws Exception {
String nsp = prefix + "_testRestoreSnapshot";
NamespaceDescriptor nspDesc = NamespaceDescriptor.create(nsp).addConfiguration(TableNamespaceManager.KEY_MAX_REGIONS, "10").build();
ADMIN.createNamespace(nspDesc);
assertNotNull("Namespace descriptor found null.", ADMIN.getNamespaceDescriptor(nsp));
TableName tableName1 = TableName.valueOf(nsp + TableName.NAMESPACE_DELIM + "table1");
ColumnFamilyDescriptor columnFamilyDescriptor = ColumnFamilyDescriptorBuilder.newBuilder(Bytes.toBytes("fam1")).build();
TableDescriptorBuilder tableDescOne = TableDescriptorBuilder.newBuilder(tableName1);
tableDescOne.setColumnFamily(columnFamilyDescriptor);
ADMIN.createTable(tableDescOne.build(), Bytes.toBytes("AAA"), Bytes.toBytes("ZZZ"), 4);
NamespaceTableAndRegionInfo nstate = getNamespaceState(nsp);
assertEquals("Intial region count should be 4.", 4, nstate.getRegionCount());
String snapshot = "snapshot_testRestoreSnapshot";
ADMIN.snapshot(snapshot, tableName1);
List<RegionInfo> regions = ADMIN.getRegions(tableName1);
Collections.sort(regions, RegionInfo.COMPARATOR);
ADMIN.split(tableName1, Bytes.toBytes("JJJ"));
Thread.sleep(2000);
assertEquals("Total regions count should be 5.", 5, nstate.getRegionCount());
ADMIN.disableTable(tableName1);
ADMIN.restoreSnapshot(snapshot);
assertEquals("Total regions count should be 4 after restore.", 4, nstate.getRegionCount());
ADMIN.enableTable(tableName1);
ADMIN.deleteSnapshot(snapshot);
}
use of org.apache.hadoop.hbase.client.TableDescriptorBuilder in project hbase by apache.
the class TestNamespaceAuditor method testTableOperations.
@Test
public void testTableOperations() throws Exception {
String nsp = prefix + "_np2";
NamespaceDescriptor nspDesc = NamespaceDescriptor.create(nsp).addConfiguration(TableNamespaceManager.KEY_MAX_REGIONS, "5").addConfiguration(TableNamespaceManager.KEY_MAX_TABLES, "2").build();
ADMIN.createNamespace(nspDesc);
assertNotNull("Namespace descriptor found null.", ADMIN.getNamespaceDescriptor(nsp));
assertEquals(3, ADMIN.listNamespaceDescriptors().length);
ColumnFamilyDescriptor columnFamilyDescriptor = ColumnFamilyDescriptorBuilder.newBuilder(Bytes.toBytes("fam1")).build();
TableDescriptorBuilder tableDescOne = TableDescriptorBuilder.newBuilder(TableName.valueOf(nsp + TableName.NAMESPACE_DELIM + "table1"));
tableDescOne.setColumnFamily(columnFamilyDescriptor);
TableDescriptorBuilder tableDescTwo = TableDescriptorBuilder.newBuilder(TableName.valueOf(nsp + TableName.NAMESPACE_DELIM + "table2"));
tableDescTwo.setColumnFamily(columnFamilyDescriptor);
TableDescriptorBuilder tableDescThree = TableDescriptorBuilder.newBuilder(TableName.valueOf(nsp + TableName.NAMESPACE_DELIM + "table3"));
tableDescThree.setColumnFamily(columnFamilyDescriptor);
ADMIN.createTable(tableDescOne.build());
boolean constraintViolated = false;
try {
ADMIN.createTable(tableDescTwo.build(), Bytes.toBytes("AAA"), Bytes.toBytes("ZZZ"), 5);
} catch (Exception exp) {
assertTrue(exp instanceof IOException);
constraintViolated = true;
} finally {
assertTrue("Constraint not violated for table " + tableDescTwo.build().getTableName(), constraintViolated);
}
ADMIN.createTable(tableDescTwo.build(), Bytes.toBytes("AAA"), Bytes.toBytes("ZZZ"), 4);
NamespaceTableAndRegionInfo nspState = getQuotaManager().getState(nsp);
assertNotNull(nspState);
assertTrue(nspState.getTables().size() == 2);
assertTrue(nspState.getRegionCount() == 5);
constraintViolated = false;
try {
ADMIN.createTable(tableDescThree.build());
} catch (Exception exp) {
assertTrue(exp instanceof IOException);
constraintViolated = true;
} finally {
assertTrue("Constraint not violated for table " + tableDescThree.build().getTableName(), constraintViolated);
}
}
use of org.apache.hadoop.hbase.client.TableDescriptorBuilder in project hbase by apache.
the class TestNamespaceAuditor method testExceedTableQuotaInNamespace.
@Test(expected = QuotaExceededException.class)
public void testExceedTableQuotaInNamespace() throws Exception {
String nsp = prefix + "_testExceedTableQuotaInNamespace";
NamespaceDescriptor nspDesc = NamespaceDescriptor.create(nsp).addConfiguration(TableNamespaceManager.KEY_MAX_TABLES, "1").build();
ADMIN.createNamespace(nspDesc);
assertNotNull("Namespace descriptor found null.", ADMIN.getNamespaceDescriptor(nsp));
assertEquals(3, ADMIN.listNamespaceDescriptors().length);
ColumnFamilyDescriptor columnFamilyDescriptor = ColumnFamilyDescriptorBuilder.newBuilder(Bytes.toBytes("fam1")).build();
TableDescriptorBuilder tableDescOne = TableDescriptorBuilder.newBuilder(TableName.valueOf(nsp + TableName.NAMESPACE_DELIM + "table1"));
tableDescOne.setColumnFamily(columnFamilyDescriptor);
TableDescriptorBuilder tableDescTwo = TableDescriptorBuilder.newBuilder(TableName.valueOf(nsp + TableName.NAMESPACE_DELIM + "table2"));
tableDescTwo.setColumnFamily(columnFamilyDescriptor);
ADMIN.createTable(tableDescOne.build());
ADMIN.createTable(tableDescTwo.build(), Bytes.toBytes("AAA"), Bytes.toBytes("ZZZ"), 4);
}
use of org.apache.hadoop.hbase.client.TableDescriptorBuilder in project hbase by apache.
the class TestWalAndCompactingMemStoreFlush method initHRegion.
private HRegion initHRegion(String callingMethod, Configuration conf) throws IOException {
int i = 0;
TableDescriptorBuilder builder = TableDescriptorBuilder.newBuilder(TABLENAME);
for (byte[] family : FAMILIES) {
ColumnFamilyDescriptorBuilder cfBuilder = ColumnFamilyDescriptorBuilder.newBuilder(family);
// even column families are going to have compacted memstore
if (i % 2 == 0) {
cfBuilder.setInMemoryCompaction(MemoryCompactionPolicy.valueOf(conf.get(CompactingMemStore.COMPACTING_MEMSTORE_TYPE_KEY)));
} else {
cfBuilder.setInMemoryCompaction(MemoryCompactionPolicy.NONE);
}
builder.setColumnFamily(cfBuilder.build());
i++;
}
RegionInfo info = RegionInfoBuilder.newBuilder(TABLENAME).build();
Path path = new Path(DIR, callingMethod);
HRegion region = HBaseTestingUtil.createRegionAndWAL(info, path, conf, builder.build(), false);
region.regionServicesForStores = Mockito.spy(region.regionServicesForStores);
ThreadPoolExecutor pool = (ThreadPoolExecutor) Executors.newFixedThreadPool(1);
Mockito.when(region.regionServicesForStores.getInMemoryCompactionPool()).thenReturn(pool);
region.initialize(null);
return region;
}
Aggregations