private static AsyncAdmin getRawAsyncAdmin() { return ASYNC_CONN.getAdmin(); }
private static AsyncAdmin getAsyncAdmin() { return ASYNC_CONN.getAdmin(ForkJoinPool.commonPool()); }
@Test public void testSwitchRpcThrottle() throws Exception { CompletableFuture<Boolean> future1 = ASYNC_CONN.getAdmin().switchRpcThrottle(true); assertEquals(true, future1.get().booleanValue()); CompletableFuture<Boolean> future2 = ASYNC_CONN.getAdmin().isRpcThrottleEnabled(); assertEquals(true, future2.get().booleanValue()); }
@Test public void testDisabled() throws InterruptedException, ExecutionException { ASYNC_CONN.getAdmin().disableTable(TABLE_NAME).get(); try { getTable.get().get(new Get(row)).get(); fail("Should fail since table has been disabled"); } catch (ExecutionException e) { Throwable cause = e.getCause(); assertThat(cause, instanceOf(TableNotEnabledException.class)); assertThat(cause.getMessage(), containsString(TABLE_NAME.getNameAsString())); } } }
@Test public void testAsyncFlushTable() throws Exception { AsyncAdmin admin = asyncConn.getAdmin(); admin.flush(tableName).get(); assertFalse(getRegionInfo().stream().anyMatch(r -> r.getMemStoreDataSize() != 0)); }
@Test public void testAsyncFlushRegionServer() throws Exception { AsyncAdmin admin = asyncConn.getAdmin(); for (HRegionServer rs : TEST_UTIL.getHBaseCluster() .getLiveRegionServerThreads() .stream().map(JVMClusterUtil.RegionServerThread::getRegionServer) .collect(Collectors.toList())) { admin.flushRegionServer(rs.getServerName()).get(); assertFalse(getRegionInfo(rs).stream().anyMatch(r -> r.getMemStoreDataSize() != 0)); } }
return; AsyncAdmin peerAdmin = conn.getAdmin(); addListener(peerAdmin.tableExists(tableName), (exist, err2) -> { if (err2 != null) {
@Before @Override public void setUp() throws Exception { TEST_UTIL.startMiniCluster(3); ASYNC_CONN = ConnectionFactory.createAsyncConnection(TEST_UTIL.getConfiguration()).get(); admin = ASYNC_CONN.getAdmin(); }
@Test public void testAsyncFlushRegion() throws Exception { AsyncAdmin admin = asyncConn.getAdmin(); for (HRegion r : getRegionInfo()) { admin.flushRegion(r.getRegionInfo().getRegionName()).get(); TimeUnit.SECONDS.sleep(1); assertEquals(0, r.getMemStoreDataSize()); } }
@BeforeClass public static void setUpBeforeClass() throws Exception { TEST_UTIL.getConfiguration().setInt(HConstants.HBASE_RPC_TIMEOUT_KEY, 60000); TEST_UTIL.getConfiguration().setInt(HConstants.HBASE_CLIENT_OPERATION_TIMEOUT, 120000); TEST_UTIL.getConfiguration().setInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER, 2); TEST_UTIL.getConfiguration().setInt(START_LOG_ERRORS_AFTER_COUNT_KEY, 0); TEST_UTIL.startMiniCluster(); ASYNC_CONN = ConnectionFactory.createAsyncConnection(TEST_UTIL.getConfiguration()).get(); conf2 = HBaseConfiguration.create(TEST_UTIL.getConfiguration()); conf2.set(HConstants.ZOOKEEPER_ZNODE_PARENT, "/2"); TEST_UTIL2 = new HBaseTestingUtility(conf2); TEST_UTIL2.startMiniCluster(); admin2 = ConnectionFactory.createAsyncConnection(TEST_UTIL2.getConfiguration()).get().getAdmin(); ReplicationPeerConfig rpc = new ReplicationPeerConfig(); rpc.setClusterKey(TEST_UTIL2.getClusterKey()); ASYNC_CONN.getAdmin().addReplicationPeer(ID_SECOND, rpc).join(); }
@Test public void testAsyncTable() throws Exception { TableName tn = TableName.valueOf(name.getMethodName()); ColumnFamilyDescriptorBuilder cfDescBuilder = ColumnFamilyDescriptorBuilder.newBuilder(family); TableDescriptorBuilder tableDescBuilder = TableDescriptorBuilder.newBuilder(tn).setColumnFamily(cfDescBuilder.build()); try (AsyncConnection ASYNC_CONN = ConnectionFactory.createAsyncConnection(TEST_UTIL.getConfiguration()).get()) { ASYNC_CONN.getAdmin().createTable(tableDescBuilder.build()).get(); AsyncTable<?> table = ASYNC_CONN.getTable(tn); // put some data Put put = new Put(row); put.addColumn(family, qualifier, value); table.put(put).get(); // get and verify Get get = new Get(row); Result result = table.get(get).get(); LOG.debug("Result: " + Bytes.toString(result.getValue(family, qualifier))); Assert.assertArrayEquals(value, result.getValue(family, qualifier)); } } }
@Test public void testGetRegionLocation() throws Exception { RawAsyncHBaseAdmin rawAdmin = (RawAsyncHBaseAdmin) ASYNC_CONN.getAdmin(); TEST_UTIL.createMultiRegionTable(tableName, HConstants.CATALOG_FAMILY); AsyncTableRegionLocator locator = ASYNC_CONN.getRegionLocator(tableName); HRegionLocation regionLocation = locator.getRegionLocation(Bytes.toBytes("mmm")).get(); RegionInfo region = regionLocation.getRegion(); byte[] regionName = regionLocation.getRegion().getRegionName(); HRegionLocation location = rawAdmin.getRegionLocation(regionName).get(); assertTrue(Bytes.equals(regionName, location.getRegion().getRegionName())); location = rawAdmin.getRegionLocation(region.getEncodedNameAsBytes()).get(); assertTrue(Bytes.equals(regionName, location.getRegion().getRegionName())); }
RawAsyncHBaseAdmin rawAdmin = (RawAsyncHBaseAdmin) ASYNC_CONN.getAdmin(); ServerName serverName = rawAdmin.getRegionLocation(hri.getRegionName()).get().getServerName();
@Test public void testAsyncClient() throws Exception { try (AsyncConnection asyncConnect = ConnectionFactory.createAsyncConnection( UTIL.getConfiguration()).get()) { AsyncAdmin asyncAdmin = asyncConnect.getAdmin(); CompletableFuture<ClusterMetrics> originFuture = asyncAdmin.getClusterMetrics(); CompletableFuture<ClusterMetrics> defaultsFuture = asyncAdmin.getClusterMetrics(EnumSet.allOf(Option.class)); ClusterMetrics origin = originFuture.get(); ClusterMetrics defaults = defaultsFuture.get(); Assert.assertEquals(origin.getHBaseVersion(), defaults.getHBaseVersion()); Assert.assertEquals(origin.getClusterId(), defaults.getClusterId()); Assert.assertEquals(origin.getHBaseVersion(), defaults.getHBaseVersion()); Assert.assertEquals(origin.getClusterId(), defaults.getClusterId()); Assert.assertEquals(origin.getAverageLoad(), defaults.getAverageLoad(), 0); Assert.assertEquals(origin.getBackupMasterNames().size(), defaults.getBackupMasterNames().size()); Assert.assertEquals(origin.getDeadServerNames().size(), defaults.getDeadServerNames().size()); Assert.assertEquals(origin.getRegionCount(), defaults.getRegionCount()); Assert.assertEquals(origin.getLiveServerMetrics().size(), defaults.getLiveServerMetrics().size()); Assert.assertEquals(origin.getMasterInfoPort(), defaults.getMasterInfoPort()); } }
try (AsyncConnection conn = ConnectionFactory.createAsyncConnection(UTIL.getConfiguration()).get()) { AsyncAdmin admin = conn.getAdmin(); CompletableFuture<Void> future = admin.move(hri.getRegionName()); rs.abort("For testing!");
try (AsyncConnection conn = ConnectionFactory.createAsyncConnection(UTIL.getConfiguration()).get()) { AsyncAdmin admin = conn.getAdmin(); CompletableFuture<Void> future = admin.move(hri.getRegionName()); rs.abort("For testing!");
@Test public void testClearBlockCacheFromAsyncAdmin() throws Exception { AsyncAdmin admin = ConnectionFactory.createAsyncConnection(HTU.getConfiguration()).get().getAdmin(); BlockCache blockCache1 = rs1.getBlockCache().get(); BlockCache blockCache2 = rs2.getBlockCache().get(); long initialBlockCount1 = blockCache1.getBlockCount(); long initialBlockCount2 = blockCache2.getBlockCount(); // scan will cause blocks to be added in BlockCache scanAllRegionsForRS(rs1); assertEquals(blockCache1.getBlockCount() - initialBlockCount1, HTU.getNumHFilesForRS(rs1, TABLE_NAME, FAMILY)); scanAllRegionsForRS(rs2); assertEquals(blockCache2.getBlockCount() - initialBlockCount2, HTU.getNumHFilesForRS(rs2, TABLE_NAME, FAMILY)); CacheEvictionStats stats = admin.clearBlockCache(TABLE_NAME).get(); assertEquals(stats.getEvictedBlocks(), HTU.getNumHFilesForRS(rs1, TABLE_NAME, FAMILY) + HTU .getNumHFilesForRS(rs2, TABLE_NAME, FAMILY)); assertEquals(initialBlockCount1, blockCache1.getBlockCount()); assertEquals(initialBlockCount2, blockCache2.getBlockCount()); }
return; AsyncAdmin peerAdmin = conn.getAdmin(); peerAdmin.tableExists(tableName).whenComplete( (exist, err2) -> {
@Before @Override public void setUp() throws Exception { TEST_UTIL.startMiniCluster(1, 3); ASYNC_CONN = ConnectionFactory.createAsyncConnection(TEST_UTIL.getConfiguration()).get(); admin = ASYNC_CONN.getAdmin(); }