use of com.google.cloud.bigtable.data.v2.models.Query in project java-bigtable by googleapis.
the class BigtableDataClientTests method proxyReadRowsAsyncTest.
@Test
public void proxyReadRowsAsyncTest() {
Mockito.when(mockStub.readRowsCallable()).thenReturn(mockReadRowsCallable);
Query query = Query.create("fake-table");
@SuppressWarnings("unchecked") ResponseObserver<Row> mockObserver = Mockito.mock(ResponseObserver.class);
bigtableDataClient.readRowsAsync(query, mockObserver);
Mockito.verify(mockReadRowsCallable).call(query, mockObserver);
}
use of com.google.cloud.bigtable.data.v2.models.Query in project java-bigtable by googleapis.
the class BulkMutateIT method test.
@Test(timeout = 60 * 1000)
public void test() throws IOException, InterruptedException {
BigtableDataSettings settings = testEnvRule.env().getDataClientSettings();
String rowPrefix = UUID.randomUUID().toString();
// Set target latency really low so it'll trigger adjusting thresholds
BigtableDataSettings.Builder builder = settings.toBuilder().enableBatchMutationLatencyBasedThrottling(2L);
try (BigtableDataClient client = BigtableDataClient.create(builder.build());
BatcherImpl<RowMutationEntry, Void, BulkMutation, Void> batcher = (BatcherImpl<RowMutationEntry, Void, BulkMutation, Void>) client.newBulkMutationBatcher(testEnvRule.env().getTableId())) {
FlowControlEventStats events = batcher.getFlowController().getFlowControlEventStats();
long initialThreashold = Objects.requireNonNull(batcher.getFlowController().getCurrentElementCountLimit());
assertThat(batcher.getFlowController().getCurrentElementCountLimit()).isNotEqualTo(batcher.getFlowController().getMinElementCountLimit());
assertThat(batcher.getFlowController().getCurrentElementCountLimit()).isNotEqualTo(batcher.getFlowController().getMaxElementCountLimit());
String familyId = testEnvRule.env().getFamilyId();
long initial = batcher.getFlowController().getCurrentElementCountLimit();
for (long i = 0; i < initial * 3; i++) {
String key = rowPrefix + "test-key" + i;
batcher.add(RowMutationEntry.create(key).setCell(familyId, "qualifier", i));
}
batcher.flush();
assertThat(events.getLastFlowControlEvent()).isNotNull();
// Verify that the threshold is adjusted
assertThat(batcher.getFlowController().getCurrentElementCountLimit()).isNotEqualTo(initialThreashold);
// Query a key to make sure the write succeeded
Row row = testEnvRule.env().getDataClient().readRowsCallable().first().call(Query.create(testEnvRule.env().getTableId()).rowKey(rowPrefix + "test-key" + initial));
assertThat(row.getCells()).hasSize(1);
}
}
use of com.google.cloud.bigtable.data.v2.models.Query in project java-bigtable by googleapis.
the class ReadIT method read.
@Test
public void read() throws Throwable {
int numRows = 5;
List<Row> expectedRows = Lists.newArrayList();
String uniqueKey = prefix + "-read";
long timestampMicros = System.currentTimeMillis() * 1_000;
for (int i = 0; i < numRows; i++) {
testEnvRule.env().getDataClient().mutateRowCallable().call(RowMutation.create(testEnvRule.env().getTableId(), uniqueKey + "-" + i).setCell(testEnvRule.env().getFamilyId(), "q", timestampMicros, "my-value"));
expectedRows.add(Row.create(ByteString.copyFromUtf8(uniqueKey + "-" + i), ImmutableList.of(RowCell.create(testEnvRule.env().getFamilyId(), ByteString.copyFromUtf8("q"), timestampMicros, ImmutableList.<String>of(), ByteString.copyFromUtf8("my-value")))));
}
String tableId = testEnvRule.env().getTableId();
// Sync
Query query = Query.create(tableId).range(uniqueKey + "-0", uniqueKey + "-" + numRows);
ArrayList<Row> actualResults = Lists.newArrayList(testEnvRule.env().getDataClient().readRows(query));
assertThat(actualResults).containsExactlyElementsIn(expectedRows);
// Async
AccumulatingObserver observer = new AccumulatingObserver();
testEnvRule.env().getDataClient().readRowsAsync(query, observer);
observer.awaitCompletion();
assertThat(observer.responses).containsExactlyElementsIn(expectedRows);
// Point Sync
Row actualRow = testEnvRule.env().getDataClient().readRow(tableId, expectedRows.get(0).getKey());
assertThat(actualRow).isEqualTo(expectedRows.get(0));
// Point Async
ApiFuture<Row> actualRowFuture = testEnvRule.env().getDataClient().readRowAsync(tableId, expectedRows.get(0).getKey());
assertThat(actualRowFuture.get()).isEqualTo(expectedRows.get(0));
}
use of com.google.cloud.bigtable.data.v2.models.Query in project java-bigtable by googleapis.
the class ReadIT method readEmpty.
@Test
public void readEmpty() throws Throwable {
String uniqueKey = prefix + "-readEmpty";
Query query = Query.create(testEnvRule.env().getTableId()).rowKey(uniqueKey);
// Sync
ArrayList<Row> rows = Lists.newArrayList(testEnvRule.env().getDataClient().readRows(query));
assertThat(rows).isEmpty();
// Async
AccumulatingObserver observer = new AccumulatingObserver();
testEnvRule.env().getDataClient().readRowsAsync(query, observer);
observer.awaitCompletion();
assertThat(observer.responses).isEmpty();
}
use of com.google.cloud.bigtable.data.v2.models.Query in project java-bigtable by googleapis.
the class NativeImageBigtableSample method readData.
static void readData(BigtableDataClient client, String tableId) {
Query query = Query.create(tableId).prefix("");
ServerStream<Row> rows = client.readRows(query);
System.out.println("Reading phone data in table:");
for (Row row : rows) {
System.out.println("Key: " + row.getKey().toStringUtf8());
for (RowCell cell : row.getCells()) {
System.out.printf("\t%s: %s @%s\n", cell.getQualifier().toStringUtf8(), cell.getValue().toStringUtf8(), cell.getTimestamp());
}
System.out.println();
}
}
Aggregations