BigtableDataClientWrapper implements IBigtableDataClient { @Override public ApiFuture<List<KeyOffset>> sampleRowKeysAsync(String tableId) { String fullTableName = NameUtil.formatTableName( requestContext.getProjectId(), requestContext.getInstanceId(), tableId); SampleRowKeysRequest requestProto = SampleRowKeysRequest.newBuilder().setTableName(fullTableName).build(); ListenableFuture<List<SampleRowKeysResponse>> responseProto = delegate.sampleRowKeysAsync(requestProto); return ApiFutureUtil.transformAndAdapt( responseProto, new Function<List<SampleRowKeysResponse>, List<KeyOffset>>() { @Override public List<KeyOffset> apply(@Nonnull List<SampleRowKeysResponse> rowKeysList) { if (rowKeysList == null || rowKeysList.isEmpty()) { return Collections.EMPTY_LIST; } ImmutableList.Builder<KeyOffset> keyOffsetBuilder = ImmutableList.builderWithExpectedSize(rowKeysList.size()); for (SampleRowKeysResponse rowKeys : rowKeysList) { keyOffsetBuilder.add(KeyOffset.create(rowKeys.getRowKey(), rowKeys.getOffsetBytes())); } return keyOffsetBuilder.build(); } }); } BigtableDataClientWrapper(
      BigtableDataClient bigtableDataClient, RequestContext requestContext); @Override void mutateRow(RowMutation rowMutation); @Override ApiFuture<Void> mutateRowAsync(RowMutation rowMutation); @Override Row readModifyWriteRow(ReadModifyWriteRow readModifyWriteRow); @Override ApiFuture<Row> readModifyWriteRowAsync(ReadModifyWriteRow readModifyWriteRow); @Override IBulkMutation createBulkMutationBatcher(String tableId); @Override ApiFuture<Boolean> checkAndMutateRowAsync(ConditionalRowMutation conditionalRowMutation); @Override Boolean checkAndMutateRow(ConditionalRowMutation conditionalRowMutation); @Override List<KeyOffset> sampleRowKeys(String tableId); @Override ApiFuture<List<KeyOffset>> sampleRowKeysAsync(String tableId); @Override ResultScanner<Row> readRows(Query request); @Override ApiFuture<List<Row>> readRowsAsync(Query request); @Override List<FlatRow> readFlatRowsList(Query request); @Override ResultScanner<FlatRow> readFlatRows(Query request); @Override ApiFuture<List<FlatRow>> readFlatRowsAsync(Query request); @Override void readFlatRowsAsync(Query request, StreamObserver<FlatRow> observer);  }
@Test public void testSampleRowKeysAsync() throws Exception { final ByteString ROW_KEY_1 = ByteString.copyFromUtf8("row-key-1"); final ByteString ROW_KEY_2 = ByteString.copyFromUtf8("row-key-2"); final ByteString ROW_KEY_3 = ByteString.copyFromUtf8("row-key-3"); String tableName = NameUtil.formatTableName(PROJECT_ID, INSTANCE_ID, TABLE_ID); SampleRowKeysRequest requestProto = SampleRowKeysRequest.newBuilder().setTableName(tableName).build(); ImmutableList.Builder sampleKeys = ImmutableList.builder(); sampleKeys.add( SampleRowKeysResponse.newBuilder().setRowKey(ROW_KEY_1).setOffsetBytes(11).build()); sampleKeys.add( SampleRowKeysResponse.newBuilder().setRowKey(ROW_KEY_2).setOffsetBytes(12).build()); sampleKeys.add( SampleRowKeysResponse.newBuilder().setRowKey(ROW_KEY_3).setOffsetBytes(13).build()); List<SampleRowKeysResponse> responseProtos = sampleKeys.build(); when(client.sampleRowKeysAsync(requestProto)) .thenReturn(Futures.immediateFuture(responseProtos)); List<KeyOffset> keyOffsetList = clientWrapper.sampleRowKeysAsync(TABLE_ID).get(); assertEquals(keyOffsetList.get(0).getKey(), ROW_KEY_1); assertEquals(keyOffsetList.get(1).getKey(), ROW_KEY_2); assertEquals(keyOffsetList.get(2).getKey(), ROW_KEY_3); verify(client).sampleRowKeysAsync(requestProto); }