Author: maschmid
Date: 2012-07-24 11:11:55 -0400 (Tue, 24 Jul 2012)
New Revision: 15000
Modified:
branches/enterprise/JBPAPP_5_0/src/test/integration/src/org/jboss/seam/test/integration/FactoryLockTest.java
Log:
update FactoryLockTest re JBPAPP-9391 regression
Modified:
branches/enterprise/JBPAPP_5_0/src/test/integration/src/org/jboss/seam/test/integration/FactoryLockTest.java
===================================================================
---
branches/enterprise/JBPAPP_5_0/src/test/integration/src/org/jboss/seam/test/integration/FactoryLockTest.java 2012-07-24
14:25:43 UTC (rev 14999)
+++
branches/enterprise/JBPAPP_5_0/src/test/integration/src/org/jboss/seam/test/integration/FactoryLockTest.java 2012-07-24
15:11:55 UTC (rev 15000)
@@ -35,37 +35,43 @@
}
}
+ private void multiThreadedTest(Thread... threads) throws InterruptedException {
+ exceptionOccured = false;
+
+ for (Thread thread : threads) {
+ thread.start();
+ }
+
+ for (Thread thread : threads) {
+ thread.join();
+ }
+
+ assert !exceptionOccured;
+ }
+
+
// JBSEAM-4993
// The test starts two threads, one evaluates #{factoryLock.test.testOtherFactory()}
and the other #{factoryLock.testString} 200ms later
@Test
public void factoryLock()
throws Exception
{
- exceptionOccured = false;
- Thread thread1 = new TestThread() {
+ multiThreadedTest(new TestThread() {
@Override
public void runTest() throws Exception
{
FactoryLockTest.this.invokeMethod("foo",
"#{factoryLock.test.testOtherFactory()}");
}
- };
-
- Thread thread2 = new TestThread() {
+ },
+
+ new TestThread() {
@Override
public void runTest() throws Exception
{
Thread.sleep(200);
FactoryLockTest.this.getValue("testString",
"#{factoryLock.testString}");
}
- };
-
- thread1.start();
- thread2.start();
-
- thread1.join();
- thread2.join();
-
- assert !exceptionOccured;
+ });
}
// This test is the same as factoryLock test, except it uses the same factory in both
threads.
@@ -73,31 +79,46 @@
public void sameFactoryLock()
throws Exception
{
- exceptionOccured = false;
- Thread thread1 = new TestThread() {
+ multiThreadedTest(new TestThread() {
@Override
public void runTest() throws Exception
{
FactoryLockTest.this.invokeMethod("testString",
"#{factoryLock.test.testSameFactory()}");
}
- };
+ },
- Thread thread2 = new TestThread() {
+ new TestThread() {
@Override
public void runTest() throws Exception
{
Thread.sleep(200);
FactoryLockTest.this.getValue("testString",
"#{factoryLock.testString}");
}
- };
+ });
+ }
+
+ // Test the behavior of two components using factories of each other.
+ // Skip the test, as it causes deadlock.
+ @Test(enabled=false)
+ public void interleavingFactories()
+ throws Exception
+ {
+ multiThreadedTest(new TestThread() {
+ @Override
+ public void runTest() throws Exception
+ {
+ FactoryLockTest.this.getValue("knit(purl)",
"#{factoryLock.knitPurl}");
+ }
+ },
- thread1.start();
- thread2.start();
-
- thread1.join();
- thread2.join();
-
- assert !exceptionOccured;
+ new TestThread() {
+ @Override
+ public void runTest() throws Exception
+ {
+ Thread.sleep(200);
+ FactoryLockTest.this.getValue("purl(knit)",
"#{factoryLock.purlKnit}");
+ }
+ });
}
private void invokeMethod(final String expected, final String el) throws Exception {
@@ -173,4 +194,42 @@
return "foo";
}
}
+
+ @Scope(ScopeType.APPLICATION)
+ @Name("factoryLock.knitFactory")
+ public static class KnitFactory
+ {
+ @Factory(value="factoryLock.knitPurl", scope=ScopeType.SESSION)
+ public String getDoubleKnit() {
+ try
+ {
+ Thread.sleep(500);
+ }
+ catch (InterruptedException e)
+ {
+ e.printStackTrace();
+ }
+ return "knit(" +
(String)Component.getInstance("factoryLock.purl") + ")";
+ }
+
+ @Factory(value="factoryLock.knit", scope=ScopeType.SESSION)
+ public String getKnit() {
+ return "knit";
+ }
+ }
+
+ @Scope(ScopeType.APPLICATION)
+ @Name("factoryLock.purlFactory")
+ public static class PurlFactory
+ {
+ @Factory(value="factoryLock.purlKnit", scope=ScopeType.SESSION)
+ public String getDoublePurl() {
+ return "purl(" +
(String)Component.getInstance("factoryLock.knit") + ")";
+ }
+
+ @Factory(value="factoryLock.purl", scope=ScopeType.SESSION)
+ public String getPurl() {
+ return "purl";
+ }
+ }
}
Show replies by date