@Test
  public void testCloseRegion() throws CacheException {
    // @todo added a remote region to make sure close just does a localDestroy

    String name = getUniqueName();

    RegionFactory<Object, Object> regionFactory =
        getCache().createRegionFactory(getRegionAttributes());

    TestCacheListener<Object, Object> list = new TestCacheListener<Object, Object>() {
      @Override
      public void afterCreate2(EntryEvent event) {
        // do nothing
      }

      @Override
      public void afterRegionDestroy2(RegionEvent re) {
        assertEquals(Operation.REGION_CLOSE, re.getOperation());
      }

      @Override
      public void close2() {
        // okay
      }
    };

    regionFactory.addCacheListener(list);

    Region<Object, Object> region = createRegion(name, regionFactory);

    File diskDir = null;
    if (getRegionAttributes().getDataPolicy().withPersistence()) {
      diskDir = getCache().findDiskStore(getRegionAttributes().getDiskStoreName()).getDiskDirs()[0];
      // @todo We no longer start with a clean slate because the DiskStore hangs around.
      // If we want a clean slate then we need to destroy the DiskStore after each
      // test completes.
      // assert that if this is a disk region, the disk dirs are empty
      // to make sure we start with a clean slate
      getCache().getLogger().info("list=" + Arrays.toString(diskDir.list()));
      // assertIndexDetailsEquals("list="+Arrays.toString(diskDir.list()),
      // 0, diskDir.list().length);
    }

    for (int i = 0; i < 1000; i++) {
      region.put(i, String.valueOf(i));
    }

    // reset wasInvoked after creates
    assertTrue(list.wasInvoked());

    // assert that if this is a disk region, the disk dirs are not empty
    if (getRegionAttributes().getDataPolicy().withPersistence()) {
      assertTrue(diskDir.list().length > 0);
    }
    region.getAttributes().getDataPolicy().withPersistence();
    region.close();

    // assert that if this is a disk region, the disk dirs are not empty
    if (getRegionAttributes().getDataPolicy().withPersistence()) {
      assertTrue(diskDir.list().length > 0);
    }

    assertTrue(list.waitForInvocation(333));
    assertTrue(list.isClosed());
    assertTrue(region.isDestroyed());

    // if this is a disk region, then check to see if recreating the region
    // repopulates with data
    RegionFactory<Object, Object> regionFactory2 =
        getCache().createRegionFactory(getRegionAttributes());
    region = createRegion(name, regionFactory2);

    if (getRegionAttributes().getDataPolicy().withPersistence()) {
      for (int i = 0; i < 1000; i++) {
        Region.Entry entry = region.getEntry(i);
        assertNotNull("entry " + i + " not found", entry);
        assertEquals(String.valueOf(i), entry.getValue());
      }
      assertEquals(1000, region.keySet().size());
    } else {
      assertEquals(0, region.keySet().size());
    }

    region.localDestroyRegion();
  }
Tests closing a region, and checks different behavior when this is a disk region with
persistBackup.
geode-dunit/src/main/java/org/apache/geode/cache30/RegionTestCase.java