use of com.google.cloud.bigtable.data.v2.models.Row in project testcontainers-java by testcontainers.
the class BigtableEmulatorContainerTest method testSimple.
// }
@Test
public // testWithEmulatorContainer {
void testSimple() throws IOException, InterruptedException, ExecutionException {
ManagedChannel channel = ManagedChannelBuilder.forTarget(emulator.getEmulatorEndpoint()).usePlaintext().build();
TransportChannelProvider channelProvider = FixedTransportChannelProvider.create(GrpcTransportChannel.create(channel));
NoCredentialsProvider credentialsProvider = NoCredentialsProvider.create();
try {
createTable(channelProvider, credentialsProvider, "test-table");
BigtableDataClient client = BigtableDataClient.create(BigtableDataSettings.newBuilderForEmulator(emulator.getHost(), emulator.getEmulatorPort()).setProjectId(PROJECT_ID).setInstanceId(INSTANCE_ID).build());
client.mutateRow(RowMutation.create("test-table", "1").setCell("name", "firstName", "Ray"));
Row row = client.readRow("test-table", "1");
List<RowCell> cells = row.getCells("name", "firstName");
assertThat(cells).isNotNull().hasSize(1);
assertThat(cells.get(0).getValue().toStringUtf8()).isEqualTo("Ray");
} finally {
channel.shutdown();
}
}
use of com.google.cloud.bigtable.data.v2.models.Row in project java-bigtable-hbase by googleapis.
the class AbstractBigtableTable method checkAndDelete.
/**
* {@inheritDoc}
*/
@Override
public boolean checkAndDelete(byte[] row, byte[] family, byte[] qualifier, CompareFilter.CompareOp compareOp, byte[] value, Delete delete) throws IOException {
LOG.trace("checkAndDelete(byte[], byte[], byte[], CompareOp, byte[], Delete)");
ConditionalRowMutation request = new CheckAndMutateUtil.RequestBuilder(hbaseAdapter, row, family).qualifier(qualifier).ifMatches(compareOp, value).withDelete(delete).build();
return checkAndMutate(row, request, "checkAndDelete");
}
use of com.google.cloud.bigtable.data.v2.models.Row in project java-bigtable-hbase by googleapis.
the class BigtableTable method checkAndMutate.
@Override
public CheckAndMutateBuilder checkAndMutate(byte[] row, byte[] family) {
final CheckAndMutateUtil.RequestBuilder builder = new CheckAndMutateUtil.RequestBuilder(hbaseAdapter, row, family);
return new CheckAndMutateBuilder() {
/**
* {@inheritDoc}
*/
@Override
public CheckAndMutateBuilder qualifier(byte[] qualifier) {
builder.qualifier(qualifier);
return this;
}
/**
* {@inheritDoc}
*/
@Override
public CheckAndMutateBuilder ifNotExists() {
builder.ifNotExists();
return this;
}
/**
* {@inheritDoc}
*/
@Override
public CheckAndMutateBuilder ifMatches(CompareOperator compareOp, byte[] value) {
Preconditions.checkNotNull(compareOp, "compareOp is null");
if (compareOp != CompareOperator.NOT_EQUAL) {
Preconditions.checkNotNull(value, "value is null for compareOperator: " + compareOp);
}
builder.ifMatches(BigtableTable.toCompareOp(compareOp), value);
return this;
}
/**
* {@inheritDoc}
*/
public CheckAndMutateBuilder timeRange(TimeRange timeRange) {
builder.timeRange(timeRange.getMin(), timeRange.getMax());
return this;
}
/**
* {@inheritDoc}
*/
@Override
public boolean thenPut(Put put) throws IOException {
try {
builder.withPut(put);
return call();
} catch (Exception e) {
throw new IOException("Could not CheckAndMutate.thenPut: " + e.getMessage(), e);
}
}
/**
* {@inheritDoc}
*/
@Override
public boolean thenDelete(Delete delete) throws IOException {
try {
builder.withDelete(delete);
return call();
} catch (Exception e) {
throw new IOException("Could not CheckAndMutate.thenDelete: " + e.getMessage(), e);
}
}
/**
* {@inheritDoc}
*/
@Override
public boolean thenMutate(RowMutations rowMutations) throws IOException {
try {
builder.withMutations(rowMutations);
return call();
} catch (Exception e) {
throw new IOException("Could not CheckAndMutate.thenMutate: " + e.getMessage(), e);
}
}
private boolean call() throws IOException {
ConditionalRowMutation conditionalRowMutation = builder.build();
Boolean response = FutureUtil.unwrap(clientWrapper.checkAndMutateRowAsync(conditionalRowMutation));
return CheckAndMutateUtil.wasMutationApplied(conditionalRowMutation, response);
}
};
}
use of com.google.cloud.bigtable.data.v2.models.Row in project java-bigtable-hbase by googleapis.
the class ColumnPaginationFilterAdapter method createChain.
/**
* Create a filter chain that allows the latest values for each qualifier, those cells that pass
* an option intermediate filter and are less than the limit per row.
*/
private Filter createChain(ColumnPaginationFilter filter, Filter intermediate) {
ChainFilter chain = FILTERS.chain();
chain.filter(FILTERS.limit().cellsPerColumn(1));
if (intermediate != null) {
chain.filter(intermediate);
}
chain.filter(FILTERS.limit().cellsPerRow(filter.getLimit()));
return chain;
}
use of com.google.cloud.bigtable.data.v2.models.Row in project java-bigtable-hbase by googleapis.
the class TestDataClientVeneerApi method testReadRowAsync.
@Test
public void testReadRowAsync() throws Exception {
Query expectedRequest = Query.create(TABLE_ID).rowKey(ROW_KEY).limit(1);
UnaryCallable<Query, Row> mockCallable = Mockito.mock(UnaryCallable.class);
when(mockCallable.futureCall(Mockito.eq(expectedRequest), Mockito.any(GrpcCallContext.class))).thenReturn(ApiFutures.immediateFuture(MODEL_ROW));
when(mockDataClient.readRowCallable()).thenReturn(mockCallable);
Result actualResult = dataClientWrapper.readRowAsync(TABLE_ID, ROW_KEY, null).get();
assertResult(EXPECTED_RESULT, actualResult);
verify(mockCallable).futureCall(Mockito.eq(expectedRequest), Mockito.any(GrpcCallContext.class));
}
Aggregations