void closeBeforeFlush(final Region region) {
    hasBeenNotified = false;
    alreadyComeHere = false;
    CacheObserverHolder.setInstance(new CacheObserverAdapter() {

      @Override
      public void goingToFlush() {
        if (!alreadyComeHere) {
          try {
            new Close(region).start();
            try {
              Thread.sleep(3000);
            } catch (InterruptedException ok) {
              // this is ok; the async writer thread is interrupted during shutdown
              Thread.currentThread().interrupt();
            }
          } catch (Exception e) {
            logWriter.error("Exception occurred", e);
            fail("Exception occurred when it was not supposed to occur");
          }
        }
        alreadyComeHere = true;
      }
    });
    ((LocalRegion) region).getDiskRegion().pauseFlusherForTesting();
    region.put("Key", "Value1");
    ((LocalRegion) region).getDiskRegion().flushForTesting();
    synchronized (region) {
      try {
        if (!hasBeenNotified) {
          region.wait();
        }
      } catch (InterruptedException e) {
        logWriter.error("Exception occurred", e);
        fail("interrupted");
      }
    }
  }
region is closed before going to be flushed The region is going to be closed in a separate
thread. A 3000 ms wait is done to ensure that the separate thread has successfully closed the
region
geode-core/src/integrationTest/java/org/apache/geode/internal/cache/ConcurrentFlushingAndRegionOperationsJUnitTest.java