From f3bab5638253c48dc3e1909f77d17ca45356f0b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Galder=20Zamarre=C3=B1o?= Date: Tue, 15 Mar 2011 14:08:36 +0100 Subject: [PATCH] HHH-6015 - hibernate-infinispan test failures after migration to JUnit4 Fixed isolated classloader test making sure the two classloaders required are created, one with the classes and the other without them. --- .../classloader/IsolatedClassLoaderTest.java | 28 +++++++++---------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/classloader/IsolatedClassLoaderTest.java b/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/classloader/IsolatedClassLoaderTest.java index 3175efc521..5d0d4fdc0f 100644 --- a/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/classloader/IsolatedClassLoaderTest.java +++ b/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/classloader/IsolatedClassLoaderTest.java @@ -60,32 +60,30 @@ import org.hibernate.test.cache.infinispan.functional.cluster.DualNodeTestCase; * @since 3.5 */ public class IsolatedClassLoaderTest extends DualNodeTestCase { - private static final String CACHE_CONFIG = "classloader"; - protected static final long SLEEP_TIME = 300L; - static int test = 0; - private Cache localQueryCache; private CacheAccessListener localQueryListener; private Cache remoteQueryCache; private CacheAccessListener remoteQueryListener; - private static ClassLoader originalTCCL; + private static ClassLoader originalTCCL; @BeforeClass public static void prepareClassLoader() { - originalTCCL = Thread.currentThread().getContextClassLoader(); - final String packageName = IsolatedClassLoaderTest.class.getPackage().getName(); - final String[] isolatedClassNames = new String[] { packageName + "Account", packageName + "AccountHolder" }; - final SelectedClassnameClassLoader visible = new SelectedClassnameClassLoader( - isolatedClassNames, - null, - null, - originalTCCL - ); - Thread.currentThread().setContextClassLoader( visible ); + final String packageName = IsolatedClassLoaderTest.class.getPackage().getName(); + final String[] classes = new String[] { packageName + ".Account", packageName + ".AccountHolder" }; + originalTCCL = Thread.currentThread().getContextClassLoader(); + // Most likely, it will point to system classloader + ClassLoader parent = originalTCCL == null ? IsolatedClassLoaderTest.class.getClassLoader() : originalTCCL; + + // First, create a classloader where classes won't be found + ClassLoader selectedTCCL = new SelectedClassnameClassLoader(null, null, classes, parent); + + // Now, make the class visible to the test driver + SelectedClassnameClassLoader visible = new SelectedClassnameClassLoader(classes, null, null, selectedTCCL); + Thread.currentThread().setContextClassLoader(visible); } @AfterClass