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));
}
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));
}
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)?");
}
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);
}
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);
}
Aggregations