Search in sources :

Example 11 with Mutation

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

the class TestRowMutationsAdapter method toMutateRowRequest.

private MutateRowRequest toMutateRowRequest(byte[] rowKey, com.google.cloud.bigtable.data.v2.models.Mutation mutation) {
    RowMutation rowMutation = toRowMutationModel(rowKey, mutation);
    MutateRowRequest.Builder builder = rowMutation.toProto(REQUEST_CONTEXT).toBuilder();
    return builder.build();
}
Also used : MutateRowRequest(com.google.bigtable.v2.MutateRowRequest) RowMutation(com.google.cloud.bigtable.data.v2.models.RowMutation)

Example 12 with Mutation

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

the class TestRowMutationsAdapter method testMultipleMutationsAreAdapted.

@Test
public void testMultipleMutationsAreAdapted() throws IOException {
    byte[] rowKey = dataHelper.randomData("rk-1");
    RowMutations mutations = new RowMutations(rowKey);
    byte[] family1 = dataHelper.randomData("cf1");
    byte[] qualifier1 = dataHelper.randomData("qualifier1");
    byte[] value1 = dataHelper.randomData("value1");
    byte[] family2 = dataHelper.randomData("cf2");
    byte[] qualifier2 = dataHelper.randomData("qualifier2");
    byte[] value2 = dataHelper.randomData("value2");
    mutations.add(new Put(rowKey).addColumn(family1, qualifier1, value1));
    mutations.add(new Put(rowKey).addColumn(family2, qualifier2, value2));
    com.google.cloud.bigtable.data.v2.models.Mutation mutation = com.google.cloud.bigtable.data.v2.models.Mutation.create();
    // Adapt the RowMutations to a Mutation:
    adapter.adapt(mutations, mutation);
    MutateRowRequest result = toMutateRowRequest(rowKey, mutation);
    Assert.assertArrayEquals(rowKey, result.getRowKey().toByteArray());
    Mockito.verify(mutationAdapter, times(2)).adapt(any(org.apache.hadoop.hbase.client.Mutation.class), eq(mutation));
}
Also used : MutateRowRequest(com.google.bigtable.v2.MutateRowRequest) RowMutation(com.google.cloud.bigtable.data.v2.models.RowMutation) Put(org.apache.hadoop.hbase.client.Put) RowMutations(org.apache.hadoop.hbase.client.RowMutations) Test(org.junit.Test)

Example 13 with Mutation

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

the class TestPutAdapter method testUnsetTimestampsAreNotPopulated.

@Test
public void testUnsetTimestampsAreNotPopulated() {
    PutAdapter adapter = new PutAdapter(-1, false);
    byte[] row = dataHelper.randomData("rk-");
    byte[] family1 = dataHelper.randomData("f1");
    byte[] qualifier1 = dataHelper.randomData("qual1");
    byte[] value1 = dataHelper.randomData("v1");
    Put hbasePut = new Put(row).addColumn(family1, qualifier1, value1);
    com.google.cloud.bigtable.data.v2.models.Mutation unsafeMutation = com.google.cloud.bigtable.data.v2.models.Mutation.createUnsafe();
    adapter.adapt(hbasePut, unsafeMutation);
    RowMutation rowMutation = RowMutation.create(TABLE_ID, ByteString.copyFrom(hbasePut.getRow()), unsafeMutation);
    MutateRowRequest request = rowMutation.toProto(REQUEST_CONTEXT);
    Assert.assertArrayEquals(row, request.getRowKey().toByteArray());
    Assert.assertEquals(1, request.getMutationsCount());
    Mutation mutation = request.getMutations(0);
    Assert.assertEquals(MutationCase.SET_CELL, mutation.getMutationCase());
    SetCell setCell = mutation.getSetCell();
    Assert.assertArrayEquals(family1, setCell.getFamilyNameBytes().toByteArray());
    Assert.assertArrayEquals(qualifier1, setCell.getColumnQualifier().toByteArray());
    Assert.assertEquals(-1, setCell.getTimestampMicros());
    Assert.assertArrayEquals(value1, setCell.getValue().toByteArray());
}
Also used : MutateRowRequest(com.google.bigtable.v2.MutateRowRequest) SetCell(com.google.bigtable.v2.Mutation.SetCell) RowMutation(com.google.cloud.bigtable.data.v2.models.RowMutation) Mutation(com.google.bigtable.v2.Mutation) RowMutation(com.google.cloud.bigtable.data.v2.models.RowMutation) Put(org.apache.hadoop.hbase.client.Put) Test(org.junit.Test)

Example 14 with Mutation

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

the class TestPutAdapter method testMultipleCellsInOneFamilyAreConverted.

@Test
public void testMultipleCellsInOneFamilyAreConverted() {
    byte[] row = dataHelper.randomData("rk-");
    byte[] family = dataHelper.randomData("f1");
    byte[] qualifier1 = dataHelper.randomData("qual1");
    byte[] qualifier2 = dataHelper.randomData("qual2");
    byte[] value1 = dataHelper.randomData("v1");
    byte[] value2 = dataHelper.randomData("v2");
    long timestamp1 = 1L;
    long timestamp2 = 2L;
    Put hbasePut = new Put(row);
    hbasePut.addColumn(family, qualifier1, timestamp1, value1);
    hbasePut.addColumn(family, qualifier2, timestamp2, value2);
    MutateRowRequest request = adapt(hbasePut);
    Assert.assertArrayEquals(row, request.getRowKey().toByteArray());
    Assert.assertEquals(2, request.getMutationsCount());
    Mutation mutation = request.getMutations(0);
    Assert.assertEquals(MutationCase.SET_CELL, mutation.getMutationCase());
    SetCell setCell = mutation.getSetCell();
    Assert.assertArrayEquals(family, setCell.getFamilyNameBytes().toByteArray());
    Assert.assertArrayEquals(qualifier1, setCell.getColumnQualifier().toByteArray());
    Assert.assertEquals(TimeUnit.MILLISECONDS.toMicros(timestamp1), setCell.getTimestampMicros());
    Assert.assertArrayEquals(value1, setCell.getValue().toByteArray());
    Mutation mod2 = request.getMutations(1);
    SetCell setCell2 = mod2.getSetCell();
    Assert.assertArrayEquals(family, setCell2.getFamilyNameBytes().toByteArray());
    Assert.assertArrayEquals(qualifier2, setCell2.getColumnQualifier().toByteArray());
    Assert.assertEquals(TimeUnit.MILLISECONDS.toMicros(timestamp2), setCell2.getTimestampMicros());
    Assert.assertArrayEquals(value2, setCell2.getValue().toByteArray());
}
Also used : MutateRowRequest(com.google.bigtable.v2.MutateRowRequest) SetCell(com.google.bigtable.v2.Mutation.SetCell) Mutation(com.google.bigtable.v2.Mutation) RowMutation(com.google.cloud.bigtable.data.v2.models.RowMutation) Put(org.apache.hadoop.hbase.client.Put) Test(org.junit.Test)

Example 15 with Mutation

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

the class BigtableDataClientTest method proxyCheckAndMutateRowTest.

@Test
public void proxyCheckAndMutateRowTest() {
    Mockito.when(mockStub.checkAndMutateRowCallable()).thenReturn(mockCheckAndMutateRowCallable);
    ConditionalRowMutation mutation = ConditionalRowMutation.create("fake-table", "fake-key").then(Mutation.create().setCell("fake-family", "fake-qualifier", "fake-value"));
    bigtableDataClient.checkAndMutateRowAsync(mutation);
    Mockito.verify(mockCheckAndMutateRowCallable).futureCall(mutation);
}
Also used : ConditionalRowMutation(com.google.cloud.bigtable.data.v2.models.ConditionalRowMutation) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)10 RowMutation (com.google.cloud.bigtable.data.v2.models.RowMutation)9 MutateRowRequest (com.google.bigtable.v2.MutateRowRequest)7 Put (org.apache.hadoop.hbase.client.Put)6 Mutation (com.google.bigtable.v2.Mutation)5 SetCell (com.google.bigtable.v2.Mutation.SetCell)5 ConditionalRowMutation (com.google.cloud.bigtable.data.v2.models.ConditionalRowMutation)4 MutateRowsException (com.google.cloud.bigtable.data.v2.models.MutateRowsException)3 MutateRowsRequest (com.google.bigtable.v2.MutateRowsRequest)2 Builder (com.google.bigtable.v2.MutateRowsRequest.Builder)2 BigtableDataClient (com.google.cloud.bigtable.data.v2.BigtableDataClient)2 FailedMutation (com.google.cloud.bigtable.data.v2.models.MutateRowsException.FailedMutation)2 ApiException (com.google.api.gax.rpc.ApiException)1 DeadlineExceededException (com.google.api.gax.rpc.DeadlineExceededException)1 UnavailableException (com.google.api.gax.rpc.UnavailableException)1 MutateRowsResponse (com.google.bigtable.v2.MutateRowsResponse)1 Entry (com.google.bigtable.v2.MutateRowsResponse.Entry)1 Filter (com.google.cloud.bigtable.data.v2.models.Filters.Filter)1 Mutation (com.google.cloud.bigtable.data.v2.models.Mutation)1 ReadModifyWriteRow (com.google.cloud.bigtable.data.v2.models.ReadModifyWriteRow)1