@Test
  public void testPRQueryForDuplicates() throws CacheException {
    final String regionName = "exampleRegion";
    final Host host = Host.getHost(0);
    final VM vm0 = host.getVM(0);
    final VM vm1 = host.getVM(1);
    final VM vm2 = host.getVM(2);
    final String name = SEPARATOR + regionName;
    final String[] qs =
        {"select distinct pkid from " + name, "select distinct pkid, status from " + name};

    // Start server1
    final int port1 = (Integer) vm0.invoke(new SerializableCallable("Create Server1") {
      @Override
      public Object call() throws Exception {
        Region r1 = getCache().createRegionFactory(RegionShortcut.PARTITION).create(regionName);
        CacheServer server = getCache().addCacheServer();
        int port = AvailablePortHelper.getRandomAvailableTCPPort();
        server.setPort(port);
        server.start();
        return port;
      }
    });

    // Start server2
    final int port2 = (Integer) vm1.invoke(new SerializableCallable("Create Server1") {
      @Override
      public Object call() throws Exception {
        Region r1 = getCache().createRegionFactory(RegionShortcut.PARTITION).create(regionName);

        CacheServer server = getCache().addCacheServer();
        int port = AvailablePortHelper.getRandomAvailableTCPPort();
        server.setPort(port);
        server.start();
        return port;
      }
    });

    // create client load data and execute queries
    vm2.invoke(new SerializableCallable("Create client") {
      @Override
      public Object call() throws Exception {
        ClientCacheFactory cf = new ClientCacheFactory();
        cf.addPoolServer(NetworkUtils.getServerHostName(vm0.getHost()), port1);
        cf.addPoolServer(NetworkUtils.getServerHostName(vm1.getHost()), port2);
        ClientCache cache = getClientCache(cf);
        Region region =
            cache.createClientRegionFactory(ClientRegionShortcut.PROXY).create(regionName);
        // Put Portfolios with 2 different pkids
        for (int set = 1; set <= 2; set++) {
          for (int current = 1; current <= 5; current++) {
            region.put("key-" + set + "_" + current, new PortfolioPdx(set, current));
          }
        }

        for (final String q : qs) {
          SelectResults sr = (SelectResults) cache.getQueryService().newQuery(q).execute();
          assertEquals("Did not get expected result from query: " + q + " ", 2, sr.size());
        }

        return null;
      }
    });

    // execute query on server by setting DefaultQuery.setPdxReadSerialized
    // to simulate remote query
    vm0.invoke("Create server", () -> {

      Boolean previousPdxReadSerializedFlag = cache.getPdxReadSerializedOverride();
      cache.setPdxReadSerializedOverride(true);
      try {
        for (final String q : qs) {
          SelectResults sr = (SelectResults) getCache().getQueryService().newQuery(q).execute();
          assertEquals("Did not get expected result from query: " + q + " ", 2, sr.size());
        }
      } finally {
        cache.setPdxReadSerializedOverride(previousPdxReadSerializedFlag);
      }
      return null;
    });

    disconnectAllFromDS();
  }
Test to verify if duplicate results are not being accumulated when PdxString is used in PR
query
geode-core/src/distributedTest/java/org/apache/geode/cache/query/dunit/PdxStringQueryDUnitTest.java