Search in sources :

Example 1 with MockDatabaseAdminImpl

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);
}
Also used : ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) MockDatabaseAdminImpl(com.google.cloud.spanner.admin.database.v1.MockDatabaseAdminImpl) BeforeClass(org.junit.BeforeClass)

Example 2 with MockDatabaseAdminImpl

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();
}
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 3 with MockDatabaseAdminImpl

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

Example 4 with MockDatabaseAdminImpl

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();
}
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 5 with MockDatabaseAdminImpl

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();
}
Also used : InetSocketAddress(java.net.InetSocketAddress) MockDatabaseAdminImpl(com.google.cloud.spanner.admin.database.v1.MockDatabaseAdminImpl) MockInstanceAdminImpl(com.google.cloud.spanner.admin.instance.v1.MockInstanceAdminImpl) BeforeClass(org.junit.BeforeClass)

Aggregations

MockDatabaseAdminImpl (com.google.cloud.spanner.admin.database.v1.MockDatabaseAdminImpl)7 InetSocketAddress (java.net.InetSocketAddress)6 MockSpannerServiceImpl (com.google.cloud.spanner.MockSpannerServiceImpl)5 BeforeClass (org.junit.BeforeClass)5 MockInstanceAdminImpl (com.google.cloud.spanner.admin.instance.v1.MockInstanceAdminImpl)4 UpdateDatabaseDdlMetadata (com.google.spanner.admin.database.v1.UpdateDatabaseDdlMetadata)2 ResultSetMetadata (com.google.spanner.v1.ResultSetMetadata)2 Metadata (io.grpc.Metadata)2 ServerCall (io.grpc.ServerCall)2 ServerCallHandler (io.grpc.ServerCallHandler)2 ServerInterceptor (io.grpc.ServerInterceptor)2 OptionsMetadata (com.google.cloud.spanner.pgadapter.metadata.OptionsMetadata)1 ImmutableList (com.google.common.collect.ImmutableList)1 AbstractFuture (com.google.common.util.concurrent.AbstractFuture)1 GetOperationRequest (com.google.longrunning.GetOperationRequest)1 Operation (com.google.longrunning.Operation)1 OperationsImplBase (com.google.longrunning.OperationsGrpc.OperationsImplBase)1 LogExceptionRunnable (io.grpc.internal.LogExceptionRunnable)1 ScheduledThreadPoolExecutor (java.util.concurrent.ScheduledThreadPoolExecutor)1 BeforeAll (org.junit.jupiter.api.BeforeAll)1