use of com.google.cloud.bigtable.data.v2.models.RowMutationEntry in project java-bigtable by googleapis.
the class RowMutationEntryBatcherIT method testNewBatcher.
@Test
public void testNewBatcher() throws Exception {
BigtableDataClient client = testEnvRule.env().getDataClient();
String tableId = testEnvRule.env().getTableId();
String family = testEnvRule.env().getFamilyId();
String rowPrefix = UUID.randomUUID().toString();
try (Batcher<RowMutationEntry, Void> batcher = client.newBulkMutationBatcher(tableId)) {
for (int i = 0; i < 10; i++) {
batcher.add(RowMutationEntry.create(rowPrefix + "-" + i).setCell(family, "qualifier", 10_000L, "value-" + i));
}
}
List<Row> expectedRows = new ArrayList<>();
for (int i = 0; i < 10; i++) {
expectedRows.add(Row.create(ByteString.copyFromUtf8(rowPrefix + "-" + i), ImmutableList.of(RowCell.create(family, ByteString.copyFromUtf8("qualifier"), 10_000L, ImmutableList.<String>of(), ByteString.copyFromUtf8("value-" + i)))));
}
ServerStream<Row> actualRows = client.readRows(Query.create(tableId).prefix(rowPrefix));
assertThat(actualRows).containsExactlyElementsIn(expectedRows);
}
use of com.google.cloud.bigtable.data.v2.models.RowMutationEntry in project java-bigtable by googleapis.
the class BigtableBackupIT method createAndPopulateTestTable.
private static Table createAndPopulateTestTable(BigtableTableAdminClient tableAdmin, BigtableDataClient dataClient) throws InterruptedException {
String tableId = PrefixGenerator.newPrefix("BigtableBackupIT#createAndPopulateTestTable");
Table testTable = tableAdmin.createTable(CreateTableRequest.of(tableId).addFamily("cf1"));
// Populate test data.
byte[] rowBytes = new byte[1024];
Random random = new Random();
random.nextBytes(rowBytes);
try (Batcher<RowMutationEntry, Void> batcher = dataClient.newBulkMutationBatcher(tableId)) {
for (int i = 0; i < 10; i++) {
batcher.add(RowMutationEntry.create("test-row-" + i).setCell("cf1", ByteString.EMPTY, ByteString.copyFrom(rowBytes)));
}
}
return testTable;
}
use of com.google.cloud.bigtable.data.v2.models.RowMutationEntry in project java-bigtable-hbase by googleapis.
the class HBaseRequestAdapter method adaptEntry.
/**
* adaptEntry.
*
* @param put a {@link Put} object.
* @return a {@link RowMutationEntry} object.
*/
public RowMutationEntry adaptEntry(Put put) {
RowMutationEntry rowMutation = buildRowMutationEntry(put.getRow());
adapt(put, rowMutation);
return rowMutation;
}
use of com.google.cloud.bigtable.data.v2.models.RowMutationEntry in project java-bigtable-hbase by googleapis.
the class TestBigtableAsyncBufferedMutator method testMutateWithList.
@Test
public void testMutateWithList() {
Put put = new Put(Bytes.toBytes("rowKey"));
Delete delete = new Delete(Bytes.toBytes("to-be-deleted-row"));
Append append = new Append(Bytes.toBytes("appended-row"));
RowMutationEntry rowEntryForPut = RowMutationEntry.create("rowKey");
RowMutationEntry rowEntryForDelete = RowMutationEntry.create("to-be-deleted-row");
ReadModifyWriteRow readModifyWriteRow = ReadModifyWriteRow.create(TABLE_ID, "appended-row");
when(mockRequestAdapter.adaptEntry(put)).thenReturn(rowEntryForPut);
when(mockRequestAdapter.adaptEntry(delete)).thenReturn(rowEntryForDelete);
when(mockRequestAdapter.adapt(append)).thenReturn(readModifyWriteRow);
when(mockBulkMutation.add(rowEntryForPut)).thenReturn(ApiFutures.immediateFuture(null));
when(mockBulkMutation.add(rowEntryForDelete)).thenReturn(ApiFutures.immediateFuture(null));
when(mockDataClient.readModifyWriteRowAsync(readModifyWriteRow)).thenReturn(ApiFutures.immediateFuture(Result.EMPTY_RESULT));
asyncBufferedMutator.mutate(Arrays.asList(put, delete, append)).forEach(future -> {
try {
future.get();
} catch (InterruptedException | ExecutionException e) {
throw new AssertionError("BigtableAsyncBufferedMutator#mutate test failed");
}
});
verify(mockRequestAdapter).adaptEntry(put);
verify(mockRequestAdapter).adaptEntry(delete);
verify(mockRequestAdapter).adapt(append);
verify(mockBulkMutation).add(rowEntryForPut);
verify(mockBulkMutation).add(rowEntryForDelete);
verify(mockDataClient).readModifyWriteRowAsync(readModifyWriteRow);
}
use of com.google.cloud.bigtable.data.v2.models.RowMutationEntry in project java-bigtable-hbase by googleapis.
the class TestBulkMutationVeneerApi method testWhenBatcherIsClosed.
@Test
public void testWhenBatcherIsClosed() throws IOException {
BatchingSettings batchingSettings = mock(BatchingSettings.class);
FlowControlSettings flowControlSettings = FlowControlSettings.newBuilder().setLimitExceededBehavior(LimitExceededBehavior.Ignore).build();
when(batchingSettings.getFlowControlSettings()).thenReturn(flowControlSettings);
@SuppressWarnings("unchecked") Batcher<RowMutationEntry, Void> actualBatcher = new BatcherImpl(mock(BatchingDescriptor.class), mock(UnaryCallable.class), new Object(), batchingSettings, mock(ScheduledExecutorService.class));
BulkMutationWrapper underTest = new BulkMutationVeneerApi(actualBatcher);
underTest.close();
Exception actualEx = null;
try {
underTest.add(rowMutation);
fail("batcher should throw exception");
} catch (Exception e) {
actualEx = e;
}
assertTrue(actualEx instanceof IllegalStateException);
}
Aggregations