@Test
  public void testThreeZonesHaveTwoCopiesAfterRebalance() throws Exception {
    SERVER_ZONE_MAP = new HashMap<Integer, String>() {
      {
        put(1, ZONE_A);
        put(2, ZONE_B);
        put(3, ZONE_C);
      }
    };

    cleanOutServerDirectories();

    // Startup the servers
    for (Map.Entry<Integer, String> entry : SERVER_ZONE_MAP.entrySet()) {
      startServerInRedundancyZone(entry.getKey(), entry.getValue());
    }

    // Put data in the server regions
    clientPopulateServers();

    // Rebalance Server VM will initiate the rebalances in this test
    VM server2 = clusterStartupRule.getVM(2);

    // Baseline rebalance with everything up
    server2.invoke(() -> doRebalance(ClusterStartupRule.getCache().getResourceManager()));

    // Take the server 1 offline
    clusterStartupRule.stop(1, false);

    // Rebalance so that now all the buckets are on the other two servers.
    // Zone b servers should not be touched.
    server2.invoke(() -> doRebalance(ClusterStartupRule.getCache().getResourceManager()));

    // Restart server 1
    startServerInRedundancyZone(1, SERVER_ZONE_MAP.get(1));
    // Rebalance so that now all the buckets are on the other two servers.
    // Zone b servers should not be touched.

    server2.invoke(() -> doRebalance(ClusterStartupRule.getCache().getResourceManager()));

    int zoneABucketCount = getBucketCount(1);
    int zoneBBucketCount = getBucketCount(2);
    int zoneCBucketCount = getBucketCount(3);
    final int LOWER_BOUND = (EXPECTED_BUCKET_COUNT * 2) / 3;
    final int UPPER_BOUND = 1 + (EXPECTED_BUCKET_COUNT * 2) / 3;
    assertThat(zoneABucketCount).isGreaterThanOrEqualTo(LOWER_BOUND)
        .isLessThanOrEqualTo(UPPER_BOUND);
    assertThat(zoneBBucketCount).isGreaterThanOrEqualTo(LOWER_BOUND)
        .isLessThanOrEqualTo(UPPER_BOUND);
    assertThat(zoneCBucketCount).isGreaterThanOrEqualTo(LOWER_BOUND)
        .isLessThanOrEqualTo(UPPER_BOUND);

    assertThat(zoneABucketCount + zoneBBucketCount + zoneCBucketCount)
        .isEqualTo(2 * EXPECTED_BUCKET_COUNT);
  }
This test tests the case that we don't accidentally leave extra copies in a
redundancy zone after a server recovers.
geode-core/src/distributedTest/java/org/apache/geode/internal/cache/control/RebalanceOperationComplexDistributedTest.java