use of com.google.cloud.bigtable.data.v2.models.Query in project java-bigtable-hbase by googleapis.
the class TestBigtableVeneerApi method testGetDataClient.
@Test
public void testGetDataClient() throws Exception {
assertTrue(bigtableApi.getDataClient() instanceof DataClientVeneerApi);
Query query = Query.create(TABLE_ID).rowKey(ROW_KEY);
bigtableApi.getDataClient().readRowsAsync(query);
ReadRowsRequest request = fakeDataService.popLastRequest();
assertEquals(ROW_KEY, request.getRows().getRowKeys(0).toStringUtf8());
}
use of com.google.cloud.bigtable.data.v2.models.Query in project java-bigtable-hbase by googleapis.
the class TestGetAdapter method testAdKeyOnlyFilterWithFilter.
@Test
public void testAdKeyOnlyFilterWithFilter() throws IOException {
Get get = makeValidGet(dataHelper.randomData(PREFIX_DATA));
get.setCheckExistenceOnly(true);
get.setFilter(new KeyOnlyFilter());
getAdapter.adapt(get, throwingReadHooks, query);
Filters.Filter filterOne = FILTERS.chain().filter(FILTERS.limit().cellsPerColumn(1)).filter(FILTERS.value().strip());
Filters.Filter filterTwo = FILTERS.chain().filter(FILTERS.limit().cellsPerColumn(1)).filter(FILTERS.value().strip());
Assert.assertEquals(FILTERS.chain().filter(filterOne).filter(filterTwo).toProto(), query.toProto(requestContext).getFilter());
}
use of com.google.cloud.bigtable.data.v2.models.Query in project java-bigtable-hbase by googleapis.
the class BigtableAsyncTable method scan.
/**
* {@inheritDoc}
*/
public void scan(Scan scan, final ScanResultConsumer consumer) {
if (AbstractBigtableTable.hasWhileMatchFilter(scan.getFilter())) {
throw new UnsupportedOperationException("scan with consumer and while match filter is not allowed");
}
Query query = hbaseAdapter.adapt(scan);
clientWrapper.readRowsAsync(query, new StreamObserver<Result>() {
@Override
public void onNext(Result value) {
consumer.onNext(value);
}
@Override
public void onError(Throwable t) {
consumer.onError(t);
}
@Override
public void onCompleted() {
consumer.onComplete();
}
});
}
use of com.google.cloud.bigtable.data.v2.models.Query in project java-bigtable-hbase by googleapis.
the class TestDataClientVeneerApi method testReadRows.
@Test
public void testReadRows() throws IOException {
Query query = Query.create(TABLE_ID).rowKey(ROW_KEY);
when(mockDataClient.readRowsCallable(Mockito.<RowResultAdapter>any())).thenReturn(mockStreamingCallable).thenReturn(mockStreamingCallable);
when(serverStream.iterator()).thenReturn(ImmutableList.of(Result.EMPTY_RESULT, EXPECTED_RESULT, EXPECTED_RESULT).iterator()).thenReturn(ImmutableList.<Result>of().iterator());
when(mockStreamingCallable.call(Mockito.eq(query), Mockito.any(GrpcCallContext.class))).thenReturn(serverStream).thenReturn(serverStream);
ResultScanner resultScanner = dataClientWrapper.readRows(query);
assertResult(Result.EMPTY_RESULT, resultScanner.next());
assertResult(EXPECTED_RESULT, resultScanner.next());
doNothing().when(serverStream).cancel();
resultScanner.close();
ResultScanner noRowsResultScanner = dataClientWrapper.readRows(query);
assertNull(noRowsResultScanner.next());
verify(serverStream).cancel();
verify(mockDataClient, times(2)).readRowsCallable(Mockito.<RowResultAdapter>any());
verify(serverStream, times(2)).iterator();
verify(mockStreamingCallable, times(2)).call(Mockito.eq(query), Mockito.any(GrpcCallContext.class));
}
use of com.google.cloud.bigtable.data.v2.models.Query in project java-bigtable by googleapis.
the class ReadRowsUserCallableTest method testFirstIsLimited.
@Test
public void testFirstIsLimited() {
ServerStreamingStashCallable<ReadRowsRequest, Row> innerCallable = new ServerStreamingStashCallable<>();
ReadRowsUserCallable<Row> callable = new ReadRowsUserCallable<>(innerCallable, REQUEST_CONTEXT);
Query query = Query.create("fake-table");
callable.first().call(query);
Truth.assertThat(innerCallable.getActualRequest()).isEqualTo(query.limit(1).toProto(REQUEST_CONTEXT));
}
Aggregations