Search in sources :

Example 16 with ReadModifyWriteRow

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

the class TestIncrementAdapter method testBasicRowKeyIncrement.

@Test
public void testBasicRowKeyIncrement() {
    byte[] rowKey = dataHelper.randomData("rk1-");
    Increment incr = new Increment(rowKey);
    ReadModifyWriteRow readModifyWriteRow = ReadModifyWriteRow.create(TABLE_ID, ByteString.copyFrom(rowKey));
    incrementAdapter.adapt(incr, readModifyWriteRow);
    ReadModifyWriteRowRequest requestBuilder = readModifyWriteRow.toProto(requestContext);
    ByteString adaptedRowKey = requestBuilder.getRowKey();
    Assert.assertArrayEquals(rowKey, adaptedRowKey.toByteArray());
}
Also used : ReadModifyWriteRowRequest(com.google.bigtable.v2.ReadModifyWriteRowRequest) ByteString(com.google.protobuf.ByteString) Increment(org.apache.hadoop.hbase.client.Increment) ReadModifyWriteRow(com.google.cloud.bigtable.data.v2.models.ReadModifyWriteRow) Test(org.junit.Test)

Example 17 with ReadModifyWriteRow

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

the class TestAppendAdapter method testMultipleAppends.

@Test
public void testMultipleAppends() {
    byte[] rowKey = dataHelper.randomData("rk1-");
    byte[] family1 = Bytes.toBytes("family1");
    byte[] qualifier1 = Bytes.toBytes("qualifier1");
    byte[] value1 = Bytes.toBytes("value1");
    byte[] family2 = Bytes.toBytes("family2");
    byte[] qualifier2 = Bytes.toBytes("qualifier2");
    byte[] value2 = Bytes.toBytes("value2");
    Append append = new Append(rowKey);
    append.add(family1, qualifier1, value1);
    append.add(family2, qualifier2, value2);
    ReadModifyWriteRow readModifyWriteRow = ReadModifyWriteRow.create(TABLE_ID, ByteString.copyFrom(rowKey));
    appendAdapter.adapt(append, readModifyWriteRow);
    ReadModifyWriteRowRequest request = readModifyWriteRow.toProto(requestContext);
    List<ReadModifyWriteRule> rules = request.getRulesList();
    Assert.assertEquals(2, rules.size());
    Assert.assertEquals("family1", rules.get(0).getFamilyName());
    Assert.assertEquals("qualifier1", rules.get(0).getColumnQualifier().toStringUtf8());
    Assert.assertEquals("value1", rules.get(0).getAppendValue().toStringUtf8());
    Assert.assertEquals("family2", rules.get(1).getFamilyName());
    Assert.assertEquals("qualifier2", rules.get(1).getColumnQualifier().toStringUtf8());
    Assert.assertEquals("value2", rules.get(1).getAppendValue().toStringUtf8());
}
Also used : Append(org.apache.hadoop.hbase.client.Append) ReadModifyWriteRowRequest(com.google.bigtable.v2.ReadModifyWriteRowRequest) ReadModifyWriteRule(com.google.bigtable.v2.ReadModifyWriteRule) ReadModifyWriteRow(com.google.cloud.bigtable.data.v2.models.ReadModifyWriteRow) Test(org.junit.Test)

Example 18 with ReadModifyWriteRow

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

the class TestAppendAdapter method testBasicRowKeyAppend.

@Test
public void testBasicRowKeyAppend() {
    byte[] rowKey = dataHelper.randomData("rk1-");
    Append append = new Append(rowKey);
    ReadModifyWriteRow readModifyWriteRow = ReadModifyWriteRow.create(TABLE_ID, ByteString.copyFrom(rowKey));
    appendAdapter.adapt(append, readModifyWriteRow);
    ReadModifyWriteRowRequest request = readModifyWriteRow.toProto(requestContext);
    ByteString adaptedRowKey = request.getRowKey();
    Assert.assertArrayEquals(rowKey, adaptedRowKey.toByteArray());
}
Also used : Append(org.apache.hadoop.hbase.client.Append) ReadModifyWriteRowRequest(com.google.bigtable.v2.ReadModifyWriteRowRequest) ByteString(com.google.protobuf.ByteString) ReadModifyWriteRow(com.google.cloud.bigtable.data.v2.models.ReadModifyWriteRow) Test(org.junit.Test)

Example 19 with ReadModifyWriteRow

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

the class EnhancedBigtableStub method createReadModifyWriteRowCallable.

/**
 * Creates a callable chain to handle ReadModifyWriteRow RPCs. The chain will:
 *
 * <ul>
 *   <li>Convert {@link ReadModifyWriteRow}s into {@link
 *       com.google.bigtable.v2.ReadModifyWriteRowRequest}s.
 *   <li>Convert the responses into {@link Row}.
 *   <li>Add tracing & metrics.
 * </ul>
 */
private UnaryCallable<ReadModifyWriteRow, Row> createReadModifyWriteRowCallable() {
    UnaryCallable<ReadModifyWriteRowRequest, ReadModifyWriteRowResponse> base = GrpcRawCallableFactory.createUnaryCallable(GrpcCallSettings.<ReadModifyWriteRowRequest, ReadModifyWriteRowResponse>newBuilder().setMethodDescriptor(BigtableGrpc.getReadModifyWriteRowMethod()).setParamsExtractor(new RequestParamsExtractor<ReadModifyWriteRowRequest>() {

        @Override
        public Map<String, String> extract(ReadModifyWriteRowRequest request) {
            return ImmutableMap.of("table_name", request.getTableName(), "app_profile_id", request.getAppProfileId());
        }
    }).build(), settings.readModifyWriteRowSettings().getRetryableCodes());
    UnaryCallable<ReadModifyWriteRowRequest, ReadModifyWriteRowResponse> withStatsHeaders = new StatsHeadersUnaryCallable<>(base);
    String methodName = "ReadModifyWriteRow";
    UnaryCallable<ReadModifyWriteRowRequest, ReadModifyWriteRowResponse> withHeaderTracer = new HeaderTracerUnaryCallable<>(withStatsHeaders);
    UnaryCallable<ReadModifyWriteRowRequest, ReadModifyWriteRowResponse> retrying = Callables.retrying(withHeaderTracer, settings.readModifyWriteRowSettings(), clientContext);
    return createUserFacingUnaryCallable(methodName, new ReadModifyWriteRowCallable(retrying, requestContext));
}
Also used : HeaderTracerUnaryCallable(com.google.cloud.bigtable.data.v2.stub.metrics.HeaderTracerUnaryCallable) ReadModifyWriteRowRequest(com.google.bigtable.v2.ReadModifyWriteRowRequest) StatsHeadersUnaryCallable(com.google.cloud.bigtable.data.v2.stub.metrics.StatsHeadersUnaryCallable) ByteString(com.google.protobuf.ByteString) ReadModifyWriteRowResponse(com.google.bigtable.v2.ReadModifyWriteRowResponse) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 20 with ReadModifyWriteRow

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

Aggregations

ReadModifyWriteRow (com.google.cloud.bigtable.data.v2.models.ReadModifyWriteRow)20 Test (org.junit.Test)16 ReadModifyWriteRowRequest (com.google.bigtable.v2.ReadModifyWriteRowRequest)9 ReadModifyWriteRule (com.google.bigtable.v2.ReadModifyWriteRule)6 Append (org.apache.hadoop.hbase.client.Append)5 Increment (org.apache.hadoop.hbase.client.Increment)5 ByteString (com.google.protobuf.ByteString)3 ReadModifyWriteRowResponse (com.google.bigtable.v2.ReadModifyWriteRowResponse)1 BigtableDataClient (com.google.cloud.bigtable.data.v2.BigtableDataClient)1 Row (com.google.cloud.bigtable.data.v2.models.Row)1 RowMutationEntry (com.google.cloud.bigtable.data.v2.models.RowMutationEntry)1 HeaderTracerUnaryCallable (com.google.cloud.bigtable.data.v2.stub.metrics.HeaderTracerUnaryCallable)1 StatsHeadersUnaryCallable (com.google.cloud.bigtable.data.v2.stub.metrics.StatsHeadersUnaryCallable)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 Scope (io.opencensus.common.Scope)1 Span (io.opencensus.trace.Span)1 Map (java.util.Map)1 ExecutionException (java.util.concurrent.ExecutionException)1 Delete (org.apache.hadoop.hbase.client.Delete)1 Put (org.apache.hadoop.hbase.client.Put)1