use of com.google.cloud.bigtable.data.v2.models.RowCell in project java-bigtable by googleapis.
the class BigtableDataClientTest method readRowStrFilterTest.
@Test
public void readRowStrFilterTest() {
Mockito.when(mockStub.readRowCallable()).thenReturn(mockReadRowCallable);
// Build the filter expression
Filter filter = FILTERS.chain().filter(FILTERS.qualifier().regex("prefix.*")).filter(FILTERS.limit().cellsPerRow(10));
Row expectedRow = Row.create(ByteString.copyFromUtf8("fake-row-key"), ImmutableList.<RowCell>of());
Mockito.when(mockReadRowCallable.futureCall(Query.create("fake-table").rowKey("fake-row-key").filter(filter))).thenReturn(ApiFutures.immediateFuture(expectedRow));
Row actualRow = bigtableDataClient.readRow("fake-table", "fake-row-key", filter);
assertThat(actualRow).isEqualTo(expectedRow);
}
use of com.google.cloud.bigtable.data.v2.models.RowCell in project java-bigtable by googleapis.
the class BigtableDataClientTest method readModifyWriteRowTest.
@Test
public void readModifyWriteRowTest() {
Mockito.when(mockStub.readModifyWriteRowCallable()).thenReturn(mockReadModifyWriteRowCallable);
Mockito.when(mockReadModifyWriteRowCallable.futureCall(ArgumentMatchers.any(ReadModifyWriteRow.class))).thenReturn(ApiFutures.immediateFuture(Row.create(ByteString.copyFromUtf8("fake-row-key"), Collections.<RowCell>emptyList())));
ReadModifyWriteRow request = ReadModifyWriteRow.create("fake-table", "some-key").append("fake-family", "fake-qualifier", "suffix");
bigtableDataClient.readModifyWriteRow(request);
Mockito.verify(mockReadModifyWriteRowCallable).futureCall(request);
}
use of com.google.cloud.bigtable.data.v2.models.RowCell in project java-bigtable by googleapis.
the class ReadRowsMergingAcceptanceTest method test.
@Test
public void test() throws Exception {
List<ReadRowsResponse> responses = Lists.newArrayList();
// Convert the chunks into a single ReadRowsResponse
for (CellChunk chunk : testCase.getChunksList()) {
ReadRowsResponse.Builder responseBuilder = ReadRowsResponse.newBuilder();
responseBuilder.addChunks(chunk);
responses.add(responseBuilder.build());
}
// Wrap the responses in a callable
ServerStreamingCallable<ReadRowsRequest, ReadRowsResponse> source = new ServerStreamingStashCallable<>(responses);
RowMergingCallable<Row> mergingCallable = new RowMergingCallable<>(source, new DefaultRowAdapter());
// Invoke the callable to get the merged rows
ServerStream<Row> stream = mergingCallable.call(ReadRowsRequest.getDefaultInstance());
// Read all of the rows and transform them into logical cells
List<ReadRowsTest.Result> actualResults = Lists.newArrayList();
Exception error = null;
try {
for (Row row : stream) {
for (RowCell cell : row.getCells()) {
actualResults.add(ReadRowsTest.Result.newBuilder().setRowKeyBytes(row.getKey()).setFamilyName(cell.getFamily()).setQualifierBytes(cell.getQualifier()).setTimestampMicros(cell.getTimestamp()).setValueBytes(cell.getValue()).setLabel(cell.getLabels().isEmpty() ? "" : cell.getLabels().get(0)).build());
}
}
} catch (Exception e) {
error = e;
}
// Verify the results
if (expectsError(testCase)) {
assertThat(error).isNotNull();
} else {
if (error != null) {
throw error;
}
}
assertThat(getNonExceptionResults(testCase)).isEqualTo(actualResults);
}
use of com.google.cloud.bigtable.data.v2.models.RowCell in project java-bigtable by googleapis.
the class RowMergingCallableTest method scanMarker.
@Test
public void scanMarker() {
FakeStreamingApi.ServerStreamingStashCallable<ReadRowsRequest, ReadRowsResponse> inner = new ServerStreamingStashCallable<>(Lists.newArrayList(// send a scan marker
ReadRowsResponse.newBuilder().setLastScannedRowKey(ByteString.copyFromUtf8("key1")).build()));
RowMergingCallable<Row> rowMergingCallable = new RowMergingCallable<>(inner, new DefaultRowAdapter());
List<Row> results = rowMergingCallable.all().call(ReadRowsRequest.getDefaultInstance());
Truth.assertThat(results).containsExactly(Row.create(ByteString.copyFromUtf8("key1"), Lists.<RowCell>newArrayList()));
}
use of com.google.cloud.bigtable.data.v2.models.RowCell in project java-bigtable by googleapis.
the class HelloWorld method readSpecificCells.
/**
* Demonstrates how to access specific cells by family and qualifier.
*/
public List<RowCell> readSpecificCells() {
// [START bigtable_hw_get_by_key]
try {
System.out.println("\nReading specific cells by family and qualifier");
Row row = dataClient.readRow(tableId, ROW_KEY_PREFIX + 0);
System.out.println("Row: " + row.getKey().toStringUtf8());
List<RowCell> cells = row.getCells(COLUMN_FAMILY, COLUMN_QUALIFIER_NAME);
for (RowCell cell : cells) {
System.out.printf("Family: %s Qualifier: %s Value: %s%n", cell.getFamily(), cell.getQualifier().toStringUtf8(), cell.getValue().toStringUtf8());
}
return cells;
} catch (NotFoundException e) {
System.err.println("Failed to read from a non-existent table: " + e.getMessage());
return null;
}
// [END bigtable_hw_get_by_key]
}
Aggregations