|
23 | 23 | import com.google.api.core.SettableApiFuture; |
24 | 24 | import com.google.api.gax.rpc.ResponseObserver; |
25 | 25 | 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; |
26 | 28 | import com.google.cloud.bigtable.data.v2.models.Query; |
| 29 | +import com.google.cloud.bigtable.data.v2.models.Range.ByteStringRange; |
27 | 30 | import com.google.cloud.bigtable.data.v2.models.Row; |
28 | 31 | import com.google.cloud.bigtable.data.v2.models.RowCell; |
29 | 32 | import com.google.cloud.bigtable.data.v2.models.RowMutation; |
| 33 | +import com.google.cloud.bigtable.data.v2.models.RowMutationEntry; |
30 | 34 | import com.google.cloud.bigtable.test_helpers.env.TestEnvRule; |
31 | 35 | import com.google.common.collect.ImmutableList; |
32 | 36 | import com.google.common.collect.Lists; |
@@ -149,6 +153,77 @@ public void read() throws Throwable { |
149 | 153 | assertThat(actualRowFuture.get()).isEqualTo(expectedRows.get(0)); |
150 | 154 | } |
151 | 155 |
|
| 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 | + |
152 | 227 | @Test |
153 | 228 | public void readSingleNonexistentAsyncCallback() throws Exception { |
154 | 229 | ApiFuture<Row> future = |
|
0 commit comments