diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/bootstrap/registry/classloading/ClassLoaderLeakDetector.java b/hibernate-core/src/test/java/org/hibernate/orm/test/bootstrap/registry/classloading/ClassLoaderLeakDetector.java index e43ff5adc1..fc09042812 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/bootstrap/registry/classloading/ClassLoaderLeakDetector.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/bootstrap/registry/classloading/ClassLoaderLeakDetector.java @@ -38,6 +38,11 @@ public final class ClassLoaderLeakDetector { return PhantomReferenceLeakDetector.verifyActionNotLeaking( () -> actionInClassloader( fullClassnameOfRunnableAction ) ); } + static boolean verifyActionNotLeakingClassloader(String fullClassnameOfRunnableAction, final int gcAttempts, final int totalWaitSeconds) { + Objects.requireNonNull( fullClassnameOfRunnableAction ); + return PhantomReferenceLeakDetector.verifyActionNotLeaking( () -> actionInClassloader( fullClassnameOfRunnableAction ), gcAttempts, totalWaitSeconds ); + } + public static ClassLoader actionInClassloader(final String actionName) { final Thread currentThread = Thread.currentThread(); final ClassLoader initialClassloader = currentThread.getContextClassLoader(); diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/bootstrap/registry/classloading/ClassLoaderLeaksUtilityTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/bootstrap/registry/classloading/ClassLoaderLeaksUtilityTest.java index dd8027b522..250567dcc7 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/bootstrap/registry/classloading/ClassLoaderLeaksUtilityTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/bootstrap/registry/classloading/ClassLoaderLeaksUtilityTest.java @@ -16,7 +16,9 @@ public class ClassLoaderLeaksUtilityTest { @Test public void testClassLoaderLeaksDetected() { - Assert.assertFalse( ClassLoaderLeakDetector.verifyActionNotLeakingClassloader( "org.hibernate.orm.test.bootstrap.registry.classloading.LeakingTestAction" ) ); + //N.B. since we expect to timeout in this case, reduce the timeouts to not require + //a significant amount of time during each ORM test run. + Assert.assertFalse( ClassLoaderLeakDetector.verifyActionNotLeakingClassloader( "org.hibernate.orm.test.bootstrap.registry.classloading.LeakingTestAction", 2 , 2 ) ); } @Test diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/bootstrap/registry/classloading/PhantomReferenceLeakDetector.java b/hibernate-core/src/test/java/org/hibernate/orm/test/bootstrap/registry/classloading/PhantomReferenceLeakDetector.java index 163b6ef2ec..0567c61f69 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/bootstrap/registry/classloading/PhantomReferenceLeakDetector.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/bootstrap/registry/classloading/PhantomReferenceLeakDetector.java @@ -74,7 +74,7 @@ public final class PhantomReferenceLeakDetector { /** * Exposed for self-testing w/o having to wait for the regular timeout */ - static boolean verifyActionNotLeaking(Supplier action, final int gcAttempts, final int totalWaitSeconds ) { + static boolean verifyActionNotLeaking(Supplier action, final int gcAttempts, final int totalWaitSeconds) { T criticalReference = action.get(); final ReferenceQueue referenceQueue = new ReferenceQueue<>(); final PhantomReference reference = new PhantomReference<>( criticalReference, referenceQueue );