Java Code Examples for org.apache.hadoop.hbase.HBaseTestingUtility#waitUntilAllRegionsAssigned()

The following examples show how to use org.apache.hadoop.hbase.HBaseTestingUtility#waitUntilAllRegionsAssigned() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HbaseTestUtil.java    From kafka-connect-hbase with Apache License 2.0 6 votes vote down vote up
/**
 * Creates the table with the column families
 *
 * @param tableName
 * @param columnFamilies
 * @return
 */
public static void createTable(String tableName, String... columnFamilies) {
    HBaseTestingUtility testingUtility = getUtility();
    if (!status.get()) {
        throw new RuntimeException("The mini cluster hasn't started yet. " +
          " Call HBaseTestUtil#startMiniCluster() before creating a table");
    }
    final TableName name = TableName.valueOf(tableName);
    try (HBaseAdmin hBaseAdmin = testingUtility.getHBaseAdmin()) {
        final HTableDescriptor hTableDescriptor = new HTableDescriptor(name);
        for (String family : columnFamilies) {
            final HColumnDescriptor hColumnDescriptor = new HColumnDescriptor(Bytes.toBytes(family));
            hTableDescriptor.addFamily(hColumnDescriptor);
        }

        hBaseAdmin.createTable(hTableDescriptor);
        testingUtility.waitUntilAllRegionsAssigned(name);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
 
Example 2
Source File: SecureTestUtil.java    From hbase with Apache License 2.0 6 votes vote down vote up
public static void createTable(HBaseTestingUtility testUtil, Admin admin, TableDescriptor htd,
    byte[][] splitKeys) throws Exception {
  // NOTE: We need a latch because admin is not sync,
  // so the postOp coprocessor method may be called after the admin operation returned.
  MasterSyncObserver observer = testUtil.getHBaseCluster().getMaster()
    .getMasterCoprocessorHost().findCoprocessor(MasterSyncObserver.class);
  observer.tableCreationLatch = new CountDownLatch(1);
  if (splitKeys != null) {
    admin.createTable(htd, splitKeys);
  } else {
    admin.createTable(htd);
  }
  observer.tableCreationLatch.await();
  observer.tableCreationLatch = null;
  testUtil.waitUntilAllRegionsAssigned(htd.getTableName());
}
 
Example 3
Source File: TestEnableTable.java    From hbase with Apache License 2.0 6 votes vote down vote up
public static void createTable(HBaseTestingUtility testUtil,
    TableDescriptorBuilder.ModifyableTableDescriptor tableDescriptor, byte [][] splitKeys)
    throws Exception {
  // NOTE: We need a latch because admin is not sync,
  // so the postOp coprocessor method may be called after the admin operation returned.
  MasterSyncObserver observer = testUtil.getHBaseCluster().getMaster()
    .getMasterCoprocessorHost().findCoprocessor(MasterSyncObserver.class);
  observer.tableCreationLatch = new CountDownLatch(1);
  Admin admin = testUtil.getAdmin();
  if (splitKeys != null) {
    admin.createTable(tableDescriptor, splitKeys);
  } else {
    admin.createTable(tableDescriptor);
  }
  observer.tableCreationLatch.await();
  observer.tableCreationLatch = null;
  testUtil.waitUntilAllRegionsAssigned(tableDescriptor.getTableName());
}
 
Example 4
Source File: MobSnapshotTestingUtils.java    From hbase with Apache License 2.0 6 votes vote down vote up
/**
 * Create a Mob table.
 *
 * @param util
 * @param tableName
 * @param families
 * @return An Table instance for the created table.
 * @throws IOException
 */
public static Table createMobTable(final HBaseTestingUtility util,
    final TableName tableName, final byte[]... families) throws IOException {
  TableDescriptorBuilder builder = TableDescriptorBuilder.newBuilder(tableName);
  for (byte[] family : families) {
    // Disable blooms (they are on by default as of 0.95) but we disable them
    // here because
    // tests have hard coded counts of what to expect in block cache, etc.,
    // and blooms being
    // on is interfering.
    builder.setColumnFamily(ColumnFamilyDescriptorBuilder.newBuilder(family)
            .setBloomFilterType(BloomType.NONE)
            .setMobEnabled(true)
            .setMobThreshold(0L)
            .build());
  }
  util.getAdmin().createTable(builder.build());
  // HBaseAdmin only waits for regions to appear in hbase:meta we should wait
  // until they are assigned
  util.waitUntilAllRegionsAssigned(tableName);
  return ConnectionFactory.createConnection(util.getConfiguration()).getTable(tableName);
}
 
Example 5
Source File: TestRegionSnapshotTask.java    From hbase with Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void setupBeforeClass() throws Exception {
  TEST_UTIL = new HBaseTestingUtility();

  conf = TEST_UTIL.getConfiguration();

  // Try to frequently clean up compacted files
  conf.setInt("hbase.hfile.compaction.discharger.interval", 1000);
  conf.setInt("hbase.master.hfilecleaner.ttl", 1000);

  TEST_UTIL.startMiniCluster(1);
  TEST_UTIL.getHBaseCluster().waitForActiveAndReadyMaster();
  TEST_UTIL.waitUntilAllRegionsAssigned(TableName.META_TABLE_NAME);

  rootDir = CommonFSUtils.getRootDir(conf);
  fs = TEST_UTIL.getTestFileSystem();
}
 
Example 6
Source File: BaseTestHBaseFsck.java    From hbase with Apache License 2.0 6 votes vote down vote up
public static void createTable(HBaseTestingUtility testUtil, TableDescriptor tableDescriptor,
    byte[][] splitKeys) throws Exception {
  // NOTE: We need a latch because admin is not sync,
  // so the postOp coprocessor method may be called after the admin operation returned.
  MasterSyncCoprocessor coproc = testUtil.getHBaseCluster().getMaster()
      .getMasterCoprocessorHost().findCoprocessor(MasterSyncCoprocessor.class);
  coproc.tableCreationLatch = new CountDownLatch(1);
  if (splitKeys != null) {
    admin.createTable(tableDescriptor, splitKeys);
  } else {
    admin.createTable(tableDescriptor);
  }
  coproc.tableCreationLatch.await();
  coproc.tableCreationLatch = null;
  testUtil.waitUntilAllRegionsAssigned(tableDescriptor.getTableName());
}