Author: maschmid
Date: 2012-07-03 07:02:30 -0400 (Tue, 03 Jul 2012)
New Revision: 14978
Modified:
branches/community/Seam_2_3/seam-integration-tests/src/test/java/org/jboss/seam/test/integration/FactoryLockTest.java
Log:
add seamSynchronizedFactoryLock to FactoryLockTest to verify the locking behavior between
the Seam Synchronization interceptor lock and the factory lock
Modified:
branches/community/Seam_2_3/seam-integration-tests/src/test/java/org/jboss/seam/test/integration/FactoryLockTest.java
===================================================================
---
branches/community/Seam_2_3/seam-integration-tests/src/test/java/org/jboss/seam/test/integration/FactoryLockTest.java 2012-07-03
10:38:24 UTC (rev 14977)
+++
branches/community/Seam_2_3/seam-integration-tests/src/test/java/org/jboss/seam/test/integration/FactoryLockTest.java 2012-07-03
11:02:30 UTC (rev 14978)
@@ -1,5 +1,7 @@
package org.jboss.seam.test.integration;
+import java.io.Serializable;
+
import javax.ejb.Local;
import javax.ejb.Remove;
import javax.ejb.Stateful;
@@ -13,6 +15,7 @@
import org.jboss.seam.annotations.JndiName;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;
+import org.jboss.seam.annotations.Synchronized;
import org.jboss.seam.mock.JUnitSeamTest;
import org.jboss.shrinkwrap.api.Archive;
import org.junit.Test;
@@ -30,7 +33,7 @@
public static Archive<?> createDeployment()
{
return Deployments.defaultSeamDeployment()
- .addClasses(FactoryLockAction.class, FactoryLockLocal.class,
TestProducer.class);
+ .addClasses(FactoryLockAction.class, FactoryLockLocal.class,
TestProducer.class, SeamSynchronizedFactoryLockAction.class);
}
private abstract class TestThread extends Thread {
@@ -51,37 +54,42 @@
}
}
+ 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.
@@ -89,31 +97,45 @@
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}");
}
- };
-
- thread1.start();
- thread2.start();
+ });
+ }
- thread1.join();
- thread2.join();
+ // This test is the same as sameFactoryLock test, except it uses a @Syncrhonized Seam
component, instead of an SFSB
+ @Test
+ public void seamSynchronizedFactoryLock()
+ throws Exception
+ {
+ multiThreadedTest(new TestThread() {
+ @Override
+ public void runTest() throws Exception
+ {
+ FactoryLockTest.this.invokeMethod("testString",
"#{seamSynchronizedFactoryLock.test.testFactory()}");
+ }
+ },
- assert !exceptionOccured;
+ new TestThread() {
+ @Override
+ public void runTest() throws Exception
+ {
+ Thread.sleep(200);
+ FactoryLockTest.this.getValue("testString",
"#{seamSynchronizedFactoryLock.testString}");
+ }
+ });
}
private void invokeMethod(final String expected, final String el) throws Exception {
@@ -183,6 +205,35 @@
public void remove() {}
}
+ // Mostly the same as FactoryLockAction, except not a SFSB
+ @SuppressWarnings("serial")
+ @Scope(ScopeType.SESSION)
+ @Name("seamSynchronizedFactoryLock.test")
+ @Synchronized(timeout=10000)
+ public static class SeamSynchronizedFactoryLockAction implements Serializable
+ {
+ // gets instance produced by this component's factory
+ public String testFactory() {
+ try
+ {
+ Thread.sleep(500);
+ }
+ catch (InterruptedException e)
+ {
+ e.printStackTrace();
+ }
+ return
(String)Component.getInstance("seamSynchronizedFactoryLock.testString", true);
+ }
+
+ @Factory(value="seamSynchronizedFactoryLock.testString",
scope=ScopeType.SESSION)
+ public String getTestString() {
+ return "testString";
+ }
+ @Remove
+ public void remove() {}
+ }
+
+
@Name("factoryLock.testProducer")
public static class TestProducer {
@Factory(value="factoryLock.foo", scope=ScopeType.SESSION)
Show replies by date