Class EngineTestCache<T extends Engine>

java.lang.Object
org.flowable.common.engine.impl.test.EngineTestCache<T>

public class EngineTestCache<T extends Engine> extends Object
A small bounded, least-recently-used cache of engines for tests, keyed by configuration resource.

This is a deliberately rudimentary analog of Spring's ContextCache: when more than maxSize engines are cached, the least-recently-used engine is closed and evicted. It keeps the number of simultaneously-live engines bounded across a large test suite that runs in a single JVM.

The maximum size defaults to DEFAULT_MAX_SIZE and can be overridden with the flowable.test.engine.cache.maxSize system property.

Note on the bound: a test helper may hold a direct reference to an engine it obtained from this cache for the duration of a test class. Eviction closes the least-recently-used engine, so the configured size must comfortably exceed the maximum number of distinct configuration resources that can be live within any single test class. The default is ample for the usual one-configuration-per-class tests; setting it very low (e.g. 1) is only safe for suites where each class uses a single configuration resource.

Author:
Filip Hrisafov
  • Field Details

  • Constructor Details

    • EngineTestCache

      public EngineTestCache()
    • EngineTestCache

      public EngineTestCache(int maxSize)
  • Method Details

    • getOrCreate

      public T getOrCreate(String key, Function<String,T> builder)
      Returns the cached engine for the given configuration resource, building and caching it with the supplied builder on a miss. Accessing an entry marks it most-recently-used; a miss that would exceed the maximum size first evicts and closes the least-recently-used engine.
    • evictLeastRecentlyUsedIfNecessary

      protected void evictLeastRecentlyUsedIfNecessary()
      Evicts and closes the least-recently-used engine when the cache is full, before a new entry is added. Mirrors Spring's DefaultContextCache: the LRU entry is the first key in an access-ordered map.
    • closeAll

      public void closeAll()
      Closes every cached engine (ignoring individual close failures) and empties the cache.
    • size

      public int size()
    • resolveMaxSize

      protected static int resolveMaxSize()