Search in sources :

Example 1 with MockOperationsServiceImpl

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

the class AbstractMockServerTest method startMockSpannerAndPgAdapterServers.

@BeforeClass
public static void startMockSpannerAndPgAdapterServers() 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.update(UPDATE_STATEMENT, UPDATE_COUNT));
    mockSpanner.putStatementResult(StatementResult.update(INSERT_STATEMENT, INSERT_COUNT));
    mockSpanner.putStatementResult(MockSpannerServiceImpl.StatementResult.detectDialectResult(Dialect.POSTGRESQL));
    mockOperationsService = new MockOperationsServiceImpl();
    mockDatabaseAdmin = new MockDatabaseAdminServiceImpl(mockOperationsService);
    InetSocketAddress address = new InetSocketAddress("localhost", 0);
    spannerServer = NettyServerBuilder.forAddress(address).addService(mockSpanner).addService(mockDatabaseAdmin).addService(mockOperationsService).build().start();
    // Create the test database on the mock server. This should be replaced by a simple feature in
    // the mock server to just add a database instead of having to simulate the creation of it.
    createDatabase();
    ImmutableList.Builder<String> argsListBuilder = ImmutableList.<String>builder().add("-p", "p", "-i", "i", "-d", "d", "-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;");
    String[] args = argsListBuilder.build().toArray(new String[0]);
    pgServer = new ProxyServer(new OptionsMetadata(args));
    pgServer.startServer();
}
Also used : InetSocketAddress(java.net.InetSocketAddress) ImmutableList(com.google.common.collect.ImmutableList) OptionsMetadata(com.google.cloud.spanner.pgadapter.metadata.OptionsMetadata) MockOperationsServiceImpl(com.google.cloud.spanner.MockOperationsServiceImpl) MockDatabaseAdminServiceImpl(com.google.cloud.spanner.MockDatabaseAdminServiceImpl) MockSpannerServiceImpl(com.google.cloud.spanner.MockSpannerServiceImpl) BeforeClass(org.junit.BeforeClass)

Aggregations

MockDatabaseAdminServiceImpl (com.google.cloud.spanner.MockDatabaseAdminServiceImpl)1 MockOperationsServiceImpl (com.google.cloud.spanner.MockOperationsServiceImpl)1 MockSpannerServiceImpl (com.google.cloud.spanner.MockSpannerServiceImpl)1 OptionsMetadata (com.google.cloud.spanner.pgadapter.metadata.OptionsMetadata)1 ImmutableList (com.google.common.collect.ImmutableList)1 InetSocketAddress (java.net.InetSocketAddress)1 BeforeClass (org.junit.BeforeClass)1