use of com.google.bigtable.v2.ReadRowsRequest.Builder in project java-bigtable-hbase by googleapis.
the class TestRowRangeAdapter method testSingleClosedRangeRowSet.
@Test
public void testSingleClosedRangeRowSet() {
ByteString key1 = ByteString.copyFromUtf8("myKey");
ByteString key2 = ByteString.copyFromUtf8("otherKey");
RowSet in = RowSet.newBuilder().addRowRanges(RowRange.newBuilder().setStartKeyClosed(key1).setEndKeyClosed(key2)).build();
RangeSet<RowKeyWrapper> out = adapter.rowSetToRangeSet(in);
RangeSet<RowKeyWrapper> expected = ImmutableRangeSet.<RowKeyWrapper>builder().add(Range.closed(new RowKeyWrapper(key1), new RowKeyWrapper(key2))).build();
assertEquals(expected, out);
adapter.rangeSetToByteStringRange(out, query);
assertEquals(in, query.toProto(requestContext).getRows());
}
use of com.google.bigtable.v2.ReadRowsRequest.Builder in project java-bigtable-hbase by googleapis.
the class TestRowRangeAdapter method testAllRowSet.
@Test
public void testAllRowSet() {
RowSet in = RowSet.newBuilder().addRowRanges(RowRange.newBuilder()).build();
RangeSet<RowKeyWrapper> out = adapter.rowSetToRangeSet(in);
RangeSet<RowKeyWrapper> expected = ImmutableRangeSet.<RowKeyWrapper>builder().add(Range.<RowKeyWrapper>all()).build();
assertEquals(expected, out);
adapter.rangeSetToByteStringRange(out, query);
assertEquals(in, query.toProto(requestContext).getRows());
}
use of com.google.bigtable.v2.ReadRowsRequest.Builder in project java-bigtable-hbase by googleapis.
the class TestRowRangeAdapter method testSingleOpenClosedRangeRowSet.
@Test
public void testSingleOpenClosedRangeRowSet() {
ByteString key1 = ByteString.copyFromUtf8("myKey");
ByteString key2 = ByteString.copyFromUtf8("otherKey");
RowSet in = RowSet.newBuilder().addRowRanges(RowRange.newBuilder().setStartKeyOpen(key1).setEndKeyClosed(key2)).build();
RangeSet<RowKeyWrapper> out = adapter.rowSetToRangeSet(in);
RangeSet<RowKeyWrapper> expected = ImmutableRangeSet.<RowKeyWrapper>builder().add(Range.openClosed(new RowKeyWrapper(key1), new RowKeyWrapper(key2))).build();
assertEquals(expected, out);
adapter.rangeSetToByteStringRange(out, query);
assertEquals(in, query.toProto(requestContext).getRows());
}
use of com.google.bigtable.v2.ReadRowsRequest.Builder in project java-bigtable by googleapis.
the class DefaultRowAdapter method createRowFromProto.
/**
* Helper to convert a proto Row to a model Row.
*
* <p>For internal use only.
*/
@InternalApi
public Row createRowFromProto(com.google.bigtable.v2.Row row) {
RowBuilder<Row> builder = createRowBuilder();
builder.startRow(row.getKey());
for (Family family : row.getFamiliesList()) {
for (Column column : family.getColumnsList()) {
for (Cell cell : column.getCellsList()) {
builder.startCell(family.getName(), column.getQualifier(), cell.getTimestampMicros(), cell.getLabelsList(), cell.getValue().size());
builder.cellValue(cell.getValue());
builder.finishCell();
}
}
}
return builder.finishRow();
}
use of com.google.bigtable.v2.ReadRowsRequest.Builder in project java-bigtable by googleapis.
the class BigtableDataClientFactoryTest method testCreateWithRefreshingChannel.
@Test
public void testCreateWithRefreshingChannel() throws Exception {
String[] tableIds = { "fake-table1", "fake-table2" };
int poolSize = 3;
BigtableDataSettings.Builder builder = BigtableDataSettings.newBuilderForEmulator(port).setProjectId(DEFAULT_PROJECT_ID).setInstanceId(DEFAULT_INSTANCE_ID).setAppProfileId(DEFAULT_APP_PROFILE_ID).setPrimingTableIds(tableIds).setRefreshingChannel(true);
builder.stubSettings().setCredentialsProvider(credentialsProvider).setStreamWatchdogProvider(watchdogProvider).setExecutorProvider(executorProvider);
InstantiatingGrpcChannelProvider channelProvider = (InstantiatingGrpcChannelProvider) builder.stubSettings().getTransportChannelProvider();
InstantiatingGrpcChannelProvider.Builder channelProviderBuilder = channelProvider.toBuilder();
channelProviderBuilder.setPoolSize(poolSize);
builder.stubSettings().setTransportChannelProvider(channelProviderBuilder.build());
BigtableDataClientFactory factory = BigtableDataClientFactory.create(builder.build());
factory.createDefault();
factory.createForAppProfile("other-appprofile");
factory.createForInstance("other-project", "other-instance");
// Make sure that only 1 instance is created for all clients
Mockito.verify(credentialsProvider, Mockito.times(1)).getCredentials();
Mockito.verify(executorProvider, Mockito.times(1)).getExecutor();
Mockito.verify(watchdogProvider, Mockito.times(1)).getWatchdog();
// Make sure that the clients are sharing the same ChannelPool
assertThat(setUpAttributes).hasSize(poolSize);
// Make sure that prime requests were sent only once per table per connection
assertThat(service.readRowsRequests).hasSize(poolSize * tableIds.length);
List<ReadRowsRequest> expectedRequests = new LinkedList<>();
for (String tableId : tableIds) {
for (int i = 0; i < poolSize; i++) {
expectedRequests.add(ReadRowsRequest.newBuilder().setTableName(String.format("projects/%s/instances/%s/tables/%s", DEFAULT_PROJECT_ID, DEFAULT_INSTANCE_ID, tableId)).setAppProfileId(DEFAULT_APP_PROFILE_ID).setRows(RowSet.newBuilder().addRowKeys(ByteString.copyFromUtf8("nonexistent-priming-row"))).setFilter(RowFilter.newBuilder().setBlockAllFilter(true).build()).setRowsLimit(1).build());
}
}
assertThat(service.readRowsRequests).containsExactly(expectedRequests.toArray());
// Wait for all the connections to close asynchronously
factory.close();
long sleepTimeMs = 1000;
Thread.sleep(sleepTimeMs);
// Verify that all the channels are closed
assertThat(terminateAttributes).hasSize(poolSize);
}
Aggregations