use of com.google.cloud.bigtable.data.v2.BigtableDataSettings.Builder in project java-bigtable by googleapis.
the class BigtableBatchingCallSettingsTest method testEmptyBuilder.
@Test
public void testEmptyBuilder() {
BigtableBatchingCallSettings.Builder builder = BigtableBatchingCallSettings.newBuilder(new MutateRowsBatchingDescriptor());
assertThat(builder.getBatchingSettings()).isNull();
assertThat(builder.getRetryableCodes()).isEmpty();
assertThat(builder.getRetrySettings()).isNotNull();
assertThat(builder.isLatencyBasedThrottlingEnabled()).isFalse();
assertThat(builder.getTargetRpcLatencyMs()).isNull();
assertThat(builder.getDynamicFlowControlSettings()).isNull();
}
use of com.google.cloud.bigtable.data.v2.BigtableDataSettings.Builder in project java-bigtable by googleapis.
the class BigtableBatchingCallSettingsTest method testBuilder.
@Test
public void testBuilder() {
BigtableBatchingCallSettings.Builder builder = BigtableBatchingCallSettings.newBuilder(new MutateRowsBatchingDescriptor());
Set<StatusCode.Code> retryCodes = ImmutableSet.of(StatusCode.Code.UNAVAILABLE);
RetrySettings retrySettings = RetrySettings.newBuilder().build();
builder.setBatchingSettings(BATCHING_SETTINGS).setRetryableCodes(retryCodes).setRetrySettings(retrySettings);
BigtableBatchingCallSettings settings = builder.build();
assertThat(settings.getBatchingSettings()).isEqualTo(BATCHING_SETTINGS);
assertThat(settings.getRetryableCodes()).isEqualTo(retryCodes);
assertThat(settings.getRetrySettings()).isEqualTo(retrySettings);
assertThat(settings.isLatencyBasedThrottlingEnabled()).isFalse();
assertThat(settings.getTargetRpcLatencyMs()).isNull();
assertThat(settings.getDynamicFlowControlSettings()).isNotNull();
verifyFlowControlSettingWhenLatencyBasedThrottlingDisabled(settings.getDynamicFlowControlSettings());
builder.enableLatencyBasedThrottling(10L);
settings = builder.build();
assertThat(settings.isLatencyBasedThrottlingEnabled()).isTrue();
assertThat(settings.getTargetRpcLatencyMs()).isEqualTo(10);
assertThat(settings.getDynamicFlowControlSettings()).isNotNull();
verifyFlowControlSettingWhenLatencyBasedThrottlingEnabled(settings.getDynamicFlowControlSettings());
builder.disableLatencyBasedThrottling();
settings = builder.build();
assertThat(settings.isLatencyBasedThrottlingEnabled()).isFalse();
assertThat(settings.getTargetRpcLatencyMs()).isNull();
assertThat(settings.getDynamicFlowControlSettings()).isNotNull();
verifyFlowControlSettingWhenLatencyBasedThrottlingDisabled(settings.getDynamicFlowControlSettings());
}
use of com.google.cloud.bigtable.data.v2.BigtableDataSettings.Builder in project java-bigtable by googleapis.
the class DirectPathFallbackIT method setup.
@Before
public void setup() throws IOException {
Set<ConnectionMode> validModes = ImmutableSet.of(ConnectionMode.REQUIRE_DIRECT_PATH, ConnectionMode.REQUIRE_DIRECT_PATH_IPV4);
assume().withMessage("DirectPathFallbackIT can only return when explicitly requested").that(validModes.contains(testEnvRule.env().getConnectionMode())).isTrue();
BigtableDataSettings defaultSettings = testEnvRule.env().getDataClientSettings();
InstantiatingGrpcChannelProvider defaultTransportProvider = (InstantiatingGrpcChannelProvider) defaultSettings.getStubSettings().getTransportChannelProvider();
InstantiatingGrpcChannelProvider instrumentedTransportChannelProvider = defaultTransportProvider.toBuilder().setAttemptDirectPath(true).setPoolSize(1).setChannelConfigurator(new ApiFunction<ManagedChannelBuilder, ManagedChannelBuilder>() {
@Override
public ManagedChannelBuilder apply(ManagedChannelBuilder builder) {
injectNettyChannelHandler(builder);
// Fail fast when blackhole is active
builder.keepAliveTime(1, TimeUnit.SECONDS);
builder.keepAliveTimeout(1, TimeUnit.SECONDS);
return builder;
}
}).build();
// Inject the instrumented transport provider into a new client
BigtableDataSettings.Builder settingsBuilder = testEnvRule.env().getDataClientSettings().toBuilder();
settingsBuilder.stubSettings().setTransportChannelProvider(instrumentedTransportChannelProvider).setCredentialsProvider(FixedCredentialsProvider.create(ComputeEngineCredentials.create()));
instrumentedClient = BigtableDataClient.create(settingsBuilder.build());
}
use of com.google.cloud.bigtable.data.v2.BigtableDataSettings.Builder in project java-bigtable by googleapis.
the class BulkMutateIT method test.
@Test(timeout = 60 * 1000)
public void test() throws IOException, InterruptedException {
BigtableDataSettings settings = testEnvRule.env().getDataClientSettings();
String rowPrefix = UUID.randomUUID().toString();
// Set target latency really low so it'll trigger adjusting thresholds
BigtableDataSettings.Builder builder = settings.toBuilder().enableBatchMutationLatencyBasedThrottling(2L);
try (BigtableDataClient client = BigtableDataClient.create(builder.build());
BatcherImpl<RowMutationEntry, Void, BulkMutation, Void> batcher = (BatcherImpl<RowMutationEntry, Void, BulkMutation, Void>) client.newBulkMutationBatcher(testEnvRule.env().getTableId())) {
FlowControlEventStats events = batcher.getFlowController().getFlowControlEventStats();
long initialThreashold = Objects.requireNonNull(batcher.getFlowController().getCurrentElementCountLimit());
assertThat(batcher.getFlowController().getCurrentElementCountLimit()).isNotEqualTo(batcher.getFlowController().getMinElementCountLimit());
assertThat(batcher.getFlowController().getCurrentElementCountLimit()).isNotEqualTo(batcher.getFlowController().getMaxElementCountLimit());
String familyId = testEnvRule.env().getFamilyId();
long initial = batcher.getFlowController().getCurrentElementCountLimit();
for (long i = 0; i < initial * 3; i++) {
String key = rowPrefix + "test-key" + i;
batcher.add(RowMutationEntry.create(key).setCell(familyId, "qualifier", i));
}
batcher.flush();
assertThat(events.getLastFlowControlEvent()).isNotNull();
// Verify that the threshold is adjusted
assertThat(batcher.getFlowController().getCurrentElementCountLimit()).isNotEqualTo(initialThreashold);
// Query a key to make sure the write succeeded
Row row = testEnvRule.env().getDataClient().readRowsCallable().first().call(Query.create(testEnvRule.env().getTableId()).rowKey(rowPrefix + "test-key" + initial));
assertThat(row.getCells()).hasSize(1);
}
}
use of com.google.cloud.bigtable.data.v2.BigtableDataSettings.Builder in project java-bigtable by googleapis.
the class EnhancedBigtableStub method finalizeSettings.
public static EnhancedBigtableStubSettings finalizeSettings(EnhancedBigtableStubSettings settings, Tagger tagger, StatsRecorder stats) throws IOException {
EnhancedBigtableStubSettings.Builder builder = settings.toBuilder();
// TODO: this implementation is on the cusp of unwieldy, if we end up adding more features
// consider splitting it up by feature.
// workaround JWT audience issues
patchCredentials(builder);
// Inject channel priming
if (settings.isRefreshingChannel()) {
// Fix the credentials so that they can be shared
Credentials credentials = null;
if (settings.getCredentialsProvider() != null) {
credentials = settings.getCredentialsProvider().getCredentials();
}
builder.setCredentialsProvider(FixedCredentialsProvider.create(credentials));
// Inject the primer
InstantiatingGrpcChannelProvider transportProvider = (InstantiatingGrpcChannelProvider) settings.getTransportChannelProvider();
builder.setTransportChannelProvider(transportProvider.toBuilder().setChannelPrimer(BigtableChannelPrimer.create(credentials, settings.getProjectId(), settings.getInstanceId(), settings.getAppProfileId(), settings.getPrimedTableIds())).build());
}
ImmutableMap<TagKey, TagValue> attributes = ImmutableMap.<TagKey, TagValue>builder().put(RpcMeasureConstants.BIGTABLE_PROJECT_ID, TagValue.create(settings.getProjectId())).put(RpcMeasureConstants.BIGTABLE_INSTANCE_ID, TagValue.create(settings.getInstanceId())).put(RpcMeasureConstants.BIGTABLE_APP_PROFILE_ID, TagValue.create(settings.getAppProfileId())).build();
// Inject Opencensus instrumentation
builder.setTracerFactory(new CompositeTracerFactory(ImmutableList.of(// Add OpenCensus Tracing
new OpencensusTracerFactory(ImmutableMap.<String, String>builder().put(RpcMeasureConstants.BIGTABLE_PROJECT_ID.getName(), settings.getProjectId()).put(RpcMeasureConstants.BIGTABLE_INSTANCE_ID.getName(), settings.getInstanceId()).put(RpcMeasureConstants.BIGTABLE_APP_PROFILE_ID.getName(), settings.getAppProfileId()).put("gax", GaxGrpcProperties.getGaxGrpcVersion()).put("grpc", GaxGrpcProperties.getGrpcVersion()).put("gapic", Version.VERSION).build()), // Add OpenCensus Metrics
MetricsTracerFactory.create(tagger, stats, attributes), // Add user configured tracer
settings.getTracerFactory())));
return builder.build();
}
Aggregations