use of org.apache.hadoop.hbase.client.TableDescriptorBuilder in project hbase by apache.
the class HBaseTestingUtility method createTable.
/**
* Create a table.
* @return A Table instance for the created table.
*/
public Table createTable(TableName tableName, byte[] family, byte[][] splitRows) throws IOException {
TableDescriptorBuilder builder = TableDescriptorBuilder.newBuilder(tableName);
ColumnFamilyDescriptorBuilder cfBuilder = ColumnFamilyDescriptorBuilder.newBuilder(family);
if (isNewVersionBehaviorEnabled()) {
cfBuilder.setNewVersionBehavior(true);
}
builder.setColumnFamily(cfBuilder.build());
getAdmin().createTable(builder.build(), splitRows);
// HBaseAdmin only waits for regions to appear in hbase:meta we should wait until they are
// assigned
waitUntilAllRegionsAssigned(tableName);
return getConnection().getTable(tableName);
}
use of org.apache.hadoop.hbase.client.TableDescriptorBuilder in project hbase by apache.
the class HBaseFsck method fabricateTableInfo.
/**
* To fabricate a .tableinfo file with following contents<br>
* 1. the correct tablename <br>
* 2. the correct colfamily list<br>
* 3. the default properties for both {@link TableDescriptor} and {@link ColumnFamilyDescriptor}<br>
* @throws IOException
*/
private boolean fabricateTableInfo(FSTableDescriptors fstd, TableName tableName, Set<String> columns) throws IOException {
if (columns == null || columns.isEmpty())
return false;
TableDescriptorBuilder builder = TableDescriptorBuilder.newBuilder(tableName);
for (String columnfamimly : columns) {
builder.setColumnFamily(ColumnFamilyDescriptorBuilder.of(columnfamimly));
}
fstd.createTableDescriptor(builder.build(), true);
return true;
}
use of org.apache.hadoop.hbase.client.TableDescriptorBuilder in project hbase by apache.
the class TestConstraint method testDisableConstraint.
/**
* Check that if we just disable one constraint, then
*/
@Test
public void testDisableConstraint() throws Exception {
// create the table
TableDescriptorBuilder builder = TableDescriptorBuilder.newBuilder(tableName);
// add a family to the table
for (byte[] family : new byte[][] { dummy, test }) {
builder.setColumnFamily(ColumnFamilyDescriptorBuilder.of(family));
}
// add a constraint to make sure it others get run
Constraints.add(builder, CheckWasRunConstraint.class);
// Add Constraint to check
Constraints.add(builder, AllFailConstraint.class);
// and then disable the failing constraint
Constraints.disableConstraint(builder, AllFailConstraint.class);
util.getAdmin().createTable(builder.build());
Table table = util.getConnection().getTable(tableName);
try {
// test that we don't fail because its disabled
Put put = new Put(row1);
byte[] qualifier = new byte[0];
put.addColumn(dummy, qualifier, Bytes.toBytes("pass"));
table.put(put);
} finally {
table.close();
}
assertTrue(CheckWasRunConstraint.wasRun);
}
use of org.apache.hadoop.hbase.client.TableDescriptorBuilder in project hbase by apache.
the class TestConstraint method testConstraintPasses.
/**
* Test that we run a passing constraint
*/
@Test
public void testConstraintPasses() throws Exception {
// create the table
// it would be nice if this was also a method on the util
TableDescriptorBuilder builder = TableDescriptorBuilder.newBuilder(tableName);
for (byte[] family : new byte[][] { dummy, test }) {
builder.setColumnFamily(ColumnFamilyDescriptorBuilder.of(family));
}
// add a constraint
Constraints.add(builder, CheckWasRunConstraint.class);
util.getAdmin().createTable(builder.build());
Table table = util.getConnection().getTable(tableName);
try {
// test that we don't fail on a valid put
Put put = new Put(row1);
byte[] value = Bytes.toBytes(Integer.toString(10));
byte[] qualifier = new byte[0];
put.addColumn(dummy, qualifier, value);
table.put(put);
} finally {
table.close();
}
assertTrue(CheckWasRunConstraint.wasRun);
}
use of org.apache.hadoop.hbase.client.TableDescriptorBuilder in project hbase by apache.
the class TestConstraints method testRemoveUnsetConstraint.
/**
* Test that if a constraint hasn't been set that there are no problems with attempting to remove
* it.
*/
@Test
public void testRemoveUnsetConstraint() throws Exception {
TableDescriptorBuilder builder = TableDescriptorBuilder.newBuilder(name.getTableName());
Constraints.remove(builder);
Constraints.remove(builder, AlsoWorks.class);
}
Aggregations