use of org.apache.hadoop.hbase.client.TableDescriptorBuilder in project hbase by apache.
the class TestConstraints method testEnableDisableRemove.
/**
* Test that Constraints are properly enabled, disabled, and removed
*/
@Test
public void testEnableDisableRemove() throws Exception {
TableDescriptorBuilder builder = TableDescriptorBuilder.newBuilder(name.getTableName());
// check general enabling/disabling of constraints
// first add a constraint
Constraints.add(builder, AllPassConstraint.class);
// make sure everything is enabled
assertTrue(Constraints.enabled(builder.build(), AllPassConstraint.class));
assertTrue(builder.hasCoprocessor(ConstraintProcessor.class.getName()));
// check disabling
Constraints.disable(builder);
assertFalse(builder.hasCoprocessor(ConstraintProcessor.class.getName()));
// make sure the added constraints are still present
assertTrue(Constraints.enabled(builder.build(), AllPassConstraint.class));
// check just removing the single constraint
Constraints.remove(builder, AllPassConstraint.class);
assertFalse(Constraints.has(builder.build(), AllPassConstraint.class));
// Add back the single constraint
Constraints.add(builder, AllPassConstraint.class);
// and now check that when we remove constraints, all are gone
Constraints.remove(builder);
assertFalse(builder.hasCoprocessor(ConstraintProcessor.class.getName()));
assertFalse(Constraints.has(builder.build(), AllPassConstraint.class));
}
use of org.apache.hadoop.hbase.client.TableDescriptorBuilder in project hbase by apache.
the class TestConstraints method testConfigurationPreserved.
@Test
public void testConfigurationPreserved() throws Exception {
Configuration conf = new Configuration();
conf.setBoolean("_ENABLED", false);
conf.setLong("_PRIORITY", 10);
TableDescriptorBuilder builder = TableDescriptorBuilder.newBuilder(name.getTableName());
Constraints.add(builder, AlsoWorks.class, conf);
Constraints.add(builder, WorksConstraint.class);
assertFalse(Constraints.enabled(builder.build(), AlsoWorks.class));
List<? extends Constraint> constraints = Constraints.getConstraints(builder.build(), this.getClass().getClassLoader());
for (Constraint c : constraints) {
Configuration storedConf = c.getConf();
if (c instanceof AlsoWorks) {
assertEquals(10, storedConf.getLong("_PRIORITY", -1));
} else // its just a worksconstraint
{
assertEquals(2, storedConf.getLong("_PRIORITY", -1));
}
}
}
use of org.apache.hadoop.hbase.client.TableDescriptorBuilder in project hbase by apache.
the class TestConstraints method testSimpleReadWrite.
@Test
public void testSimpleReadWrite() throws Exception {
TableDescriptorBuilder builder = TableDescriptorBuilder.newBuilder(name.getTableName());
Constraints.add(builder, WorksConstraint.class);
List<? extends Constraint> constraints = Constraints.getConstraints(builder.build(), this.getClass().getClassLoader());
assertEquals(1, constraints.size());
assertEquals(WorksConstraint.class, constraints.get(0).getClass());
// Check that we can add more than 1 constraint and that ordering is
// preserved
Constraints.add(builder, AlsoWorks.class, NameConstraint.class);
constraints = Constraints.getConstraints(builder.build(), this.getClass().getClassLoader());
assertEquals(3, constraints.size());
assertEquals(WorksConstraint.class, constraints.get(0).getClass());
assertEquals(AlsoWorks.class, constraints.get(1).getClass());
assertEquals(NameConstraint.class, constraints.get(2).getClass());
}
use of org.apache.hadoop.hbase.client.TableDescriptorBuilder in project hbase by apache.
the class TestCloneSnapshotProcedure method createTableDescriptor.
public static TableDescriptor createTableDescriptor(TableName tableName, byte[]... family) {
TableDescriptorBuilder builder = TableDescriptorBuilder.newBuilder(tableName);
Stream.of(family).map(ColumnFamilyDescriptorBuilder::of).forEachOrdered(builder::setColumnFamily);
return builder.build();
}
use of org.apache.hadoop.hbase.client.TableDescriptorBuilder in project hbase by apache.
the class TestCreateTableProcedure method testCreateWithoutColumnFamily.
@Test
public void testCreateWithoutColumnFamily() throws Exception {
final ProcedureExecutor<MasterProcedureEnv> procExec = getMasterProcedureExecutor();
final TableName tableName = TableName.valueOf(name.getMethodName());
// create table with 0 families will fail
final TableDescriptorBuilder builder = TableDescriptorBuilder.newBuilder(MasterProcedureTestingUtility.createHTD(tableName));
// disable sanity check
builder.setValue(TableDescriptorChecker.TABLE_SANITY_CHECKS, Boolean.FALSE.toString());
TableDescriptor htd = builder.build();
final RegionInfo[] regions = ModifyRegionUtils.createRegionInfos(htd, null);
long procId = ProcedureTestingUtility.submitAndWait(procExec, new CreateTableProcedure(procExec.getEnvironment(), htd, regions));
final Procedure<?> result = procExec.getResult(procId);
assertEquals(true, result.isFailed());
Throwable cause = ProcedureTestingUtility.getExceptionCause(result);
assertTrue("expected DoNotRetryIOException, got " + cause, cause instanceof DoNotRetryIOException);
}
Aggregations