public static void executeSqlProber()

in cloudprober/src/main/java/com/google/grpc/cloudprober/SpannerProbes.java [105:150]


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

      // Probing executeSql call.
      ResultSet response =
          stub.executeSql(
              ExecuteSqlRequest.newBuilder()
                  .setSession(session.getName())
                  .setSql("select * FROM " + TABLE)
                  .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 SQL.");
      }

      // Probing streaming executeSql call.
      Iterator<PartialResultSet> responsePartial =
          stub.executeStreamingSql(
              ExecuteSqlRequest.newBuilder()
                  .setSession(session.getName())
                  .setSql("select * FROM " + TABLE)
                  .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 SQL. ");
      }

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