Search in sources :

Example 6 with Query

use of com.google.cloud.bigtable.data.v2.models.Query in project java-bigtable-hbase by googleapis.

the class TestDataClientVeneerApi method testReadRowsAsync.

@Test
public void testReadRowsAsync() throws Exception {
    Query query = Query.create(TABLE_ID).rowKey(ROW_KEY);
    when(mockDataClient.readRowsCallable(Mockito.<RowResultAdapter>any())).thenReturn(mockStreamingCallable);
    when(mockStreamingCallable.all()).thenReturn(mockUnaryCallable);
    List<Result> expectedResult = ImmutableList.of(Result.EMPTY_RESULT, EXPECTED_RESULT);
    when(mockUnaryCallable.futureCall(Mockito.eq(query), Mockito.any(GrpcCallContext.class))).thenReturn(ApiFutures.immediateFuture(expectedResult));
    List<Result> actualResult = dataClientWrapper.readRowsAsync(query).get();
    assertEquals(expectedResult.size(), actualResult.size());
    assertResult(Result.EMPTY_RESULT, actualResult.get(0));
    assertResult(EXPECTED_RESULT, actualResult.get(1));
    verify(mockDataClient).readRowsCallable(Mockito.<RowResultAdapter>any());
    verify(mockStreamingCallable).all();
    verify(mockUnaryCallable).futureCall(Mockito.eq(query), Mockito.any(GrpcCallContext.class));
}
Also used : GrpcCallContext(com.google.api.gax.grpc.GrpcCallContext) Query(com.google.cloud.bigtable.data.v2.models.Query) Result(org.apache.hadoop.hbase.client.Result) Test(org.junit.Test)

Example 7 with Query

use of com.google.cloud.bigtable.data.v2.models.Query in project java-bigtable-hbase by googleapis.

the class TestDataClientVeneerApi method testReadRowAsync.

@Test
public void testReadRowAsync() throws Exception {
    Query expectedRequest = Query.create(TABLE_ID).rowKey(ROW_KEY).limit(1);
    UnaryCallable<Query, Row> mockCallable = Mockito.mock(UnaryCallable.class);
    when(mockCallable.futureCall(Mockito.eq(expectedRequest), Mockito.any(GrpcCallContext.class))).thenReturn(ApiFutures.immediateFuture(MODEL_ROW));
    when(mockDataClient.readRowCallable()).thenReturn(mockCallable);
    Result actualResult = dataClientWrapper.readRowAsync(TABLE_ID, ROW_KEY, null).get();
    assertResult(EXPECTED_RESULT, actualResult);
    verify(mockCallable).futureCall(Mockito.eq(expectedRequest), Mockito.any(GrpcCallContext.class));
}
Also used : GrpcCallContext(com.google.api.gax.grpc.GrpcCallContext) Query(com.google.cloud.bigtable.data.v2.models.Query) Row(com.google.cloud.bigtable.data.v2.models.Row) ReadModifyWriteRow(com.google.cloud.bigtable.data.v2.models.ReadModifyWriteRow) Result(org.apache.hadoop.hbase.client.Result) Test(org.junit.Test)

Example 8 with Query

use of com.google.cloud.bigtable.data.v2.models.Query 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)?");
}
Also used : Query(com.google.cloud.bigtable.data.v2.models.Query) Metadata(io.grpc.Metadata) Row(com.google.cloud.bigtable.data.v2.models.Row) DefaultRowAdapter(com.google.cloud.bigtable.data.v2.models.DefaultRowAdapter) Test(org.junit.Test)

Example 9 with Query

use of com.google.cloud.bigtable.data.v2.models.Query 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);
}
Also used : Query(com.google.cloud.bigtable.data.v2.models.Query) ReadRowsRequest(com.google.bigtable.v2.ReadRowsRequest) Row(com.google.cloud.bigtable.data.v2.models.Row) DefaultRowAdapter(com.google.cloud.bigtable.data.v2.models.DefaultRowAdapter) Test(org.junit.Test)

Example 10 with Query

use of com.google.cloud.bigtable.data.v2.models.Query in project java-bigtable by googleapis.

the class BigtableDataClientTest method existsAsyncTest.

@Test
public void existsAsyncTest() throws Exception {
    Mockito.when(mockStub.readRowCallable()).thenReturn(mockReadRowCallable);
    Query expectedQuery = Query.create("fake-table").rowKey("fake-row-key").filter(FILTERS.chain().filter(FILTERS.limit().cellsPerRow(1)).filter(FILTERS.value().strip()));
    Row row = Row.create(ByteString.copyFromUtf8("fake-row-key"), ImmutableList.<RowCell>of());
    Mockito.when(mockReadRowCallable.futureCall(expectedQuery)).thenReturn(ApiFutures.immediateFuture(row)).thenReturn(ApiFutures.<Row>immediateFuture(null));
    ApiFuture<Boolean> result = bigtableDataClient.existsAsync("fake-table", ByteString.copyFromUtf8("fake-row-key"));
    assertThat(result.get()).isTrue();
    ApiFuture<Boolean> anotherResult = bigtableDataClient.existsAsync("fake-table", "fake-row-key");
    assertThat(anotherResult.get()).isFalse();
    Mockito.verify(mockReadRowCallable, Mockito.times(2)).futureCall(expectedQuery);
}
Also used : Query(com.google.cloud.bigtable.data.v2.models.Query) Row(com.google.cloud.bigtable.data.v2.models.Row) ReadModifyWriteRow(com.google.cloud.bigtable.data.v2.models.ReadModifyWriteRow) Test(org.junit.Test)

Aggregations

Query (com.google.cloud.bigtable.data.v2.models.Query)34 Row (com.google.cloud.bigtable.data.v2.models.Row)24 Test (org.junit.Test)20 ReadRowsRequest (com.google.bigtable.v2.ReadRowsRequest)7 BigtableDataClient (com.google.cloud.bigtable.data.v2.BigtableDataClient)7 IOException (java.io.IOException)7 ReadModifyWriteRow (com.google.cloud.bigtable.data.v2.models.ReadModifyWriteRow)5 ByteString (com.google.protobuf.ByteString)5 Result (org.apache.hadoop.hbase.client.Result)5 GrpcCallContext (com.google.api.gax.grpc.GrpcCallContext)4 Filters (com.google.cloud.bigtable.data.v2.models.Filters)4 RowCell (com.google.cloud.bigtable.data.v2.models.RowCell)4 DefaultReadHooks (com.google.cloud.bigtable.hbase.adapters.read.DefaultReadHooks)3 ReadHooks (com.google.cloud.bigtable.hbase.adapters.read.ReadHooks)3 SpanName (com.google.api.gax.tracing.SpanName)2 BulkMutation (com.google.cloud.bigtable.data.v2.models.BulkMutation)2 DefaultRowAdapter (com.google.cloud.bigtable.data.v2.models.DefaultRowAdapter)2 ReadRowsUserCallable (com.google.cloud.bigtable.data.v2.stub.readrows.ReadRowsUserCallable)2 ServerStreamingStashCallable (com.google.cloud.bigtable.gaxx.testing.FakeStreamingApi.ServerStreamingStashCallable)2 Scan (org.apache.hadoop.hbase.client.Scan)2