/**
   * Verify the result of the CQs registered for this VM. Query results from
   * executeWithInitialResults are combined with subsequent cq events to form the final result.
   */
  protected void verifyQueryResultsCombine() {
    Log.getLogWriter().info("In verifyQueryResultsCombine");
    Iterator it = queryMap.keySet().iterator();
    int count = 0;
    while (it.hasNext()) {
      count++;
      String cqName = (String) (it.next());
      Log.getLogWriter()
          .info("Verifying query " + count + " out of " + queryMap.size() + " with name " + cqName);
      CqQuery cq = qService.getCq(cqName);
      String queryStr = cq.getQueryString();
      String readableQueryStr = CQTest.getReadableQueryString(queryStr);

      // combine the initial selectResults with history of events
      CQHistory history = CQHistoryListener.getCQHistory(cqName);
      Map combinedMap = history.getCombinedResults();
      List combinedList = new ArrayList(combinedMap.values());
      List expectedResults = CQTestInstance.getExpectedResults(queryStr);
      List missingInCombined = new ArrayList(expectedResults);
      List unexpectedInCombined = new ArrayList(combinedList);
      unexpectedInCombined.removeAll(expectedResults);
      missingInCombined.removeAll(combinedList);

      // prepare error Strings
      StringBuffer aStr = new StringBuffer();
      if (unexpectedInCombined.size() > 0) {
        String tmpStr =
            getLocationString(unexpectedInCombined, expectedResults, history)
                + "\n"
                + "Found the following "
                + unexpectedInCombined.size()
                + " unexpected elements in combined results for cq "
                + cqName
                + ", "
                + readableQueryStr
                + ": "
                + QueryObject.toStringFull(unexpectedInCombined);
        Log.getLogWriter().info(tmpStr);
        aStr.append(tmpStr);
      }
      if (missingInCombined.size() > 0) {
        String tmpStr =
            getLocationString(missingInCombined, expectedResults, history)
                + "\n"
                + "The following "
                + missingInCombined.size()
                + " elements were missing from combined results for cq "
                + cqName
                + ", "
                + readableQueryStr
                + ": "
                + QueryObject.toStringFull(missingInCombined);
        Log.getLogWriter().info(tmpStr);
        aStr.append(tmpStr);
      }

      if (aStr.length() > 0) {
        throw new TestException(
            "Probably bug 38065: For cq "
                + cqName
                + ", "
                + readableQueryStr
                + "\n"
                + aStr.toString());
      }
    }
    Log.getLogWriter().info("Done verifying " + count + " queries");
  }