@Test
  public void testQueryMonitorRegionWithIndex() throws Exception {
    gfsh.executeAndAssertThat("create region --name=exampleRegion --type=REPLICATE")
        .statusIsSuccess();
    locator.waitUntilRegionIsReadyOnExactlyThisManyServers(SEPARATOR + "exampleRegion", 2);

    // create the indices using API
    VMProvider.invokeInEveryMember(() -> {
      // create index.
      QueryService cacheQS = ClusterStartupRule.getCache().getQueryService();
      cacheQS.createIndex("idIndex", "p.ID", SEPARATOR + "exampleRegion p");
      cacheQS.createIndex("statusIndex", "p.status", SEPARATOR + "exampleRegion p");
      cacheQS.createIndex("secIdIndex", "pos.secId",
          SEPARATOR + "exampleRegion p, p.positions.values pos");
      cacheQS.createIndex("posIdIndex", "pos.Id",
          SEPARATOR + "exampleRegion p, p.positions.values pos");
      cacheQS.createKeyIndex("pkIndex", "pk", SEPARATOR + "exampleRegion");
      cacheQS.createKeyIndex("pkidIndex", "pkid", SEPARATOR + "exampleRegion");
      populateRegion(0, 150);
    }, server1, server2);

    // client3 connects to server1, client4 connects to server2
    int server1Port = server1.getPort();
    int server2Port = server2.getPort();
    client3 =
        cluster.startClientVM(3,
            c1 -> c1.withPoolSubscription(true).withServerConnection(server1Port));
    client4 =
        cluster.startClientVM(4,
            c -> c.withPoolSubscription(true).withServerConnection(server2Port));

    client3.invoke(QueryMonitorDUnitTest::executeQueries);
    client4.invoke(QueryMonitorDUnitTest::executeQueries);
  }
These tests add a test hook to make sure query execution sleeps for at least 20 ms, so the
queryMonitor thread will get a chance to cancel the query before it completes.

The MAX_QUERY_EXECUTION_TIME is set as 1 ms, i.e, theoretically all queries will be cancelled
after 1ms, but due to thread scheduling, this may not be true. we can only decrease the flakyness
of the test by making MAX_QUERY_EXECUTION_TIME the smallest possible (1) and making the query
execution time longer (but not too long to make the test run too slow).
geode-cq/src/distributedTest/java/org/apache/geode/cache/query/dunit/QueryMonitorDUnitTest.java