@Test
  public void testCQStatistics() throws Exception {

    final Host host = Host.getHost(0);
    VM server = host.getVM(0);
    VM client = host.getVM(1);

    /* Init Server and Client */
    cqDUnitTest.createServer(server);
    final int port = server.invoke(CqQueryUsingPoolDUnitTest::getCacheServerPort);
    final String host0 = NetworkUtils.getServerHostName(server.getHost());

    String poolName = "testCQStatistics";
    cqDUnitTest.createPool(client, poolName, host0, port);

    // cqDUnitTest.createClient(client, port, host0);

    /* Create CQs. */
    cqDUnitTest.createCQ(client, poolName, "testCQStatistics_0", cqDUnitTest.cqs[0]);

    /* Init values at server. */
    int size = 100;
    cqDUnitTest.createValues(server, cqDUnitTest.regions[0], size);

    cqDUnitTest.executeCQ(client, "testCQStatistics_0", true, null);

    // Wait for CQ to be executed.
    cqDUnitTest.waitForCqState(client, "testCQStatistics_0", CqStateImpl.RUNNING);

    // Test CQ stats
    validateCQStats(client, "testCQStatistics_0", 0, 0, 0, 0, 0);

    // The stat would have not updated yet.
    // Commenting out the following check; the check for resultset initialization
    // is anyway done in the next validation.
    // validateCQStats(server, "testCQStatistics_0", 0, 0, 0, 0, CqQueryUsingPoolDUnitTest.noTest,
    // 1);

    /* Init values at server. */
    cqDUnitTest.createValues(server, cqDUnitTest.regions[0], 200);
    // Wait for client to Synch.
    cqDUnitTest.waitForCreated(client, "testCQStatistics_0", CqQueryUsingPoolDUnitTest.KEY + 200);
    Wait.pause(PAUSE);
    size = 200;

    // validate CQs.
    cqDUnitTest.validateCQ(client, "testCQStatistics_0",
        /* resultSize: */ CqQueryUsingPoolDUnitTest.noTest, /* creates: */ 100, /* updates: */ 100,
        /* deletes; */ 0, /* queryInserts: */ 100, /* queryUpdates: */ 100, /* queryDeletes: */ 0,
        /* totalEvents: */ 200);

    // Test CQ stats
    validateCQStats(client, "testCQStatistics_0", 100, 100, 0, 200, 200);
    // We don't have serverside CQ name
    validateCQStats(server, "testCQStatistics_0", 100, 100, 0, 200,
        CqQueryUsingPoolDUnitTest.noTest);

    /* Delete values at server. */
    cqDUnitTest.deleteValues(server, cqDUnitTest.regions[0], 100);
    // Wait for client to Synch.
    cqDUnitTest.waitForDestroyed(client, "testCQStatistics_0", CqQueryUsingPoolDUnitTest.KEY + 100);
    size = 10;
    Wait.pause(PAUSE);

    cqDUnitTest.validateCQ(client, "testCQStatistics_0",
        /* resultSize: */ CqQueryUsingPoolDUnitTest.noTest, /* creates: */100, /* updates: */ 100,
        /* deletes; */ 100, /* queryInserts: */ 100, /* queryUpdates: */ 100,
        /* queryDeletes: */ 100, /* totalEvents: */ 300);

    // Test CQ stats
    validateCQStats(client, "testCQStatistics_0", 100, 100, 100, 300, 300);
    // We don't have serverside CQ name
    validateCQStats(server, "testCQStatistics_0", 100, 100, 100, 300,
        CqQueryUsingPoolDUnitTest.noTest);

    // Test CQ Close
    cqDUnitTest.closeCQ(client, "testCQStatistics_0");
    Wait.pause(PAUSE);

    // Close.
    cqDUnitTest.closeClient(client);
    cqDUnitTest.closeServer(server);
  }
Test for CQ and CQ Service Statistics
geode-cq/src/distributedTest/java/org/apache/geode/cache/query/cq/dunit/CqStatsUsingPoolDUnitTest.java