Search in sources :

Example 1 with EnhancedBigtableStubSettings

use of com.google.cloud.bigtable.data.v2.stub.EnhancedBigtableStubSettings in project java-bigtable by googleapis.

the class EnhancedBigtableStubCloseTest method setUp.

@Before
public void setUp() throws Exception {
    testExecutor = Executors.newCachedThreadPool();
    requestReceivedBarrier = SettableFuture.create();
    clientClosedBarrier = SettableFuture.create();
    serviceHelper = new FakeServiceHelper(new FakeBigtable());
    serviceHelper.start();
    EnhancedBigtableStubSettings stubSettings = BigtableDataSettings.newBuilderForEmulator(serviceHelper.getPort()).setProjectId(PROJECT_ID).setInstanceId(INSTANCE_ID).setCredentialsProvider(NoCredentialsProvider.create()).setRefreshingChannel(false).build().getStubSettings();
    stub = EnhancedBigtableStub.create(stubSettings);
}
Also used : FakeServiceHelper(com.google.cloud.bigtable.data.v2.FakeServiceHelper) Before(org.junit.Before)

Example 2 with EnhancedBigtableStubSettings

use of com.google.cloud.bigtable.data.v2.stub.EnhancedBigtableStubSettings in project java-bigtable by googleapis.

the class MetricsTracerTest method setUp.

@Before
public void setUp() throws Exception {
    serviceHelper = new FakeServiceHelper(mockService);
    serviceHelper.start();
    RpcViews.registerBigtableClientViews(localStats.getViewManager());
    settings = BigtableDataSettings.newBuilderForEmulator(serviceHelper.getPort()).setProjectId(PROJECT_ID).setInstanceId(INSTANCE_ID).setAppProfileId(APP_PROFILE_ID).build();
    EnhancedBigtableStubSettings stubSettings = EnhancedBigtableStub.finalizeSettings(settings.getStubSettings(), Tags.getTagger(), localStats.getStatsRecorder());
    stub = new EnhancedBigtableStub(stubSettings, ClientContext.create(stubSettings));
}
Also used : EnhancedBigtableStubSettings(com.google.cloud.bigtable.data.v2.stub.EnhancedBigtableStubSettings) FakeServiceHelper(com.google.cloud.bigtable.data.v2.FakeServiceHelper) EnhancedBigtableStub(com.google.cloud.bigtable.data.v2.stub.EnhancedBigtableStub) Before(org.junit.Before)

Example 3 with EnhancedBigtableStubSettings

use of com.google.cloud.bigtable.data.v2.stub.EnhancedBigtableStubSettings 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;
    }
}
Also used : EnhancedBigtableStubSettings(com.google.cloud.bigtable.data.v2.stub.EnhancedBigtableStubSettings) ClientContext(com.google.api.gax.rpc.ClientContext) Builder(com.google.cloud.bigtable.data.v2.BigtableDataSettings.Builder) IOException(java.io.IOException) BigtableDataSettings(com.google.cloud.bigtable.data.v2.BigtableDataSettings)

Example 4 with EnhancedBigtableStubSettings

use of com.google.cloud.bigtable.data.v2.stub.EnhancedBigtableStubSettings in project java-bigtable by googleapis.

the class HeaderTracerCallableTest method setUp.

@Before
public void setUp() throws Exception {
    RpcViews.registerBigtableClientGfeViews(localStats.getViewManager());
    // Create a server that'll inject a server-timing header with a random number and a stub that
    // connects to this server.
    fakeServerTiming = new AtomicInteger(new Random().nextInt(1000) + 1);
    serviceHelper = new FakeServiceHelper(new ServerInterceptor() {

        @Override
        public <ReqT, RespT> ServerCall.Listener<ReqT> interceptCall(ServerCall<ReqT, RespT> serverCall, Metadata metadata, ServerCallHandler<ReqT, RespT> serverCallHandler) {
            return serverCallHandler.startCall(new SimpleForwardingServerCall<ReqT, RespT>(serverCall) {

                @Override
                public void sendHeaders(Metadata headers) {
                    headers.put(Metadata.Key.of("server-timing", Metadata.ASCII_STRING_MARSHALLER), String.format("gfet4t7; dur=%d", fakeServerTiming.get()));
                    super.sendHeaders(headers);
                }
            }, metadata);
        }
    }, fakeService);
    serviceHelper.start();
    BigtableDataSettings settings = BigtableDataSettings.newBuilderForEmulator(serviceHelper.getPort()).setProjectId(PROJECT_ID).setInstanceId(INSTANCE_ID).setAppProfileId(APP_PROFILE_ID).build();
    EnhancedBigtableStubSettings stubSettings = EnhancedBigtableStub.finalizeSettings(settings.getStubSettings(), Tags.getTagger(), localStats.getStatsRecorder());
    attempts = stubSettings.readRowsSettings().getRetrySettings().getMaxAttempts();
    stub = new EnhancedBigtableStub(stubSettings, ClientContext.create(stubSettings));
    // Create another server without injecting the server-timing header and another stub that
    // connects to it.
    serviceHelperNoHeader = new FakeServiceHelper(fakeService);
    serviceHelperNoHeader.start();
    BigtableDataSettings noHeaderSettings = BigtableDataSettings.newBuilderForEmulator(serviceHelperNoHeader.getPort()).setProjectId(PROJECT_ID).setInstanceId(INSTANCE_ID).setAppProfileId(APP_PROFILE_ID).build();
    EnhancedBigtableStubSettings noHeaderStubSettings = EnhancedBigtableStub.finalizeSettings(noHeaderSettings.getStubSettings(), Tags.getTagger(), localStats.getStatsRecorder());
    noHeaderStub = new EnhancedBigtableStub(noHeaderStubSettings, ClientContext.create(noHeaderStubSettings));
}
Also used : ServerCallHandler(io.grpc.ServerCallHandler) FakeServiceHelper(com.google.cloud.bigtable.data.v2.FakeServiceHelper) Metadata(io.grpc.Metadata) BigtableDataSettings(com.google.cloud.bigtable.data.v2.BigtableDataSettings) EnhancedBigtableStubSettings(com.google.cloud.bigtable.data.v2.stub.EnhancedBigtableStubSettings) Random(java.util.Random) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) SimpleForwardingServerCall(io.grpc.ForwardingServerCall.SimpleForwardingServerCall) ServerCall(io.grpc.ServerCall) ServerInterceptor(io.grpc.ServerInterceptor) EnhancedBigtableStub(com.google.cloud.bigtable.data.v2.stub.EnhancedBigtableStub) Before(org.junit.Before)

Example 5 with EnhancedBigtableStubSettings

use of com.google.cloud.bigtable.data.v2.stub.EnhancedBigtableStubSettings in project java-bigtable by googleapis.

the class StatsHeadersCallableTest method setUp.

@Before
public void setUp() throws Exception {
    metadataInterceptor = new MetadataInterceptor();
    serviceHelper = new FakeServiceHelper(metadataInterceptor, fakeService);
    serviceHelper.start();
    EnhancedBigtableStubSettings settings = BigtableDataSettings.newBuilderForEmulator(serviceHelper.getPort()).setProjectId(PROJECT_ID).setInstanceId(INSTANCE_ID).setAppProfileId(APP_PROFILE_ID).build().getStubSettings();
    stub = EnhancedBigtableStub.create(settings);
}
Also used : EnhancedBigtableStubSettings(com.google.cloud.bigtable.data.v2.stub.EnhancedBigtableStubSettings) FakeServiceHelper(com.google.cloud.bigtable.data.v2.FakeServiceHelper) Before(org.junit.Before)

Aggregations

EnhancedBigtableStubSettings (com.google.cloud.bigtable.data.v2.stub.EnhancedBigtableStubSettings)5 FakeServiceHelper (com.google.cloud.bigtable.data.v2.FakeServiceHelper)4 Before (org.junit.Before)4 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 ByteString (com.google.protobuf.ByteString)2 Context (io.grpc.Context)2 ApiFuture (com.google.api.core.ApiFuture)1 InstantiatingGrpcChannelProvider (com.google.api.gax.grpc.InstantiatingGrpcChannelProvider)1 ClientContext (com.google.api.gax.rpc.ClientContext)1 OpencensusTracerFactory (com.google.api.gax.tracing.OpencensusTracerFactory)1 Credentials (com.google.auth.Credentials)1 ServiceAccountJwtAccessCredentials (com.google.auth.oauth2.ServiceAccountJwtAccessCredentials)1 Builder (com.google.cloud.bigtable.data.v2.BigtableDataSettings.Builder)1 DefaultRowAdapter (com.google.cloud.bigtable.data.v2.models.DefaultRowAdapter)1 RowMutationEntry (com.google.cloud.bigtable.data.v2.models.RowMutationEntry)1