use of com.google.cloud.bigtable.data.v2.models.Row in project java-bigtable by googleapis.
the class CheckAndMutateIT method test.
@Test
public void test() throws Exception {
String tableId = testEnvRule.env().getTableId();
String familyId = testEnvRule.env().getFamilyId();
String rowKey = UUID.randomUUID().toString();
testEnvRule.env().getDataClient().mutateRowCallable().call(RowMutation.create(tableId, rowKey).setCell(familyId, "q1", "val1").setCell(familyId, "q2", "val2"));
testEnvRule.env().getDataClient().checkAndMutateRowAsync(ConditionalRowMutation.create(tableId, rowKey).condition(FILTERS.qualifier().exactMatch("q1")).then(Mutation.create().setCell(familyId, "q3", "q1"))).get(1, TimeUnit.MINUTES);
Row row = testEnvRule.env().getDataClient().readRowsCallable().first().call(Query.create(tableId).rowKey(rowKey));
assertThat(row.getCells()).hasSize(3);
assertThat(row.getCells().get(2).getValue()).isEqualTo(ByteString.copyFromUtf8("q1"));
}
use of com.google.cloud.bigtable.data.v2.models.Row in project java-bigtable by googleapis.
the class LargeRowIT method testWriteRead.
@Test
public void testWriteRead() throws Exception {
String rowKey = UUID.randomUUID().toString();
String familyId = testEnvRule.env().getFamilyId();
byte[] largeValueBytes = new byte[100 * 1024 * 1024];
Random random = new Random();
random.nextBytes(largeValueBytes);
ByteString largeValue = ByteString.copyFrom(largeValueBytes);
// Create a 200 MB row
logger.info("Sending large row, this will take awhile");
for (int i = 0; i < 2; i++) {
testEnvRule.env().getDataClient().mutateRowAsync(RowMutation.create(testEnvRule.env().getTableId(), rowKey).setCell(familyId, ByteString.copyFromUtf8("q" + i), largeValue)).get(10, TimeUnit.MINUTES);
}
logger.info("Reading large row, this will take awhile");
// Read it back
Row row = testEnvRule.env().getDataClient().readRowsCallable().first().call(Query.create(testEnvRule.env().getTableId()).rowKey(rowKey));
assertThat(row.getCells()).hasSize(2);
assertThat(row.getCells().get(0).getValue()).isEqualTo(largeValue);
assertThat(row.getCells().get(1).getValue()).isEqualTo(largeValue);
}
use of com.google.cloud.bigtable.data.v2.models.Row in project java-bigtable by googleapis.
the class ReadIT method read.
@Test
public void read() throws Throwable {
int numRows = 5;
List<Row> expectedRows = Lists.newArrayList();
String uniqueKey = prefix + "-read";
long timestampMicros = System.currentTimeMillis() * 1_000;
for (int i = 0; i < numRows; i++) {
testEnvRule.env().getDataClient().mutateRowCallable().call(RowMutation.create(testEnvRule.env().getTableId(), uniqueKey + "-" + i).setCell(testEnvRule.env().getFamilyId(), "q", timestampMicros, "my-value"));
expectedRows.add(Row.create(ByteString.copyFromUtf8(uniqueKey + "-" + i), ImmutableList.of(RowCell.create(testEnvRule.env().getFamilyId(), ByteString.copyFromUtf8("q"), timestampMicros, ImmutableList.<String>of(), ByteString.copyFromUtf8("my-value")))));
}
String tableId = testEnvRule.env().getTableId();
// Sync
Query query = Query.create(tableId).range(uniqueKey + "-0", uniqueKey + "-" + numRows);
ArrayList<Row> actualResults = Lists.newArrayList(testEnvRule.env().getDataClient().readRows(query));
assertThat(actualResults).containsExactlyElementsIn(expectedRows);
// Async
AccumulatingObserver observer = new AccumulatingObserver();
testEnvRule.env().getDataClient().readRowsAsync(query, observer);
observer.awaitCompletion();
assertThat(observer.responses).containsExactlyElementsIn(expectedRows);
// Point Sync
Row actualRow = testEnvRule.env().getDataClient().readRow(tableId, expectedRows.get(0).getKey());
assertThat(actualRow).isEqualTo(expectedRows.get(0));
// Point Async
ApiFuture<Row> actualRowFuture = testEnvRule.env().getDataClient().readRowAsync(tableId, expectedRows.get(0).getKey());
assertThat(actualRowFuture.get()).isEqualTo(expectedRows.get(0));
}
use of com.google.cloud.bigtable.data.v2.models.Row in project java-bigtable by googleapis.
the class ReadIT method readSingleNonexistentAsyncCallback.
@Test
public void readSingleNonexistentAsyncCallback() throws Exception {
ApiFuture<Row> future = testEnvRule.env().getDataClient().readRowAsync(testEnvRule.env().getTableId(), "somenonexistentkey");
final AtomicReference<Throwable> unexpectedError = new AtomicReference<>();
final AtomicBoolean found = new AtomicBoolean();
final CountDownLatch latch = new CountDownLatch(1);
ApiFutures.addCallback(future, new ApiFutureCallback<Row>() {
@Override
public void onFailure(Throwable t) {
unexpectedError.set(t);
latch.countDown();
}
@Override
public void onSuccess(Row result) {
found.set(true);
latch.countDown();
}
}, MoreExecutors.directExecutor());
latch.await(1, TimeUnit.MINUTES);
if (unexpectedError.get() != null) {
throw new RuntimeException("Unexpected async error", unexpectedError.get());
}
assertThat(found.get()).isTrue();
}
use of com.google.cloud.bigtable.data.v2.models.Row in project java-bigtable by googleapis.
the class ReadIT method readEmpty.
@Test
public void readEmpty() throws Throwable {
String uniqueKey = prefix + "-readEmpty";
Query query = Query.create(testEnvRule.env().getTableId()).rowKey(uniqueKey);
// Sync
ArrayList<Row> rows = Lists.newArrayList(testEnvRule.env().getDataClient().readRows(query));
assertThat(rows).isEmpty();
// Async
AccumulatingObserver observer = new AccumulatingObserver();
testEnvRule.env().getDataClient().readRowsAsync(query, observer);
observer.awaitCompletion();
assertThat(observer.responses).isEmpty();
}
Aggregations