use of com.google.cloud.bigquery.storage.v1beta2.ReadRowsResponse in project java-bigtable by googleapis.
the class MetricsTracerTest method testReadRowsAttemptsPerOp.
@Test
public void testReadRowsAttemptsPerOp() throws InterruptedException {
final AtomicInteger callCount = new AtomicInteger(0);
doAnswer(new Answer() {
@Override
public Object answer(InvocationOnMock invocation) {
@SuppressWarnings("unchecked") StreamObserver<ReadRowsResponse> observer = (StreamObserver<ReadRowsResponse>) invocation.getArguments()[1];
// First call will trigger a transient error
if (callCount.getAndIncrement() == 0) {
observer.onError(new StatusRuntimeException(Status.UNAVAILABLE));
return null;
}
// Next attempt will return a row
observer.onNext(DEFAULT_READ_ROWS_RESPONSES);
observer.onCompleted();
return null;
}
}).when(mockService).readRows(any(ReadRowsRequest.class), any());
Lists.newArrayList(stub.readRowsCallable().call(Query.create(TABLE_ID)));
// Give OpenCensus a chance to update the views asynchronously.
Thread.sleep(100);
long opLatency = StatsTestUtils.getAggregationValueAsLong(localStats, RpcViewConstants.BIGTABLE_ATTEMPTS_PER_OP_VIEW, ImmutableMap.of(RpcMeasureConstants.BIGTABLE_OP, TagValue.create("Bigtable.ReadRows"), RpcMeasureConstants.BIGTABLE_STATUS, TagValue.create("OK")), PROJECT_ID, INSTANCE_ID, APP_PROFILE_ID);
assertThat(opLatency).isEqualTo(2);
}
use of com.google.cloud.bigquery.storage.v1beta2.ReadRowsResponse 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.bigquery.storage.v1beta2.ReadRowsResponse in project java-bigtable by googleapis.
the class RowMergingCallableTest method invalidMarkerInCell.
@Test
public void invalidMarkerInCell() {
FakeStreamingApi.ServerStreamingStashCallable<ReadRowsRequest, ReadRowsResponse> inner = new ServerStreamingStashCallable<>(Lists.newArrayList(ReadRowsResponse.newBuilder().addChunks(CellChunk.newBuilder().setRowKey(ByteString.copyFromUtf8("key1")).setFamilyName(StringValue.newBuilder().setValue("family")).setQualifier(BytesValue.newBuilder().setValue(ByteString.EMPTY)).setTimestampMicros(1_000).setValue(ByteString.copyFromUtf8("a")).setValueSize(2)).build(), // send a scan marker
ReadRowsResponse.newBuilder().setLastScannedRowKey(ByteString.copyFromUtf8("key1")).build(), // finish the cell & row
ReadRowsResponse.newBuilder().addChunks(CellChunk.newBuilder().setValue(ByteString.copyFromUtf8("b")).setValueSize(0).setCommitRow(true)).build()));
RowMergingCallable<Row> rowMergingCallable = new RowMergingCallable<>(inner, new DefaultRowAdapter());
Throwable actualError = null;
try {
rowMergingCallable.all().call(ReadRowsRequest.getDefaultInstance());
} catch (Throwable t) {
actualError = t;
}
Truth.assertThat(actualError).isInstanceOf(IllegalStateException.class);
}
use of com.google.cloud.bigquery.storage.v1beta2.ReadRowsResponse 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()));
}
use of com.google.cloud.bigquery.storage.v1beta2.ReadRowsResponse in project java-bigtable by googleapis.
the class EmulatorTest method testDataClient.
@Test
public void testDataClient() {
tableAdminStub.createTable(CreateTableRequest.newBuilder().setParent("projects/fake-project/instances/fake-instance").setTableId("fake-table").setTable(Table.newBuilder().putColumnFamilies("cf", ColumnFamily.getDefaultInstance())).build());
dataStub.mutateRow(MutateRowRequest.newBuilder().setTableName("projects/fake-project/instances/fake-instance/tables/fake-table").setRowKey(ByteString.copyFromUtf8("fake-key")).addMutations(Mutation.newBuilder().setSetCell(SetCell.newBuilder().setFamilyName("cf").setColumnQualifier(ByteString.EMPTY).setValue(ByteString.copyFromUtf8("value")))).build());
Iterator<ReadRowsResponse> results = dataStub.readRows(ReadRowsRequest.newBuilder().setTableName("projects/fake-project/instances/fake-instance/tables/fake-table").build());
ReadRowsResponse row = results.next();
assertThat(row.getChunks(0).getValue()).isEqualTo(ByteString.copyFromUtf8("value"));
}
Aggregations