Search in sources :

Example 56 with TableDescriptorBuilder

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));
}
Also used : TableDescriptorBuilder(org.apache.hadoop.hbase.client.TableDescriptorBuilder) Test(org.junit.Test)

Example 57 with TableDescriptorBuilder

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));
        }
    }
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) NameConstraint(org.apache.hadoop.hbase.constraint.WorksConstraint.NameConstraint) CheckWasRunConstraint(org.apache.hadoop.hbase.constraint.TestConstraint.CheckWasRunConstraint) TableDescriptorBuilder(org.apache.hadoop.hbase.client.TableDescriptorBuilder) Test(org.junit.Test)

Example 58 with TableDescriptorBuilder

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());
}
Also used : TableDescriptorBuilder(org.apache.hadoop.hbase.client.TableDescriptorBuilder) Test(org.junit.Test)

Example 59 with TableDescriptorBuilder

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();
}
Also used : TableDescriptorBuilder(org.apache.hadoop.hbase.client.TableDescriptorBuilder)

Example 60 with TableDescriptorBuilder

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);
}
Also used : TableName(org.apache.hadoop.hbase.TableName) DoNotRetryIOException(org.apache.hadoop.hbase.DoNotRetryIOException) TableDescriptorBuilder(org.apache.hadoop.hbase.client.TableDescriptorBuilder) RegionInfo(org.apache.hadoop.hbase.client.RegionInfo) TableDescriptor(org.apache.hadoop.hbase.client.TableDescriptor) StoreFileTrackerForTest(org.apache.hadoop.hbase.regionserver.storefiletracker.StoreFileTrackerForTest) Test(org.junit.Test)

Aggregations

TableDescriptorBuilder (org.apache.hadoop.hbase.client.TableDescriptorBuilder)190 ColumnFamilyDescriptor (org.apache.hadoop.hbase.client.ColumnFamilyDescriptor)76 Test (org.junit.Test)68 TableDescriptor (org.apache.hadoop.hbase.client.TableDescriptor)61 ColumnFamilyDescriptorBuilder (org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder)47 RegionInfo (org.apache.hadoop.hbase.client.RegionInfo)39 TableName (org.apache.hadoop.hbase.TableName)34 Path (org.apache.hadoop.fs.Path)31 Admin (org.apache.hadoop.hbase.client.Admin)29 Put (org.apache.hadoop.hbase.client.Put)25 IOException (java.io.IOException)24 Configuration (org.apache.hadoop.conf.Configuration)20 Table (org.apache.hadoop.hbase.client.Table)18 ArrayList (java.util.ArrayList)17 FileSystem (org.apache.hadoop.fs.FileSystem)15 HRegion (org.apache.hadoop.hbase.regionserver.HRegion)15 Before (org.junit.Before)12 Cell (org.apache.hadoop.hbase.Cell)11 NamespaceDescriptor (org.apache.hadoop.hbase.NamespaceDescriptor)10 HashMap (java.util.HashMap)9