@Test
  public void testClearInteractionWithCreateOperation_Bug37606() throws Exception {
    DiskRegionProperties diskRegionProperties = new DiskRegionProperties();
    diskRegionProperties.setOverflow(false);
    diskRegionProperties.setRolling(false);
    diskRegionProperties.setDiskDirs(diskDirs);
    diskRegionProperties.setPersistBackup(true);
    diskRegionProperties.setRegionName(regionName);

    DiskStoreFactory diskStoreFactory = toDiskStoreFactory(diskRegionProperties);

    createDiskStoreWithSizeInBytes(diskStoreName, diskStoreFactory);

    Region<String, String> region =
        createRegion(regionName, diskStoreName, true, true, false, false, 0);

    AtomicReference<Future<Void>> doCreateFuture = new AtomicReference<>();
    LocalRegion.ISSUE_CALLBACKS_TO_CACHE_OBSERVER = true;
    CacheObserverHolder.setInstance(new CacheObserverAdapter() {
      @Override
      public void beforeDiskClear() {
        LocalRegion.ISSUE_CALLBACKS_TO_CACHE_OBSERVER = false;
        doCreateFuture.set(executorServiceRule.runAsync(() -> {
          try {
            region.create("key1", "value1");
          } catch (AssertionError | Exception e) {
            errorCollector.addError(e);
          }
        }));
      }
    });

    region.clear();
    awaitFuture(doCreateFuture);

    // We expect 1 entry to exist, because the clear was triggered before the update
    assertThat(region.size()).isEqualTo(1);

    // close and recreate region and the entry should still exist
    region.close();
    Region<String, String> region2 =
        createRegion(regionName, diskStoreName, true, true, false, false, 0);
    assertThat(region2.size()).isEqualTo(1);
  }
Regression test for TRAC #37606: A cleared entry may still get logged into the Oplog due to a
very small window of race condition

<p>
As in the clear operation, previously the code was such that Htree Ref was first reset & then
the underlying region map got cleared, it was possible for the create op to set the new Htree
ref in thread local. Now if clear happened, the entry on which create op is going on was no
longer valid, but we would not be able to detect the conflict. The fix was to first clear the
region map & then reset the Htree Ref.
geode-core/src/integrationTest/java/org/apache/geode/internal/cache/DiskRegionJUnitTest.java