use of com.google.cloud.bigtable.data.v2.models.RowCell in project quarkus-google-cloud-services by quarkiverse.
the class BigtableResource method bigtable.
@GET
public String bigtable() throws IOException {
BigtableDataSettings.Builder settings = BigtableDataSettings.newBuilder().setProjectId(projectId).setInstanceId(INSTANCE_ID);
if (authenticated) {
settings.setCredentialsProvider(credentialsProvider);
}
try (BigtableDataClient dataClient = BigtableDataClient.create(settings.build())) {
// create a row
RowMutation rowMutation = RowMutation.create(TABLE_ID, "key1").setCell(COLUMN_FAMILY_ID, "test", "value1");
dataClient.mutateRow(rowMutation);
Row row = dataClient.readRow(TABLE_ID, "key1");
StringBuilder cells = new StringBuilder();
for (RowCell cell : row.getCells()) {
cells.append(String.format("Family: %s Qualifier: %s Value: %s%n", cell.getFamily(), cell.getQualifier().toStringUtf8(), cell.getValue().toStringUtf8()));
}
return cells.toString();
}
}
use of com.google.cloud.bigtable.data.v2.models.RowCell in project java-bigtable by googleapis.
the class BigtableDataClientTest method existsTest.
@Test
public void existsTest() {
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));
boolean result = bigtableDataClient.exists("fake-table", "fake-row-key");
boolean anotherResult = bigtableDataClient.exists("fake-table", ByteString.copyFromUtf8("fake-row-key"));
assertThat(result).isTrue();
assertThat(anotherResult).isFalse();
Mockito.verify(mockReadRowCallable, Mockito.times(2)).futureCall(expectedQuery);
}
Aggregations