use of com.google.cloud.bigtable.data.v2.BigtableDataSettings.Builder in project java-bigtable-hbase by googleapis.
the class SharedDataClientWrapperFactory method createDataClient.
synchronized DataClientWrapper createDataClient(BigtableHBaseVeneerSettings settings) throws IOException {
Preconditions.checkArgument(!settings.getDataSettings().isRefreshingChannel(), "Channel refreshing is not compatible with cached channel pools");
Key key = Key.createFromSettings(settings.getDataSettings());
// Get or create ClientContext that will contained the shared resources
ClientContext sharedCtx = cachedContexts.get(key);
if (sharedCtx == null) {
EnhancedBigtableStubSettings stubSettings = settings.getDataSettings().getStubSettings();
sharedCtx = ClientContext.create(stubSettings);
cachedContexts.put(key, sharedCtx);
refCounts.put(key, 0);
int channelPoolSize = BigtableVeneerApi.getChannelPoolSize(stubSettings);
for (int i = 0; i < channelPoolSize; i++) {
BigtableClientMetrics.counter(MetricLevel.Info, "grpc.channel.active").inc();
}
channelPoolSizes.put(key, channelPoolSize);
}
// Increment the count
refCounts.put(key, refCounts.get(key) + 1);
try {
// Patch settings to use shared resources
Builder builder = settings.getDataSettings().toBuilder();
builder.stubSettings().setTransportChannelProvider(FixedTransportChannelProvider.create(sharedCtx.getTransportChannel())).setCredentialsProvider(FixedCredentialsProvider.create(sharedCtx.getCredentials())).setExecutorProvider(FixedExecutorProvider.create(sharedCtx.getExecutor())).setStreamWatchdogProvider(FixedWatchdogProvider.create(sharedCtx.getStreamWatchdog())).setHeaderProvider(FixedHeaderProvider.create(sharedCtx.getHeaders())).setClock(sharedCtx.getClock());
BigtableDataSettings data = builder.build();
// Create a reference counted client wrapper
return new SharedDataClientWrapper(this, key, new DataClientVeneerApi(BigtableDataClient.create(data), settings.getClientTimeouts()));
} catch (IOException | RuntimeException e) {
release(key);
throw e;
}
}
use of com.google.cloud.bigtable.data.v2.BigtableDataSettings.Builder in project java-bigtable-hbase by googleapis.
the class TestMultiRowRangeAdapter method testDisjoint.
@Test
public void testDisjoint() throws IOException {
MultiRowRangeFilter filter = new MultiRowRangeFilter(Arrays.asList(new RowRange("bb", true, "cc", true), new RowRange("ss", true, "yy", true)));
Filters.Filter adaptedFilter = adapter.adapt(context, filter);
Assert.assertEquals(unaffectedRowFilter, adaptedFilter);
RangeSet<RowKeyWrapper> indexScanHint = adapter.getIndexScanHint(filter);
RangeSet<RowKeyWrapper> expected = ImmutableRangeSet.<RowKeyWrapper>builder().add(Range.closed(new RowKeyWrapper(ByteString.copyFromUtf8("bb")), new RowKeyWrapper(ByteString.copyFromUtf8("cc")))).add(Range.closed(new RowKeyWrapper(ByteString.copyFromUtf8("ss")), new RowKeyWrapper(ByteString.copyFromUtf8("yy")))).build();
Assert.assertEquals(expected, indexScanHint);
}
use of com.google.cloud.bigtable.data.v2.BigtableDataSettings.Builder in project java-bigtable by googleapis.
the class BigtableBulkReadRowsCallSettingsTest method testEmptyBuilder.
@Test
public void testEmptyBuilder() {
BigtableBulkReadRowsCallSettings.Builder builder = BigtableBulkReadRowsCallSettings.newBuilder(new ReadRowsBatchingDescriptor());
assertThat(builder.getBatchingSettings()).isNull();
assertThat(builder.getRetryableCodes()).isEmpty();
assertThat(builder.getRetrySettings()).isNotNull();
}
use of com.google.cloud.bigtable.data.v2.BigtableDataSettings.Builder in project java-bigtable by googleapis.
the class BigtableBulkReadRowsCallSettingsTest method testBuilder.
@Test
public void testBuilder() {
BigtableBulkReadRowsCallSettings.Builder builder = BigtableBulkReadRowsCallSettings.newBuilder(new ReadRowsBatchingDescriptor());
Set<StatusCode.Code> retryCodes = ImmutableSet.of(StatusCode.Code.UNAVAILABLE);
RetrySettings retrySettings = RetrySettings.newBuilder().build();
builder.setBatchingSettings(BATCHING_SETTINGS).setRetryableCodes(retryCodes).setRetrySettings(retrySettings);
BigtableBulkReadRowsCallSettings settings = builder.build();
assertThat(settings.getBatchingSettings()).isEqualTo(BATCHING_SETTINGS);
assertThat(settings.getRetryableCodes()).isEqualTo(retryCodes);
assertThat(settings.getRetrySettings()).isEqualTo(retrySettings);
}
use of com.google.cloud.bigtable.data.v2.BigtableDataSettings.Builder in project java-bigtable by googleapis.
the class BigtableBulkReadRowsCallSettingsTest method testBuilderFromSettings.
@Test
public void testBuilderFromSettings() {
BigtableBulkReadRowsCallSettings.Builder builder = BigtableBulkReadRowsCallSettings.newBuilder(new ReadRowsBatchingDescriptor());
RetrySettings retrySettings = RetrySettings.newBuilder().setTotalTimeout(Duration.ofMinutes(1)).build();
builder.setBatchingSettings(BATCHING_SETTINGS).setRetryableCodes(StatusCode.Code.UNAVAILABLE, StatusCode.Code.UNAUTHENTICATED).setRetrySettings(retrySettings);
BigtableBulkReadRowsCallSettings settings = builder.build();
BigtableBulkReadRowsCallSettings.Builder newBuilder = settings.toBuilder();
assertThat(newBuilder.getBatchingSettings()).isEqualTo(BATCHING_SETTINGS);
assertThat(newBuilder.getRetryableCodes()).containsExactly(StatusCode.Code.UNAVAILABLE, StatusCode.Code.UNAUTHENTICATED);
assertThat(newBuilder.getRetrySettings()).isEqualTo(retrySettings);
}
Aggregations