Merge branch '6.0.x'

# Conflicts:
#	spring-test/src/main/java/org/springframework/test/context/cache/DefaultCacheAwareContextLoaderDelegate.java
This commit is contained in:
Sam Brannen 2023-06-11 15:56:23 +02:00
commit b4ba80b09e
1 changed files with 44 additions and 41 deletions

View File

@ -135,57 +135,60 @@ public class DefaultCacheAwareContextLoaderDelegate implements CacheAwareContext
mergedConfig = replaceIfNecessary(mergedConfig); mergedConfig = replaceIfNecessary(mergedConfig);
synchronized (this.contextCache) { synchronized (this.contextCache) {
ApplicationContext context = this.contextCache.get(mergedConfig); ApplicationContext context = this.contextCache.get(mergedConfig);
if (context == null) { try {
Integer failureCount = this.contextCache.getFailureCount(mergedConfig); if (context == null) {
if (failureCount >= this.failureThreshold) { Integer failureCount = this.contextCache.getFailureCount(mergedConfig);
throw new IllegalStateException(""" if (failureCount >= this.failureThreshold) {
ApplicationContext failure threshold (%d) exceeded: \ throw new IllegalStateException("""
skipping repeated attempt to load context for %s""" ApplicationContext failure threshold (%d) exceeded: \
.formatted(this.failureThreshold, mergedConfig)); skipping repeated attempt to load context for %s"""
} .formatted(this.failureThreshold, mergedConfig));
try {
if (mergedConfig instanceof AotMergedContextConfiguration aotMergedConfig) {
context = loadContextInAotMode(aotMergedConfig);
} }
else { try {
context = loadContextInternal(mergedConfig); if (mergedConfig instanceof AotMergedContextConfiguration aotMergedConfig) {
context = loadContextInAotMode(aotMergedConfig);
}
else {
context = loadContextInternal(mergedConfig);
}
if (logger.isTraceEnabled()) {
logger.trace("Storing ApplicationContext [%s] in cache under key %s".formatted(
System.identityHashCode(context), mergedConfig));
}
this.contextCache.put(mergedConfig, context);
} }
if (logger.isTraceEnabled()) { catch (Exception ex) {
logger.trace("Storing ApplicationContext [%s] in cache under key %s".formatted( this.contextCache.incrementFailureCount(mergedConfig);
System.identityHashCode(context), mergedConfig)); Throwable cause = ex;
} if (ex instanceof ContextLoadException cle) {
this.contextCache.put(mergedConfig, context); cause = cle.getCause();
} for (ApplicationContextFailureProcessor contextFailureProcessor : this.contextFailureProcessors) {
catch (Exception ex) { try {
this.contextCache.incrementFailureCount(mergedConfig); contextFailureProcessor.processLoadFailure(cle.getApplicationContext(), cause);
Throwable cause = ex; }
if (ex instanceof ContextLoadException cle) { catch (Throwable throwable) {
cause = cle.getCause(); if (logger.isDebugEnabled()) {
for (ApplicationContextFailureProcessor contextFailureProcessor : this.contextFailureProcessors) { logger.debug("Ignoring exception thrown from ApplicationContextFailureProcessor [%s]: %s"
try { .formatted(contextFailureProcessor, throwable));
contextFailureProcessor.processLoadFailure(cle.getApplicationContext(), cause); }
}
catch (Throwable throwable) {
if (logger.isDebugEnabled()) {
logger.debug("Ignoring exception thrown from ApplicationContextFailureProcessor [%s]: %s"
.formatted(contextFailureProcessor, throwable));
} }
} }
} }
throw new IllegalStateException(
"Failed to load ApplicationContext for " + mergedConfig, cause);
}
}
else {
if (logger.isTraceEnabled()) {
logger.trace("Retrieved ApplicationContext [%s] from cache with key %s".formatted(
System.identityHashCode(context), mergedConfig));
} }
throw new IllegalStateException(
"Failed to load ApplicationContext for " + mergedConfig, cause);
} }
} }
else { finally {
if (logger.isTraceEnabled()) { this.contextCache.logStatistics();
logger.trace("Retrieved ApplicationContext [%s] from cache with key %s".formatted(
System.identityHashCode(context), mergedConfig));
}
} }
this.contextCache.logStatistics();
return context; return context;
} }
} }