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

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

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

HBaseTestingUtility.getConnection介绍

[英]Get a Connection to the cluster. Not thread-safe (This class needs a lot of work to make it thread-safe).
[中]获取到群集的连接。非线程安全(该类需要大量工作才能使其线程安全)。

代码示例

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

protected final void write(HBaseTestingUtility util, int start, int end) throws IOException {
 try (Table table = util.getConnection().getTable(TABLE_NAME)) {
  for (int i = start; i < end; i++) {
   table.put(new Put(Bytes.toBytes(i)).addColumn(CF, CQ, Bytes.toBytes(i)));
  }
 }
}

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

/**
 * Test multithreadedTableMappper map/reduce against a multi-region table
 * @throws IOException
 * @throws ClassNotFoundException
 * @throws InterruptedException
 */
@Test
public void testMultithreadedTableMapper()
  throws IOException, InterruptedException, ClassNotFoundException {
 runTestOnTable(UTIL.getConnection().getTable(MULTI_REGION_TABLE_NAME));
}

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

@Test
public void testConnectionDefaultUsesCodec() throws Exception {
 ClusterConnection con = (ClusterConnection) TEST_UTIL.getConnection();
 assertTrue(con.hasCellBlockSupport());
}

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

@Before
public void removeAllQuotas() throws Exception {
 if (helper == null) {
  helper = new SpaceQuotaHelperForTests(TEST_UTIL, testName, new AtomicLong());
 }
 final Connection conn = TEST_UTIL.getConnection();
 // Wait for the quota table to be created
 if (!conn.getAdmin().tableExists(QuotaUtil.QUOTA_TABLE_NAME)) {
  helper.waitForQuotaTable(conn);
 } else {
  // Or, clean up any quotas from previous test runs.
  helper.removeAllQuotas(conn);
  assertEquals(0, helper.listNumDefinedQuotas(conn));
 }
}

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

public static void verifyRowCount(final HBaseTestingUtility util, final TableName tableName,
  long expectedRows) throws IOException {
 Table table = util.getConnection().getTable(tableName);
 try {
  assertEquals(expectedRows, util.countRows(table));
 } finally {
  table.close();
 }
}

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

private void moveRegion(Table table, int index) throws IOException{
 List<Pair<RegionInfo, ServerName>> regions = MetaTableAccessor
   .getTableRegionsAndLocations(TEST_UTIL.getConnection(),
     table.getName());
 assertEquals(1, regions.size());
 RegionInfo regionInfo = regions.get(0).getFirst();
 ServerName name = TEST_UTIL.getHBaseCluster().getRegionServer(index).getServerName();
 TEST_UTIL.getAdmin().move(regionInfo.getEncodedNameAsBytes(),
   Bytes.toBytes(name.getServerName()));
}

代码示例来源: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);
}

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

@BeforeClass
public static void before() throws Exception {
 HTU.startMiniCluster(NB_SERVERS);
 final TableName tableName = TableName.valueOf(TestRegionServerNoMaster.class.getSimpleName());
 // Create table then get the single region for our new table.
 table = HTU.createTable(tableName,HConstants.CATALOG_FAMILY);
 Put p = new Put(row);
 p.addColumn(HConstants.CATALOG_FAMILY, row, row);
 table.put(p);
 try (RegionLocator locator = HTU.getConnection().getRegionLocator(tableName)) {
  hri = locator.getRegionLocation(row, false).getRegionInfo();
 }
 regionName = hri.getRegionName();
 stopMasterAndAssignMeta(HTU);
}

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

@Override
public boolean evaluate() throws Exception {
 try (Table table = UTIL1.getConnection().getTable(TABLE_NAME)) {
  return table.exists(new Get(Bytes.toBytes(0)));
 }
}

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

private void prepareTest(String testId) throws IOException {
 tableName = TableName.valueOf("test_table_" + testId);
 HTableDescriptor htd = new HTableDescriptor(tableName);
 hcd = new HColumnDescriptor(CF);
 htd.addFamily(hcd);
 try (Admin admin = TEST_UTIL.getConnection().getAdmin()) {
  admin.createTable(htd);
 }
 numBatchesWritten = 0;
}

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

/**
 * For HADOOP-2579
 * @throws IOException
 */
@Test (expected=TableNotFoundException.class)
public void testTableNotFoundExceptionWithoutAnyTables() throws IOException {
 TableName tableName = TableName
   .valueOf("testTableNotFoundExceptionWithoutAnyTables");
 Table ht = TEST_UTIL.getConnection().getTable(tableName);
 ht.get(new Get(Bytes.toBytes("e")));
}

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

@Test
public void testSecurityCapabilities() throws Exception {
 List<SecurityCapability> capabilities = TEST_UTIL.getConnection().getAdmin()
  .getSecurityCapabilities();
 assertTrue("AUTHORIZATION capability is missing",
  capabilities.contains(SecurityCapability.AUTHORIZATION));
 assertTrue("CELL_AUTHORIZATION capability is missing",
  capabilities.contains(SecurityCapability.CELL_AUTHORIZATION));
}

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

@Test
public void testCombiner() throws IOException {
 Configuration conf = new Configuration(UTIL.getConfiguration());
 // force use of combiner for testing purposes
 conf.setInt("mapreduce.map.combine.minspills", 1);
 runTestOnTable(UTIL.getConnection().getTable(MULTI_REGION_TABLE_NAME));
}

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

@Before
public void removeAllQuotas() throws Exception {
 final Connection conn = TEST_UTIL.getConnection();
 if (helper == null) {
  helper = new SpaceQuotaHelperForTests(TEST_UTIL, testName, COUNTER);
 }
 // Wait for the quota table to be created
 if (!conn.getAdmin().tableExists(QuotaUtil.QUOTA_TABLE_NAME)) {
  helper.waitForQuotaTable(conn);
 } else {
  // Or, clean up any quotas from previous test runs.
  helper.removeAllQuotas(conn);
  assertEquals(0, helper.listNumDefinedQuotas(conn));
 }
}

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

@Override
protected Table createTable(byte[] fam) throws IOException {
 TableName tableName = TableName.valueOf(testName.getMethodName());
 TEST_UTIL.getAdmin().createTable(TableDescriptorBuilder.newBuilder(tableName)
   .setColumnFamily(ColumnFamilyDescriptorBuilder.of(fam)).build());
 return TEST_UTIL.getConnection().getTable(tableName);
}

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

public int testGet(final RegionInfo hri, final int nrows) throws IOException {
  int nresults = 0;
  final Table table = UTIL.getConnection().getTable(hri.getTable());
  for (int i = 0; i < nrows; ++i) {
   final byte[] row = Bytes.add(hri.getStartKey(), Bytes.toBytes(i));
   final Result result = table.get(new Get(row));
   if (result != null && !result.isEmpty() &&
     Bytes.equals(row, result.getValue(FAMILY, null))) {
    nresults++;
   }
  }
  return nresults;
 }
}

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

@Test
public void testCachingForHTableSinglePut() throws Exception {
 byte[] row = Bytes.toBytes("htable_single_put");
 byte[] value = Bytes.toBytes("value");
 Put put = new Put(row);
 put.addColumn(FAMILY, QUALIFIER, value);
 try (Table table = TEST_UTIL.getConnection().getTable(TABLE_NAME)) {
  table.put(put);
 }
 checkRegionLocationIsCached(TABLE_NAME, TEST_UTIL.getConnection());
 checkExistence(TABLE_NAME, row, FAMILY, QUALIFIER);
}

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

@Test
public void testSecurityCapabilities() throws Exception {
 List<SecurityCapability> capabilities = TEST_UTIL.getConnection().getAdmin()
  .getSecurityCapabilities();
 assertTrue("CELL_VISIBILITY capability is missing",
  capabilities.contains(SecurityCapability.CELL_VISIBILITY));
}

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

@Test
public void testNullCall() throws Throwable {
 try (Table table = util.getConnection().getTable(TEST_TABLE);
   RegionLocator locator = util.getConnection().getRegionLocator(TEST_TABLE)) {
  Map<byte[],String> results = hello(table, null, ROW_A, ROW_C);
  verifyRegionResults(locator, results, "Who are you?", ROW_A);
  verifyRegionResults(locator, results, "Who are you?", ROW_B);
  verifyRegionResults(locator, results, "Who are you?", ROW_C);
 }
}

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

@Before
public void removeAllQuotas() throws Exception {
 final Connection conn = TEST_UTIL.getConnection();
 if (helper == null) {
  helper = new SpaceQuotaHelperForTests(TEST_UTIL, testName, COUNTER);
 }
 // Wait for the quota table to be created
 if (!conn.getAdmin().tableExists(QuotaUtil.QUOTA_TABLE_NAME)) {
  helper.waitForQuotaTable(conn);
 } else {
  // Or, clean up any quotas from previous test runs.
  helper.removeAllQuotas(conn);
  assertEquals(0, helper.listNumDefinedQuotas(conn));
 }
}

相关文章

HBaseTestingUtility类方法