Search in sources :

Example 1 with CheckAndMutateRowRequest

use of com.google.bigtable.v2.CheckAndMutateRowRequest in project java-bigtable-hbase by googleapis.

the class TestCheckAndMutateUtil method testPut.

// ************************** TEST METHODS ***************************
@Test
public /**
 * Tests that a CheckAndMutate with a {@link Put} works correctly for the filter and mutation
 * aspects
 */
void testPut() throws DoNotRetryIOException {
    CheckAndMutateUtil.RequestBuilder underTest = createRequestBuilder();
    CheckAndMutateRowRequest result = underTest.qualifier(qual).ifMatches(CompareOp.EQUAL, checkValue).withPut(PUT).build().toProto(REQUEST_CONTEXT);
    Assert.assertEquals(1, result.getTrueMutationsCount());
    checkPutMutation(result.getTrueMutations(0));
    checkPredicate(result);
}
Also used : CheckAndMutateRowRequest(com.google.bigtable.v2.CheckAndMutateRowRequest) Test(org.junit.Test)

Example 2 with CheckAndMutateRowRequest

use of com.google.bigtable.v2.CheckAndMutateRowRequest in project java-bigtable-hbase by googleapis.

the class TestCheckAndMutateUtil method testIfNotExists.

@Test
public /**
 * Test to make sure that {@link CheckAndMutateUtil.RequestBuilder#ifNotExists()} works correctly
 */
void testIfNotExists() throws DoNotRetryIOException {
    CheckAndMutateUtil.RequestBuilder underTest = createRequestBuilder();
    CheckAndMutateRowRequest result = underTest.qualifier(qual).ifNotExists().withPut(PUT).build().toProto(REQUEST_CONTEXT);
    Assert.assertEquals(1, result.getFalseMutationsCount());
    checkPutMutation(result.getFalseMutations(0));
    RowFilter expected = FILTERS.chain().filter(FAMILY_AND_QUAL_FILTER).filter(FILTERS.limit().cellsPerColumn(1)).toProto();
    Assert.assertEquals(expected, result.getPredicateFilter());
}
Also used : RowFilter(com.google.bigtable.v2.RowFilter) CheckAndMutateRowRequest(com.google.bigtable.v2.CheckAndMutateRowRequest) Test(org.junit.Test)

Example 3 with CheckAndMutateRowRequest

use of com.google.bigtable.v2.CheckAndMutateRowRequest in project java-bigtable-hbase by googleapis.

the class TestCheckAndMutateUtil method testRowMutations.

@Test
public /**
 * Tests that a CheckAndMutate with a {@link RowMutations} works correctly for the filter and
 * mutation aspects
 */
void testRowMutations() throws IOException {
    CheckAndMutateUtil.RequestBuilder underTest = createRequestBuilder();
    RowMutations rowMutations = new RowMutations(rowKey);
    rowMutations.add(PUT);
    CheckAndMutateRowRequest result = underTest.qualifier(qual).ifMatches(CompareOp.EQUAL, checkValue).withMutations(rowMutations).build().toProto(REQUEST_CONTEXT);
    Assert.assertEquals(1, result.getTrueMutationsCount());
    checkPutMutation(result.getTrueMutations(0));
    checkPredicate(result);
}
Also used : CheckAndMutateRowRequest(com.google.bigtable.v2.CheckAndMutateRowRequest) RowMutations(org.apache.hadoop.hbase.client.RowMutations) Test(org.junit.Test)

Example 4 with CheckAndMutateRowRequest

use of com.google.bigtable.v2.CheckAndMutateRowRequest in project java-bigtable-hbase by googleapis.

the class TestCheckAndMutateUtil method testCompareOpsOtherThanNotEqualsNull.

@Test
public /**
 * Test to make sure that {@link CheckAndMutateUtil.RequestBuilder#ifMatches(CompareOp, byte[])}
 * wtih {@link CompareOp#NOT_EQUAL} and a null value works as expected.
 */
void testCompareOpsOtherThanNotEqualsNull() throws DoNotRetryIOException {
    CheckAndMutateUtil.RequestBuilder underTest = createRequestBuilder();
    List<CompareOp> otherOps = new ArrayList<>(Arrays.asList(CompareOp.values()));
    otherOps.remove(CompareOp.NOT_EQUAL);
    int index = (int) (Math.random() * otherOps.size());
    CheckAndMutateRowRequest result = underTest.qualifier(qual).ifMatches(otherOps.get(index), null).withPut(PUT).build().toProto(REQUEST_CONTEXT);
    Assert.assertEquals(1, result.getFalseMutationsCount());
    RowFilter expected = FILTERS.chain().filter(FAMILY_AND_QUAL_FILTER).filter(FILTERS.limit().cellsPerColumn(1)).toProto();
    checkPutMutation(result.getFalseMutations(0));
    Assert.assertEquals(expected, result.getPredicateFilter());
}
Also used : RowFilter(com.google.bigtable.v2.RowFilter) ArrayList(java.util.ArrayList) CompareOp(org.apache.hadoop.hbase.filter.CompareFilter.CompareOp) CheckAndMutateRowRequest(com.google.bigtable.v2.CheckAndMutateRowRequest) Test(org.junit.Test)

Example 5 with CheckAndMutateRowRequest

use of com.google.bigtable.v2.CheckAndMutateRowRequest in project java-bigtable by googleapis.

the class ConditionalRowMutationTest method toProtoTest.

@Test
public void toProtoTest() {
    Mutation ignoredThenMutation = Mutation.create().deleteRow();
    ConditionalRowMutation mutation = ConditionalRowMutation.create(TABLE_ID, TEST_KEY).then(ignoredThenMutation);
    CheckAndMutateRowRequest actualProto = mutation.toProto(REQUEST_CONTEXT).toBuilder().clearTrueMutations().build();
    assertThat(actualProto).isEqualTo(CheckAndMutateRowRequest.newBuilder().setTableName(NameUtil.formatTableName(PROJECT_ID, INSTANCE_ID, TABLE_ID)).setAppProfileId(APP_PROFILE_ID).setRowKey(TEST_KEY).build());
}
Also used : CheckAndMutateRowRequest(com.google.bigtable.v2.CheckAndMutateRowRequest) Test(org.junit.Test)

Aggregations

CheckAndMutateRowRequest (com.google.bigtable.v2.CheckAndMutateRowRequest)15 Test (org.junit.Test)14 Mutation (com.google.bigtable.v2.Mutation)4 RowFilter (com.google.bigtable.v2.RowFilter)4 ByteString (com.google.protobuf.ByteString)2 RowMutations (org.apache.hadoop.hbase.client.RowMutations)2 CheckAndMutateRowResponse (com.google.bigtable.v2.CheckAndMutateRowResponse)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 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 Delete (org.apache.hadoop.hbase.client.Delete)1 Put (org.apache.hadoop.hbase.client.Put)1 CompareOp (org.apache.hadoop.hbase.filter.CompareFilter.CompareOp)1