@Test
  public void testRemoveAllWithCQLocalDestroy() {
    VM server1 = getVM(0);
    VM server2 = getVM(1);
    VM client = getVM(2);

    final String cqName = "testRemoveAllWithCQLocalDestroy_0";
    createServer(server1);
    createServer(server2);
    final String host = VM.getHostName();
    final int port = server2.invoke(PartitionedRegionCqQueryDUnitTest::getCacheServerPort);
    createClient(client, port, host);
    createCQ(client, cqName, cqs[0]);

    int numObjects = 1000;

    server1.invoke(() -> {
      Region<String, Object> region =
          getCache().getRegion(SEPARATOR + "root" + SEPARATOR + regions[0]);
      Map<String, Object> buffer = new HashMap();
      for (int i = 1; i < numObjects; i++) {
        Portfolio p = new Portfolio(i);
        buffer.put("" + i, p);
      }
      region.putAll(buffer);
      assertThat(region.size()).isEqualTo(numObjects - 1);
    });

    client.invoke(() -> {
      QueryService cqService = getCache().getQueryService();
      CqQuery cqQuery = cqService.getCq(cqName);
      assertThat(cqQuery)
          .withFailMessage("Failed to get CQ " + cqName)
          .isNotNull();
      cqQuery.executeWithInitialResults();
    });

    server1.invoke(() -> {
      Region<String, Object> region =
          getCache().getRegion(SEPARATOR + "root" + SEPARATOR + regions[0]);
      Set<String> keys = new HashSet<>();
      for (int i = 1; i < numObjects; i++) {
        keys.add("" + i);
      }
      // This is to generate LOCAL_DESTROY CQ event
      region.removeAll(keys);
      assertThat(region.size()).isEqualTo(0);
    });

    client.invoke(() -> {
      QueryService cqService = getCache().getQueryService();
      CqQuery cqQuery = cqService.getCq(cqName);
      assertThat(cqQuery)
          .withFailMessage("Failed to get CQ " + cqName)
          .isNotNull();
      CqQueryTestListener cqListener =
          (CqQueryTestListener) cqQuery.getCqAttributes().getCqListener();
      await().untilAsserted(
          () -> assertThat(cqListener.getTotalEventCount()).isEqualTo(numObjects - 1));
    });

    cqHelper.closeClient(client);
    cqHelper.closeServer(server2);
    cqHelper.closeServer(server1);
  }
Test class for Partitioned Region and CQs

@since GemFire 5.5
geode-cq/src/distributedTest/java/org/apache/geode/cache/query/cq/dunit/PartitionedRegionCqQueryDUnitTest.java