@Test public void testHealthcheck() throws IOException { String sql = "SELECT 1"; SpannerImplBase spannerSpy = doTest(new SpannerImplBase() { @Override public void executeSql(ExecuteSqlRequest request, StreamObserver<ResultSet> responseObserver) { responseObserver.onNext(ResultSet.newBuilder().build()); responseObserver.onCompleted(); } }, grpcClient -> grpcClient.healthcheck(this.mockContext).block()); ArgumentCaptor<ExecuteSqlRequest> requestCaptor = ArgumentCaptor .forClass(ExecuteSqlRequest.class); verify(spannerSpy).executeSql(requestCaptor.capture(), any()); assertEquals(sql, requestCaptor.getValue().getSql()); assertEquals(SESSION_NAME, requestCaptor.getValue().getSession()); assertEquals(ByteString.EMPTY, requestCaptor.getValue().getTransaction().getId()); }
@Override public Mono<Boolean> healthcheck(StatementExecutionContext ctx) { return Mono.defer(() -> { if (ctx.getSessionName() == null) { return Mono.just(false); } return ObservableReactiveUtil.<ResultSet>unaryCall( obs -> this.spanner.executeSql(buildSqlRequest(ctx, HEALTHCHECK_SQL).build(), obs) ) .map(rs -> Boolean.TRUE) .onErrorResume(error -> { this.LOGGER.warn("Cloud Spanner healthcheck failed", error); return Mono.just(Boolean.FALSE); }); }); }
GrpcClient implements Client { @Override public Mono<Boolean> healthcheck(StatementExecutionContext ctx) { return Mono.defer(() -> { if (ctx.getSessionName() == null) { return Mono.just(false); } return ObservableReactiveUtil.<ResultSet>unaryCall( obs -> this.spanner.executeSql(buildSqlRequest(ctx, HEALTHCHECK_SQL).build(), obs) ) .map(rs -> Boolean.TRUE) .onErrorResume(error -> { this.LOGGER.warn("Cloud Spanner healthcheck failed", error); return Mono.just(Boolean.FALSE); }); }); } }
GrpcClient implements Client { @Override public Mono<Boolean> healthcheck(StatementExecutionContext ctx) { return Mono.defer(() -> { if (ctx.getSessionName() == null) { return Mono.just(false); } return ObservableReactiveUtil.<ResultSet>unaryCall( obs -> this.spanner.executeSql(buildSqlRequest(ctx, HEALTHCHECK_SQL).build(), obs) ) .map(rs -> Boolean.TRUE) .onErrorResume(error -> { this.LOGGER.warn("Cloud Spanner healthcheck failed", error); return Mono.just(Boolean.FALSE); }); }); } GrpcClient(GoogleCredentials credentials); @VisibleForTesting  GrpcClient(SpannerStub spanner, DatabaseAdminStub databaseAdmin, OperationsStub operations); }
GrpcClient implements Client { @Override public Mono<Boolean> healthcheck(StatementExecutionContext ctx) { return Mono.defer(() -> { if (ctx.getSessionName() == null) { return Mono.just(false); } return ObservableReactiveUtil.<ResultSet>unaryCall( obs -> this.spanner.executeSql(buildSqlRequest(ctx, HEALTHCHECK_SQL).build(), obs) ) .map(rs -> Boolean.TRUE) .onErrorResume(error -> { this.LOGGER.warn("Cloud Spanner healthcheck failed", error); return Mono.just(Boolean.FALSE); }); }); } 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<Boolean> healthcheck(StatementExecutionContext ctx) { return Mono.defer(() -> { if (ctx.getSessionName() == null) { return Mono.just(false); } return ObservableReactiveUtil.<ResultSet>unaryCall( obs -> this.spanner.executeSql(buildSqlRequest(ctx, HEALTHCHECK_SQL).build(), obs) ) .map(rs -> Boolean.TRUE) .onErrorResume(error -> { this.LOGGER.warn("Cloud Spanner healthcheck failed", error); return Mono.just(Boolean.FALSE); }); }); } 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();  }