org.apache.hadoop.hbase.HBaseTestingUtility.getHBaseAdmin()方法的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(12.5k)|赞(0)|评价(0)|浏览(113)

本文整理了Java中org.apache.hadoop.hbase.HBaseTestingUtility.getHBaseAdmin()方法的一些代码示例,展示了HBaseTestingUtility.getHBaseAdmin()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HBaseTestingUtility.getHBaseAdmin()方法的具体详情如下:
包路径:org.apache.hadoop.hbase.HBaseTestingUtility
类名称:HBaseTestingUtility
方法名:getHBaseAdmin

HBaseTestingUtility.getHBaseAdmin介绍

[英]Returns a Admin instance. This instance is shared between HBaseTestingUtility instance users. Closing it has no effect, it will be closed automatically when the cluster shutdowns
[中]返回一个管理实例。此实例在HBaseteStangulity实例用户之间共享。关闭它无效,当群集关闭时,它将自动关闭

代码示例

代码示例来源:origin: apache/hbase

private HBaseAdmin createTable(TableName tableName) throws IOException {
 HBaseAdmin admin = TEST_UTIL.getHBaseAdmin();
 HTableDescriptor htd = new HTableDescriptor(tableName);
 HColumnDescriptor hcd = new HColumnDescriptor("value");
 htd.addFamily(hcd);
 admin.createTable(htd, null);
 return admin;
}

代码示例来源:origin: apache/hbase

/**
 * Verify that a single table is restored using overwrite.
 *
 * @throws Exception if doing the backup or an operation on the tables fails
 */
@Test
public void testFullRestoreSingleOverwriteCommand() throws Exception {
 LOG.info("test full restore on a single table empty table: command-line");
 List<TableName> tables = Lists.newArrayList(table1);
 String backupId = fullTableBackup(tables);
 assertTrue(checkSucceeded(backupId));
 LOG.info("backup complete");
 TableName[] tableset = new TableName[] { table1 };
 // restore <backup_root_path> <backup_id> <tables> [tableMapping]
 String[] args =
   new String[] { BACKUP_ROOT_DIR, backupId, "-t", StringUtils.join(tableset, ","), "-o" };
 // Run restore
 int ret = ToolRunner.run(conf1, new RestoreDriver(), args);
 assertTrue(ret == 0);
 HBaseAdmin hba = TEST_UTIL.getHBaseAdmin();
 assertTrue(hba.tableExists(table1));
 hba.close();
}

代码示例来源:origin: apache/hbase

@Test(timeout = 180000) public void testEnsureTemporaryDirectoryTransfer() throws Exception {
 Admin admin = null;
 TableName tableName2 = TableName.valueOf("testListTableSnapshots");
 try {
  admin = UTIL.getHBaseAdmin();
  HTableDescriptor htd = new HTableDescriptor(tableName2);
  UTIL.createTable(htd, new byte[][] { TEST_FAM }, UTIL.getConfiguration());
  assertEquals(3, listTableSnapshots.size());
  for (SnapshotDescription s : listTableSnapshots) {
   listTableSnapshotNames.add(s.getName());
  assertTrue(listTableSnapshotNames.contains(table1Snapshot1));
  assertTrue(listTableSnapshotNames.contains(table1Snapshot2));
  assertTrue(listTableSnapshotNames.contains(table2Snapshot1));
 } finally {
  if (admin != null) {

代码示例来源:origin: apache/hbase

@Test
public void testFullBackupRemote() throws Exception {
 LOG.info("test remote full backup on a single table");
 t.start();
 table1Desc.addFamily(new HColumnDescriptor(fam3Name));
 String backupId =
   backupTables(BackupType.FULL, Lists.newArrayList(table1), BACKUP_REMOTE_ROOT_DIR);
 assertTrue(checkSucceeded(backupId));
 Assert.assertEquals(TEST_UTIL.countRows(t1, famName), NB_ROWS_IN_BATCH);
 Assert.assertEquals(TEST_UTIL.countRows(t1, fam3Name), NB_ROWS_IN_FAM3);
 t1.close();
 HBaseAdmin hAdmin = TEST_UTIL.getHBaseAdmin();
 assertTrue(hAdmin.tableExists(table1_restore));
 Assert.assertEquals(TEST_UTIL.countRows(hTable, famName), NB_ROWS_IN_BATCH);
 int cnt3 = TEST_UTIL.countRows(hTable, fam3Name);
 Assert.assertTrue(cnt3 >= 0 && cnt3 <= NB_ROWS_IN_FAM3);

代码示例来源:origin: forcedotcom/phoenix

@Test
public void testReplayEditsWrittenViaHRegion() throws Exception {
 final String tableNameStr = "testReplayEditsWrittenViaHRegion";
 CoveredColumnIndexer.createIndexTable(UTIL.getHBaseAdmin(), INDEX_TABLE_NAME);
 assertEquals("Index wasn't propertly updated from WAL replay!", 1, indexSize);
 Get g = new Get(rowkey);
 final Result result = region1.get(g);
 assertEquals("Primary region wasn't updated from WAL replay!", 1, result.size());
 HBaseAdmin admin = UTIL.getHBaseAdmin();
 admin.disableTable(INDEX_TABLE_NAME);
 admin.deleteTable(INDEX_TABLE_NAME);

代码示例来源:origin: apache/hbase

/**
 * Test that a coprocessor is able to override a normal regionserver stop request.
 */
@Test
public void testStopOverrideFromCoprocessor() throws Exception {
 Admin admin = testUtil.getHBaseAdmin();
 HRegionServer regionserver = cluster.getRegionServer(0);
 admin.stopRegionServer(regionserver.getServerName().getHostAndPort());
 // regionserver should have failed to stop due to coprocessor
 assertFalse(cluster.getRegionServer(0).isAborted());
 assertFalse(cluster.getRegionServer(0).isStopped());
}

代码示例来源:origin: apache/hbase

private void testCrashRsWithUserRegion(final boolean kill, final boolean withData)
  throws Exception {
 final int NROWS = 100;
 int nkilled = 0;
 for (RegionInfo hri: UTIL.getHBaseAdmin().getTableRegions(TEST_TABLE)) {
  ServerName serverName = AssignmentTestingUtil.getServerHoldingRegion(UTIL, hri);
  if (AssignmentTestingUtil.isServerHoldingMeta(UTIL, serverName)) continue;
  if (withData) {
   testInsert(hri, NROWS);
  }
  // wait for regions to enter in transition and then to get out of transition
  AssignmentTestingUtil.crashRs(UTIL, serverName, kill);
  AssignmentTestingUtil.waitForRegionToBeInTransition(UTIL, hri);
  UTIL.waitUntilNoRegionsInTransition();
  if (withData) {
   assertEquals(NROWS, testGet(hri, NROWS));
  }
  // region should be moved to another RS
  assertNotEquals(serverName, AssignmentTestingUtil.getServerHoldingRegion(UTIL, hri));
  if (++nkilled == (NUM_RS - 1)) {
   break;
  }
 }
 assertTrue("expected RSs to be killed", nkilled > 0);
}

代码示例来源:origin: apache/phoenix

@Test
public void testUpdateNonIndexedColumn() throws Exception {
  String tableName = "TBL_" + generateUniqueName();
    getUtility().getHBaseAdmin().flush(TableName.valueOf(fullTableName));
    conn.createStatement().executeUpdate("UPSERT INTO " + fullTableName + "(k,v1,v2) VALUES ('testKey','v1_4','v2_3')");
    conn.commit();

代码示例来源:origin: apache/eagle

Assert.assertTrue("Failed to start mini cluster in " + attempts + " attempts", successToStart);
HTableDescriptor descriptor = new HTableDescriptor(table.getTableDescriptor());
descriptor.addCoprocessor(AggregateProtocolEndPoint.class.getName());
hbase.getHBaseAdmin().modifyTable("unittest",descriptor);

代码示例来源:origin: apache/phoenix

/**
 * Alter the table metadata and return modified value
 * @param driver
 * @param tableName
 * @return value of VERSIONS option for the table
 * @throws Exception
 */
private int verifyModificationTableMetadata(PhoenixSysCatCreationTestingDriver driver, String tableName) throws Exception {
  // Modify table metadata
  Connection conn = driver.getConnectionQueryServices(getJdbcUrl(), new Properties()).connect(getJdbcUrl(), new Properties());
  conn.createStatement().execute("ALTER TABLE " + tableName + " SET VERSIONS = " + MODIFIED_MAX_VERSIONS);
  // Connect via a client that creates a new ConnectionQueryServices instance
  driver.resetCQS();
  driver.getConnectionQueryServices(getJdbcUrl(), new Properties()).connect(getJdbcUrl(), new Properties());
  HTableDescriptor descriptor = testUtil.getHBaseAdmin().getTableDescriptor(TableName.valueOf(tableName));
  return descriptor.getFamily(QueryConstants.DEFAULT_COLUMN_FAMILY_BYTES).getMaxVersions();
}

代码示例来源:origin: Impetus/Kundera

/**
 * Adds the column family.
 * 
 * @param tableName
 *            the table name
 * @param columnFamily
 *            the column family
 */
public void addColumnFamily(String tableName, String columnFamily)
{
  try
  {
    utility.getHBaseAdmin().disableTable(tableName);
    utility.getHBaseAdmin().addColumn(tableName, new HColumnDescriptor(columnFamily));
    utility.getHBaseAdmin().enableTable(tableName);
    while (utility.getHBaseAdmin().isTableEnabled(tableName))
    {
      return;
    }
  }
  catch (InvalidFamilyOperationException ife)
  {
    logger.info("Column family:" + columnFamily + " already exist!", ife);
  }
  catch (IOException e)
  {
    logger.error("", e);
  }
}

代码示例来源:origin: apache/hbase

@Test
public void testFullRestoreSetToOtherTable() throws Exception {
  assertTrue(names.size() == 1);
  assertTrue(names.get(0).equals(table1));
  assertTrue(ret == 0);
  List<BackupInfo> backups = table.getBackupHistory();
  assertTrue(backups.size() == 1);
  assertTrue(ret == 0);
  HBaseAdmin hba = TEST_UTIL.getHBaseAdmin();
  assertTrue(hba.tableExists(table1_restore));
  assertEquals(TEST_UTIL.countRows(table1), TEST_UTIL.countRows(table1_restore));
  TEST_UTIL.deleteTable(table1_restore);
  LOG.info("restore into other table is complete");

代码示例来源:origin: apache/hbase

@Test
public void testDisableCatalogTable() throws Exception {
 try {
  this.admin.disableTable(TableName.META_TABLE_NAME);
  fail("Expected to throw ConstraintException");
 } catch (ConstraintException e) {
 }
 // Before the fix for HBASE-6146, the below table creation was failing as the hbase:meta table
 // actually getting disabled by the disableTable() call.
 HTableDescriptor htd =
   new HTableDescriptor(TableName.valueOf(Bytes.toBytes(name.getMethodName())));
 HColumnDescriptor hcd = new HColumnDescriptor(Bytes.toBytes("cf1"));
 htd.addFamily(hcd);
 TEST_UTIL.getHBaseAdmin().createTable(htd);
}

代码示例来源:origin: apache/hbase

/**
 * Verify that multiple tables are restored to new tables using overwrite.
 *
 * @throws Exception if doing the backup or an operation on the tables fails
 */
@Test
public void testFullRestoreMultipleOverwriteCommand() throws Exception {
 LOG.info("create full backup image on multiple tables: command-line");
 List<TableName> tables = Lists.newArrayList(table2, table3);
 String backupId = fullTableBackup(tables);
 assertTrue(checkSucceeded(backupId));
 TableName[] restore_tableset = new TableName[] { table2, table3 };
 // restore <backup_root_path> <backup_id> <tables> [tableMapping]
 String[] args =
   new String[] { BACKUP_ROOT_DIR, backupId, "-t",
   StringUtils.join(restore_tableset, ","), "-o" };
 // Run backup
 int ret = ToolRunner.run(conf1, new RestoreDriver(), args);
 assertTrue(ret == 0);
 HBaseAdmin hba = TEST_UTIL.getHBaseAdmin();
 assertTrue(hba.tableExists(table2));
 assertTrue(hba.tableExists(table3));
 hba.close();
}

代码示例来源:origin: apache/hbase

@Test
public void TestIncBackupRestore() throws Exception {
 int ADD_ROWS = 99;
 final byte[] mobName = Bytes.toBytes("mob");
  BackupRequest request = createBackupRequest(BackupType.FULL, tables, BACKUP_ROOT_DIR);
  String backupIdFull = client.backupTables(request);
  assertTrue(checkSucceeded(backupIdFull));
  Assert.assertEquals(HBaseTestingUtility.countRows(t1),
      NB_ROWS_IN_BATCH + ADD_ROWS + NB_ROWS_FAM3);
  LOG.debug("written " + ADD_ROWS + " rows to " + table1);
   t2.put(p2);
  Assert.assertEquals(NB_ROWS_IN_BATCH + 5, HBaseTestingUtility.countRows(t2));
  t2.close();
  LOG.debug("written " + 5 + " rows to " + table2);
  table1Desc.addFamily(new HColumnDescriptor(fam2Name));
  assertTrue(checkSucceeded(backupIdIncMultiple2));
  HBaseAdmin hAdmin = TEST_UTIL.getHBaseAdmin();

代码示例来源:origin: urbanairship/datacube

@Test
public void testTableSplits() throws Exception {
  HBaseAdmin admin = getTestUtil().getHBaseAdmin();
  byte[] tableName = "oneSplitTest".getBytes();
  Assert.assertEquals(1, scans.size());
  Assert.assertEquals("Regions didn't split as requested, wtf", 3, startsEnds.getFirst().length);
  internalSplitKeys = BackfillUtil.getSplitKeys(startsEnds);
  scans = HBaseBackfillMerger.scansThisCubeOnly(new byte[] {}, internalSplitKeys);
  Assert.assertEquals(3, scans.size());

代码示例来源:origin: apache/hbase

@Test(timeout = 300000) public void testOfflineTableSnapshot() throws Exception {
 Admin admin = UTIL.getHBaseAdmin();

代码示例来源:origin: org.apache.hbase/hbase-server

private void testCrashRsWithUserRegion(final boolean kill, final boolean withData)
  throws Exception {
 final int NROWS = 100;
 int nkilled = 0;
 for (RegionInfo hri: UTIL.getHBaseAdmin().getTableRegions(TEST_TABLE)) {
  ServerName serverName = AssignmentTestingUtil.getServerHoldingRegion(UTIL, hri);
  if (AssignmentTestingUtil.isServerHoldingMeta(UTIL, serverName)) continue;
  if (withData) {
   testInsert(hri, NROWS);
  }
  // wait for regions to enter in transition and then to get out of transition
  AssignmentTestingUtil.crashRs(UTIL, serverName, kill);
  AssignmentTestingUtil.waitForRegionToBeInTransition(UTIL, hri);
  UTIL.waitUntilNoRegionsInTransition();
  if (withData) {
   assertEquals(NROWS, testGet(hri, NROWS));
  }
  // region should be moved to another RS
  assertNotEquals(serverName, AssignmentTestingUtil.getServerHoldingRegion(UTIL, hri));
  if (++nkilled == (NUM_RS - 1)) {
   break;
  }
 }
 assertTrue("expected RSs to be killed", nkilled > 0);
}

代码示例来源:origin: apache/hbase

@Test
public void testFullRestoreSetToSameTable() throws Exception {
  assertTrue(names.size() == 1);
  assertTrue(names.get(0).equals(table1));
  assertTrue(ret == 0);
  List<BackupInfo> backups = table.getBackupHistory();
  String backupId = backups.get(0).getBackupId();
  assertTrue(ret == 0);
  HBaseAdmin hba = TEST_UTIL.getHBaseAdmin();
  assertTrue(hba.tableExists(table1));
  assertEquals(count, TEST_UTIL.countRows(table1));
  LOG.info("restore into same table is complete");
  hba.close();

代码示例来源:origin: apache/hbase

private Table createTable() throws IOException {
 TableName tableName = TableName.valueOf(name.getMethodName());
 HTableDescriptor table = new HTableDescriptor(tableName);
 HColumnDescriptor fam = new HColumnDescriptor(FAMILY);
 fam.setNewVersionBehavior(true);
 fam.setMaxVersions(3);
 table.addFamily(fam);
 TEST_UTIL.getHBaseAdmin().createTable(table);
 return TEST_UTIL.getConnection().getTable(tableName);
}

相关文章

HBaseTestingUtility类方法