Search in sources :

Example 1 with EnhancedBigtableStub

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

the class EnhancedBigtableStubTest method setUp.

@Before
public void setUp() throws IOException, IllegalAccessException, InstantiationException {
    metadataInterceptor = new MetadataInterceptor();
    contextInterceptor = new ContextInterceptor();
    fakeDataService = new FakeDataService();
    serviceHelper = new FakeServiceHelper(ImmutableList.of(contextInterceptor, metadataInterceptor), null, ImmutableList.<BindableService>of(fakeDataService));
    serviceHelper.start();
    defaultSettings = BigtableDataSettings.newBuilderForEmulator(serviceHelper.getPort()).setProjectId(PROJECT_ID).setInstanceId(INSTANCE_ID).setAppProfileId(APP_PROFILE_ID).setCredentialsProvider(NoCredentialsProvider.create()).build().getStubSettings();
    enhancedBigtableStub = EnhancedBigtableStub.create(defaultSettings);
}
Also used : FakeServiceHelper(com.google.cloud.bigtable.data.v2.FakeServiceHelper) BindableService(io.grpc.BindableService) Before(org.junit.Before)

Example 2 with EnhancedBigtableStub

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

the class EnhancedBigtableStubTest method testBulkMutationFlowControllerConfigured.

@Test
public void testBulkMutationFlowControllerConfigured() throws Exception {
    BigtableDataSettings.Builder settings = BigtableDataSettings.newBuilder().setProjectId("my-project").setInstanceId("my-instance").setCredentialsProvider(defaultSettings.getCredentialsProvider()).enableBatchMutationLatencyBasedThrottling(10L);
    settings.stubSettings().bulkMutateRowsSettings().setBatchingSettings(BatchingSettings.newBuilder().setElementCountThreshold(50L).setRequestByteThreshold(500L).setFlowControlSettings(FlowControlSettings.newBuilder().setMaxOutstandingElementCount(100L).setMaxOutstandingRequestBytes(1000L).setLimitExceededBehavior(LimitExceededBehavior.Block).build()).build()).build();
    try (EnhancedBigtableStub stub1 = EnhancedBigtableStub.create(settings.build().getStubSettings());
        EnhancedBigtableStub stub2 = EnhancedBigtableStub.create(settings.build().getStubSettings())) {
        // FlowControlEventStats
        try (BatcherImpl batcher1 = (BatcherImpl) stub1.newMutateRowsBatcher("my-table1", null);
            BatcherImpl batcher2 = (BatcherImpl) stub1.newMutateRowsBatcher("my-table2", null)) {
            assertThat(batcher1.getFlowController()).isNotNull();
            assertThat(batcher1.getFlowController().getFlowControlEventStats()).isNotNull();
            assertThat(batcher1).isNotSameInstanceAs(batcher2);
            assertThat(batcher1.getFlowController()).isSameInstanceAs(batcher2.getFlowController());
            assertThat(batcher1.getFlowController().getFlowControlEventStats()).isSameInstanceAs(batcher2.getFlowController().getFlowControlEventStats());
            // Verify flow controller settings
            assertThat(batcher1.getFlowController().getMaxElementCountLimit()).isEqualTo(100L);
            assertThat(batcher1.getFlowController().getMaxRequestBytesLimit()).isEqualTo(1000L);
            assertThat(batcher1.getFlowController().getCurrentElementCountLimit()).isLessThan(100L);
            assertThat(batcher1.getFlowController().getCurrentRequestBytesLimit()).isEqualTo(1000L);
            assertThat(batcher1.getFlowController().getMinElementCountLimit()).isAtLeast(settings.stubSettings().bulkMutateRowsSettings().getBatchingSettings().getElementCountThreshold());
            assertThat(batcher1.getFlowController().getMinRequestBytesLimit()).isEqualTo(1000L);
        }
        // FlowControlEventStats
        try (BatcherImpl batcher1 = (BatcherImpl) stub1.newMutateRowsBatcher("my-table1", null);
            BatcherImpl batcher2 = (BatcherImpl) stub2.newMutateRowsBatcher("my-table2", null)) {
            assertThat(batcher1.getFlowController()).isNotNull();
            assertThat(batcher1.getFlowController().getFlowControlEventStats()).isNotNull();
            assertThat(batcher1.getFlowController()).isNotSameInstanceAs(batcher2.getFlowController());
            assertThat(batcher1.getFlowController().getFlowControlEventStats()).isNotSameInstanceAs(batcher2.getFlowController().getFlowControlEventStats());
        }
    }
    try (EnhancedBigtableStub stub1 = EnhancedBigtableStub.create(settings.build().getStubSettings());
        EnhancedBigtableStub stub2 = EnhancedBigtableStub.create(settings.disableBatchMutationLatencyBasedThrottling().build().getStubSettings())) {
        try (BatcherImpl batcher = (BatcherImpl) stub2.newMutateRowsBatcher("my-table", null)) {
            assertThat(batcher.getFlowController().getMaxElementCountLimit()).isEqualTo(100L);
            assertThat(batcher.getFlowController().getCurrentElementCountLimit()).isEqualTo(100L);
            assertThat(batcher.getFlowController().getMinElementCountLimit()).isEqualTo(100L);
        }
    }
}
Also used : BatcherImpl(com.google.api.gax.batching.BatcherImpl) BigtableDataSettings(com.google.cloud.bigtable.data.v2.BigtableDataSettings) Test(org.junit.Test)

Example 3 with EnhancedBigtableStub

use of com.google.cloud.bigtable.data.v2.stub.EnhancedBigtableStub 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 4 with EnhancedBigtableStub

use of com.google.cloud.bigtable.data.v2.stub.EnhancedBigtableStub 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 EnhancedBigtableStub

use of com.google.cloud.bigtable.data.v2.stub.EnhancedBigtableStub 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));
    }
}
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) RowMutationEntry(com.google.cloud.bigtable.data.v2.models.RowMutationEntry) Test(org.junit.Test)

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