BigtableAsyncTableRegionLocator extends AbstractBigtableRegionLocator implements AsyncTableRegionLocator { @Override public CompletableFuture<HRegionLocation> getRegionLocation(byte[] row, boolean reload) { return FutureUtils.toCompletableFuture(getRegionsAsync(reload)) .thenApplyAsync( result -> { for (HRegionLocation region : result) { if (region.getRegion().containsRow(row)) { hRegionLocation = region; break; } } return hRegionLocation; }); } BigtableAsyncTableRegionLocator(
      TableName tableName, BigtableHBaseSettings settings, DataClientWrapper client); @Override TableName getName(); @Override CompletableFuture<HRegionLocation> getRegionLocation(byte[] row, boolean reload); @Override CompletableFuture<HRegionLocation> getRegionLocation(
      byte[] row, int replicaId, boolean reload); @Override CompletableFuture<List<HRegionLocation>> getRegionLocations(byte[] row, boolean reload); @Override CompletableFuture<List<HRegionLocation>> getAllRegionLocations(); @Override void clearRegionLocationCache(); @Override SampledRowKeysAdapter getSampledRowKeysAdapter(
      TableName tableName, ServerName serverName);  }
@Test public void testGetRegionLocation() throws ExecutionException, InterruptedException { List<KeyOffset> keyOffsets = ImmutableList.of( KeyOffset.create(ByteString.copyFromUtf8("a"), 100L), KeyOffset.create(ByteString.copyFromUtf8("b"), 100L), KeyOffset.create(ByteString.copyFromUtf8("y"), 100L), KeyOffset.create(ByteString.copyFromUtf8("z"), 100L)); when(mockDataClient.sampleRowKeysAsync(TABLE_NAME.getNameAsString())) .thenReturn(ApiFutures.immediateFuture(keyOffsets)); HRegionLocation regionLocationFuture = regionLocator.getRegionLocation(Bytes.toBytes("rowKey"), 1, false).get(); assertEquals("b", Bytes.toString(regionLocationFuture.getRegion().getStartKey())); assertEquals("y", Bytes.toString(regionLocationFuture.getRegion().getEndKey())); assertEquals(TABLE_NAME, regionLocator.getName()); }