use of com.google.cloud.bigquery.storage.v1beta2.ReadRowsResponse in project java-bigtable by googleapis.
the class ITBigtableEmulatorRuleTest method testDataClient.
@Test
public void testDataClient() throws Exception {
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"));
}
use of com.google.cloud.bigquery.storage.v1beta2.ReadRowsResponse in project java-bigtable by googleapis.
the class MetricsTracerTest method testBatchReadRowsThrottledTime.
@Test
public void testBatchReadRowsThrottledTime() throws Exception {
doAnswer(new Answer() {
@Override
public Object answer(InvocationOnMock invocation) {
@SuppressWarnings("unchecked") StreamObserver<ReadRowsResponse> observer = (StreamObserver<ReadRowsResponse>) invocation.getArguments()[1];
observer.onNext(DEFAULT_READ_ROWS_RESPONSES);
observer.onCompleted();
return null;
}
}).when(mockService).readRows(any(ReadRowsRequest.class), any());
try (Batcher batcher = stub.newBulkReadRowsBatcher(Query.create(TABLE_ID), GrpcCallContext.createDefault())) {
batcher.add(ByteString.copyFromUtf8("row1"));
batcher.sendOutstanding();
// Give OpenCensus a chance to update the views asynchronously.
Thread.sleep(100);
long throttledTimeMetric = StatsTestUtils.getAggregationValueAsLong(localStats, RpcViewConstants.BIGTABLE_BATCH_THROTTLED_TIME_VIEW, ImmutableMap.of(RpcMeasureConstants.BIGTABLE_OP, TagValue.create("Bigtable.ReadRows")), PROJECT_ID, INSTANCE_ID, APP_PROFILE_ID);
assertThat(throttledTimeMetric).isEqualTo(0);
}
}
use of com.google.cloud.bigquery.storage.v1beta2.ReadRowsResponse in project java-bigtable by googleapis.
the class MetricsTracerTest method testReadRowsAttemptLatency.
@Test
public void testReadRowsAttemptLatency() throws InterruptedException {
final long sleepTime = 50;
final AtomicInteger callCount = new AtomicInteger(0);
doAnswer(new Answer() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
@SuppressWarnings("unchecked") StreamObserver<ReadRowsResponse> observer = (StreamObserver<ReadRowsResponse>) invocation.getArguments()[1];
Thread.sleep(sleepTime);
// First attempt will return a transient error
if (callCount.getAndIncrement() == 0) {
observer.onError(new StatusRuntimeException(Status.UNAVAILABLE));
return null;
}
// Next attempt will be ok
observer.onNext(DEFAULT_READ_ROWS_RESPONSES);
observer.onCompleted();
return null;
}
}).when(mockService).readRows(any(ReadRowsRequest.class), any());
Stopwatch stopwatch = Stopwatch.createStarted();
Lists.newArrayList(stub.readRowsCallable().call(Query.create(TABLE_ID)));
long elapsed = stopwatch.elapsed(TimeUnit.MILLISECONDS);
// Give OpenCensus a chance to update the views asynchronously.
Thread.sleep(100);
long attemptLatency = StatsTestUtils.getAggregationValueAsLong(localStats, RpcViewConstants.BIGTABLE_ATTEMPT_LATENCY_VIEW, ImmutableMap.of(RpcMeasureConstants.BIGTABLE_OP, TagValue.create("Bigtable.ReadRows"), RpcMeasureConstants.BIGTABLE_STATUS, TagValue.create("OK")), PROJECT_ID, INSTANCE_ID, APP_PROFILE_ID);
// Average attempt latency will be just a single wait (as opposed to op latency which will be 2x
// sleeptime)
assertThat(attemptLatency).isIn(Range.closed(sleepTime, elapsed - sleepTime));
}
use of com.google.cloud.bigquery.storage.v1beta2.ReadRowsResponse in project java-bigtable by googleapis.
the class MetricsTracerTest method testReadRowsOpCount.
@Test
public void testReadRowsOpCount() throws InterruptedException {
doAnswer(new Answer() {
@Override
public Object answer(InvocationOnMock invocation) {
@SuppressWarnings("unchecked") StreamObserver<ReadRowsResponse> observer = (StreamObserver<ReadRowsResponse>) invocation.getArguments()[1];
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)));
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_COMPLETED_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 BigtableChannelPrimerTest method testErrorsAreLogged.
@Test
public void testErrorsAreLogged() {
fakeService.readRowsCallback = new ApiFunction<ReadRowsRequest, ReadRowsResponse>() {
@Override
public ReadRowsResponse apply(ReadRowsRequest req) {
throw new StatusRuntimeException(Status.FAILED_PRECONDITION);
}
};
primer.primeChannel(channel);
assertThat(logHandler.logs).hasSize(2);
for (LogRecord log : logHandler.logs) {
assertThat(log.getMessage()).contains("FAILED_PRECONDITION");
}
}
Aggregations