Search in sources :

Example 6 with EnhancedBigtableStub

use of com.google.cloud.bigtable.data.v2.stub.EnhancedBigtableStub 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));
    }
}
Also used : GrpcCallContext(com.google.api.gax.grpc.GrpcCallContext) Context(io.grpc.Context) RequestContext(com.google.cloud.bigtable.data.v2.internal.RequestContext) GrpcCallContext(com.google.api.gax.grpc.GrpcCallContext) ByteString(com.google.protobuf.ByteString) Row(com.google.cloud.bigtable.data.v2.models.Row) Test(org.junit.Test)

Example 7 with EnhancedBigtableStub

use of com.google.cloud.bigtable.data.v2.stub.EnhancedBigtableStub 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()));
            }
        }
    }
}
Also used : HashMap(java.util.HashMap) ByteString(com.google.protobuf.ByteString) DefaultRowAdapter(com.google.cloud.bigtable.data.v2.models.DefaultRowAdapter) ApiFuture(com.google.api.core.ApiFuture) Row(com.google.cloud.bigtable.data.v2.models.Row) ExecutionException(java.util.concurrent.ExecutionException) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

FakeServiceHelper (com.google.cloud.bigtable.data.v2.FakeServiceHelper)3 Before (org.junit.Before)3 Test (org.junit.Test)3 GrpcCallContext (com.google.api.gax.grpc.GrpcCallContext)2 BigtableDataSettings (com.google.cloud.bigtable.data.v2.BigtableDataSettings)2 RequestContext (com.google.cloud.bigtable.data.v2.internal.RequestContext)2 Row (com.google.cloud.bigtable.data.v2.models.Row)2 EnhancedBigtableStub (com.google.cloud.bigtable.data.v2.stub.EnhancedBigtableStub)2 EnhancedBigtableStubSettings (com.google.cloud.bigtable.data.v2.stub.EnhancedBigtableStubSettings)2 ByteString (com.google.protobuf.ByteString)2 Context (io.grpc.Context)2 ApiFuture (com.google.api.core.ApiFuture)1 BatcherImpl (com.google.api.gax.batching.BatcherImpl)1 DefaultRowAdapter (com.google.cloud.bigtable.data.v2.models.DefaultRowAdapter)1 RowMutationEntry (com.google.cloud.bigtable.data.v2.models.RowMutationEntry)1 BindableService (io.grpc.BindableService)1 SimpleForwardingServerCall (io.grpc.ForwardingServerCall.SimpleForwardingServerCall)1 Metadata (io.grpc.Metadata)1 ServerCall (io.grpc.ServerCall)1 ServerCallHandler (io.grpc.ServerCallHandler)1