diff --git a/build-parent/pom.xml b/build-parent/pom.xml index d9706721a99be..62b4681b16f1d 100644 --- a/build-parent/pom.xml +++ b/build-parent/pom.xml @@ -440,7 +440,8 @@ </systemPropertyVariables> <!-- limit the amount of memory surefire can use, 1500m should be plenty--> <!-- set tmpdir as early as possible because surefire sets it too late for JDK16 --> - <argLine>${jacoco.agent.argLine} -Xmx1500m -XX:MaxMetaspaceSize=1500m -Djava.io.tmpdir="${project.build.directory}" ${surefire.argLine.additional}</argLine> + <!-- the add-opens is here to allow to clear the propertiesCache in com.sun.naming.internal.ResourceManager --> + <argLine>${jacoco.agent.argLine} -Xmx1500m -XX:MaxMetaspaceSize=1500m -Djava.io.tmpdir="${project.build.directory}" ${surefire.argLine.additional} --add-opens java.naming/com.sun.naming.internal=ALL-UNNAMED</argLine> <excludedEnvironmentVariables>MAVEN_OPTS</excludedEnvironmentVariables> </configuration> </plugin> diff --git a/extensions/jaxb/deployment/pom.xml b/extensions/jaxb/deployment/pom.xml index a496418bac757..e4cf5cd173d01 100644 --- a/extensions/jaxb/deployment/pom.xml +++ b/extensions/jaxb/deployment/pom.xml @@ -11,6 +11,9 @@ <artifactId>quarkus-jaxb-deployment</artifactId> <name>Quarkus - JAXB - Deployment</name> + <properties> + <surefire.argLine.additional>-Duser.language=en</surefire.argLine.additional> + </properties> <dependencies> <dependency> @@ -52,13 +55,6 @@ </annotationProcessorPaths> </configuration> </plugin> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-surefire-plugin</artifactId> - <configuration> - <argLine>-Duser.language=en</argLine> - </configuration> - </plugin> </plugins> </build> diff --git a/test-framework/junit5-internal/src/main/java/io/quarkus/test/ClearCache.java b/test-framework/junit5-internal/src/main/java/io/quarkus/test/ClearCache.java index 409b5e930b9f5..179ef1d5e5295 100644 --- a/test-framework/junit5-internal/src/main/java/io/quarkus/test/ClearCache.java +++ b/test-framework/junit5-internal/src/main/java/io/quarkus/test/ClearCache.java @@ -13,17 +13,26 @@ public class ClearCache { public static void clearCaches() { clearAnnotationCache(); + clearResourceManagerPropertiesCache(); clearBeansIntrospectorCache(); } private static void clearAnnotationCache() { + clearMap(AnnotationUtils.class, "repeatableAnnotationContainerCache"); + } + + /** + * This will only be effective if the tests are launched with --add-opens java.naming/com.sun.naming.internal=ALL-UNNAMED, + * which is the case in the Quarkus codebase where memory usage is actually an issue. + * <p> + * While not mandatory, this actually helps so enabling it only in the Quarkus codebase has actual value. + */ + private static void clearResourceManagerPropertiesCache() { try { - Field f = AnnotationUtils.class.getDeclaredField("repeatableAnnotationContainerCache"); - f.setAccessible(true); - ((Map) (f.get(null))).clear(); - } catch (NoSuchFieldException | IllegalAccessException e) { - //ignore - log.debug("Failed to clear annotation cache", e); + clearMap(Class.forName("com.sun.naming.internal.ResourceManager"), "propertiesCache"); + } catch (ClassNotFoundException e) { + // ignore + log.debug("Unable to load com.sun.naming.internal.ResourceManager", e); } } @@ -31,8 +40,19 @@ private static void clearBeansIntrospectorCache() { try { Introspector.flushCaches(); } catch (Exception e) { - //ignore + // ignore log.debug("Failed to clear java.beans.Introspector cache", e); } } + + private static void clearMap(Class<?> clazz, String mapField) { + try { + Field f = clazz.getDeclaredField(mapField); + f.setAccessible(true); + ((Map) (f.get(null))).clear(); + } catch (Exception e) { + // ignore + log.debugf(e, "Failed to clear cache for %s#%s cache", clazz.getName(), mapField); + } + } }