@Test
  public void testBucketFailOverDuringCacheClose() throws Exception {
    Boolean value = Boolean.TRUE;

    vm2.invoke(() -> createPartitionedRegion());
    vm3.invoke(() -> createPartitionedRegion());

    vm3.invoke(() -> {
      Cache cache = getCache();
      PartitionedRegion partitionedRegion = (PartitionedRegion) cache.getRegion(regionName);
      assertThat(partitionedRegion).isEmpty();

      // Create keys such that all buckets are created, Integer works well
      // assuming buckets are allocated on the mod of the key hashCode, x 2 just to be safe
      int numEntries = partitionedRegion.getTotalNumberOfBuckets() * 2;

      for (int i = numEntries; i >= 0; --i) {
        partitionedRegion.put(i, value);
      }

      assertThat(partitionedRegion).hasSize(numEntries + 1);
      assertThat(partitionedRegion.getRegionAdvisor().getBucketSet())
          .hasSize(partitionedRegion.getTotalNumberOfBuckets());
    });

    vm3.invoke(() -> validateEntries(value));
    vm2.invoke(() -> validateEntries(value));

    // origin VM down!
    vm2.invoke(() -> getCache().close());
    // origin down, but no data loss
    vm3.invoke(() -> validateEntries(value));

    // get back to the desired redundancy
    vm0.invoke(() -> createPartitionedRegion());
    // verify no data loss
    vm0.invoke(() -> validateEntries(value));

    // 2nd oldest VM down!
    vm3.invoke(() -> getCache().close());
    // 2nd down, but no data loss
    vm0.invoke(() -> validateEntries(value));

    // get back (for 2nd time) to desired redundancy
    vm1.invoke(() -> createPartitionedRegion());
    // verify no data loss
    vm1.invoke(() -> validateEntries(value));
    vm0.invoke(() -> validateEntries(value));
  }
Test to ensure that we have proper bucket failover, with no data loss, in the face of
sequential cache.close() events.
geode-core/src/distributedTest/java/org/apache/geode/internal/cache/PartitionedRegionHADUnitTest.java