Search in sources :

Example 6 with MockSpannerServiceImpl

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

the class JdbcPreparedStatementWithMockedServerTest method startStaticServer.

@BeforeClass
public static void startStaticServer() throws IOException {
    mockSpanner = new MockSpannerServiceImpl();
    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 7 with MockSpannerServiceImpl

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

the class PgNumericPreparedStatementTest method beforeClass.

@BeforeClass
public static void beforeClass() throws Exception {
    mockSpanner = new MockSpannerServiceImpl();
    mockSpanner.setAbortProbability(0.0D);
    mockSpanner.putStatementResult(StatementResult.detectDialectResult(Dialect.POSTGRESQL));
    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 8 with MockSpannerServiceImpl

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

the class PgNumericResultSetTest method beforeClass.

@BeforeClass
public static void beforeClass() throws Exception {
    mockSpanner = new MockSpannerServiceImpl();
    mockSpanner.setAbortProbability(0.0D);
    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 9 with MockSpannerServiceImpl

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

the class JdbcAbortedTransactionTest method startStaticServer.

@BeforeClass
public static void startStaticServer() throws IOException {
    mockSpanner = new MockSpannerServiceImpl();
    // We don't want any unpredictable aborted transactions.
    mockSpanner.setAbortProbability(0.0D);
    mockSpanner.putStatementResult(StatementResult.query(SELECT1, SELECT1_RESULTSET));
    mockSpanner.putStatementResult(StatementResult.update(UPDATE_STATEMENT, UPDATE_COUNT));
    MockInstanceAdminImpl mockInstanceAdmin = new MockInstanceAdminImpl();
    MockDatabaseAdminImpl mockDatabaseAdmin = new MockDatabaseAdminImpl();
    InetSocketAddress address = new InetSocketAddress("localhost", 0);
    server = NettyServerBuilder.forAddress(address).addService(mockSpanner).addService(mockInstanceAdmin).addService(mockDatabaseAdmin).build().start();
}
Also used : InetSocketAddress(java.net.InetSocketAddress) MockDatabaseAdminImpl(com.google.cloud.spanner.admin.database.v1.MockDatabaseAdminImpl) MockInstanceAdminImpl(com.google.cloud.spanner.admin.instance.v1.MockInstanceAdminImpl) MockSpannerServiceImpl(com.google.cloud.spanner.MockSpannerServiceImpl) BeforeClass(org.junit.BeforeClass)

Example 10 with MockSpannerServiceImpl

use of com.google.cloud.spanner.MockSpannerServiceImpl in project pgadapter by GoogleCloudPlatform.

the class AbstractMockServerTest method doStartMockSpannerAndPgAdapterServers.

protected static void doStartMockSpannerAndPgAdapterServers(String defaultDatabase, Iterable<String> extraPGAdapterOptions) throws Exception {
    mockSpanner = new MockSpannerServiceImpl();
    // We don't want any unpredictable aborted transactions.
    mockSpanner.setAbortProbability(0.0D);
    mockSpanner.putStatementResult(StatementResult.query(SELECT1, SELECT1_RESULTSET));
    mockSpanner.putStatementResult(StatementResult.query(SELECT2, SELECT2_RESULTSET));
    mockSpanner.putStatementResult(StatementResult.query(SELECT_FIVE_ROWS, SELECT_FIVE_ROWS_RESULTSET));
    mockSpanner.putStatementResult(StatementResult.update(UPDATE_STATEMENT, UPDATE_COUNT));
    mockSpanner.putStatementResult(StatementResult.update(INSERT_STATEMENT, INSERT_COUNT));
    mockSpanner.putStatementResult(MockSpannerServiceImpl.StatementResult.detectDialectResult(Dialect.POSTGRESQL));
    mockSpanner.putStatementResult(StatementResult.exception(INVALID_SELECT, EXCEPTION));
    mockSpanner.putStatementResult(StatementResult.exception(INVALID_DML, EXCEPTION));
    mockSpanner.putStatementResult(StatementResult.exception(INVALID_DDL, EXCEPTION));
    mockDatabaseAdmin = new MockDatabaseAdminImpl();
    InetSocketAddress address = new InetSocketAddress("localhost", 0);
    spannerServer = NettyServerBuilder.forAddress(address).addService(mockSpanner).addService(mockDatabaseAdmin).intercept(new ServerInterceptor() {

        @Override
        public <ReqT, RespT> Listener<ReqT> interceptCall(ServerCall<ReqT, RespT> serverCall, Metadata metadata, ServerCallHandler<ReqT, RespT> serverCallHandler) {
            if (SpannerGrpc.getExecuteStreamingSqlMethod().getFullMethodName().equals(serverCall.getMethodDescriptor().getFullMethodName())) {
                String userAgent = metadata.get(Metadata.Key.of("x-goog-api-client", Metadata.ASCII_STRING_MARSHALLER));
                assertNotNull(userAgent);
                assertTrue(userAgent.contains("pg-adapter"));
            }
            return Contexts.interceptCall(Context.current(), serverCall, metadata, serverCallHandler);
        }
    }).build().start();
    ImmutableList.Builder<String> argsListBuilder = ImmutableList.<String>builder().add("-p", "p", "-i", "i");
    if (defaultDatabase != null) {
        argsListBuilder.add("-d", defaultDatabase);
    }
    argsListBuilder.add("-jdbc", "-debug", "-c", // empty credentials file, as we are using a plain text connection.
    "", "-s", // port 0 to let the OS pick an available port
    "0", "-e", String.format("localhost:%d", spannerServer.getPort()), "-r", "usePlainText=true;");
    argsListBuilder.addAll(extraPGAdapterOptions);
    String[] args = argsListBuilder.build().toArray(new String[0]);
    pgServer = new ProxyServer(new OptionsMetadata(args));
    pgServer.startServer();
}
Also used : ServerCallHandler(io.grpc.ServerCallHandler) InetSocketAddress(java.net.InetSocketAddress) ImmutableList(com.google.common.collect.ImmutableList) MockDatabaseAdminImpl(com.google.cloud.spanner.admin.database.v1.MockDatabaseAdminImpl) OptionsMetadata(com.google.cloud.spanner.pgadapter.metadata.OptionsMetadata) Metadata(io.grpc.Metadata) UpdateDatabaseDdlMetadata(com.google.spanner.admin.database.v1.UpdateDatabaseDdlMetadata) ResultSetMetadata(com.google.spanner.v1.ResultSetMetadata) ServerCall(io.grpc.ServerCall) ServerInterceptor(io.grpc.ServerInterceptor) OptionsMetadata(com.google.cloud.spanner.pgadapter.metadata.OptionsMetadata) MockSpannerServiceImpl(com.google.cloud.spanner.MockSpannerServiceImpl)

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