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

The following examples show how to use org.apache.hadoop.hbase.HBaseTestingUtility#createTable() . 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: TestMobFileCleanerChore.java    From hbase with Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() throws Exception {
  HTU = new HBaseTestingUtility();
  tableDescriptor = HTU.createModifyableTableDescriptor("testMobCompactTable");
  conf = HTU.getConfiguration();

  initConf();

  HTU.startMiniCluster();
  admin = HTU.getAdmin();
  chore = new MobFileCleanerChore();
  familyDescriptor = new ColumnFamilyDescriptorBuilder.ModifyableColumnFamilyDescriptor(fam);
  familyDescriptor.setMobEnabled(true);
  familyDescriptor.setMobThreshold(mobLen);
  familyDescriptor.setMaxVersions(1);
  tableDescriptor.setColumnFamily(familyDescriptor);
  table = HTU.createTable(tableDescriptor, null);
}
 
Example 2
Source File: HBaseTestUtil.java    From incubator-retired-htrace with Apache License 2.0 5 votes vote down vote up
public static Table createTable(HBaseTestingUtility util) {
  Table htable = null;
  try {
    htable = util.createTable(Bytes.toBytes(HBaseSpanReceiver.DEFAULT_TABLE),
                              new byte[][]{Bytes.toBytes(HBaseSpanReceiver.DEFAULT_COLUMNFAMILY),
                                           Bytes.toBytes(HBaseSpanReceiver.DEFAULT_INDEXFAMILY)});
  } catch (IOException e) {
    Assert.fail("failed to create htrace table. " + e.getMessage());
  }
  return htable;
}
 
Example 3
Source File: HRavenTestUtil.java    From hraven with Apache License 2.0 5 votes vote down vote up
public static Table createDailyAggTable(HBaseTestingUtility util)
    throws IOException {
  return util.createTable(
      TableName.valueOf(AggregationConstants.AGG_DAILY_TABLE),
      new byte[][] { AggregationConstants.INFO_FAM_BYTES,
          AggregationConstants.SCRATCH_FAM_BYTES });
}
 
Example 4
Source File: TestMultiLogThreshold.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Before
public void setupTest() throws Exception {
  final TableName tableName = TableName.valueOf("tableName");
  TEST_UTIL = new HBaseTestingUtility();
  CONF = TEST_UTIL.getConfiguration();
  THRESHOLD = CONF.getInt(RSRpcServices.BATCH_ROWS_THRESHOLD_NAME,
    RSRpcServices.BATCH_ROWS_THRESHOLD_DEFAULT);
  CONF.setBoolean("hbase.rpc.rows.size.threshold.reject", rejectLargeBatchOp);
  TEST_UTIL.startMiniCluster();
  TEST_UTIL.createTable(tableName, TEST_FAM);
  RS = TEST_UTIL.getRSForFirstRegionInTable(tableName);
}
 
Example 5
Source File: SnapshotTestingUtils.java    From hbase with Apache License 2.0 5 votes vote down vote up
public static void createTable(final HBaseTestingUtility util, final TableName tableName,
    int regionReplication, int nRegions, final byte[]... families)
    throws IOException, InterruptedException {
  TableDescriptorBuilder builder
    = TableDescriptorBuilder
        .newBuilder(tableName)
        .setRegionReplication(regionReplication);
  for (byte[] family : families) {
    builder.setColumnFamily(ColumnFamilyDescriptorBuilder.of(family));
  }
  byte[][] splitKeys = getSplitKeys(nRegions);
  util.createTable(builder.build(), splitKeys);
  assertEquals((splitKeys.length + 1) * regionReplication,
      util.getAdmin().getRegions(tableName).size());
}
 
Example 6
Source File: TestAssignmentOnRSCrash.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Before
public void setup() throws Exception {
  UTIL = new HBaseTestingUtility();

  setupConf(UTIL.getConfiguration());
  UTIL.startMiniCluster(NUM_RS);

  UTIL.createTable(TEST_TABLE, new byte[][] { FAMILY }, new byte[][] {
    Bytes.toBytes("B"), Bytes.toBytes("D"), Bytes.toBytes("F"), Bytes.toBytes("L")
  });
}
 
Example 7
Source File: TestTableSnapshotScanner.java    From hbase with Apache License 2.0 5 votes vote down vote up
public static void createTableAndSnapshot(HBaseTestingUtility util, TableName tableName,
    String snapshotName, int numRegions)
    throws Exception {
  try {
    util.deleteTable(tableName);
  } catch(Exception ex) {
    // ignore
  }

  if (numRegions > 1) {
    util.createTable(tableName, FAMILIES, 1, bbb, yyy, numRegions);
  } else {
    util.createTable(tableName, FAMILIES);
  }
  Admin admin = util.getAdmin();

  // put some stuff in the table
  Table table = util.getConnection().getTable(tableName);
  util.loadTable(table, FAMILIES);

  Path rootDir = CommonFSUtils.getRootDir(util.getConfiguration());
  FileSystem fs = rootDir.getFileSystem(util.getConfiguration());

  SnapshotTestingUtils.createSnapshotAndValidate(admin, tableName,
      Arrays.asList(FAMILIES), null, snapshotName, rootDir, fs, true);

  // load different values
  byte[] value = Bytes.toBytes("after_snapshot_value");
  util.loadTable(table, FAMILIES, value);

  // cause flush to create new files in the region
  admin.flush(tableName);
  table.close();
}
 
Example 8
Source File: TestHDFSAclHelper.java    From hbase with Apache License 2.0 5 votes vote down vote up
static TableDescriptor createUserScanSnapshotDisabledTable(HBaseTestingUtility util,
    TableName tableName) throws IOException {
  createNamespace(util, tableName.getNamespaceAsString());
  TableDescriptor td = getTableDescriptorBuilder(util, tableName).build();
  byte[][] splits = new byte[][] { Bytes.toBytes("2"), Bytes.toBytes("4") };
  try (Table t = util.createTable(td, splits)) {
    put(t);
  }
  return td;
}
 
Example 9
Source File: TestHDFSAclHelper.java    From hbase with Apache License 2.0 5 votes vote down vote up
static Table createMobTable(HBaseTestingUtility util, TableName tableName) throws IOException {
  createNamespace(util, tableName.getNamespaceAsString());
  TableDescriptor td = TableDescriptorBuilder.newBuilder(tableName)
      .setColumnFamily(ColumnFamilyDescriptorBuilder.newBuilder(COLUMN1).setMobEnabled(true)
          .setMobThreshold(0).build())
      .setColumnFamily(ColumnFamilyDescriptorBuilder.newBuilder(COLUMN2).setMobEnabled(true)
          .setMobThreshold(0).build())
      .setOwner(User.createUserForTesting(util.getConfiguration(), "owner", new String[] {}))
      .setValue(SnapshotScannerHDFSAclHelper.ACL_SYNC_TO_HDFS_ENABLE, "true").build();
  byte[][] splits = new byte[][] { Bytes.toBytes("2"), Bytes.toBytes("4") };
  return util.createTable(td, splits);
}
 
Example 10
Source File: HBaseClientTest.java    From metron with Apache License 2.0 5 votes vote down vote up
@BeforeAll
public static void startHBase() throws Exception {
  Configuration config = HBaseConfiguration.create();
  config.set("hbase.master.hostname", "localhost");
  config.set("hbase.regionserver.hostname", "localhost");
  util = new HBaseTestingUtility(config);
  util.startMiniCluster();
  admin = util.getHBaseAdmin();
  // create the table
  table = util.createTable(Bytes.toBytes(tableName), cf);
  util.waitTableEnabled(table.getName());
  // setup the client
  client = new HBaseClient((c,t) -> table, table.getConfiguration(), tableName);
}
 
Example 11
Source File: TestWithHBaseCoprocessor.java    From eagle with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void setUpHBase() throws IOException {
    System.setProperty("config.resource", "/application-co.conf");
    Configuration conf = HBaseConfiguration.create();
    conf.setStrings(CoprocessorHost.REGION_COPROCESSOR_CONF_KEY, AggregateProtocolEndPoint.class.getName());
    conf.set("zookeeper.znode.parent", getZkZnodeParent());
    conf.setInt("hbase.master.info.port", -1);//avoid port clobbering
    conf.setInt("hbase.regionserver.info.port", -1);//avoid port clobbering

    int attempts = 0;
    hbase = new HBaseTestingUtility(conf);
    boolean successToStart = false;
    while (attempts < 3) {
        try {
            attempts ++;
            hbase.startMiniCluster();
            successToStart = true;
        } catch (Exception e) {
            LOG.error("Error to start mini cluster (tried {} times): {}", attempts, e.getMessage(), e);
            try {
                hbase.shutdownMiniCluster();
            } catch (Exception e1) {
                LOG.warn(e.getMessage(), e);
            }
        }
    }

    Assert.assertTrue("Failed to start mini cluster in " + attempts + " attempts", successToStart);

    HTable table = hbase.createTable(String.valueOf("unittest"),"f");
    HTableDescriptor descriptor = new HTableDescriptor(table.getTableDescriptor());
    descriptor.addCoprocessor(AggregateProtocolEndPoint.class.getName());
    hbase.getHBaseAdmin().modifyTable("unittest",descriptor);

    System.setProperty("storage.hbase.autoCreateTable","false");
    System.setProperty("storage.hbase.coprocessorEnabled", String.valueOf(true));
    System.setProperty("storage.hbase.zookeeperZnodeParent", getZkZnodeParent());
    System.setProperty("storage.hbase.zookeeperPropertyClientPort", String.valueOf(hbase.getZkCluster().getClientPort()));
}
 
Example 12
Source File: TestHBaseSpanReceiver.java    From incubator-retired-htrace with Apache License 2.0 5 votes vote down vote up
private Table createTable(HBaseTestingUtility util) {
  Table htable = null;
  try {
    htable = util.createTable(Bytes.toBytes(HBaseSpanReceiver.DEFAULT_TABLE),
        new byte[][]{Bytes.toBytes(HBaseSpanReceiver.DEFAULT_COLUMNFAMILY),
            Bytes.toBytes(HBaseSpanReceiver.DEFAULT_INDEXFAMILY)});
  } catch (IOException e) {
    Assert.fail("failed to create htrace table. " + e.getMessage());
  }
  return htable;
}
 
Example 13
Source File: HRavenTestUtil.java    From hraven with Apache License 2.0 5 votes vote down vote up
public static Table createWeeklyAggTable(HBaseTestingUtility util)
    throws IOException {
  return util.createTable(
      TableName.valueOf(AggregationConstants.AGG_WEEKLY_TABLE),
      new byte[][] { AggregationConstants.INFO_FAM_BYTES,
          AggregationConstants.SCRATCH_FAM_BYTES });
}
 
Example 14
Source File: HRavenTestUtil.java    From hraven with Apache License 2.0 4 votes vote down vote up
private static Table createHdfsStatsTables(HBaseTestingUtility util)
    throws IOException {
  return util.createTable(TableName.valueOf(HdfsConstants.HDFS_USAGE_TABLE),
      new byte[][] { HdfsConstants.DISK_INFO_FAM_BYTES,
          HdfsConstants.ACCESS_INFO_FAM_BYTES });
}
 
Example 15
Source File: HRavenTestUtil.java    From hraven with Apache License 2.0 4 votes vote down vote up
public static Table createFlowQueueTable(HBaseTestingUtility util)
    throws IOException {
  return util.createTable(TableName.valueOf(Constants.FLOW_QUEUE_TABLE),
      Constants.INFO_FAM_BYTES);
}
 
Example 16
Source File: HRavenTestUtil.java    From hraven with Apache License 2.0 4 votes vote down vote up
public static Table createFlowEventTable(HBaseTestingUtility util)
    throws IOException {
  return util.createTable(TableName.valueOf(Constants.FLOW_EVENT_TABLE),
      Constants.INFO_FAM_BYTES);
}
 
Example 17
Source File: HRavenTestUtil.java    From hraven with Apache License 2.0 4 votes vote down vote up
public static Table createAppVersionTable(HBaseTestingUtility util)
    throws IOException {
  return util.createTable(
      TableName.valueOf(Constants.HISTORY_APP_VERSION_TABLE),
      Constants.INFO_FAM_BYTES);
}
 
Example 18
Source File: HRavenTestUtil.java    From hraven with Apache License 2.0 4 votes vote down vote up
public static Table createProcessTable(HBaseTestingUtility util)
    throws IOException {
  return util.createTable(TableName.valueOf(Constants.JOB_FILE_PROCESS_TABLE),
      Constants.INFO_FAM_BYTES);
}
 
Example 19
Source File: HRavenTestUtil.java    From hraven with Apache License 2.0 4 votes vote down vote up
public static Table createTaskTable(HBaseTestingUtility util)
    throws IOException {
  return util.createTable(TableName.valueOf(Constants.HISTORY_TASK_TABLE),
      Constants.INFO_FAM_BYTES);
}
 
Example 20
Source File: HRavenTestUtil.java    From hraven with Apache License 2.0 4 votes vote down vote up
public static Table createHistoryByJobIdTable(HBaseTestingUtility util)
    throws IOException {
  return util.createTable(TableName.valueOf(Constants.HISTORY_BY_JOBID_TABLE),
      Constants.INFO_FAM_BYTES);
}