https://issues.apache.org/jira/browse/EXTSCRIPT-117
It was a threading issue, since we run our tests multithreaded to save time, I now added a monitor
to keep the threading issue in the affected parts at bay, if this does not resolve it we
will switch back to non threaded testing.
git-svn-id: https://svn.apache.org/repos/asf/myfaces/extensions/scripting/trunk@936397 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/extscript-core-root/extscript-core/src/test/java/org/apache/myfaces/extensions/scripting/core/reloading/SimpleReloadingStrategyTest.java b/extscript-core-root/extscript-core/src/test/java/org/apache/myfaces/extensions/scripting/core/reloading/SimpleReloadingStrategyTest.java
index bbc2e2e..57f7ddd 100644
--- a/extscript-core-root/extscript-core/src/test/java/org/apache/myfaces/extensions/scripting/core/reloading/SimpleReloadingStrategyTest.java
+++ b/extscript-core-root/extscript-core/src/test/java/org/apache/myfaces/extensions/scripting/core/reloading/SimpleReloadingStrategyTest.java
@@ -85,20 +85,21 @@
@Test
public void testReload() throws Exception {
+ synchronized (ContextUtils.COMPILE_LOAD_MONITOR) {
+ Object probe = _loader.loadClass("compiler.TestProbe1").newInstance();
+ ReloadingMetadata metaData = getMetadata(probe);
+ WeavingContext.getRefreshContext().getDaemon().getClassMap().put("compiler.TestProbe1", metaData);
- Object probe = _loader.loadClass("compiler.TestProbe1").newInstance();
- ReloadingMetadata metaData = getMetadata(probe);
- WeavingContext.getRefreshContext().getDaemon().getClassMap().put("compiler.TestProbe1", metaData);
+ ReflectUtil.executeMethod(probe, "setTestAttr", "hello");
+ Object probe2 = _strategy.reload(probe, ScriptingConst.ENGINE_TYPE_JSF_JAVA);
+ Object attr = ReflectUtil.executeMethod(probe, "getTestAttr");
+ assertFalse(probe.hashCode() == probe2.hashCode());
+ assertTrue(attr instanceof String);
+ assertTrue(((String) attr).equals("hello"));
- ReflectUtil.executeMethod(probe, "setTestAttr", "hello");
- Object probe2 = _strategy.reload(probe, ScriptingConst.ENGINE_TYPE_JSF_JAVA);
- Object attr = ReflectUtil.executeMethod(probe, "getTestAttr");
- assertFalse(probe.hashCode() == probe2.hashCode());
- assertTrue(attr instanceof String);
- assertTrue(((String)attr).equals("hello"));
-
- Object probe3 = _strategy.reload(probe2, ScriptingConst.ENGINE_TYPE_JSF_JAVA);
- assertTrue(probe2 == probe3);
+ Object probe3 = _strategy.reload(probe2, ScriptingConst.ENGINE_TYPE_JSF_JAVA);
+ assertTrue(probe2 == probe3);
+ }
}
private ReloadingMetadata getMetadata(Object probe) {
diff --git a/extscript-core-root/extscript-core/src/test/java/org/apache/myfaces/extensions/scripting/core/support/ContextUtils.java b/extscript-core-root/extscript-core/src/test/java/org/apache/myfaces/extensions/scripting/core/support/ContextUtils.java
index 100db0b..63f4369 100644
--- a/extscript-core-root/extscript-core/src/test/java/org/apache/myfaces/extensions/scripting/core/support/ContextUtils.java
+++ b/extscript-core-root/extscript-core/src/test/java/org/apache/myfaces/extensions/scripting/core/support/ContextUtils.java
@@ -37,6 +37,12 @@
* @version $Revision$ $Date$
*/
public class ContextUtils {
+
+ /**
+ * locking monitor for the compile/load parts
+ */
+ public static volatile Boolean COMPILE_LOAD_MONITOR = new Boolean(true);
+
/**
* A startup routine shared by many tests
* to do the basic weaving initialization
@@ -51,6 +57,7 @@
/**
* same as the other one but with a web.xml path being possible
+ *
* @param webXmlPath the path to the web.xml
* @return the servlet context
*/
@@ -60,17 +67,18 @@
return context;
}
-
public static File doJavaRecompile(String sourceRoot) throws ClassNotFoundException {
- DynamicCompiler compiler = new CompilerFacade(false);
- try {
- FileUtils.deleteDirectory(WeavingContext.getConfiguration().getCompileTarget());
- } catch (IOException e) {
- fail(e.getMessage());
- }
- WeavingContext.getConfiguration().getCompileTarget().mkdirs();
- return compiler.compileAllFiles(sourceRoot, "");
+ synchronized (COMPILE_LOAD_MONITOR) {
+ DynamicCompiler compiler = new CompilerFacade(false);
+ try {
+ FileUtils.deleteDirectory(WeavingContext.getConfiguration().getCompileTarget());
+ } catch (IOException e) {
+ fail(e.getMessage());
+ }
+ WeavingContext.getConfiguration().getCompileTarget().mkdirs();
+ return compiler.compileAllFiles(sourceRoot, "");
+ }
}
}
diff --git a/extscript-core-root/extscript-core/src/test/java/org/apache/myfaces/extensions/scripting/loaders/java/RecompiledClassLoaderTest.java b/extscript-core-root/extscript-core/src/test/java/org/apache/myfaces/extensions/scripting/loaders/java/RecompiledClassLoaderTest.java
index a9ac556..9a2c9b5 100644
--- a/extscript-core-root/extscript-core/src/test/java/org/apache/myfaces/extensions/scripting/loaders/java/RecompiledClassLoaderTest.java
+++ b/extscript-core-root/extscript-core/src/test/java/org/apache/myfaces/extensions/scripting/loaders/java/RecompiledClassLoaderTest.java
@@ -69,14 +69,15 @@
@Test
public void testLoadClass() throws Exception {
+ synchronized (ContextUtils.COMPILE_LOAD_MONITOR) {
+ //the simple reloading case is handled by the reloading strategy testcase
+ //so this test is mostly just to test the rest of the class
- //the simple reloading case is handled by the reloading strategy testcase
- //so this test is mostly just to test the rest of the class
+ Class clazz1 = _loader.loadClass("java.lang.String");
+ Class clazz2 = _loader.loadClass("java.lang.String");
+ assertTrue(clazz1.hashCode() == clazz2.hashCode());
- Class clazz1 = _loader.loadClass("java.lang.String");
- Class clazz2 = _loader.loadClass("java.lang.String");
- assertTrue(clazz1.hashCode() == clazz2.hashCode());
-
+ }
}
@Test
diff --git a/extscript-core-root/extscript-core/src/test/java/org/apache/myfaces/extensions/scripting/loaders/java/ScannerClassloaderTest.java b/extscript-core-root/extscript-core/src/test/java/org/apache/myfaces/extensions/scripting/loaders/java/ScannerClassloaderTest.java
index 804b7a7..433c7dd 100644
--- a/extscript-core-root/extscript-core/src/test/java/org/apache/myfaces/extensions/scripting/loaders/java/ScannerClassloaderTest.java
+++ b/extscript-core-root/extscript-core/src/test/java/org/apache/myfaces/extensions/scripting/loaders/java/ScannerClassloaderTest.java
@@ -63,10 +63,11 @@
@Test
public void testLoadClass() throws Exception {
- Class clazz1 = _loader.loadClass("compiler.TestProbe1");
- Class clazz2 = _loader.loadClass("compiler.TestProbe1");
- assertTrue(clazz1 == clazz2);
+ synchronized (ContextUtils.COMPILE_LOAD_MONITOR) {
+ Class clazz1 = _loader.loadClass("compiler.TestProbe1");
+ Class clazz2 = _loader.loadClass("compiler.TestProbe1");
+ assertTrue(clazz1 == clazz2);
+ }
}
-
}