类 DefaultCacheAwareContextLoaderDelegate
- 所有已实现的接口:
CacheAwareContextLoaderDelegate
CacheAwareContextLoaderDelegate interface.
To use a static DefaultContextCache, invoke the
DefaultCacheAwareContextLoaderDelegate() constructor; otherwise,
invoke the DefaultCacheAwareContextLoaderDelegate(ContextCache)
and provide a custom ContextCache implementation.
- 从以下版本开始:
- 4.0
- 作者:
- Sam Brannen, Harry Yang
-
字段概要
字段修饰符和类型字段说明private final AotTestContextInitializersprivate final ContextCacheprivate final List<ApplicationContextFailureProcessor>(专用程序包) static final ContextCacheDefault static cache of Infra application contexts.private final intThe configured failure threshold for errors encountered while attempting to load anApplicationContext.private static final cn.taketoday.logging.Logger从接口继承的字段 cn.taketoday.test.context.CacheAwareContextLoaderDelegate
CONTEXT_FAILURE_THRESHOLD_PROPERTY_NAME, DEFAULT_CACHE_AWARE_CONTEXT_LOADER_DELEGATE_PROPERTY_NAME, DEFAULT_CONTEXT_FAILURE_THRESHOLD -
构造器概要
构造器限定符构造器说明Construct a newDefaultCacheAwareContextLoaderDelegateusing a staticDefaultContextCache.DefaultCacheAwareContextLoaderDelegate(ContextCache contextCache) Construct a newDefaultCacheAwareContextLoaderDelegateusing the suppliedContextCacheand the default or user-configured context failure threshold.privateDefaultCacheAwareContextLoaderDelegate(ContextCache contextCache, int failureThreshold) Construct a newDefaultCacheAwareContextLoaderDelegateusing the suppliedContextCacheand context failure threshold. -
方法概要
修饰符和类型方法说明voidcloseContext(MergedContextConfiguration mergedConfig, DirtiesContext.HierarchyMode hierarchyMode) Remove the application context for the suppliedMergedContextConfigurationfrom theContextCacheand close it if it is an instance ofConfigurableApplicationContext.protected ContextCacheGet theContextCacheused by this context loader delegate.private ContextLoadergetContextLoader(MergedContextConfiguration mergedConfig) booleanisContextLoaded(MergedContextConfiguration mergedConfig) Determine if the application context for the suppliedMergedContextConfigurationhas been loaded (i.e., is present in theContextCache).cn.taketoday.context.ApplicationContextloadContext(MergedContextConfiguration mergedConfig) Load the application context for the suppliedMergedContextConfigurationby delegating to theContextLoaderconfigured in the givenMergedContextConfiguration.protected cn.taketoday.context.ApplicationContextloadContextInAotMode(AotMergedContextConfiguration aotMergedConfig) protected cn.taketoday.context.ApplicationContextloadContextInternal(MergedContextConfiguration mergedConfig) Load theApplicationContextfor the supplied merged context configuration.private MergedContextConfigurationreplaceIfNecessary(MergedContextConfiguration mergedConfig) If the test class associated with the suppliedMergedContextConfigurationhas an AOT-optimizedApplicationContext, this method will create anAotMergedContextConfigurationto replace the providedMergedContextConfiguration.
-
字段详细资料
-
logger
private static final cn.taketoday.logging.Logger logger -
defaultContextCache
Default static cache of Infra application contexts. -
contextFailureProcessors
-
aotTestContextInitializers
-
contextCache
-
failureThreshold
private final int failureThresholdThe configured failure threshold for errors encountered while attempting to load anApplicationContext.
-
-
构造器详细资料
-
DefaultCacheAwareContextLoaderDelegate
public DefaultCacheAwareContextLoaderDelegate()Construct a newDefaultCacheAwareContextLoaderDelegateusing a staticDefaultContextCache.The default cache is static so that each context can be cached and reused for all subsequent tests that declare the same unique context configuration within the same JVM process.
-
DefaultCacheAwareContextLoaderDelegate
Construct a newDefaultCacheAwareContextLoaderDelegateusing the suppliedContextCacheand the default or user-configured context failure threshold. -
DefaultCacheAwareContextLoaderDelegate
Construct a newDefaultCacheAwareContextLoaderDelegateusing the suppliedContextCacheand context failure threshold.
-
-
方法详细资料
-
isContextLoaded
从接口复制的说明:CacheAwareContextLoaderDelegateDetermine if the application context for the suppliedMergedContextConfigurationhas been loaded (i.e., is present in theContextCache).Implementations of this method must not load the application context as a side effect. In addition, implementations of this method should not log the cache statistics via
ContextCache.logStatistics().The default implementation of this method always returns
false. CustomCacheAwareContextLoaderDelegateimplementations are therefore highly encouraged to override this method with a more meaningful implementation. Note that the standardCacheAwareContextLoaderDelegateimplementation in Infra overrides this method appropriately.- 指定者:
isContextLoaded在接口中CacheAwareContextLoaderDelegate- 参数:
mergedConfig- the merged context configuration used to load the application context; nevernull- 返回:
trueif the application context has been loaded- 另请参阅:
-
loadContext
从接口复制的说明:CacheAwareContextLoaderDelegateLoad the application context for the suppliedMergedContextConfigurationby delegating to theContextLoaderconfigured in the givenMergedContextConfiguration.If the context is present in the
ContextCacheit will simply be returned; otherwise, it will be loaded, stored in the cache, and returned.Implementations of this method should load
ApplicationContextFailureProcessorimplementations via theTodayStrategiesmechanism, catch any exception thrown by theContextLoader, and delegate to each of the configured failure processors to process the context load failure if the exception is an instance ofContextLoadException.Implementations of this method are encouraged to support the failure threshold feature. Specifically, if repeated attempts are made to load an application context and that application context consistently fails to load — for example, due to a configuration error that prevents the context from successfully loading — this method should preemptively throw an
IllegalStateExceptionif the configured failure threshold has been exceeded. Note that theContextCacheprovides support for tracking and incrementing the failure count for a given context cache key.The cache statistics should be logged by invoking
ContextCache.logStatistics().- 指定者:
loadContext在接口中CacheAwareContextLoaderDelegate- 参数:
mergedConfig- the merged context configuration to use to load the application context; nevernull- 返回:
- the application context (never
null) - 另请参阅:
-
closeContext
public void closeContext(MergedContextConfiguration mergedConfig, @Nullable DirtiesContext.HierarchyMode hierarchyMode) 从接口复制的说明:CacheAwareContextLoaderDelegateRemove the application context for the suppliedMergedContextConfigurationfrom theContextCacheand close it if it is an instance ofConfigurableApplicationContext.The semantics of the supplied
HierarchyModemust be honored when removing the context from the cache. See the Javadoc forDirtiesContext.HierarchyModefor details.Generally speaking, this method should only be called if the state of a singleton bean has been changed (potentially affecting future interaction with the context) or if the context needs to be prematurely removed from the cache.
- 指定者:
closeContext在接口中CacheAwareContextLoaderDelegate- 参数:
mergedConfig- the merged context configuration for the application context to close; nevernullhierarchyMode- the hierarchy mode; may benullif the context is not part of a hierarchy- 另请参阅:
-
getContextCache
Get theContextCacheused by this context loader delegate. -
loadContextInternal
protected cn.taketoday.context.ApplicationContext loadContextInternal(MergedContextConfiguration mergedConfig) throws Exception Load theApplicationContextfor the supplied merged context configuration.Supports both the
SmartContextLoaderandContextLoaderSPIs.- 抛出:
Exception- if an error occurs while loading the application context
-
loadContextInAotMode
protected cn.taketoday.context.ApplicationContext loadContextInAotMode(AotMergedContextConfiguration aotMergedConfig) throws Exception - 抛出:
Exception
-
getContextLoader
-
replaceIfNecessary
If the test class associated with the suppliedMergedContextConfigurationhas an AOT-optimizedApplicationContext, this method will create anAotMergedContextConfigurationto replace the providedMergedContextConfiguration.Otherwise, this method simply returns the supplied
MergedContextConfigurationunmodified.This allows for transparent
ContextCachesupport for AOT-optimized application contexts.- 参数:
mergedConfig- the originalMergedContextConfiguration- 返回:
AotMergedContextConfigurationor the originalMergedContextConfiguration- 抛出:
IllegalStateException- if running in AOT mode and the test class does not have an AOT-optimizedApplicationContext
-