Search in sources :

Example 6 with RowMutationEntry

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);
}
Also used : RowMutationEntry(com.google.cloud.bigtable.data.v2.models.RowMutationEntry) ArrayList(java.util.ArrayList) ByteString(com.google.protobuf.ByteString) Row(com.google.cloud.bigtable.data.v2.models.Row) BigtableDataClient(com.google.cloud.bigtable.data.v2.BigtableDataClient) Test(org.junit.Test)

Example 7 with RowMutationEntry

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;
}
Also used : Table(com.google.cloud.bigtable.admin.v2.models.Table) Random(java.util.Random) RowMutationEntry(com.google.cloud.bigtable.data.v2.models.RowMutationEntry) ByteString(com.google.protobuf.ByteString)

Example 8 with RowMutationEntry

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;
}
Also used : RowMutationEntry(com.google.cloud.bigtable.data.v2.models.RowMutationEntry)

Example 9 with RowMutationEntry

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);
}
Also used : Delete(org.apache.hadoop.hbase.client.Delete) Append(org.apache.hadoop.hbase.client.Append) RowMutationEntry(com.google.cloud.bigtable.data.v2.models.RowMutationEntry) ReadModifyWriteRow(com.google.cloud.bigtable.data.v2.models.ReadModifyWriteRow) ExecutionException(java.util.concurrent.ExecutionException) Put(org.apache.hadoop.hbase.client.Put) Test(org.junit.Test)

Example 10 with RowMutationEntry

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);
}
Also used : ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) BatchingDescriptor(com.google.api.gax.batching.BatchingDescriptor) RowMutationEntry(com.google.cloud.bigtable.data.v2.models.RowMutationEntry) UnaryCallable(com.google.api.gax.rpc.UnaryCallable) BatcherImpl(com.google.api.gax.batching.BatcherImpl) IOException(java.io.IOException) FlowControlSettings(com.google.api.gax.batching.FlowControlSettings) BatchingSettings(com.google.api.gax.batching.BatchingSettings) BulkMutationWrapper(com.google.cloud.bigtable.hbase.wrappers.BulkMutationWrapper) Test(org.junit.Test)

Aggregations

RowMutationEntry (com.google.cloud.bigtable.data.v2.models.RowMutationEntry)16 Test (org.junit.Test)11 ByteString (com.google.protobuf.ByteString)3 BatcherImpl (com.google.api.gax.batching.BatcherImpl)2 BigtableDataClient (com.google.cloud.bigtable.data.v2.BigtableDataClient)2 BulkMutation (com.google.cloud.bigtable.data.v2.models.BulkMutation)2 MutateRowsException (com.google.cloud.bigtable.data.v2.models.MutateRowsException)2 Row (com.google.cloud.bigtable.data.v2.models.Row)2 BulkMutationWrapper (com.google.cloud.bigtable.hbase.wrappers.BulkMutationWrapper)2 ExecutionException (java.util.concurrent.ExecutionException)2 Put (org.apache.hadoop.hbase.client.Put)2 BatchingDescriptor (com.google.api.gax.batching.BatchingDescriptor)1 BatchingSettings (com.google.api.gax.batching.BatchingSettings)1 FlowControlEventStats (com.google.api.gax.batching.FlowControlEventStats)1 FlowControlSettings (com.google.api.gax.batching.FlowControlSettings)1 GrpcCallContext (com.google.api.gax.grpc.GrpcCallContext)1 DeadlineExceededException (com.google.api.gax.rpc.DeadlineExceededException)1 UnaryCallable (com.google.api.gax.rpc.UnaryCallable)1 UnavailableException (com.google.api.gax.rpc.UnavailableException)1 Table (com.google.cloud.bigtable.admin.v2.models.Table)1