use of com.google.cloud.bigtable.data.v2.models.Row in project java-bigtable by googleapis.
the class EnhancedBigtableStubTest method testUserAgent.
@Test
public void testUserAgent() throws InterruptedException {
ServerStreamingCallable<Query, Row> streamingCallable = enhancedBigtableStub.createReadRowsCallable(new DefaultRowAdapter());
Query request = Query.create("table-id").rowKey("row-key");
streamingCallable.call(request).iterator().next();
assertThat(metadataInterceptor.headers).hasSize(1);
Metadata metadata = metadataInterceptor.headers.take();
assertThat(metadata.get(Metadata.Key.of("user-agent", Metadata.ASCII_STRING_MARSHALLER))).containsMatch("bigtable-java/\\d+\\.\\d+\\.\\d+(?:-SNAPSHOT)?");
}
use of com.google.cloud.bigtable.data.v2.models.Row in project java-bigtable by googleapis.
the class EnhancedBigtableStubTest method testCreateReadRowsRawCallable.
@Test
public void testCreateReadRowsRawCallable() throws InterruptedException {
ServerStreamingCallable<ReadRowsRequest, Row> callable = enhancedBigtableStub.createReadRowsRawCallable(new DefaultRowAdapter());
ReadRowsRequest expectedRequest = ReadRowsRequest.newBuilder().setTableName(TABLE_NAME).setAppProfileId("app-profile-1").setRows(RowSet.newBuilder().addRowKeys(ByteString.copyFromUtf8("test-row-key"))).build();
callable.call(expectedRequest).iterator().next();
assertThat(fakeDataService.popLastRequest()).isEqualTo(expectedRequest);
ReadRowsRequest expectedRequest2 = ReadRowsRequest.newBuilder().setTableName(TABLE_NAME).setAppProfileId("app-profile-2").build();
callable.call(expectedRequest2).iterator().next();
assertThat(fakeDataService.popLastRequest()).isEqualTo(expectedRequest2);
}
use of com.google.cloud.bigtable.data.v2.models.Row in project java-bigtable by googleapis.
the class ReadModifyWriteRowCallableTest method responseSortsFamilies.
@Test
public void responseSortsFamilies() throws Exception {
ByteString col = ByteString.copyFromUtf8("col1");
ByteString value1 = ByteString.copyFromUtf8("value1");
ByteString value2 = ByteString.copyFromUtf8("value2");
ApiFuture<Row> result = callable.futureCall(ReadModifyWriteRow.create("my-table", "my-key").append("my-family", "col", "suffix"));
inner.response.set(ReadModifyWriteRowResponse.newBuilder().setRow(com.google.bigtable.v2.Row.newBuilder().setKey(ByteString.copyFromUtf8("my-key")).addFamilies(Family.newBuilder().setName("family2").addColumns(Column.newBuilder().setQualifier(col).addCells(Cell.newBuilder().setTimestampMicros(1_000).setValue(value2)))).addFamilies(Family.newBuilder().setName("family1").addColumns(Column.newBuilder().setQualifier(col).addCells(Cell.newBuilder().setTimestampMicros(1_000).setValue(value1))).build())).build());
assertThat(result.get(1, TimeUnit.SECONDS)).isEqualTo(Row.create(ByteString.copyFromUtf8("my-key"), ImmutableList.of(RowCell.create("family1", col, 1_000, ImmutableList.<String>of(), value1), RowCell.create("family2", col, 1_000, ImmutableList.<String>of(), value2))));
}
use of com.google.cloud.bigtable.data.v2.models.Row in project java-bigtable by googleapis.
the class MetricsTracerTest method testReadRowsFirstRow.
@Test
public void testReadRowsFirstRow() throws InterruptedException {
final long beforeSleep = 50;
final long afterSleep = 50;
SettableFuture<Void> gotFirstRow = SettableFuture.create();
ExecutorService executor = Executors.newCachedThreadPool();
doAnswer(invocation -> {
StreamObserver<ReadRowsResponse> observer = invocation.getArgument(1);
executor.submit(() -> {
Thread.sleep(beforeSleep);
observer.onNext(DEFAULT_READ_ROWS_RESPONSES);
// wait until the first row is consumed before padding the operation span
gotFirstRow.get();
Thread.sleep(afterSleep);
observer.onCompleted();
return null;
});
return null;
}).when(mockService).readRows(any(ReadRowsRequest.class), any());
Stopwatch stopwatch = Stopwatch.createStarted();
// Get the first row and notify the mock that it can start padding the operation span
Iterator<Row> it = stub.readRowsCallable().call(Query.create(TABLE_ID)).iterator();
it.next();
gotFirstRow.set(null);
// finish the stream
while (it.hasNext()) {
it.next();
}
long elapsed = stopwatch.elapsed(TimeUnit.MILLISECONDS);
// Give OpenCensus a chance to update the views asynchronously.
Thread.sleep(100);
executor.shutdown();
long firstRowLatency = StatsTestUtils.getAggregationValueAsLong(localStats, RpcViewConstants.BIGTABLE_READ_ROWS_FIRST_ROW_LATENCY_VIEW, ImmutableMap.<TagKey, TagValue>of(), PROJECT_ID, INSTANCE_ID, APP_PROFILE_ID);
assertThat(firstRowLatency).isIn(Range.closed(beforeSleep, elapsed - afterSleep));
}
use of com.google.cloud.bigtable.data.v2.models.Row in project java-bigtable by googleapis.
the class SampleRowsIT method test.
@Test
public void test() throws InterruptedException, ExecutionException, TimeoutException {
BigtableDataClient client = testEnvRule.env().getDataClient();
String rowPrefix = UUID.randomUUID().toString();
// Create some data so that sample row keys has something to show
List<ApiFuture<?>> futures = Lists.newArrayList();
for (int i = 0; i < 10; i++) {
ApiFuture<Void> future = client.mutateRowAsync(RowMutation.create(testEnvRule.env().getTableId(), rowPrefix + "-" + i).setCell(testEnvRule.env().getFamilyId(), "", "value"));
futures.add(future);
}
ApiFutures.allAsList(futures).get(1, TimeUnit.MINUTES);
ApiFuture<List<KeyOffset>> future = client.sampleRowKeysAsync(testEnvRule.env().getTableId());
List<KeyOffset> results = future.get(1, TimeUnit.MINUTES);
assertThat(results).isNotEmpty();
assertThat(results.get(results.size() - 1).getOffsetBytes()).isGreaterThan(0L);
}
Aggregations