Skip to content

Commit f7d3506

Browse files
authored
test(bigtable): add integration tests for single-row reads (#14399)
## Summary - **ReadIT**: adds three single-row read tests covering: - `readSingleRowWithReadRow` — `readRow(tableId, rowKey)` API - `readSingleRowWithRowKeyQuery` — `readRows(Query.rowKey(key))` - `readSingleRowWithRowRangeQuery` — `readRows(Query.range(closed/closed same key))` - Each test writes a row and asserts the exact key, family, qualifier, timestamp, and value returned ## Test plan - [ ] All three `ReadIT` single-row tests passed locally (`Tests run: 3, Failures: 0, Errors: 0`)
1 parent daa659b commit f7d3506

1 file changed

Lines changed: 58 additions & 0 deletions

File tree

  • java-bigtable/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/it

‎java-bigtable/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/it/ReadIT.java‎

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -823,6 +823,64 @@ public void onSuccess(Row result) {
823823
assertThat(found.get()).isTrue();
824824
}
825825

826+
@Test
827+
public void readSingleRowWithReadRow() throws Exception {
828+
String rowKey = prefix + "-readSingleRowWithReadRow";
829+
TableId tableId = testEnvRule.env().getTableId();
830+
Row expectedRow = writeTestRowAndBuildExpected(tableId, rowKey);
831+
832+
Row row = testEnvRule.env().getDataClient().readRow(tableId, rowKey);
833+
assertThat(row).isEqualTo(expectedRow);
834+
}
835+
836+
@Test
837+
public void readSingleRowWithRowKeyQuery() throws Exception {
838+
String rowKey = prefix + "-readSingleRowWithRowKeyQuery";
839+
TableId tableId = testEnvRule.env().getTableId();
840+
Row expectedRow = writeTestRowAndBuildExpected(tableId, rowKey);
841+
842+
List<Row> rows =
843+
Lists.newArrayList(
844+
testEnvRule.env().getDataClient().readRows(Query.create(tableId).rowKey(rowKey)));
845+
assertThat(rows).containsExactly(expectedRow);
846+
}
847+
848+
@Test
849+
public void readSingleRowWithRowRangeQuery() throws Exception {
850+
String rowKey = prefix + "-readSingleRowWithRowRangeQuery";
851+
TableId tableId = testEnvRule.env().getTableId();
852+
Row expectedRow = writeTestRowAndBuildExpected(tableId, rowKey);
853+
854+
List<Row> rows =
855+
Lists.newArrayList(
856+
testEnvRule
857+
.env()
858+
.getDataClient()
859+
.readRows(
860+
Query.create(tableId)
861+
.range(ByteStringRange.unbounded().startClosed(rowKey).endClosed(rowKey))));
862+
assertThat(rows).containsExactly(expectedRow);
863+
}
864+
865+
private Row writeTestRowAndBuildExpected(TableId tableId, String rowKey) {
866+
String familyId = testEnvRule.env().getFamilyId();
867+
long timestampMicros = System.currentTimeMillis() * 1_000;
868+
testEnvRule
869+
.env()
870+
.getDataClient()
871+
.mutateRow(
872+
RowMutation.create(tableId, rowKey).setCell(familyId, "q", timestampMicros, "value"));
873+
return Row.create(
874+
ByteString.copyFromUtf8(rowKey),
875+
ImmutableList.of(
876+
RowCell.create(
877+
familyId,
878+
ByteString.copyFromUtf8("q"),
879+
timestampMicros,
880+
ImmutableList.of(),
881+
ByteString.copyFromUtf8("value"))));
882+
}
883+
826884
static class AccumulatingObserver implements ResponseObserver<Row> {
827885

828886
final List<Row> responses = Lists.newArrayList();

0 commit comments

Comments
 (0)