Search in sources :

Example 1 with FakeServiceHelper

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

the class HeadersTest method setUp.

@Before
public void setUp() throws Exception {
    serviceHelper = new FakeServiceHelper(new MetadataInterceptor(), new FakeBigtableService());
    serviceHelper.start();
    BigtableDataSettings.Builder settings = BigtableDataSettings.newBuilderForEmulator(serviceHelper.getPort()).setProjectId(PROJECT_ID).setInstanceId(INSTANCE_ID).setAppProfileId(APP_PROFILE_ID);
    HeaderProvider headerProvider = FixedHeaderProvider.create(TEST_FIXED_HEADER_STRING, "test_header_value");
    // Force immediate flush
    settings.stubSettings().setHeaderProvider(headerProvider).bulkMutateRowsSettings().setBatchingSettings(settings.stubSettings().bulkMutateRowsSettings().getBatchingSettings().toBuilder().setElementCountThreshold(1L).build());
    client = BigtableDataClient.create(settings.build());
}
Also used : FakeServiceHelper(com.google.cloud.bigtable.data.v2.FakeServiceHelper) HeaderProvider(com.google.api.gax.rpc.HeaderProvider) FixedHeaderProvider(com.google.api.gax.rpc.FixedHeaderProvider) BigtableDataSettings(com.google.cloud.bigtable.data.v2.BigtableDataSettings) Before(org.junit.Before)

Example 2 with FakeServiceHelper

use of com.google.cloud.bigtable.data.v2.FakeServiceHelper 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 3 with FakeServiceHelper

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

use of com.google.cloud.bigtable.data.v2.FakeServiceHelper 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 5 with FakeServiceHelper

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

Aggregations

FakeServiceHelper (com.google.cloud.bigtable.data.v2.FakeServiceHelper)8 Before (org.junit.Before)8 BigtableDataSettings (com.google.cloud.bigtable.data.v2.BigtableDataSettings)3 EnhancedBigtableStubSettings (com.google.cloud.bigtable.data.v2.stub.EnhancedBigtableStubSettings)3 EnhancedBigtableStub (com.google.cloud.bigtable.data.v2.stub.EnhancedBigtableStub)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 FixedHeaderProvider (com.google.api.gax.rpc.FixedHeaderProvider)1 HeaderProvider (com.google.api.gax.rpc.HeaderProvider)1 AccessToken (com.google.auth.oauth2.AccessToken)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 ServerInterceptor (io.grpc.ServerInterceptor)1 Random (java.util.Random)1