public static void readProber()

in cloudprober/src/main/java/com/google/grpc/cloudprober/SpannerProbes.java [153:207]


  public static void readProber(SpannerGrpc.SpannerBlockingStub stub)
      throws ProberException {
    Session session = null;
    try {
      session = stub.createSession(CreateSessionRequest.newBuilder().setDatabase(DATABASE).build());
      KeySet keySet = KeySet.newBuilder().setAll(true).build();

      // Probing read call.
      ResultSet response =
          stub.read(
              ReadRequest.newBuilder()
                  .setSession(session.getName())
                  .setTable(TABLE)
                  .setKeySet(keySet)
                  .addColumns("username")
                  .addColumns("firstname")
                  .addColumns("lastname")
                  .build());

      if (response == null) {
        throw new ProberException("Response is null when executing SQL. ");
      } else if (response.getRowsCount() != 1) {
        throw new ProberException(
            String.format("The number of Responses '%d' is not correct.", response.getRowsCount()));
      } else if (!response
          .getRows(0)
          .getValuesList()
          .get(0)
          .getStringValue()
          .equals(TEST_USERNAME)) {
        throw new ProberException("Response value is not correct when executing Reader.");
      }

      // Probing streamingRead call.
      Iterator<PartialResultSet> responsePartial =
          stub.streamingRead(
              ReadRequest.newBuilder()
                  .setSession(session.getName())
                  .setTable(TABLE)
                  .setKeySet(keySet)
                  .addColumns("username")
                  .addColumns("firstname")
                  .addColumns("lastname")
                  .build());
      if (responsePartial == null) {
        throw new ProberException("Response is null when executing streaming SQL. ");
      } else if (!responsePartial.next().getValues(0).getStringValue().equals(TEST_USERNAME)) {
        throw new ProberException(
            "Response value is not correct when executing streaming Reader. ");
      }

    } finally {
      deleteSession(stub, session);
    }
  }