use of com.google.cloud.spanner.admin.database.v1.MockDatabaseAdminImpl in project java-spanner by googleapis.
the class DatabaseAdminGaxTest method startStaticServer.
@BeforeClass
public static void startStaticServer() throws IOException {
mockDatabaseAdmin = new MockDatabaseAdminImpl();
String uniqueName = InProcessServerBuilder.generateName();
server = InProcessServerBuilder.forName(uniqueName).scheduledExecutorService(new ScheduledThreadPoolExecutor(1)).addService(mockDatabaseAdmin).build().start();
channelProvider = LocalChannelProvider.create(uniqueName);
}
use of com.google.cloud.spanner.admin.database.v1.MockDatabaseAdminImpl 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.admin.database.v1.MockDatabaseAdminImpl 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();
}
use of com.google.cloud.spanner.admin.database.v1.MockDatabaseAdminImpl in project java-spanner-jdbc by googleapis.
the class JdbcGrpcErrorTest 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));
mockSpanner.putStatementResult(StatementResult.exception(INVALID_UPDATE_STATEMENT, Status.NOT_FOUND.withDescription("Unknown table name").asRuntimeException()));
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.admin.database.v1.MockDatabaseAdminImpl in project java-spanner by googleapis.
the class SpannerThreadsTest method startServer.
@BeforeClass
public static void startServer() throws IOException {
assumeTrue("Skip tests when emulator is enabled as this test interferes with the check whether the emulator is running", System.getenv("SPANNER_EMULATOR_HOST") == null);
mockSpanner = new MockSpannerServiceImpl();
// We don't want any unpredictable aborted transactions.
mockSpanner.setAbortProbability(0.0D);
mockSpanner.putStatementResult(StatementResult.query(SELECT1AND2, SELECT1_RESULTSET));
mockInstanceAdmin = new MockInstanceAdminImpl();
mockDatabaseAdmin = new MockDatabaseAdminImpl();
address = new InetSocketAddress("localhost", 0);
server = NettyServerBuilder.forAddress(address).addService(mockSpanner).addService(mockInstanceAdmin).addService(mockDatabaseAdmin).build().start();
}
Aggregations