Search in sources :

Example 11 with CheckAndMutateRowRequest

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

the class TestCheckAndMutateUtil method testNotEqualsNull.

@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 testNotEqualsNull() throws DoNotRetryIOException {
    CheckAndMutateUtil.RequestBuilder underTest = createRequestBuilder();
    CheckAndMutateRowRequest result = underTest.qualifier(qual).ifMatches(CompareOp.NOT_EQUAL, null).withPut(PUT).build().toProto(REQUEST_CONTEXT);
    Assert.assertEquals(1, result.getTrueMutationsCount());
    RowFilter expected = FILTERS.chain().filter(FAMILY_AND_QUAL_FILTER).filter(FILTERS.limit().cellsPerColumn(1)).toProto();
    checkPutMutation(result.getTrueMutations(0));
    Assert.assertEquals(expected, result.getPredicateFilter());
}
Also used : RowFilter(com.google.bigtable.v2.RowFilter) CheckAndMutateRowRequest(com.google.bigtable.v2.CheckAndMutateRowRequest) Test(org.junit.Test)

Example 12 with CheckAndMutateRowRequest

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

the class TestCheckAndMutateUtil method testRowMutationServerSideTimestamps.

@Test
public /**
 * Tests that a CheckAndMutate with a {@link RowMutations} with a {@link Put} which ensures that
 * the conversion to a {@link ConditionalRowMutation} sets a server-side timeatamp (-1) on the
 * {@link com.google.cloud.bigtable.data.v2.models.Mutation}.
 */
void testRowMutationServerSideTimestamps() 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());
    Mutation.SetCell setCell = result.getTrueMutations(0).getSetCell();
    Assert.assertEquals(-1, setCell.getTimestampMicros());
}
Also used : Mutation(com.google.bigtable.v2.Mutation) CheckAndMutateRowRequest(com.google.bigtable.v2.CheckAndMutateRowRequest) RowMutations(org.apache.hadoop.hbase.client.RowMutations) Test(org.junit.Test)

Example 13 with CheckAndMutateRowRequest

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

the class TestCheckAndMutateUtil method testDelete.

@Test
public /**
 * Tests that a CheckAndMutate with a {@link Delete} works correctly for the filter and mutation
 * aspects
 */
void testDelete() throws DoNotRetryIOException {
    CheckAndMutateUtil.RequestBuilder underTest = createRequestBuilder();
    CheckAndMutateRowRequest result = underTest.qualifier(qual).ifMatches(CompareOp.EQUAL, checkValue).withDelete(new Delete(rowKey).addColumns(family, qual)).build().toProto(REQUEST_CONTEXT);
    Assert.assertEquals(1, result.getTrueMutationsCount());
    Mutation.DeleteFromColumn delete = result.getTrueMutations(0).getDeleteFromColumn();
    Assert.assertArrayEquals(family, delete.getFamilyNameBytes().toByteArray());
    Assert.assertArrayEquals(qual, delete.getColumnQualifier().toByteArray());
    checkPredicate(result);
}
Also used : Delete(org.apache.hadoop.hbase.client.Delete) Mutation(com.google.bigtable.v2.Mutation) CheckAndMutateRowRequest(com.google.bigtable.v2.CheckAndMutateRowRequest) Test(org.junit.Test)

Example 14 with CheckAndMutateRowRequest

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

the class ConditionalRowMutationTest method fromProtoTest.

@Test
public void fromProtoTest() {
    ConditionalRowMutation mutation = ConditionalRowMutation.create(TABLE_ID, TEST_KEY).condition(Filters.FILTERS.key().regex("test")).then(Mutation.create().setCell("family1", "qualifier1", 10_000L, "value")).otherwise(Mutation.create().deleteFamily("family"));
    CheckAndMutateRowRequest protoRequest = mutation.toProto(REQUEST_CONTEXT);
    ConditionalRowMutation actualRequest = ConditionalRowMutation.fromProto(protoRequest);
    assertThat(actualRequest.toProto(REQUEST_CONTEXT)).isEqualTo(protoRequest);
    String projectId = "fresh-project";
    String instanceId = "fresh-instance";
    String appProfile = "fresh-app-profile";
    CheckAndMutateRowRequest overriddenRequest = actualRequest.toProto(RequestContext.create(projectId, instanceId, appProfile));
    assertThat(overriddenRequest).isNotEqualTo(protoRequest);
    assertThat(overriddenRequest.getTableName()).matches(NameUtil.formatTableName(projectId, instanceId, TABLE_ID));
    assertThat(overriddenRequest.getAppProfileId()).matches(appProfile);
}
Also used : ByteString(com.google.protobuf.ByteString) CheckAndMutateRowRequest(com.google.bigtable.v2.CheckAndMutateRowRequest) Test(org.junit.Test)

Example 15 with CheckAndMutateRowRequest

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

the class ConditionalRowMutationTest method otherwiseTest.

@Test
public void otherwiseTest() {
    ConditionalRowMutation mutation = ConditionalRowMutation.create(TABLE_ID, TEST_KEY).otherwise(Mutation.create().deleteCells("family1", "qualifier1")).otherwise(Mutation.create().deleteCells("family2", "qualifier2"));
    CheckAndMutateRowRequest actualProto = mutation.toProto(REQUEST_CONTEXT);
    assertThat(actualProto.getFalseMutationsList()).containsExactly(com.google.bigtable.v2.Mutation.newBuilder().setDeleteFromColumn(DeleteFromColumn.newBuilder().setFamilyName("family1").setColumnQualifier(ByteString.copyFromUtf8("qualifier1"))).build(), com.google.bigtable.v2.Mutation.newBuilder().setDeleteFromColumn(DeleteFromColumn.newBuilder().setFamilyName("family2").setColumnQualifier(ByteString.copyFromUtf8("qualifier2"))).build()).inOrder();
}
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