Search in sources :

Example 26 with RowMutation

use of com.google.cloud.bigtable.data.v2.models.RowMutation 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)

Example 27 with RowMutation

use of com.google.cloud.bigtable.data.v2.models.RowMutation in project java-bigtable by googleapis.

the class NativeImageBigtableSample method insertData.

public static void insertData(BigtableDataClient client, String tableId, long timestamp, ImmutableMap<String, Long> dataWithLong, ImmutableMap<String, String> dataWithStrings) {
    String rowKey = String.format("phone#%d", timestamp);
    RowMutation rowMutation = RowMutation.create(tableId, rowKey);
    for (Entry<String, Long> longEntry : dataWithLong.entrySet()) {
        rowMutation.setCell(COLUMN_FAMILY_NAME, ByteString.copyFrom(longEntry.getKey().getBytes()), timestamp, longEntry.getValue());
    }
    for (Entry<String, String> stringEntry : dataWithStrings.entrySet()) {
        rowMutation.setCell(COLUMN_FAMILY_NAME, stringEntry.getKey(), timestamp, stringEntry.getValue());
    }
    client.mutateRow(rowMutation);
    System.out.println("Successfully wrote row: " + rowKey);
}
Also used : RowMutation(com.google.cloud.bigtable.data.v2.models.RowMutation) ByteString(com.google.protobuf.ByteString)

Example 28 with RowMutation

use of com.google.cloud.bigtable.data.v2.models.RowMutation in project java-bigtable by googleapis.

the class BigtableDataClientTest method mutateRowTest.

@Test
public void mutateRowTest() {
    Mockito.when(mockStub.mutateRowCallable()).thenReturn(mockMutateRowCallable);
    Mockito.when(mockMutateRowCallable.futureCall(ArgumentMatchers.any(RowMutation.class))).thenAnswer((Answer) invocationOnMock -> ApiFutures.immediateFuture(Empty.getDefaultInstance()));
    RowMutation request = RowMutation.create("fake-table", "some-key").setCell("some-family", "fake-qualifier", "fake-value");
    bigtableDataClient.mutateRow(request);
    Mockito.verify(mockMutateRowCallable).futureCall(request);
}
Also used : Strictness(org.mockito.quality.Strictness) Row(com.google.cloud.bigtable.data.v2.models.Row) ArgumentMatchers(org.mockito.ArgumentMatchers) Mock(org.mockito.Mock) RunWith(org.junit.runner.RunWith) Query(com.google.cloud.bigtable.data.v2.models.Query) RowMutation(com.google.cloud.bigtable.data.v2.models.RowMutation) Empty(com.google.protobuf.Empty) Answer(org.mockito.stubbing.Answer) ImmutableList(com.google.common.collect.ImmutableList) ReadModifyWriteRow(com.google.cloud.bigtable.data.v2.models.ReadModifyWriteRow) MockitoJUnit(org.mockito.junit.MockitoJUnit) ConditionalRowMutation(com.google.cloud.bigtable.data.v2.models.ConditionalRowMutation) Batcher(com.google.api.gax.batching.Batcher) ServerStreamingCallable(com.google.api.gax.rpc.ServerStreamingCallable) Before(org.junit.Before) Answers(org.mockito.Answers) ApiFutures(com.google.api.core.ApiFutures) ResponseObserver(com.google.api.gax.rpc.ResponseObserver) RowMutationEntry(com.google.cloud.bigtable.data.v2.models.RowMutationEntry) RowCell(com.google.cloud.bigtable.data.v2.models.RowCell) Test(org.junit.Test) Mutation(com.google.cloud.bigtable.data.v2.models.Mutation) JUnit4(org.junit.runners.JUnit4) Truth.assertThat(com.google.common.truth.Truth.assertThat) FILTERS(com.google.cloud.bigtable.data.v2.models.Filters.FILTERS) ApiFuture(com.google.api.core.ApiFuture) Filter(com.google.cloud.bigtable.data.v2.models.Filters.Filter) KeyOffset(com.google.cloud.bigtable.data.v2.models.KeyOffset) EnhancedBigtableStub(com.google.cloud.bigtable.data.v2.stub.EnhancedBigtableStub) ByteString(com.google.protobuf.ByteString) UnaryCallable(com.google.api.gax.rpc.UnaryCallable) Mockito(org.mockito.Mockito) List(java.util.List) Rule(org.junit.Rule) BulkMutation(com.google.cloud.bigtable.data.v2.models.BulkMutation) MockitoRule(org.mockito.junit.MockitoRule) Collections(java.util.Collections) RowMutation(com.google.cloud.bigtable.data.v2.models.RowMutation) ConditionalRowMutation(com.google.cloud.bigtable.data.v2.models.ConditionalRowMutation) Test(org.junit.Test)

Aggregations

RowMutation (com.google.cloud.bigtable.data.v2.models.RowMutation)23 ByteString (com.google.protobuf.ByteString)8 Test (org.junit.Test)7 ConditionalRowMutation (com.google.cloud.bigtable.data.v2.models.ConditionalRowMutation)5 RowMutationEntry (com.google.cloud.bigtable.data.v2.models.RowMutationEntry)5 MutateRowRequest (com.google.bigtable.v2.MutateRowRequest)3 ApiFuture (com.google.api.core.ApiFuture)2 UnaryCallable (com.google.api.gax.rpc.UnaryCallable)2 BigtableDataClient (com.google.cloud.bigtable.data.v2.BigtableDataClient)2 ApiFutures (com.google.api.core.ApiFutures)1 Batcher (com.google.api.gax.batching.Batcher)1 BatcherImpl (com.google.api.gax.batching.BatcherImpl)1 BatchingDescriptor (com.google.api.gax.batching.BatchingDescriptor)1 BatchingSettings (com.google.api.gax.batching.BatchingSettings)1 FlowControlSettings (com.google.api.gax.batching.FlowControlSettings)1 NotFoundException (com.google.api.gax.rpc.NotFoundException)1 ResponseObserver (com.google.api.gax.rpc.ResponseObserver)1 ServerStreamingCallable (com.google.api.gax.rpc.ServerStreamingCallable)1 CheckAndMutateRowRequest (com.google.bigtable.v2.CheckAndMutateRowRequest)1 CheckAndMutateRowResponse (com.google.bigtable.v2.CheckAndMutateRowResponse)1