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();
}
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));
}
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());
}
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());
}
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);
}
Aggregations