use of com.google.cloud.bigtable.data.v2.models.DefaultRowAdapter 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.DefaultRowAdapter in project java-bigtable by googleapis.
the class EnhancedBigtableStubTest method testCreateReadRowsCallable.
@Test
public void testCreateReadRowsCallable() throws InterruptedException {
ServerStreamingCallable<Query, Row> streamingCallable = enhancedBigtableStub.createReadRowsCallable(new DefaultRowAdapter());
Query request = Query.create("table-id").rowKey("row-key");
streamingCallable.call(request).iterator().next();
ReadRowsRequest expected = request.toProto(RequestContext.create(PROJECT_ID, INSTANCE_ID, APP_PROFILE_ID));
assertThat(fakeDataService.popLastRequest()).isEqualTo(expected);
}
use of com.google.cloud.bigtable.data.v2.models.DefaultRowAdapter 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.DefaultRowAdapter in project java-bigtable by googleapis.
the class ReadRowsMergingAcceptanceTest method test.
@Test
public void test() throws Exception {
List<ReadRowsResponse> responses = Lists.newArrayList();
// Convert the chunks into a single ReadRowsResponse
for (CellChunk chunk : testCase.getChunksList()) {
ReadRowsResponse.Builder responseBuilder = ReadRowsResponse.newBuilder();
responseBuilder.addChunks(chunk);
responses.add(responseBuilder.build());
}
// Wrap the responses in a callable
ServerStreamingCallable<ReadRowsRequest, ReadRowsResponse> source = new ServerStreamingStashCallable<>(responses);
RowMergingCallable<Row> mergingCallable = new RowMergingCallable<>(source, new DefaultRowAdapter());
// Invoke the callable to get the merged rows
ServerStream<Row> stream = mergingCallable.call(ReadRowsRequest.getDefaultInstance());
// Read all of the rows and transform them into logical cells
List<ReadRowsTest.Result> actualResults = Lists.newArrayList();
Exception error = null;
try {
for (Row row : stream) {
for (RowCell cell : row.getCells()) {
actualResults.add(ReadRowsTest.Result.newBuilder().setRowKeyBytes(row.getKey()).setFamilyName(cell.getFamily()).setQualifierBytes(cell.getQualifier()).setTimestampMicros(cell.getTimestamp()).setValueBytes(cell.getValue()).setLabel(cell.getLabels().isEmpty() ? "" : cell.getLabels().get(0)).build());
}
}
} catch (Exception e) {
error = e;
}
// Verify the results
if (expectsError(testCase)) {
assertThat(error).isNotNull();
} else {
if (error != null) {
throw error;
}
}
assertThat(getNonExceptionResults(testCase)).isEqualTo(actualResults);
}
use of com.google.cloud.bigtable.data.v2.models.DefaultRowAdapter in project java-bigtable by googleapis.
the class RowMergingCallableTest method scanMarker.
@Test
public void scanMarker() {
FakeStreamingApi.ServerStreamingStashCallable<ReadRowsRequest, ReadRowsResponse> inner = new ServerStreamingStashCallable<>(Lists.newArrayList(// send a scan marker
ReadRowsResponse.newBuilder().setLastScannedRowKey(ByteString.copyFromUtf8("key1")).build()));
RowMergingCallable<Row> rowMergingCallable = new RowMergingCallable<>(inner, new DefaultRowAdapter());
List<Row> results = rowMergingCallable.all().call(ReadRowsRequest.getDefaultInstance());
Truth.assertThat(results).containsExactly(Row.create(ByteString.copyFromUtf8("key1"), Lists.<RowCell>newArrayList()));
}
Aggregations