Search in sources :

Example 6 with RowCell

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

the class BigtableDataClientTest 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 7 with RowCell

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

the class BigtableDataClientTest 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 8 with RowCell

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

the class BigtableDataClientTest 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 9 with RowCell

use of com.google.cloud.bigtable.data.v2.models.RowCell in project testcontainers-java by testcontainers.

the class BigtableEmulatorContainerTest method testSimple.

// }
@Test
public // testWithEmulatorContainer {
void testSimple() throws IOException, InterruptedException, ExecutionException {
    ManagedChannel channel = ManagedChannelBuilder.forTarget(emulator.getEmulatorEndpoint()).usePlaintext().build();
    TransportChannelProvider channelProvider = FixedTransportChannelProvider.create(GrpcTransportChannel.create(channel));
    NoCredentialsProvider credentialsProvider = NoCredentialsProvider.create();
    try {
        createTable(channelProvider, credentialsProvider, "test-table");
        BigtableDataClient client = BigtableDataClient.create(BigtableDataSettings.newBuilderForEmulator(emulator.getHost(), emulator.getEmulatorPort()).setProjectId(PROJECT_ID).setInstanceId(INSTANCE_ID).build());
        client.mutateRow(RowMutation.create("test-table", "1").setCell("name", "firstName", "Ray"));
        Row row = client.readRow("test-table", "1");
        List<RowCell> cells = row.getCells("name", "firstName");
        assertThat(cells).isNotNull().hasSize(1);
        assertThat(cells.get(0).getValue().toStringUtf8()).isEqualTo("Ray");
    } finally {
        channel.shutdown();
    }
}
Also used : NoCredentialsProvider(com.google.api.gax.core.NoCredentialsProvider) ManagedChannel(io.grpc.ManagedChannel) RowCell(com.google.cloud.bigtable.data.v2.models.RowCell) Row(com.google.cloud.bigtable.data.v2.models.Row) FixedTransportChannelProvider(com.google.api.gax.rpc.FixedTransportChannelProvider) TransportChannelProvider(com.google.api.gax.rpc.TransportChannelProvider) BigtableDataClient(com.google.cloud.bigtable.data.v2.BigtableDataClient) Test(org.junit.Test)

Example 10 with RowCell

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

the class TestRowResultAdapter method testWithSingleCellRow.

@Test
public void testWithSingleCellRow() {
    RowAdapter.RowBuilder<Result> rowBuilder = underTest.createRowBuilder();
    rowBuilder.startRow(ROW_KEY);
    rowBuilder.startCell(COL_FAMILY, QUAL_ONE, 10000L, Collections.<String>emptyList(), VALUE.size());
    rowBuilder.cellValue(VALUE);
    rowBuilder.finishCell();
    rowBuilder.startCell(COL_FAMILY, QUAL_TWO, 20000L, LABELS, -1);
    rowBuilder.cellValue(VALUE);
    rowBuilder.finishCell();
    Result expected = Result.create(ImmutableList.<Cell>of(new RowCell(ROW_KEY.toByteArray(), COL_FAMILY.getBytes(), QUAL_ONE.toByteArray(), 10L, VALUE.toByteArray()), new RowCell(ROW_KEY.toByteArray(), COL_FAMILY.getBytes(), QUAL_TWO.toByteArray(), 20L, VALUE.toByteArray(), LABELS)));
    assertResult(expected, rowBuilder.finishRow());
    assertEquals(ROW_KEY, underTest.getKey(expected));
}
Also used : RowAdapter(com.google.cloud.bigtable.data.v2.models.RowAdapter) RowCell(com.google.cloud.bigtable.hbase.adapters.read.RowCell) Result(org.apache.hadoop.hbase.client.Result) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)31 Row (com.google.cloud.bigtable.data.v2.models.Row)30 RowCell (com.google.cloud.bigtable.data.v2.models.RowCell)19 ReadModifyWriteRow (com.google.cloud.bigtable.data.v2.models.ReadModifyWriteRow)18 Query (com.google.cloud.bigtable.data.v2.models.Query)14 ByteString (com.google.protobuf.ByteString)12 Result (org.apache.hadoop.hbase.client.Result)10 RowCell (com.google.cloud.bigtable.hbase.adapters.read.RowCell)8 NotFoundException (com.google.api.gax.rpc.NotFoundException)4 Filter (com.google.cloud.bigtable.data.v2.models.Filters.Filter)4 RowAdapter (com.google.cloud.bigtable.data.v2.models.RowAdapter)4 BigtableDataClient (com.google.cloud.bigtable.data.v2.BigtableDataClient)3 QualifierFilter (org.apache.hadoop.hbase.filter.QualifierFilter)3 ReadRowsRequest (com.google.bigtable.v2.ReadRowsRequest)2 ReadRowsResponse (com.google.bigtable.v2.ReadRowsResponse)2 BigtableDataSettings (com.google.cloud.bigtable.data.v2.BigtableDataSettings)2 DefaultRowAdapter (com.google.cloud.bigtable.data.v2.models.DefaultRowAdapter)2 Filters (com.google.cloud.bigtable.data.v2.models.Filters)2 ServerStreamingStashCallable (com.google.cloud.bigtable.gaxx.testing.FakeStreamingApi.ServerStreamingStashCallable)2 Cell (org.apache.hadoop.hbase.Cell)2