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