use of com.google.cloud.bigtable.data.v2.models.Row in project java-bigtable-hbase by googleapis.
the class AbstractBigtableTable method checkAndMutate.
/**
* {@inheritDoc}
*/
@Override
public boolean checkAndMutate(final byte[] row, final byte[] family, final byte[] qualifier, final CompareFilter.CompareOp compareOp, final byte[] value, final RowMutations rm) throws IOException {
LOG.trace("checkAndMutate(byte[], byte[], byte[], CompareOp, byte[], RowMutations)");
ConditionalRowMutation request = new CheckAndMutateUtil.RequestBuilder(hbaseAdapter, row, family).qualifier(qualifier).ifMatches(compareOp, value).withMutations(rm).build();
return checkAndMutate(row, request, "checkAndMutate");
}
use of com.google.cloud.bigtable.data.v2.models.Row in project java-bigtable-hbase by googleapis.
the class TestBigtableAsyncBufferedMutator method testMutateWithList.
@Test
public void testMutateWithList() {
Put put = new Put(Bytes.toBytes("rowKey"));
Delete delete = new Delete(Bytes.toBytes("to-be-deleted-row"));
Append append = new Append(Bytes.toBytes("appended-row"));
RowMutationEntry rowEntryForPut = RowMutationEntry.create("rowKey");
RowMutationEntry rowEntryForDelete = RowMutationEntry.create("to-be-deleted-row");
ReadModifyWriteRow readModifyWriteRow = ReadModifyWriteRow.create(TABLE_ID, "appended-row");
when(mockRequestAdapter.adaptEntry(put)).thenReturn(rowEntryForPut);
when(mockRequestAdapter.adaptEntry(delete)).thenReturn(rowEntryForDelete);
when(mockRequestAdapter.adapt(append)).thenReturn(readModifyWriteRow);
when(mockBulkMutation.add(rowEntryForPut)).thenReturn(ApiFutures.immediateFuture(null));
when(mockBulkMutation.add(rowEntryForDelete)).thenReturn(ApiFutures.immediateFuture(null));
when(mockDataClient.readModifyWriteRowAsync(readModifyWriteRow)).thenReturn(ApiFutures.immediateFuture(Result.EMPTY_RESULT));
asyncBufferedMutator.mutate(Arrays.asList(put, delete, append)).forEach(future -> {
try {
future.get();
} catch (InterruptedException | ExecutionException e) {
throw new AssertionError("BigtableAsyncBufferedMutator#mutate test failed");
}
});
verify(mockRequestAdapter).adaptEntry(put);
verify(mockRequestAdapter).adaptEntry(delete);
verify(mockRequestAdapter).adapt(append);
verify(mockBulkMutation).add(rowEntryForPut);
verify(mockBulkMutation).add(rowEntryForDelete);
verify(mockDataClient).readModifyWriteRowAsync(readModifyWriteRow);
}
use of com.google.cloud.bigtable.data.v2.models.Row in project java-bigtable-hbase by googleapis.
the class SimpleIT method testConnection.
@Test
public void testConnection() throws Exception {
String projectId = "fake-project";
String instanceId = "fake-instance";
String tableId = "myTable";
String family = "cf";
String key = "key";
String value = "value";
BigtableOptions opts = new BigtableOptions.Builder().setUserAgent("fake").setProjectId(projectId).setInstanceId(instanceId).build();
try (BigtableSession session = new BigtableSession(opts)) {
IBigtableTableAdminClient tableAdminClient = session.getTableAdminClientWrapper();
tableAdminClient.createTable(CreateTableRequest.of(tableId).addFamily(family));
IBigtableDataClient dataClient = session.getDataClientWrapper();
dataClient.mutateRow(RowMutation.create(tableId, key).setCell(family, "", value));
List<Row> results = dataClient.readRowsAsync(Query.create(tableId).rowKey(key)).get();
Assert.assertEquals(ByteString.copyFromUtf8(value), results.get(0).getCells().get(0).getValue());
}
}
use of com.google.cloud.bigtable.data.v2.models.Row 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.Row 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());
}
Aggregations