@Test
  public void testLocalStatListenerRegistration() throws Exception {
    final CountDownLatch latch = new CountDownLatch(1);
    Cache cache = getCache();
    InternalDistributedSystem internalSystem =
        (InternalDistributedSystem) cache.getDistributedSystem();
    final GemFireStatSampler sampler = internalSystem.getStatSampler();
    sampler.waitForInitialization(10000); // fix: remove infinite wait
    final LocalStatListener l = value -> latch.countDown();

    // fix: found race condition here...
    WaitCriterion wc = new WaitCriterion() {
      @Override
      public boolean done() {
        Statistics si = getTenuredPoolStatistics(internalSystem.getStatisticsManager());
        if (si != null) {
          sampler.addLocalStatListener(l, si, "currentUsedMemory");
          return true;
        }
        return false;
      }

      @Override
      public String description() {
        String tenuredPoolName = getTenuredMemoryPoolMXBean().getName();
        return "Waiting for " + tenuredPoolName + " statistics to be added to create listener for";
      }
    };
    GeodeAwaitility.await().untilAsserted(wc);

    assertTrue("expected at least one stat listener, found " + sampler.getLocalListeners().size(),
        sampler.getLocalListeners().size() > 0);
    long maxTenuredMemory = getTenuredPoolMaxMemory();
    AttributesFactory factory = new AttributesFactory();
    factory.setScope(LOCAL);
    Region r = createRegion(getUniqueName() + "region", factory.create());
    // keep putting objects (of size 1% of maxTenuredMemory) and wait for stat callback
    // if we don't get a callback after 75 attempts, throw exception
    int count = 0;
    while (true) {
      count++;
      if (count > 75) {
        throw new AssertionError("Did not receive a stat listener callback");
      }
      byte[] value = new byte[(int) (maxTenuredMemory * 0.01)];
      r.put("key-" + count, value);
      if (latch.await(50, MILLISECONDS)) {
        break;
      } else {
        continue;
      }
    }
    r.close();
  }
putting this test here because junit does not have host stat sampler enabled
geode-core/src/distributedTest/java/org/apache/geode/cache/management/MemoryThresholdsDUnitTest.java