@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(); List<SampleRowKeysResponse> responseProto = ImmutableList.of( SampleRowKeysResponse.newBuilder().setRowKey(ROW_KEY_1).setOffsetBytes(11).build(), SampleRowKeysResponse.newBuilder().setRowKey(ROW_KEY_2).setOffsetBytes(12).build(), SampleRowKeysResponse.newBuilder().setRowKey(ROW_KEY_3).setOffsetBytes(13).build()); when(delegate.sampleRowKeysAsync(requestProto)) .thenReturn(Futures.immediateFuture(responseProto)); List<KeyOffset> keyOffsetList = dataClientWrapper.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(delegate).sampleRowKeysAsync(requestProto); }
@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(List<SampleRowKeysResponse> rowKeysList) { ImmutableList.Builder<KeyOffset> keyOffsetBuilder = ImmutableList.builder(); for (SampleRowKeysResponse rowKeys : rowKeysList) { keyOffsetBuilder.add(KeyOffset.create(rowKeys.getRowKey(), rowKeys.getOffsetBytes())); } return keyOffsetBuilder.build(); } }); }
DataClientClassicApi implements DataClientWrapper { @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(List<SampleRowKeysResponse> rowKeysList) { ImmutableList.Builder<KeyOffset> keyOffsetBuilder = ImmutableList.builder(); for (SampleRowKeysResponse rowKeys : rowKeysList) { keyOffsetBuilder.add(KeyOffset.create(rowKeys.getRowKey(), rowKeys.getOffsetBytes())); } return keyOffsetBuilder.build(); } }); } }
DataClientClassicApi implements DataClientWrapper { @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(List<SampleRowKeysResponse> rowKeysList) { ImmutableList.Builder<KeyOffset> keyOffsetBuilder = ImmutableList.builder(); for (SampleRowKeysResponse rowKeys : rowKeysList) { keyOffsetBuilder.add(KeyOffset.create(rowKeys.getRowKey(), rowKeys.getOffsetBytes())); } return keyOffsetBuilder.build(); } }); } DataClientClassicApi(BigtableSession session, RequestContext requestContext); }
DataClientClassicApi implements DataClientWrapper { @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(List<SampleRowKeysResponse> rowKeysList) { ImmutableList.Builder<KeyOffset> keyOffsetBuilder = ImmutableList.builder(); for (SampleRowKeysResponse rowKeys : rowKeysList) { keyOffsetBuilder.add(KeyOffset.create(rowKeys.getRowKey(), rowKeys.getOffsetBytes())); } return keyOffsetBuilder.build(); } }); } DataClientClassicApi(BigtableSession session, RequestContext requestContext); @Override BulkMutationWrapper createBulkMutation(String tableId); @Override BulkReadWrapper createBulkRead(String tableId); @Override ApiFuture<Void> mutateRowAsync(RowMutation rowMutation); @Override ApiFuture<Result> readModifyWriteRowAsync(ReadModifyWriteRow readModifyWriteRow); @Override ApiFuture<Boolean> checkAndMutateRowAsync(ConditionalRowMutation conditionalRowMutation); @Override ApiFuture<List<KeyOffset>> sampleRowKeysAsync(String tableId); @Override ApiFuture<Result> readRowAsync(String tableId, ByteString rowKey, Filters.Filter filter); @Override org.apache.hadoop.hbase.client.ResultScanner readRows(Query request); @Override ApiFuture<List<Result>> readRowsAsync(Query request); @Override void readRowsAsync(Query request, final StreamObserver<Result> observer); @Override void close(); }
DataClientClassicApi implements DataClientWrapper { @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(List<SampleRowKeysResponse> rowKeysList) { ImmutableList.Builder<KeyOffset> keyOffsetBuilder = ImmutableList.builder(); for (SampleRowKeysResponse rowKeys : rowKeysList) { keyOffsetBuilder.add(KeyOffset.create(rowKeys.getRowKey(), rowKeys.getOffsetBytes())); } return keyOffsetBuilder.build(); } }); } DataClientClassicApi(BigtableSession session, RequestContext requestContext); @Override BulkMutationWrapper createBulkMutation(String tableId); @Override BulkReadWrapper createBulkRead(String tableId); @Override ApiFuture<Void> mutateRowAsync(RowMutation rowMutation); @Override ApiFuture<Result> readModifyWriteRowAsync(ReadModifyWriteRow readModifyWriteRow); @Override ApiFuture<Boolean> checkAndMutateRowAsync(ConditionalRowMutation conditionalRowMutation); @Override ApiFuture<List<KeyOffset>> sampleRowKeysAsync(String tableId); @Override ApiFuture<Result> readRowAsync(String tableId, ByteString rowKey, Filters.Filter filter); @Override org.apache.hadoop.hbase.client.ResultScanner readRows(Query request); @Override ApiFuture<List<Result>> readRowsAsync(Query request); @Override void readRowsAsync(Query request, final StreamObserver<Result> observer); @Override void close();  }