Class ReachabilityChecker

java.lang.Object
org.elasticsearch.test.ReachabilityChecker

public class ReachabilityChecker extends Object
Utility class for checking that objects become unreachable when expected. Registered objects become unreachable only when the GC notices them. This class attempts to trigger the GC at various points but does not guarantee a full GC. If we're unlucky, some of these objects may move to old enough heap generations that they are not subject to our GC attempts, resulting in test flakiness. Time will tell whether this is a problem in practice or not; if it is then we'll have to introduce some extra measures here.
  • Constructor Details

    • ReachabilityChecker

      public ReachabilityChecker()
  • Method Details

    • register

      public <T> T register(T target)
      Register the given target object for reachability checks.
      Returns:
      the given target object.
    • ensureUnreachable

      public void ensureUnreachable()
      Ensure that all registered objects have become unreachable.
    • checkReachable

      public void checkReachable()
      From the objects registered since the most recent call to ensureUnreachable() (or since the construction of this ReachabilityChecker if ensureUnreachable() has not been called) this method chooses one at random and verifies that it has not yet become unreachable.