Class EngineTestCache<T extends Engine>
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 Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidcloseAll()Closes every cached engine (ignoring individual close failures) and empties the cache.protected voidEvicts and closes the least-recently-used engine when the cache is full, before a new entry is added.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.protected static intintsize()
-
Field Details
-
DEFAULT_MAX_SIZE
public static final int DEFAULT_MAX_SIZE- See Also:
-
MAX_SIZE_PROPERTY
- See Also:
-
maxSize
protected final int maxSize -
engines
-
-
Constructor Details
-
EngineTestCache
public EngineTestCache() -
EngineTestCache
public EngineTestCache(int maxSize)
-
-
Method Details
-
getOrCreate
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'sDefaultContextCache: 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()
-