@Test public void testCreateSession() throws IOException { SpannerImplBase spannerSpy = doTest(new SpannerImplBase() { @Override public void createSession(CreateSessionRequest request, StreamObserver<Session> responseObserver) { responseObserver.onNext(Session.newBuilder().build()); responseObserver.onCompleted(); } }, grpcClient -> grpcClient.createSession("testDb").block() ); ArgumentCaptor<CreateSessionRequest> requestCaptor = ArgumentCaptor .forClass(CreateSessionRequest.class); verify(spannerSpy).createSession(requestCaptor.capture(), any()); assertEquals("testDb", requestCaptor.getValue().getDatabase()); }
@Override public Mono<Session> createSession(String databaseName) { return Mono.defer(() -> { Assert.requireNonEmpty(databaseName, "Database name must not be empty"); CreateSessionRequest request = CreateSessionRequest.newBuilder() .setDatabase(databaseName) .build(); return ObservableReactiveUtil.unaryCall((obs) -> this.spanner.createSession(request, obs)); }); }
GrpcClient implements Client { @Override public Mono<Session> createSession(String databaseName) { return Mono.defer(() -> { Assert.requireNonEmpty(databaseName, "Database name must not be empty"); CreateSessionRequest request = CreateSessionRequest.newBuilder() .setDatabase(databaseName) .build(); return ObservableReactiveUtil.unaryCall((obs) -> this.spanner.createSession(request, obs)); }); } }
GrpcClient implements Client { @Override public Mono<Session> createSession(String databaseName) { return Mono.defer(() -> { Assert.requireNonEmpty(databaseName, "Database name must not be empty"); CreateSessionRequest request = CreateSessionRequest.newBuilder() .setDatabase(databaseName) .build(); return ObservableReactiveUtil.unaryCall((obs) -> this.spanner.createSession(request, obs)); }); } GrpcClient(GoogleCredentials credentials); @VisibleForTesting  GrpcClient(SpannerStub spanner, DatabaseAdminStub databaseAdmin, OperationsStub operations); }
GrpcClient implements Client { @Override public Mono<Session> createSession(String databaseName) { return Mono.defer(() -> { Assert.requireNonEmpty(databaseName, "Database name must not be empty"); CreateSessionRequest request = CreateSessionRequest.newBuilder() .setDatabase(databaseName) .build(); return ObservableReactiveUtil.unaryCall((obs) -> this.spanner.createSession(request, obs)); }); } GrpcClient(GoogleCredentials credentials); @VisibleForTesting  GrpcClient(SpannerStub spanner, DatabaseAdminStub databaseAdmin, OperationsStub operations); @Override Mono<Transaction> beginTransaction(
      String sessionName, TransactionOptions transactionOptions); @Override Mono<CommitResponse> commitTransaction(String sessionName, Transaction transaction); @Override Mono<Void> rollbackTransaction(String sessionName, Transaction transaction); @Override Mono<Session> createSession(String databaseName); @Override Mono<Void> deleteSession(String sessionName); @Override Flux<ResultSet> executeBatchDml(
      StatementExecutionContext ctx,
      List<Statement> statements); @Override Flux<PartialResultSet> executeStreamingSql(
      StatementExecutionContext ctx,
      String sql,
      Struct params,
      Map<String, Type> types); @Override Mono<Operation> executeDdl(
      String fullyQualifiedDatabaseName,
      List<String> ddlStatements,
      Duration ddlOperationTimeout,
      Duration ddlPollInterval); @Override Mono<Void> close(); @Override Mono<Boolean> healthcheck(StatementExecutionContext ctx); @VisibleForTesting SpannerStub getSpanner(); }
GrpcClient implements Client { @Override public Mono<Session> createSession(String databaseName) { return Mono.defer(() -> { Assert.requireNonEmpty(databaseName, "Database name must not be empty"); CreateSessionRequest request = CreateSessionRequest.newBuilder() .setDatabase(databaseName) .build(); return ObservableReactiveUtil.unaryCall((obs) -> this.spanner.createSession(request, obs)); }); } GrpcClient(GoogleCredentials credentials); @VisibleForTesting  GrpcClient(SpannerStub spanner, DatabaseAdminStub databaseAdmin, OperationsStub operations); @Override Mono<Transaction> beginTransaction(
      String sessionName, TransactionOptions transactionOptions); @Override Mono<CommitResponse> commitTransaction(String sessionName, Transaction transaction); @Override Mono<Void> rollbackTransaction(String sessionName, Transaction transaction); @Override Mono<Session> createSession(String databaseName); @Override Mono<Void> deleteSession(String sessionName); @Override Flux<ResultSet> executeBatchDml(
      StatementExecutionContext ctx,
      List<Statement> statements); @Override Flux<PartialResultSet> executeStreamingSql(
      StatementExecutionContext ctx,
      String sql,
      Struct params,
      Map<String, Type> types); @Override Mono<Operation> executeDdl(
      String fullyQualifiedDatabaseName,
      List<String> ddlStatements,
      Duration ddlOperationTimeout,
      Duration ddlPollInterval); @Override Mono<Void> close(); @Override Mono<Boolean> healthcheck(StatementExecutionContext ctx); @VisibleForTesting SpannerStub getSpanner();  }