use of com.google.bigtable.repackaged.com.google.bigtable.v2.ReadRowsRequest in project java-bigtable by googleapis.
the class QueryTest method testFromProto.
@Test
public void testFromProto() {
ReadRowsRequest request = ReadRowsRequest.newBuilder().setTableName(NameUtil.formatTableName(PROJECT_ID, INSTANCE_ID, TABLE_ID)).setAppProfileId(APP_PROFILE_ID).setFilter(RowFilter.newBuilder().setRowKeyRegexFilter(ByteString.copyFromUtf8(".*"))).setRows(RowSet.newBuilder().addRowKeys(ByteString.copyFromUtf8("row-key")).addRowRanges(RowRange.newBuilder().setStartKeyClosed(ByteString.copyFromUtf8("j")).setEndKeyClosed(ByteString.copyFromUtf8("z")))).build();
Query query = Query.fromProto(request);
assertThat(query.toProto(requestContext)).isEqualTo(request);
}
use of com.google.bigtable.repackaged.com.google.bigtable.v2.ReadRowsRequest in project java-bigtable by googleapis.
the class QueryTest method rowKeysTest.
@Test
public void rowKeysTest() {
Query query = Query.create(TABLE_ID).rowKey("simple-string").rowKey(ByteString.copyFromUtf8("byte-string"));
ReadRowsRequest.Builder expectedProto = expectedProtoBuilder();
expectedProto.getRowsBuilder().addRowKeys(ByteString.copyFromUtf8("simple-string")).addRowKeys(ByteString.copyFromUtf8("byte-string"));
ReadRowsRequest actualProto = query.toProto(requestContext);
assertThat(actualProto).isEqualTo(expectedProto.build());
}
use of com.google.bigtable.repackaged.com.google.bigtable.v2.ReadRowsRequest in project java-bigtable by googleapis.
the class QueryTest method testClone.
@Test
public void testClone() {
Query query = Query.create(TABLE_ID).filter(FILTERS.key().regex("temp")).limit(10);
ReadRowsRequest request = ReadRowsRequest.newBuilder().setTableName(NameUtil.formatTableName(PROJECT_ID, INSTANCE_ID, TABLE_ID)).setAppProfileId(APP_PROFILE_ID).setRowsLimit(10).setFilter(RowFilter.newBuilder().setRowKeyRegexFilter(ByteString.copyFromUtf8("temp")).build()).build();
Query clonedReq = query.clone();
assertThat(clonedReq).isEqualTo(query);
assertThat(clonedReq.toProto(requestContext)).isEqualTo(request);
}
use of com.google.bigtable.repackaged.com.google.bigtable.v2.ReadRowsRequest in project java-bigtable by googleapis.
the class QueryTest method requestContextTest.
@Test
public void requestContextTest() {
Query query = Query.create(TABLE_ID);
ReadRowsRequest proto = query.toProto(requestContext);
assertThat(proto).isEqualTo(expectedProtoBuilder().build());
}
use of com.google.bigtable.repackaged.com.google.bigtable.v2.ReadRowsRequest 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);
}
Aggregations