use of com.google.cloud.bigtable.data.v2.stub.EnhancedBigtableStubSettings in project java-bigtable by googleapis.
the class EnhancedBigtableStubTest method testCallContextPropagatedInMutationBatcher.
@Test
public void testCallContextPropagatedInMutationBatcher() throws IOException, InterruptedException, ExecutionException {
EnhancedBigtableStubSettings settings = defaultSettings.toBuilder().setRefreshingChannel(true).setPrimedTableIds("table1", "table2").build();
try (EnhancedBigtableStub stub = EnhancedBigtableStub.create(settings)) {
// clear the previous contexts
contextInterceptor.contexts.clear();
// Override the timeout
GrpcCallContext clientCtx = GrpcCallContext.createDefault().withTimeout(Duration.ofMinutes(10));
// Send a batch
try (Batcher<RowMutationEntry, Void> batcher = stub.newMutateRowsBatcher("table1", clientCtx)) {
batcher.add(RowMutationEntry.create("key").deleteRow()).get();
}
// Ensure that the server got the overriden deadline
Context serverCtx = contextInterceptor.contexts.poll();
assertThat(serverCtx).isNotNull();
assertThat(serverCtx.getDeadline()).isAtLeast(Deadline.after(8, TimeUnit.MINUTES));
}
}
use of com.google.cloud.bigtable.data.v2.stub.EnhancedBigtableStubSettings in project java-bigtable by googleapis.
the class EnhancedBigtableStubTest method testCallContextPropagatedInReadBatcher.
@Test
public void testCallContextPropagatedInReadBatcher() throws IOException, InterruptedException, ExecutionException {
EnhancedBigtableStubSettings settings = defaultSettings.toBuilder().setRefreshingChannel(true).setPrimedTableIds("table1", "table2").build();
try (EnhancedBigtableStub stub = EnhancedBigtableStub.create(settings)) {
// clear the previous contexts
contextInterceptor.contexts.clear();
// Override the timeout
GrpcCallContext clientCtx = GrpcCallContext.createDefault().withTimeout(Duration.ofMinutes(10));
// Send a batch
try (Batcher<ByteString, Row> batcher = stub.newBulkReadRowsBatcher(Query.create("table1"), clientCtx)) {
batcher.add(ByteString.copyFromUtf8("key")).get();
}
// Ensure that the server got the overriden deadline
Context serverCtx = contextInterceptor.contexts.poll();
assertThat(serverCtx).isNotNull();
assertThat(serverCtx.getDeadline()).isAtLeast(Deadline.after(8, TimeUnit.MINUTES));
}
}
use of com.google.cloud.bigtable.data.v2.stub.EnhancedBigtableStubSettings in project java-bigtable by googleapis.
the class BigtableDataSettingsTest method testToString.
@Test
public void testToString() {
BigtableDataSettings settings = BigtableDataSettings.newBuilder().setProjectId("our-project-2-12").setInstanceId("our-instance-85").setAppProfileId("our-appProfile-06").enableBatchMutationLatencyBasedThrottling(10).build();
EnhancedBigtableStubSettings stubSettings = settings.getStubSettings();
assertThat(settings.toString()).isEqualTo("BigtableDataSettings{stubSettings=" + stubSettings.toString() + "}");
}
use of com.google.cloud.bigtable.data.v2.stub.EnhancedBigtableStubSettings in project java-bigtable by googleapis.
the class BigtableChannelPrimer method sendPrimeRequests.
private void sendPrimeRequests(ManagedChannel managedChannel) throws IOException {
// Wrap the channel in a temporary stub
EnhancedBigtableStubSettings primingSettings = settingsTemplate.toBuilder().setTransportChannelProvider(FixedTransportChannelProvider.create(GrpcTransportChannel.create(managedChannel))).build();
try (EnhancedBigtableStub stub = EnhancedBigtableStub.create(primingSettings)) {
Map<String, ApiFuture<?>> primeFutures = new HashMap<>();
// Prime all of the table ids in parallel
for (String tableId : tableIds) {
ApiFuture<Row> f = stub.createReadRowsRawCallable(new DefaultRowAdapter()).first().futureCall(ReadRowsRequest.newBuilder().setTableName(TableName.format(primingSettings.getProjectId(), primingSettings.getInstanceId(), tableId)).setAppProfileId(primingSettings.getAppProfileId()).setRows(RowSet.newBuilder().addRowKeys(PRIMING_ROW_KEY).build()).setFilter(RowFilter.newBuilder().setBlockAllFilter(true).build()).setRowsLimit(1).build());
primeFutures.put(tableId, f);
}
// Wait for all of the prime requests to complete.
for (Map.Entry<String, ApiFuture<?>> entry : primeFutures.entrySet()) {
try {
entry.getValue().get();
} catch (Throwable e) {
if (e instanceof ExecutionException) {
e = e.getCause();
}
LOG.warning(String.format("Failed to prime channel for table: %s: %s", entry.getKey(), e.getMessage()));
}
}
}
}
use of com.google.cloud.bigtable.data.v2.stub.EnhancedBigtableStubSettings 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