Search in sources :

Example 11 with MutateRowsResponse

use of org.apache.hadoop.hbase.shaded.protobuf.generated.MultiRowMutationProtos.MutateRowsResponse in project hbase by apache.

the class TestFromClientSide5 method testMultiRowMutationWithMultipleConditionsWhenConditionsNotMatch.

@Test
public void testMultiRowMutationWithMultipleConditionsWhenConditionsNotMatch() throws Exception {
    final TableName tableName = name.getTableName();
    final byte[] ROW1 = Bytes.toBytes("testRow1");
    final byte[] ROW2 = Bytes.toBytes("testRow2");
    final byte[] VALUE1 = Bytes.toBytes("testValue1");
    final byte[] VALUE2 = Bytes.toBytes("testValue2");
    try (Table t = TEST_UTIL.createTable(tableName, FAMILY)) {
        // Add initial data
        t.put(new Put(ROW2).addColumn(FAMILY, QUALIFIER, VALUE2));
        // Execute MultiRowMutation with conditions
        Put put1 = new Put(ROW).addColumn(FAMILY, QUALIFIER, VALUE);
        MutationProto m1 = ProtobufUtil.toMutation(MutationType.PUT, put1);
        Put put2 = new Put(ROW1).addColumn(FAMILY, QUALIFIER, VALUE1);
        MutationProto m2 = ProtobufUtil.toMutation(MutationType.PUT, put2);
        Delete delete = new Delete(ROW2);
        MutationProto m3 = ProtobufUtil.toMutation(MutationType.DELETE, delete);
        MutateRowsRequest.Builder mrmBuilder = MutateRowsRequest.newBuilder();
        mrmBuilder.addMutationRequest(m1);
        mrmBuilder.addMutationRequest(m2);
        mrmBuilder.addMutationRequest(m3);
        mrmBuilder.addCondition(ProtobufUtil.toCondition(ROW1, FAMILY, QUALIFIER, CompareOperator.EQUAL, null, null));
        mrmBuilder.addCondition(ProtobufUtil.toCondition(ROW2, FAMILY, QUALIFIER, CompareOperator.EQUAL, VALUE1, null));
        CoprocessorRpcChannel channel = t.coprocessorService(ROW);
        MultiRowMutationService.BlockingInterface service = MultiRowMutationService.newBlockingStub(channel);
        MutateRowsResponse response = service.mutateRows(null, mrmBuilder.build());
        // Assert
        assertFalse(response.getProcessed());
        Result r = t.get(new Get(ROW));
        assertTrue(r.isEmpty());
        r = t.get(new Get(ROW1));
        assertTrue(r.isEmpty());
        r = t.get(new Get(ROW2));
        assertEquals(Bytes.toString(VALUE2), Bytes.toString(r.getValue(FAMILY, QUALIFIER)));
    }
}
Also used : CoprocessorRpcChannel(org.apache.hadoop.hbase.ipc.CoprocessorRpcChannel) MultiRowMutationService(org.apache.hadoop.hbase.shaded.protobuf.generated.MultiRowMutationProtos.MultiRowMutationService) MutationProto(org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.MutationProto) TableName(org.apache.hadoop.hbase.TableName) MutateRowsResponse(org.apache.hadoop.hbase.shaded.protobuf.generated.MultiRowMutationProtos.MutateRowsResponse) MutateRowsRequest(org.apache.hadoop.hbase.shaded.protobuf.generated.MultiRowMutationProtos.MutateRowsRequest) Test(org.junit.Test)

Aggregations

MultiRowMutationService (org.apache.hadoop.hbase.shaded.protobuf.generated.MultiRowMutationProtos.MultiRowMutationService)11 MutateRowsResponse (org.apache.hadoop.hbase.shaded.protobuf.generated.MultiRowMutationProtos.MutateRowsResponse)11 MutateRowsRequest (org.apache.hadoop.hbase.shaded.protobuf.generated.MultiRowMutationProtos.MutateRowsRequest)10 TableName (org.apache.hadoop.hbase.TableName)9 MutationProto (org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.MutationProto)8 Test (org.junit.Test)8 CoprocessorRpcChannel (org.apache.hadoop.hbase.ipc.CoprocessorRpcChannel)6 DoNotRetryIOException (org.apache.hadoop.hbase.DoNotRetryIOException)3 Delete (org.apache.hadoop.hbase.client.Delete)3 Mutation (org.apache.hadoop.hbase.client.Mutation)3 Put (org.apache.hadoop.hbase.client.Put)3 IOException (java.io.IOException)2 List (java.util.List)2 Set (java.util.Set)2 Collectors (java.util.stream.Collectors)2 Configuration (org.apache.hadoop.conf.Configuration)2 HConstants (org.apache.hadoop.hbase.HConstants)2 ServerName (org.apache.hadoop.hbase.ServerName)2 MultiRowMutationEndpoint (org.apache.hadoop.hbase.coprocessor.MultiRowMutationEndpoint)2 FilterList (org.apache.hadoop.hbase.filter.FilterList)2