Search in sources :

Example 36 with ReadRowsResponse

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"));
}
Also used : ReadRowsResponse(com.google.bigtable.v2.ReadRowsResponse) Test(org.junit.Test)

Example 37 with ReadRowsResponse

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);
    }
}
Also used : StreamObserver(io.grpc.stub.StreamObserver) Mockito.doAnswer(org.mockito.Mockito.doAnswer) Answer(org.mockito.stubbing.Answer) ReadRowsResponse(com.google.bigtable.v2.ReadRowsResponse) Batcher(com.google.api.gax.batching.Batcher) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ReadRowsRequest(com.google.bigtable.v2.ReadRowsRequest) Test(org.junit.Test)

Example 38 with ReadRowsResponse

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));
}
Also used : StreamObserver(io.grpc.stub.StreamObserver) Mockito.doAnswer(org.mockito.Mockito.doAnswer) Answer(org.mockito.stubbing.Answer) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ReadRowsResponse(com.google.bigtable.v2.ReadRowsResponse) InvocationOnMock(org.mockito.invocation.InvocationOnMock) StatusRuntimeException(io.grpc.StatusRuntimeException) Stopwatch(com.google.common.base.Stopwatch) ReadRowsRequest(com.google.bigtable.v2.ReadRowsRequest) Test(org.junit.Test)

Example 39 with ReadRowsResponse

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);
}
Also used : StreamObserver(io.grpc.stub.StreamObserver) Mockito.doAnswer(org.mockito.Mockito.doAnswer) Answer(org.mockito.stubbing.Answer) ReadRowsResponse(com.google.bigtable.v2.ReadRowsResponse) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ReadRowsRequest(com.google.bigtable.v2.ReadRowsRequest) Test(org.junit.Test)

Example 40 with ReadRowsResponse

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");
    }
}
Also used : ReadRowsResponse(com.google.bigtable.v2.ReadRowsResponse) LogRecord(java.util.logging.LogRecord) StatusRuntimeException(io.grpc.StatusRuntimeException) ReadRowsRequest(com.google.bigtable.v2.ReadRowsRequest) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)44 ReadRowsResponse (com.google.cloud.bigquery.storage.v1.ReadRowsResponse)40 ReadRowsRequest (com.google.cloud.bigquery.storage.v1.ReadRowsRequest)25 ReadRowsResponse (com.google.bigtable.v2.ReadRowsResponse)19 ReadSession (com.google.cloud.bigquery.storage.v1.ReadSession)17 StorageClient (org.apache.beam.sdk.io.gcp.bigquery.BigQueryServices.StorageClient)17 FakeBigQueryServices (org.apache.beam.sdk.io.gcp.testing.FakeBigQueryServices)17 ReadRowsRequest (com.google.bigtable.v2.ReadRowsRequest)15 TableRow (com.google.api.services.bigquery.model.TableRow)14 TableRowParser (org.apache.beam.sdk.io.gcp.bigquery.BigQueryIO.TableRowParser)13 ReadRowsResponse (com.google.cloud.bigquery.storage.v1beta2.ReadRowsResponse)11 ReadRowsRequest (com.google.cloud.bigquery.storage.v1beta2.ReadRowsRequest)10 ByteString (com.google.protobuf.ByteString)10 CreateReadSessionRequest (com.google.cloud.bigquery.storage.v1.CreateReadSessionRequest)8 GenericRecord (org.apache.avro.generic.GenericRecord)7 StatusRuntimeException (io.grpc.StatusRuntimeException)6 ReadSession (com.google.cloud.bigquery.storage.v1beta2.ReadSession)5 StreamObserver (io.grpc.stub.StreamObserver)5 Mockito.doAnswer (org.mockito.Mockito.doAnswer)5 InvocationOnMock (org.mockito.invocation.InvocationOnMock)5