private void validateCQServiceStats(VM vm, final int created, final int activated,
      final int stopped, final int closed, final int cqsOnClient, final int cqsOnRegion,
      final int clientsWithCqs) {
    vm.invoke(new CacheSerializableRunnable("Validate CQ Service Stats") {
      @Override
      public void run2() throws CacheException {
        LogWriterUtils.getLogWriter().info("### Validating CQ Service Stats. ### ");
        // Get CQ Service.
        QueryService qService = null;
        try {
          qService = getCache().getQueryService();
        } catch (Exception cqe) {
          cqe.printStackTrace();
          fail("Failed to getCQService.");
        }
        CqServiceStatistics cqServiceStats = null;
        cqServiceStats = qService.getCqStatistics();
        CqServiceVsdStats cqServiceVsdStats = null;
        try {
          cqServiceVsdStats =
              ((CqServiceImpl) ((DefaultQueryService) qService).getCqService()).stats();
        } catch (CqException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        }
        if (cqServiceStats == null) {
          fail("Failed to get CQ Service Stats");
        }

        getCache().getLogger()
            .info("#### CQ Service stats: " + " CQs created: " + cqServiceStats.numCqsCreated()
                + " CQs active: " + cqServiceStats.numCqsActive() + " CQs stopped: "
                + cqServiceStats.numCqsStopped() + " CQs closed: " + cqServiceStats.numCqsClosed()
                + " CQs on Client: " + cqServiceStats.numCqsOnClient()
                + " CQs on region " + SEPARATOR + "root" + SEPARATOR + "regionA : "
                + cqServiceVsdStats.numCqsOnRegion(getCache(),
                    SEPARATOR + "root" + SEPARATOR + "regionA")
                + " Clients with CQs: " + cqServiceVsdStats.getNumClientsWithCqs());


        // Check for created count.
        if (created != CqQueryUsingPoolDUnitTest.noTest) {
          assertEquals("Number of CQs created mismatch", created, cqServiceStats.numCqsCreated());
        }

        // Check for activated count.
        if (activated != CqQueryUsingPoolDUnitTest.noTest) {
          assertEquals("Number of CQs activated mismatch", activated,
              cqServiceStats.numCqsActive());
        }

        // Check for stopped count.
        if (stopped != CqQueryUsingPoolDUnitTest.noTest) {
          assertEquals("Number of CQs stopped mismatch", stopped, cqServiceStats.numCqsStopped());
        }

        // Check for closed count.
        if (closed != CqQueryUsingPoolDUnitTest.noTest) {
          assertEquals("Number of CQs closed mismatch", closed, cqServiceStats.numCqsClosed());
        }

        // Check for CQs on client count.
        if (cqsOnClient != CqQueryUsingPoolDUnitTest.noTest) {
          assertEquals("Number of CQs on client mismatch", cqsOnClient,
              cqServiceStats.numCqsOnClient());
        }

        // Check for CQs on region.
        if (cqsOnRegion != CqQueryUsingPoolDUnitTest.noTest) {
          assertEquals(
              "Number of CQs on region " + SEPARATOR + "root" + SEPARATOR + "regionA mismatch",
              cqsOnRegion,
              cqServiceVsdStats.numCqsOnRegion(getCache(),
                  SEPARATOR + "root" + SEPARATOR + "regionA"));
        }

        // Check for clients with CQs count.
        if (clientsWithCqs != CqQueryUsingPoolDUnitTest.noTest) {
          assertEquals("Clints with CQs mismatch", clientsWithCqs,
              cqServiceVsdStats.getNumClientsWithCqs());
        }
      }
    });
  }
This class tests the ContinuousQuery mechanism in GemFire. This includes the test with different
data activities.
geode-cq/src/distributedTest/java/org/apache/geode/cache/query/cq/dunit/CqStatsUsingPoolDUnitTest.java