@Test
  public void testRebalanceDuringQueryEvaluation() throws Exception {
    vm0.invoke(this::createAccessor);
    vm1.invoke(this::createPartitionedRegion);
    vm1.invoke(this::createBuckets);
    vm2.invoke(this::createPartitionedRegion);

    // Add a listener that will trigger a rebalance as soon as the query arrives on this node.
    vm1.invoke("add listener", () -> {
      DistributionMessageObserver.setInstance(new DistributionMessageObserver() {

        @Override
        public void beforeProcessMessage(ClusterDistributionManager dm,
            DistributionMessage message) {
          if (message instanceof QueryMessage) {
            RebalanceOperation rebalance =
                cacheRule.getCache().getResourceManager().createRebalanceFactory().start();
            // wait for the rebalance
            try {
              REBALANCE_RESULTS.compareAndSet(null, rebalance.getResults());
            } catch (CancellationException | InterruptedException e) {
              errorCollector.addError(e);
            }
          }
        }
      });
    });

    vm0.invoke(this::executeQuery);

    vm1.invoke("check rebalance happened", () -> {
      assertThat(REBALANCE_RESULTS.get()).isNotNull();
      assertThat(REBALANCE_RESULTS.get().getTotalBucketTransfersCompleted()).isEqualTo(5);
    });
  }
1. Buckets are created on several nodes <br>
2. A query is started 3. While the query is executing, several buckets are moved.
geode-core/src/distributedTest/java/org/apache/geode/internal/cache/PRQueryWithPdxDuringRebalanceRegressionTest.java