Search in sources :

Example 46 with Row

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

the class BigtableDataClientTests method readRowStrFilterTest.

@Test
public void readRowStrFilterTest() {
    Mockito.when(mockStub.readRowCallable()).thenReturn(mockReadRowCallable);
    // Build the filter expression
    Filter filter = FILTERS.chain().filter(FILTERS.qualifier().regex("prefix.*")).filter(FILTERS.limit().cellsPerRow(10));
    Row expectedRow = Row.create(ByteString.copyFromUtf8("fake-row-key"), ImmutableList.<RowCell>of());
    Mockito.when(mockReadRowCallable.futureCall(Query.create("fake-table").rowKey("fake-row-key").filter(filter))).thenReturn(ApiFutures.immediateFuture(expectedRow));
    Row actualRow = bigtableDataClient.readRow("fake-table", "fake-row-key", filter);
    assertThat(actualRow).isEqualTo(expectedRow);
}
Also used : Filter(com.google.cloud.bigtable.data.v2.models.Filters.Filter) Row(com.google.cloud.bigtable.data.v2.models.Row) ReadModifyWriteRow(com.google.cloud.bigtable.data.v2.models.ReadModifyWriteRow) Test(org.junit.Test)

Example 47 with Row

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

the class BigtableDataClientTests method existsTest.

@Test
public void existsTest() {
    Mockito.when(mockStub.readRowCallable()).thenReturn(mockReadRowCallable);
    Query expectedQuery = Query.create("fake-table").rowKey("fake-row-key").filter(FILTERS.chain().filter(FILTERS.limit().cellsPerRow(1)).filter(FILTERS.value().strip()));
    Row row = Row.create(ByteString.copyFromUtf8("fake-row-key"), ImmutableList.<RowCell>of());
    Mockito.when(mockReadRowCallable.futureCall(expectedQuery)).thenReturn(ApiFutures.immediateFuture(row)).thenReturn(ApiFutures.<Row>immediateFuture(null));
    boolean result = bigtableDataClient.exists("fake-table", "fake-row-key");
    boolean anotherResult = bigtableDataClient.exists("fake-table", ByteString.copyFromUtf8("fake-row-key"));
    assertThat(result).isTrue();
    assertThat(anotherResult).isFalse();
    Mockito.verify(mockReadRowCallable, Mockito.times(2)).futureCall(expectedQuery);
}
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 48 with Row

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

the class BigtableDataClientTests method readRowFilterAsyncTest.

@Test
public void readRowFilterAsyncTest() {
    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", ByteString.copyFromUtf8("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 49 with Row

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

the class BigtableDataClientTests method readRowFilterTest.

@Test
public void readRowFilterTest() {
    Mockito.when(mockStub.readRowCallable()).thenReturn(mockReadRowCallable);
    // Build the filter expression
    Filter filter = FILTERS.chain().filter(FILTERS.qualifier().regex("prefix.*")).filter(FILTERS.limit().cellsPerRow(10));
    Row expectedRow = Row.create(ByteString.copyFromUtf8("fake-row-key"), ImmutableList.<RowCell>of());
    Mockito.when(mockReadRowCallable.futureCall(Query.create("fake-table").rowKey("fake-row-key").filter(filter))).thenReturn(ApiFutures.immediateFuture(expectedRow));
    Row actualRow = bigtableDataClient.readRow("fake-table", ByteString.copyFromUtf8("fake-row-key"), filter);
    assertThat(actualRow).isEqualTo(expectedRow);
}
Also used : Filter(com.google.cloud.bigtable.data.v2.models.Filters.Filter) Row(com.google.cloud.bigtable.data.v2.models.Row) ReadModifyWriteRow(com.google.cloud.bigtable.data.v2.models.ReadModifyWriteRow) Test(org.junit.Test)

Example 50 with Row

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

the class BigtableDataClientTests method proxyNewBulkReadRowsWithFilterTest.

@Test
public void proxyNewBulkReadRowsWithFilterTest() {
    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", FILTERS.key().regex("fake-row"));
    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)

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