public void validateQuery(VM vm, final String query, final int resultSize) {
    vm.invoke(new CacheSerializableRunnable("Validate Query") {
      @Override
      public void run2() throws CacheException {
        LogWriterUtils.getLogWriter().info("### Validating Query. ###");
        QueryService qs = getCache().getQueryService();

        Query q = qs.newQuery(query);
        try {
          Object r = q.execute();
          if (r instanceof Collection) {
            int rSize = ((Collection) r).size();
            LogWriterUtils.getLogWriter().info("### Result Size is :" + rSize);
            assertEquals(rSize, resultSize);
          }
        } catch (Exception e) {
          Assert.fail("Failed to execute the query.", e);
        }
      }
    });
  }
Waits till the CQ state is same as the expected. Waits for max time, if the CQ state is not
same as expected throws exception.
geode-cq/src/distributedTest/java/org/apache/geode/cache/query/cq/dunit/CqQueryUsingPoolDUnitTest.java