use of com.google.cloud.spanner.admin.database.v1.MockDatabaseAdminImpl in project java-spanner by googleapis.
the class AbstractMockServerTest method startStaticServer.
@BeforeClass
public static void startStaticServer() throws IOException {
mockSpanner = new MockSpannerServiceImpl();
// We don't want any unpredictable aborted transactions.
mockSpanner.setAbortProbability(0.0D);
mockInstanceAdmin = new MockInstanceAdminImpl();
mockDatabaseAdmin = new MockDatabaseAdminImpl();
mockOperations = new OperationsImplBase() {
@Override
public void getOperation(GetOperationRequest request, StreamObserver<Operation> responseObserver) {
responseObserver.onNext(Operation.newBuilder().setDone(false).setName(request.getName()).setMetadata(Any.pack(Empty.getDefaultInstance())).build());
responseObserver.onCompleted();
}
};
address = new InetSocketAddress("localhost", 0);
server = NettyServerBuilder.forAddress(address).addService(mockSpanner).addService(mockInstanceAdmin).addService(mockDatabaseAdmin).addService(mockOperations).build().start();
mockSpanner.putStatementResult(StatementResult.query(SELECT_COUNT_STATEMENT, SELECT_COUNT_RESULTSET_BEFORE_INSERT));
mockSpanner.putStatementResult(StatementResult.update(INSERT_STATEMENT, UPDATE_COUNT));
mockSpanner.putStatementResult(StatementResult.query(SELECT_RANDOM_STATEMENT, RANDOM_RESULT_SET));
futureParentHandlers = Logger.getLogger(AbstractFuture.class.getName()).getUseParentHandlers();
exceptionRunnableParentHandlers = Logger.getLogger(LogExceptionRunnable.class.getName()).getUseParentHandlers();
nettyServerParentHandlers = Logger.getLogger("io.grpc.netty.shaded.io.grpc.netty.NettyServerHandler").getUseParentHandlers();
clientStreamParentHandlers = Logger.getLogger("io.grpc.netty.shaded.io.grpc.netty.NettyServerHandler").getUseParentHandlers();
Logger.getLogger(AbstractFuture.class.getName()).setUseParentHandlers(false);
Logger.getLogger(LogExceptionRunnable.class.getName()).setUseParentHandlers(false);
Logger.getLogger("io.grpc.netty.shaded.io.grpc.netty.NettyServerHandler").setUseParentHandlers(false);
Logger.getLogger("io.grpc.internal.AbstractClientStream").setUseParentHandlers(false);
}
use of com.google.cloud.spanner.admin.database.v1.MockDatabaseAdminImpl in project liquibase-spanner by cloudspannerecosystem.
the class AbstractMockServerTest method startStaticServer.
@BeforeAll
static void startStaticServer() throws IOException {
mockSpanner = new MockSpannerServiceImpl();
mockSpanner.setAbortProbability(0.0D);
mockAdmin = new MockDatabaseAdminImpl();
address = new InetSocketAddress("localhost", 0);
server = NettyServerBuilder.forAddress(address).addService(mockSpanner).addService(mockAdmin).intercept(new ServerInterceptor() {
@Override
public <ReqT, RespT> ServerCall.Listener<ReqT> interceptCall(ServerCall<ReqT, RespT> call, Metadata headers, ServerCallHandler<ReqT, RespT> next) {
// backend is the 'right' database, instead of at least checking the driver first...
if (!(call.getMethodDescriptor().getFullMethodName().equals("google.spanner.v1.Spanner/BatchCreateSessions") || call.getMethodDescriptor().getFullMethodName().equals("google.spanner.v1.Spanner/ExecuteStreamingSql") || call.getMethodDescriptor().getFullMethodName().equals("google.spanner.v1.Spanner/DeleteSession"))) {
String clientLibToken = headers.get(Key.of("x-goog-api-client", Metadata.ASCII_STRING_MARSHALLER));
if (clientLibToken == null || !clientLibToken.contains("sp-liq")) {
if (!receivedRequestWithNonLiquibaseToken.getAndSet(true)) {
invalidClientLibToken = clientLibToken;
}
}
}
return Contexts.interceptCall(Context.current(), call, headers, next);
}
}).build().start();
registerDefaultResults();
}
Aggregations