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();
}
Aggregations