Search in sources :

Example 1 with MockSpannerServiceImpl

use of com.google.cloud.spanner.MockSpannerServiceImpl in project java-spanner by googleapis.

the class LocalConnectionCheckerTest method beforeClass.

@BeforeClass
public static void beforeClass() throws Exception {
    mockSpanner = new MockSpannerServiceImpl();
    // We don't want any unpredictable aborted transactions.
    mockSpanner.setAbortProbability(0.0D);
    final InetSocketAddress address = new InetSocketAddress("localhost", 0);
    server = NettyServerBuilder.forAddress(address).addService(mockSpanner).build();
    server.start();
}
Also used : InetSocketAddress(java.net.InetSocketAddress) MockSpannerServiceImpl(com.google.cloud.spanner.MockSpannerServiceImpl) BeforeClass(org.junit.BeforeClass)

Example 2 with MockSpannerServiceImpl

use of com.google.cloud.spanner.MockSpannerServiceImpl in project java-spanner by googleapis.

the class GfeLatencyTest method startServer.

@BeforeClass
public static void startServer() throws IOException {
    SpannerRpcViews.registerGfeLatencyAndHeaderMissingCountViews();
    assumeFalse(EmulatorSpannerHelper.isUsingEmulator());
    mockSpanner = new MockSpannerServiceImpl();
    // We don't want any unpredictable aborted transactions.
    mockSpanner.setAbortProbability(0.0D);
    mockSpanner.putStatementResult(MockSpannerServiceImpl.StatementResult.query(SELECT1AND2, SELECT1_RESULTSET));
    mockSpanner.putStatementResult(MockSpannerServiceImpl.StatementResult.update(UPDATE_FOO_STATEMENT, 1L));
    address = new InetSocketAddress("localhost", 0);
    server = NettyServerBuilder.forAddress(address).addService(mockSpanner).intercept(new ServerInterceptor() {

        @Override
        public <ReqT, RespT> ServerCall.Listener<ReqT> interceptCall(ServerCall<ReqT, RespT> serverCall, Metadata headers, ServerCallHandler<ReqT, RespT> serverCallHandler) {
            return serverCallHandler.startCall(new ForwardingServerCall.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);
                }
            }, headers);
        }
    }).build().start();
    optionsMap.put(SpannerRpc.Option.CHANNEL_HINT, 1L);
    spanner = createSpannerOptions(address, server).getService();
    databaseClient = spanner.getDatabaseClient(DatabaseId.of(projectId, instanceId, databaseId));
    mockSpannerNoHeader = new MockSpannerServiceImpl();
    mockSpannerNoHeader.setAbortProbability(0.0D);
    mockSpannerNoHeader.putStatementResult(MockSpannerServiceImpl.StatementResult.query(SELECT1AND2, SELECT1_RESULTSET));
    mockSpannerNoHeader.putStatementResult(MockSpannerServiceImpl.StatementResult.update(UPDATE_FOO_STATEMENT, 1L));
    addressNoHeader = new InetSocketAddress("localhost", 0);
    serverNoHeader = NettyServerBuilder.forAddress(addressNoHeader).addService(mockSpannerNoHeader).build().start();
    spannerNoHeader = createSpannerOptions(addressNoHeader, serverNoHeader).getService();
    databaseClientNoHeader = spannerNoHeader.getDatabaseClient(DatabaseId.of(projectId, instanceId, databaseId));
}
Also used : ServerCallHandler(io.grpc.ServerCallHandler) ForwardingServerCall(io.grpc.ForwardingServerCall) ServerCall(io.grpc.ServerCall) InetSocketAddress(java.net.InetSocketAddress) ServerInterceptor(io.grpc.ServerInterceptor) Metadata(io.grpc.Metadata) ResultSetMetadata(com.google.spanner.v1.ResultSetMetadata) ForwardingServerCall(io.grpc.ForwardingServerCall) MockSpannerServiceImpl(com.google.cloud.spanner.MockSpannerServiceImpl) BeforeClass(org.junit.BeforeClass)

Example 3 with MockSpannerServiceImpl

use of com.google.cloud.spanner.MockSpannerServiceImpl in project beam by apache.

the class SpannerChangeStreamErrorTest method setUp.

@Before
public void setUp() throws Exception {
    mockSpannerService = new MockSpannerServiceImpl();
    serviceHelper = new MockServiceHelper(SPANNER_HOST, Collections.singletonList(mockSpannerService));
    serviceHelper.start();
    serviceHelper.reset();
}
Also used : MockServiceHelper(com.google.api.gax.grpc.testing.MockServiceHelper) MockSpannerServiceImpl(com.google.cloud.spanner.MockSpannerServiceImpl) Before(org.junit.Before)

Example 4 with MockSpannerServiceImpl

use of com.google.cloud.spanner.MockSpannerServiceImpl in project java-spanner-jdbc by googleapis.

the class JdbcDatabaseMetaDataWithMockedServerTest method startStaticServer.

@BeforeClass
public static void startStaticServer() throws IOException {
    mockSpanner = new MockSpannerServiceImpl();
    // We don't want any unpredictable aborted transactions.
    mockSpanner.setAbortProbability(0.0D);
    InetSocketAddress address = new InetSocketAddress("localhost", 0);
    server = NettyServerBuilder.forAddress(address).addService(mockSpanner).build().start();
}
Also used : InetSocketAddress(java.net.InetSocketAddress) MockSpannerServiceImpl(com.google.cloud.spanner.MockSpannerServiceImpl) BeforeClass(org.junit.BeforeClass)

Example 5 with MockSpannerServiceImpl

use of com.google.cloud.spanner.MockSpannerServiceImpl in project java-spanner-jdbc by googleapis.

the class JdbcDriverTest method startStaticServer.

@BeforeClass
public static void startStaticServer() throws IOException {
    MockSpannerServiceImpl mockSpanner = new MockSpannerServiceImpl();
    InetSocketAddress address = new InetSocketAddress("localhost", 0);
    server = NettyServerBuilder.forAddress(address).addService(mockSpanner).build().start();
}
Also used : InetSocketAddress(java.net.InetSocketAddress) MockSpannerServiceImpl(com.google.cloud.spanner.MockSpannerServiceImpl) BeforeClass(org.junit.BeforeClass)

Aggregations

MockSpannerServiceImpl (com.google.cloud.spanner.MockSpannerServiceImpl)15 InetSocketAddress (java.net.InetSocketAddress)14 BeforeClass (org.junit.BeforeClass)11 MockDatabaseAdminImpl (com.google.cloud.spanner.admin.database.v1.MockDatabaseAdminImpl)5 ResultSetMetadata (com.google.spanner.v1.ResultSetMetadata)4 Metadata (io.grpc.Metadata)4 ServerCall (io.grpc.ServerCall)4 ServerCallHandler (io.grpc.ServerCallHandler)4 ServerInterceptor (io.grpc.ServerInterceptor)4 MockInstanceAdminImpl (com.google.cloud.spanner.admin.instance.v1.MockInstanceAdminImpl)3 OptionsMetadata (com.google.cloud.spanner.pgadapter.metadata.OptionsMetadata)2 ImmutableList (com.google.common.collect.ImmutableList)2 UpdateDatabaseDdlMetadata (com.google.spanner.admin.database.v1.UpdateDatabaseDdlMetadata)2 Before (org.junit.Before)2 MockServiceHelper (com.google.api.gax.grpc.testing.MockServiceHelper)1 MockDatabaseAdminServiceImpl (com.google.cloud.spanner.MockDatabaseAdminServiceImpl)1 MockOperationsServiceImpl (com.google.cloud.spanner.MockOperationsServiceImpl)1 AbstractFuture (com.google.common.util.concurrent.AbstractFuture)1 GetOperationRequest (com.google.longrunning.GetOperationRequest)1 Operation (com.google.longrunning.Operation)1