Skip to content

Commit 1fa6f62

Browse files
chore(test): Add test to verify that query ranges work as expected (googleapis#445)
* chore(test): Add test to verify that query ranges work as expected * format
1 parent 8f53b43 commit 1fa6f62

1 file changed

Lines changed: 75 additions & 0 deletions

File tree

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

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

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,14 @@
2323
import com.google.api.core.SettableApiFuture;
2424
import com.google.api.gax.rpc.ResponseObserver;
2525
import com.google.api.gax.rpc.StreamController;
26+
import com.google.cloud.bigtable.data.v2.BigtableDataClient;
27+
import com.google.cloud.bigtable.data.v2.models.BulkMutation;
2628
import com.google.cloud.bigtable.data.v2.models.Query;
29+
import com.google.cloud.bigtable.data.v2.models.Range.ByteStringRange;
2730
import com.google.cloud.bigtable.data.v2.models.Row;
2831
import com.google.cloud.bigtable.data.v2.models.RowCell;
2932
import com.google.cloud.bigtable.data.v2.models.RowMutation;
33+
import com.google.cloud.bigtable.data.v2.models.RowMutationEntry;
3034
import com.google.cloud.bigtable.test_helpers.env.TestEnvRule;
3135
import com.google.common.collect.ImmutableList;
3236
import com.google.common.collect.Lists;
@@ -149,6 +153,77 @@ public void read() throws Throwable {
149153
assertThat(actualRowFuture.get()).isEqualTo(expectedRows.get(0));
150154
}
151155

156+
@Test
157+
public void rangeQueries() {
158+
BigtableDataClient client = testEnvRule.env().getDataClient();
159+
String tableId = testEnvRule.env().getTableId();
160+
String familyId = testEnvRule.env().getFamilyId();
161+
String uniqueKey = prefix + "-range-queries";
162+
String keyA = uniqueKey + "-" + "a";
163+
String keyZ = uniqueKey + "-" + "z";
164+
165+
long timestampMicros = System.currentTimeMillis() * 1_000;
166+
167+
client.bulkMutateRows(
168+
BulkMutation.create(tableId)
169+
.add(RowMutationEntry.create(keyA).setCell(familyId, "", timestampMicros, "A"))
170+
.add(RowMutationEntry.create(keyZ).setCell(familyId, "", timestampMicros, "Z")));
171+
172+
Row expectedRowA =
173+
Row.create(
174+
ByteString.copyFromUtf8(keyA),
175+
ImmutableList.of(
176+
RowCell.create(
177+
testEnvRule.env().getFamilyId(),
178+
ByteString.copyFromUtf8(""),
179+
timestampMicros,
180+
ImmutableList.<String>of(),
181+
ByteString.copyFromUtf8("A"))));
182+
183+
Row expectedRowZ =
184+
Row.create(
185+
ByteString.copyFromUtf8(keyZ),
186+
ImmutableList.of(
187+
RowCell.create(
188+
testEnvRule.env().getFamilyId(),
189+
ByteString.copyFromUtf8(""),
190+
timestampMicros,
191+
ImmutableList.<String>of(),
192+
ByteString.copyFromUtf8("Z"))));
193+
194+
// Closed/Open
195+
assertThat(
196+
ImmutableList.copyOf(
197+
client.readRows(
198+
Query.create(tableId)
199+
.range(ByteStringRange.unbounded().startClosed(keyA).endOpen(keyZ)))))
200+
.containsExactly(expectedRowA);
201+
202+
// Closed/Closed
203+
assertThat(
204+
ImmutableList.copyOf(
205+
client.readRows(
206+
Query.create(tableId)
207+
.range(ByteStringRange.unbounded().startClosed(keyA).endClosed(keyZ)))))
208+
.containsExactly(expectedRowA, expectedRowZ);
209+
210+
// Open/Closed
211+
assertThat(
212+
ImmutableList.copyOf(
213+
client.readRows(
214+
Query.create(tableId)
215+
.range(ByteStringRange.unbounded().startOpen(keyA).endClosed(keyZ)))))
216+
.containsExactly(expectedRowZ);
217+
218+
// Open/Open
219+
assertThat(
220+
ImmutableList.copyOf(
221+
client.readRows(
222+
Query.create(tableId)
223+
.range(ByteStringRange.unbounded().startOpen(keyA).endOpen(keyZ)))))
224+
.isEmpty();
225+
}
226+
152227
@Test
153228
public void readSingleNonexistentAsyncCallback() throws Exception {
154229
ApiFuture<Row> future =

0 commit comments

Comments
 (0)