@Test public void testUserAgentConfig() throws IOException, ClassNotFoundException, NoSuchFieldException, IllegalAccessException { GrpcClient grpcClient = new GrpcClient(GoogleCredentials.getApplicationDefault()); Channel channel = grpcClient.getSpanner().getChannel(); Class innerChannelWrapperClass = Class.forName("io.grpc.internal.ForwardingManagedChannel"); Class channelImplClass = Class.forName("io.grpc.internal.ManagedChannelImpl"); Field deletegateField = innerChannelWrapperClass.getDeclaredField("delegate"); deletegateField.setAccessible(true); Field userAgentField = channelImplClass.getDeclaredField("userAgent"); userAgentField.setAccessible(true); assertTrue(Pattern.matches("cloud-spanner-r2dbc/[0-9A-Za-z._-]+", (String) userAgentField.get(deletegateField.get(channel)))); }
@VisibleForTesting public SpannerStub getSpanner() { return this.spanner; }
GrpcClient implements Client { @VisibleForTesting public SpannerStub getSpanner() { return this.spanner; } }
GrpcClient implements Client { @VisibleForTesting public SpannerStub getSpanner() { return this.spanner; } GrpcClient(GoogleCredentials credentials); @VisibleForTesting  GrpcClient(SpannerStub spanner, DatabaseAdminStub databaseAdmin, OperationsStub operations); }
GrpcClient implements Client { @VisibleForTesting public SpannerStub getSpanner() { return this.spanner; } 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 { @VisibleForTesting public SpannerStub getSpanner() { return this.spanner; } 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();  }