Search in sources :

Example 76 with Row

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

the class BigtableDataClientTests method readModifyWriteRowTest.

@Test
public void readModifyWriteRowTest() {
    Mockito.when(mockStub.readModifyWriteRowCallable()).thenReturn(mockReadModifyWriteRowCallable);
    Mockito.when(mockReadModifyWriteRowCallable.futureCall(ArgumentMatchers.any(ReadModifyWriteRow.class))).thenReturn(ApiFutures.immediateFuture(Row.create(ByteString.copyFromUtf8("fake-row-key"), Collections.<RowCell>emptyList())));
    ReadModifyWriteRow request = ReadModifyWriteRow.create("fake-table", "some-key").append("fake-family", "fake-qualifier", "suffix");
    bigtableDataClient.readModifyWriteRow(request);
    Mockito.verify(mockReadModifyWriteRowCallable).futureCall(request);
}
Also used : ReadModifyWriteRow(com.google.cloud.bigtable.data.v2.models.ReadModifyWriteRow) Test(org.junit.Test)

Example 77 with Row

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

the class BigtableDataClientTests method proxyReadRowsAsyncTest.

@Test
public void proxyReadRowsAsyncTest() {
    Mockito.when(mockStub.readRowsCallable()).thenReturn(mockReadRowsCallable);
    Query query = Query.create("fake-table");
    @SuppressWarnings("unchecked") ResponseObserver<Row> mockObserver = Mockito.mock(ResponseObserver.class);
    bigtableDataClient.readRowsAsync(query, mockObserver);
    Mockito.verify(mockReadRowsCallable).call(query, mockObserver);
}
Also used : Query(com.google.cloud.bigtable.data.v2.models.Query) Row(com.google.cloud.bigtable.data.v2.models.Row) ReadModifyWriteRow(com.google.cloud.bigtable.data.v2.models.ReadModifyWriteRow) Test(org.junit.Test)

Example 78 with Row

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

the class BigtableDataClientTests method readRowFilterStrAsyncTest.

@Test
public void readRowFilterStrAsyncTest() {
    Mockito.when(mockStub.readRowCallable()).thenReturn(mockReadRowCallable);
    // Build the filter expression
    Filter filter = FILTERS.chain().filter(FILTERS.qualifier().regex("prefix.*")).filter(FILTERS.limit().cellsPerRow(10));
    bigtableDataClient.readRowAsync("fake-table", "fake-row-key", filter);
    Mockito.verify(mockReadRowCallable).futureCall(Query.create("fake-table").rowKey("fake-row-key").filter(filter));
}
Also used : Filter(com.google.cloud.bigtable.data.v2.models.Filters.Filter) Test(org.junit.Test)

Example 79 with Row

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

the class BigtableDataClientTests method proxyNewBulkReadRowsTest.

@Test
public void proxyNewBulkReadRowsTest() {
    Mockito.when(mockStub.newBulkReadRowsBatcher(Mockito.any(Query.class), Mockito.any())).thenReturn(mockBulkReadRowsBatcher);
    ApiFuture<Row> expectedResponse = ApiFutures.immediateFuture(Row.create(ByteString.copyFromUtf8("fake-row-key"), Collections.<RowCell>emptyList()));
    ByteString request = ByteString.copyFromUtf8("fake-row-key");
    Batcher<ByteString, Row> batcher = bigtableDataClient.newBulkReadRowsBatcher("fake-table");
    Mockito.when(mockBulkReadRowsBatcher.add(request)).thenReturn(expectedResponse);
    ApiFuture<Row> actualResponse = batcher.add(request);
    assertThat(actualResponse).isSameInstanceAs(expectedResponse);
    Mockito.verify(mockStub).newBulkReadRowsBatcher(Mockito.any(Query.class), Mockito.any());
}
Also used : Query(com.google.cloud.bigtable.data.v2.models.Query) ByteString(com.google.protobuf.ByteString) RowCell(com.google.cloud.bigtable.data.v2.models.RowCell) Row(com.google.cloud.bigtable.data.v2.models.Row) ReadModifyWriteRow(com.google.cloud.bigtable.data.v2.models.ReadModifyWriteRow) Test(org.junit.Test)

Example 80 with Row

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

the class BulkMutateIT method test.

@Test(timeout = 60 * 1000)
public void test() throws IOException, InterruptedException {
    BigtableDataSettings settings = testEnvRule.env().getDataClientSettings();
    String rowPrefix = UUID.randomUUID().toString();
    // Set target latency really low so it'll trigger adjusting thresholds
    BigtableDataSettings.Builder builder = settings.toBuilder().enableBatchMutationLatencyBasedThrottling(2L);
    try (BigtableDataClient client = BigtableDataClient.create(builder.build());
        BatcherImpl<RowMutationEntry, Void, BulkMutation, Void> batcher = (BatcherImpl<RowMutationEntry, Void, BulkMutation, Void>) client.newBulkMutationBatcher(testEnvRule.env().getTableId())) {
        FlowControlEventStats events = batcher.getFlowController().getFlowControlEventStats();
        long initialThreashold = Objects.requireNonNull(batcher.getFlowController().getCurrentElementCountLimit());
        assertThat(batcher.getFlowController().getCurrentElementCountLimit()).isNotEqualTo(batcher.getFlowController().getMinElementCountLimit());
        assertThat(batcher.getFlowController().getCurrentElementCountLimit()).isNotEqualTo(batcher.getFlowController().getMaxElementCountLimit());
        String familyId = testEnvRule.env().getFamilyId();
        long initial = batcher.getFlowController().getCurrentElementCountLimit();
        for (long i = 0; i < initial * 3; i++) {
            String key = rowPrefix + "test-key" + i;
            batcher.add(RowMutationEntry.create(key).setCell(familyId, "qualifier", i));
        }
        batcher.flush();
        assertThat(events.getLastFlowControlEvent()).isNotNull();
        // Verify that the threshold is adjusted
        assertThat(batcher.getFlowController().getCurrentElementCountLimit()).isNotEqualTo(initialThreashold);
        // Query a key to make sure the write succeeded
        Row row = testEnvRule.env().getDataClient().readRowsCallable().first().call(Query.create(testEnvRule.env().getTableId()).rowKey(rowPrefix + "test-key" + initial));
        assertThat(row.getCells()).hasSize(1);
    }
}
Also used : BulkMutation(com.google.cloud.bigtable.data.v2.models.BulkMutation) FlowControlEventStats(com.google.api.gax.batching.FlowControlEventStats) RowMutationEntry(com.google.cloud.bigtable.data.v2.models.RowMutationEntry) Row(com.google.cloud.bigtable.data.v2.models.Row) BigtableDataClient(com.google.cloud.bigtable.data.v2.BigtableDataClient) BatcherImpl(com.google.api.gax.batching.BatcherImpl) BigtableDataSettings(com.google.cloud.bigtable.data.v2.BigtableDataSettings) Test(org.junit.Test)

Aggregations

Row (com.google.cloud.bigtable.data.v2.models.Row)71 Test (org.junit.Test)64 Query (com.google.cloud.bigtable.data.v2.models.Query)34 ByteString (com.google.protobuf.ByteString)28 ReadModifyWriteRow (com.google.cloud.bigtable.data.v2.models.ReadModifyWriteRow)26 BigtableDataClient (com.google.cloud.bigtable.data.v2.BigtableDataClient)19 RowCell (com.google.cloud.bigtable.data.v2.models.RowCell)19 ReadRowsRequest (com.google.bigtable.v2.ReadRowsRequest)13 Filter (com.google.cloud.bigtable.data.v2.models.Filters.Filter)11 IOException (java.io.IOException)10 RowMutation (com.google.cloud.bigtable.data.v2.models.RowMutation)9 ServerStreamingStashCallable (com.google.cloud.bigtable.gaxx.testing.FakeStreamingApi.ServerStreamingStashCallable)7 Put (org.apache.hadoop.hbase.client.Put)7 DefaultRowAdapter (com.google.cloud.bigtable.data.v2.models.DefaultRowAdapter)6 MutateRowRequest (com.google.bigtable.v2.MutateRowRequest)5 Mutation (com.google.bigtable.v2.Mutation)5 SetCell (com.google.bigtable.v2.Mutation.SetCell)5 NotFoundException (com.google.api.gax.rpc.NotFoundException)4 ReadRowsResponse (com.google.bigtable.v2.ReadRowsResponse)4 ConditionalRowMutation (com.google.cloud.bigtable.data.v2.models.ConditionalRowMutation)4