Author: maschmid
Date: 2012-08-23 07:30:44 -0400 (Thu, 23 Aug 2012)
New Revision: 15068
Added:
branches/community/Seam_2_3/seam-integration-tests/src/test/java/org/jboss/seam/test/integration/TestQueueListener.java
branches/community/Seam_2_3/seam-integration-tests/src/test/java/org/jboss/seam/test/integration/TestTopicListener.java
branches/community/Seam_2_3/seam-integration-tests/src/test/java/org/jboss/seam/test/integration/synchronization/
branches/community/Seam_2_3/seam-integration-tests/src/test/java/org/jboss/seam/test/integration/synchronization/FactoryLockAction.java
branches/community/Seam_2_3/seam-integration-tests/src/test/java/org/jboss/seam/test/integration/synchronization/FactoryLockLocal.java
branches/community/Seam_2_3/seam-integration-tests/src/test/java/org/jboss/seam/test/integration/synchronization/FactoryLockTest.java
branches/community/Seam_2_3/seam-integration-tests/src/test/java/org/jboss/seam/test/integration/synchronization/SFSBSynchronizationTest.java
branches/community/Seam_2_3/seam-integration-tests/src/test/java/org/jboss/seam/test/integration/synchronization/TestAction.java
branches/community/Seam_2_3/seam-integration-tests/src/test/java/org/jboss/seam/test/integration/synchronization/TestLocal.java
Removed:
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/SFSBSynchronizationTest.java
Modified:
branches/community/Seam_2_3/seam-integration-tests/src/test/java/org/jboss/seam/test/integration/MessagingTest.java
Log:
integration tests EJB cannot be inner classes.
Deleted:
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-08-23
11:03:43 UTC (rev 15067)
+++
branches/community/Seam_2_3/seam-integration-tests/src/test/java/org/jboss/seam/test/integration/FactoryLockTest.java 2012-08-23
11:30:44 UTC (rev 15068)
@@ -1,309 +0,0 @@
-package org.jboss.seam.test.integration;
-
-import java.io.Serializable;
-
-import javax.ejb.Local;
-import javax.ejb.Remove;
-import javax.ejb.Stateful;
-
-import org.jboss.arquillian.container.test.api.Deployment;
-import org.jboss.arquillian.container.test.api.OverProtocol;
-import org.jboss.arquillian.junit.Arquillian;
-import org.jboss.seam.Component;
-import org.jboss.seam.ScopeType;
-import org.jboss.seam.annotations.Factory;
-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.Ignore;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-
-import static org.junit.Assert.assertEquals;
-
-(a)RunWith(Arquillian.class)
-public class FactoryLockTest extends JUnitSeamTest
-{
- private volatile boolean exceptionOccured = false;
-
- @Deployment(name="FactoryLockTest")
- @OverProtocol("Servlet 3.0")
- public static Archive<?> createDeployment()
- {
- return Deployments.defaultSeamDeployment()
- .addClasses(FactoryLockAction.class, FactoryLockLocal.class,
TestProducer.class, SeamSynchronizedFactoryLockAction.class, KnitFactory.class,
PurlFactory.class);
- }
-
- private abstract class TestThread extends Thread {
- public abstract void runTest() throws Exception;
-
- @Override
- public void run()
- {
- try
- {
- runTest();
- }
- catch (Throwable e)
- {
- e.printStackTrace();
- FactoryLockTest.this.exceptionOccured = true;
- }
- }
- }
-
- private void multiThreadedTest(Thread... threads) throws InterruptedException {
- exceptionOccured = false;
-
- for (Thread thread : threads) {
- thread.start();
- }
-
- for (Thread thread : threads) {
- thread.join();
- }
-
- assertEquals(exceptionOccured,false);
- }
-
- // 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
- {
- multiThreadedTest(new TestThread() {
- @Override
- public void runTest() throws Exception
- {
- FactoryLockTest.this.invokeMethod("foo",
"#{factoryLock.test.testOtherFactory()}");
- }
- },
-
- new TestThread() {
- @Override
- public void runTest() throws Exception
- {
- Thread.sleep(200);
- FactoryLockTest.this.getValue("testString",
"#{factoryLock.testString}");
- }
- });
- }
-
- // This test is the same as factoryLock test, except it uses the same factory in both
threads.
- @Test
- @Ignore // this is weird use case so we don't test it as we know it doesn't
work due SFSB doesn't serve for multithread request from same client
- public void sameFactoryLock()
- throws Exception
- {
- multiThreadedTest(new TestThread() {
- @Override
- public void runTest() throws Exception
- {
- FactoryLockTest.this.invokeMethod("testString",
"#{factoryLock.test.testSameFactory()}");
- }
- },
-
- new TestThread() {
- @Override
- public void runTest() throws Exception
- {
- Thread.sleep(200);
- FactoryLockTest.this.getValue("testString",
"#{factoryLock.testString}");
- }
- });
- }
-
- // This test is the same as sameFactoryLock test, except it uses a @Synchronized 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()}");
- }
- },
-
- new TestThread() {
- @Override
- public void runTest() throws Exception
- {
- Thread.sleep(200);
- FactoryLockTest.this.getValue("testString",
"#{seamSynchronizedFactoryLock.testString}");
- }
- });
- }
-
- // Test the behavior of two components using factories of each other.
- @Test
- // Skip the test, as it causes deadlock.
- //@Ignore
- public void interleavingFactories()
- throws Exception
- {
- multiThreadedTest(new TestThread() {
- @Override
- public void runTest() throws Exception
- {
- FactoryLockTest.this.getValue("knit(purl)",
"#{factoryLock.knitPurl}");
- }
- },
-
- 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 {
- new ComponentTest() {
- @Override
- protected void testComponents() throws Exception {
- assertEquals(expected, invokeMethod(el));
- }
- }.run();
- }
-
- private void getValue(final String expected, final String el) throws Exception {
- new ComponentTest() {
- @Override
- protected void testComponents() throws Exception {
- assertEquals(expected, getValue(el));
- }
- }.run();
- }
-
- @Local
- public static interface FactoryLockLocal
- {
- public String getTestString();
- public String testOtherFactory();
- public String testSameFactory();
- public void remove();
- }
-
-
- @Stateful
- @Scope(ScopeType.SESSION)
- @Name("factoryLock.test")
- @JndiName("java:global/test/FactoryLockTest$FactoryLockAction")
- public static class FactoryLockAction implements FactoryLockLocal
- {
- public String testOtherFactory() {
- try
- {
- Thread.sleep(500);
- }
- catch (InterruptedException e)
- {
- e.printStackTrace();
- }
- return (String)Component.getInstance("factoryLock.foo", true);
- }
-
- // gets instance produced by this component's factory
- public String testSameFactory() {
- try
- {
- Thread.sleep(500);
- }
- catch (InterruptedException e)
- {
- e.printStackTrace();
- }
- return (String)Component.getInstance("factoryLock.testString", true);
- }
-
- @Factory(value="factoryLock.testString", scope=ScopeType.SESSION)
- public String getTestString() {
- return "testString";
- }
- @Remove
- public void remove() {}
- }
-
- // Mostly the same as FactoryLockAction, except not a SFSB
- @SuppressWarnings("serial")
- @Scope(ScopeType.SESSION)
- @Name("seamSynchronizedFactoryLock.test")
- @Synchronized(timeout=3000)
- 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)
- public String getFoo() {
- 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";
- }
- }
-}
Modified:
branches/community/Seam_2_3/seam-integration-tests/src/test/java/org/jboss/seam/test/integration/MessagingTest.java
===================================================================
---
branches/community/Seam_2_3/seam-integration-tests/src/test/java/org/jboss/seam/test/integration/MessagingTest.java 2012-08-23
11:03:43 UTC (rev 15067)
+++
branches/community/Seam_2_3/seam-integration-tests/src/test/java/org/jboss/seam/test/integration/MessagingTest.java 2012-08-23
11:30:44 UTC (rev 15068)
@@ -1,13 +1,8 @@
package org.jboss.seam.test.integration;
-import javax.ejb.ActivationConfigProperty;
-import javax.ejb.MessageDriven;
import javax.jms.JMSException;
-import javax.jms.Message;
-import javax.jms.MessageListener;
import javax.jms.QueueSender;
import javax.jms.QueueSession;
-import javax.jms.TextMessage;
import javax.jms.TopicPublisher;
import javax.jms.TopicSession;
@@ -30,7 +25,7 @@
@OverProtocol("Servlet 3.0")
public static Archive<?> createDeployment()
{
- return Deployments.defaultSeamDeployment();
+ return Deployments.defaultSeamDeployment().addClasses(TestQueueListener.class,
TestTopicListener.class);
}
@Test
@@ -47,7 +42,7 @@
Contexts.getApplicationContext().set("testMessage",
messageText);
invokeAction("#{testTopic.publish}");
}
- }.run();
+ }.run();
// need to delay a bit to make sure the message is delivered
// might need
@@ -70,7 +65,7 @@
Contexts.getApplicationContext().set("testMessage",
messageText);
invokeAction("#{testQueue.send}");
}
- }.run();
+ }.run();
// need to delay a bit to make sure the message is delivered
// might need
@@ -90,9 +85,9 @@
public void publish()
throws JMSException
- {
+ {
testPublisher.publish(topicSession.createTextMessage("message for
topic"));
- }
+ }
}
@Name("testQueue")
@@ -107,53 +102,11 @@
testSender.send(queueSession.createTextMessage("message for
queue"));
}
}
-
- @MessageDriven(activationConfig={
- @ActivationConfigProperty(propertyName="destinationType",
propertyValue="javax.jms.Topic"),
- @ActivationConfigProperty(propertyName="destination",
propertyValue="topic/seamTest")
- })
- @Name("testTopicListener")
- static public class TestTopicListener
- implements MessageListener
- {
- @In
- private SimpleReference<String> testMessage;
- public void onMessage(Message msg)
- {
- try {
- testMessage.setValue(((TextMessage) msg).getText());
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- }
-
- @MessageDriven(activationConfig={
- @ActivationConfigProperty(propertyName="destinationType",
propertyValue="javax.jms.Queue"),
- @ActivationConfigProperty(propertyName="destination",
propertyValue="queue/seamTest")
- })
- @Name("testQueueListener")
- static public class TestQueueListener
- implements MessageListener
- {
- @In
- private SimpleReference<String> testMessage;
- public void onMessage(Message msg)
- {
- try {
- testMessage.setValue(((TextMessage) msg).getText());
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- }
-
-
static class SimpleReference<T> {
T value;
- public SimpleReference() {
+ public SimpleReference() {
}
public SimpleReference(T value) {
setValue(value);
Deleted:
branches/community/Seam_2_3/seam-integration-tests/src/test/java/org/jboss/seam/test/integration/SFSBSynchronizationTest.java
===================================================================
---
branches/community/Seam_2_3/seam-integration-tests/src/test/java/org/jboss/seam/test/integration/SFSBSynchronizationTest.java 2012-08-23
11:03:43 UTC (rev 15067)
+++
branches/community/Seam_2_3/seam-integration-tests/src/test/java/org/jboss/seam/test/integration/SFSBSynchronizationTest.java 2012-08-23
11:30:44 UTC (rev 15068)
@@ -1,161 +0,0 @@
-package org.jboss.seam.test.integration;
-
-import java.net.URL;
-import java.net.URLConnection;
-
-import javax.ejb.Local;
-import javax.ejb.Remove;
-import javax.ejb.Stateful;
-
-import org.apache.commons.io.IOUtils;
-import org.jboss.arquillian.container.test.api.Deployment;
-import org.jboss.arquillian.container.test.api.OverProtocol;
-import org.jboss.arquillian.container.test.api.RunAsClient;
-import org.jboss.arquillian.junit.Arquillian;
-import org.jboss.arquillian.test.api.ArquillianResource;
-import org.jboss.seam.ScopeType;
-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.shrinkwrap.api.Archive;
-import org.jboss.shrinkwrap.api.asset.StringAsset;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-
-@RunAsClient
-(a)RunWith(Arquillian.class)
-public class SFSBSynchronizationTest
-{
- @Deployment(name="SFSBSynchronizationTest")
- @OverProtocol("Servlet 3.0")
- public static Archive<?> createDeployment()
- {
- // This is a client test, use a real (non-mocked) Seam deployment
- return Deployments.realSeamDeployment()
- .addClasses(TestAction.class, TestLocal.class)
- .addAsWebResource(new StringAsset(
- "<html
xmlns=\"http://www.w3.org/1999/xhtml\""
+
- "
xmlns:s=\"http://jboss.org/schema/seam/taglib\""
+
- "
xmlns:h=\"http://java.sun.com/jsf/html\"" +
- "
xmlns:f=\"http://java.sun.com/jsf/core\">" +
- "<h:head></h:head>" +
- "<h:body>" +
- "<h:outputText value=\"#{test.test1()} \"
/><h:outputText value=\"#{test.test2()}\" />" +
- "</h:body>" +
- "</html>"), "test.xhtml");
- }
-
- @ArquillianResource
- private URL deploymentUrl;
-
- private volatile boolean exceptionOccured = false;
-
- private class ClientThread extends Thread {
-
- private String cookie;
- private URL url;
-
- private ClientThread(URL url, String cookie) {
- this.url = url;
- this.cookie = cookie;
- }
-
- @Override
- public void run()
- {
- try
- {
- // 10 iterations are enough to be very likely to reproduce the lock and takes
only 2 seconds
- for (int i = 0; i < 10; ++i) {
- URLConnection urlConn;
- urlConn = url.openConnection();
- urlConn.setRequestProperty("Cookie", cookie);
- urlConn.connect();
-
- String content = IOUtils.toString(urlConn.getInputStream());
- assert content.contains("test1 test2");
- }
- }
- catch (Throwable e)
- {
- e.printStackTrace();
- exceptionOccured = true;
- }
- }
- }
-
- // JBPAPP-8869 (JBSEAM-4943)
- @Test
- public void synchronizationInterceptor()
- throws Exception
- {
- System.out.println(deploymentUrl.toString());
-
- // Initial request to get the session
- URL testUrl = new URL(deploymentUrl.toString() + "/test.seam");
- URLConnection urlConn = testUrl.openConnection();
- urlConn.connect();
-
- String cookie = urlConn.getHeaderField("Set-Cookie");
- assert cookie != null;
- assert cookie.startsWith("JSESSIONID=");
-
- Thread thread1 = new ClientThread(testUrl, cookie);
- Thread thread2 = new ClientThread(testUrl, cookie);
-
- thread1.start();
- thread2.start();
-
- thread1.join();
- thread2.join();
-
- assert !exceptionOccured;
- }
-
- @Local
- public static interface TestLocal
- {
- public String test1();
- public String test2();
- public void remove();
- }
-
-
- @Stateful
- @Scope(ScopeType.SESSION)
- @Name("test")
- @JndiName("java:global/test/SFSBSynchronizationTest$TestAction")
- @Synchronized(timeout=10000)
- public static class TestAction implements TestLocal
- {
- public String test1() {
- try
- {
- Thread.sleep(100);
- }
-
- catch (InterruptedException e)
- {
- e.printStackTrace();
- }
- return "test1";
- }
-
- public String test2() {
- try
- {
- Thread.sleep(100);
- }
-
- catch (InterruptedException e)
- {
- e.printStackTrace();
- }
- return "test2";
- }
-
- @Remove
- public void remove() {}
- }
-}
Added:
branches/community/Seam_2_3/seam-integration-tests/src/test/java/org/jboss/seam/test/integration/TestQueueListener.java
===================================================================
---
branches/community/Seam_2_3/seam-integration-tests/src/test/java/org/jboss/seam/test/integration/TestQueueListener.java
(rev 0)
+++
branches/community/Seam_2_3/seam-integration-tests/src/test/java/org/jboss/seam/test/integration/TestQueueListener.java 2012-08-23
11:30:44 UTC (rev 15068)
@@ -0,0 +1,35 @@
+package org.jboss.seam.test.integration;
+
+import javax.ejb.ActivationConfigProperty;
+import javax.ejb.MessageDriven;
+import javax.jms.Message;
+import javax.jms.MessageListener;
+import javax.jms.TextMessage;
+
+import org.jboss.seam.annotations.In;
+import org.jboss.seam.annotations.Name;
+import org.jboss.seam.test.integration.MessagingTest.SimpleReference;
+
+@MessageDriven(activationConfig =
+{
+ @ActivationConfigProperty(propertyName = "destinationType", propertyValue
= "javax.jms.Queue"),
+ @ActivationConfigProperty(propertyName = "destination", propertyValue =
"queue/seamTest")
+})
+@Name("testQueueListener")
+public class TestQueueListener implements MessageListener
+{
+ @In
+ private SimpleReference<String> testMessage;
+
+ public void onMessage(Message msg)
+ {
+ try
+ {
+ testMessage.setValue(((TextMessage) msg).getText());
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ }
+}
\ No newline at end of file
Added:
branches/community/Seam_2_3/seam-integration-tests/src/test/java/org/jboss/seam/test/integration/TestTopicListener.java
===================================================================
---
branches/community/Seam_2_3/seam-integration-tests/src/test/java/org/jboss/seam/test/integration/TestTopicListener.java
(rev 0)
+++
branches/community/Seam_2_3/seam-integration-tests/src/test/java/org/jboss/seam/test/integration/TestTopicListener.java 2012-08-23
11:30:44 UTC (rev 15068)
@@ -0,0 +1,35 @@
+package org.jboss.seam.test.integration;
+
+import javax.ejb.ActivationConfigProperty;
+import javax.ejb.MessageDriven;
+import javax.jms.Message;
+import javax.jms.MessageListener;
+import javax.jms.TextMessage;
+
+import org.jboss.seam.annotations.In;
+import org.jboss.seam.annotations.Name;
+import org.jboss.seam.test.integration.MessagingTest.SimpleReference;
+
+@MessageDriven(activationConfig =
+{
+ @ActivationConfigProperty(propertyName = "destinationType", propertyValue
= "javax.jms.Topic"),
+ @ActivationConfigProperty(propertyName = "destination", propertyValue =
"topic/seamTest")
+})
+@Name("testTopicListener")
+public class TestTopicListener implements MessageListener
+{
+ @In
+ private SimpleReference<String> testMessage;
+
+ public void onMessage(Message msg)
+ {
+ try
+ {
+ testMessage.setValue(((TextMessage) msg).getText());
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ }
+}
\ No newline at end of file
Added:
branches/community/Seam_2_3/seam-integration-tests/src/test/java/org/jboss/seam/test/integration/synchronization/FactoryLockAction.java
===================================================================
---
branches/community/Seam_2_3/seam-integration-tests/src/test/java/org/jboss/seam/test/integration/synchronization/FactoryLockAction.java
(rev 0)
+++
branches/community/Seam_2_3/seam-integration-tests/src/test/java/org/jboss/seam/test/integration/synchronization/FactoryLockAction.java 2012-08-23
11:30:44 UTC (rev 15068)
@@ -0,0 +1,50 @@
+package org.jboss.seam.test.integration.synchronization;
+
+import javax.ejb.Remove;
+import javax.ejb.Stateful;
+
+import org.jboss.seam.Component;
+import org.jboss.seam.ScopeType;
+import org.jboss.seam.annotations.Factory;
+import org.jboss.seam.annotations.JndiName;
+import org.jboss.seam.annotations.Name;
+import org.jboss.seam.annotations.Scope;
+
+@Stateful
+(a)Scope(ScopeType.SESSION)
+(a)Name("factoryLock.test")
+@JndiName("java:global/test/FactoryLockAction")
+public class FactoryLockAction implements FactoryLockLocal
+{
+ public String testOtherFactory() {
+ try
+ {
+ Thread.sleep(500);
+ }
+ catch (InterruptedException e)
+ {
+ e.printStackTrace();
+ }
+ return (String)Component.getInstance("factoryLock.foo", true);
+ }
+
+ // gets instance produced by this component's factory
+ public String testSameFactory() {
+ try
+ {
+ Thread.sleep(500);
+ }
+ catch (InterruptedException e)
+ {
+ e.printStackTrace();
+ }
+ return (String)Component.getInstance("factoryLock.testString", true);
+ }
+
+ @Factory(value="factoryLock.testString", scope=ScopeType.SESSION)
+ public String getTestString() {
+ return "testString";
+ }
+ @Remove
+ public void remove() {}
+}
Added:
branches/community/Seam_2_3/seam-integration-tests/src/test/java/org/jboss/seam/test/integration/synchronization/FactoryLockLocal.java
===================================================================
---
branches/community/Seam_2_3/seam-integration-tests/src/test/java/org/jboss/seam/test/integration/synchronization/FactoryLockLocal.java
(rev 0)
+++
branches/community/Seam_2_3/seam-integration-tests/src/test/java/org/jboss/seam/test/integration/synchronization/FactoryLockLocal.java 2012-08-23
11:30:44 UTC (rev 15068)
@@ -0,0 +1,12 @@
+package org.jboss.seam.test.integration.synchronization;
+
+import javax.ejb.Local;
+
+@Local
+public interface FactoryLockLocal
+{
+ public String getTestString();
+ public String testOtherFactory();
+ public String testSameFactory();
+ public void remove();
+}
\ No newline at end of file
Added:
branches/community/Seam_2_3/seam-integration-tests/src/test/java/org/jboss/seam/test/integration/synchronization/FactoryLockTest.java
===================================================================
---
branches/community/Seam_2_3/seam-integration-tests/src/test/java/org/jboss/seam/test/integration/synchronization/FactoryLockTest.java
(rev 0)
+++
branches/community/Seam_2_3/seam-integration-tests/src/test/java/org/jboss/seam/test/integration/synchronization/FactoryLockTest.java 2012-08-23
11:30:44 UTC (rev 15068)
@@ -0,0 +1,254 @@
+package org.jboss.seam.test.integration.synchronization;
+
+import java.io.Serializable;
+
+import org.jboss.arquillian.container.test.api.Deployment;
+import org.jboss.arquillian.container.test.api.OverProtocol;
+import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.seam.Component;
+import org.jboss.seam.ScopeType;
+import org.jboss.seam.annotations.Factory;
+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.seam.test.integration.Deployments;
+import org.jboss.shrinkwrap.api.Archive;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import static org.junit.Assert.assertEquals;
+
+(a)RunWith(Arquillian.class)
+public class FactoryLockTest extends JUnitSeamTest
+{
+ private volatile boolean exceptionOccured = false;
+
+ @Deployment(name="FactoryLockTest")
+ @OverProtocol("Servlet 3.0")
+ public static Archive<?> createDeployment()
+ {
+ return Deployments.defaultSeamDeployment()
+ .addClasses(FactoryLockAction.class, FactoryLockLocal.class,
TestProducer.class, SeamSynchronizedFactoryLockAction.class, KnitFactory.class,
PurlFactory.class);
+ }
+
+ private abstract class TestThread extends Thread {
+ public abstract void runTest() throws Exception;
+
+ @Override
+ public void run()
+ {
+ try
+ {
+ runTest();
+ }
+ catch (Throwable e)
+ {
+ e.printStackTrace();
+ FactoryLockTest.this.exceptionOccured = true;
+ }
+ }
+ }
+
+ private void multiThreadedTest(Thread... threads) throws InterruptedException {
+ exceptionOccured = false;
+
+ for (Thread thread : threads) {
+ thread.start();
+ }
+
+ for (Thread thread : threads) {
+ thread.join();
+ }
+
+ assertEquals(exceptionOccured,false);
+ }
+
+ // 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
+ {
+ multiThreadedTest(new TestThread() {
+ @Override
+ public void runTest() throws Exception
+ {
+ FactoryLockTest.this.invokeMethod("foo",
"#{factoryLock.test.testOtherFactory()}");
+ }
+ },
+
+ new TestThread() {
+ @Override
+ public void runTest() throws Exception
+ {
+ Thread.sleep(200);
+ FactoryLockTest.this.getValue("testString",
"#{factoryLock.testString}");
+ }
+ });
+ }
+
+ // This test is the same as factoryLock test, except it uses the same factory in both
threads.
+ @Test
+ @Ignore // this is weird use case so we don't test it as we know it doesn't
work due SFSB doesn't serve for multithread request from same client
+ public void sameFactoryLock()
+ throws Exception
+ {
+ multiThreadedTest(new TestThread() {
+ @Override
+ public void runTest() throws Exception
+ {
+ FactoryLockTest.this.invokeMethod("testString",
"#{factoryLock.test.testSameFactory()}");
+ }
+ },
+
+ new TestThread() {
+ @Override
+ public void runTest() throws Exception
+ {
+ Thread.sleep(200);
+ FactoryLockTest.this.getValue("testString",
"#{factoryLock.testString}");
+ }
+ });
+ }
+
+ // This test is the same as sameFactoryLock test, except it uses a @Synchronized 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()}");
+ }
+ },
+
+ new TestThread() {
+ @Override
+ public void runTest() throws Exception
+ {
+ Thread.sleep(200);
+ FactoryLockTest.this.getValue("testString",
"#{seamSynchronizedFactoryLock.testString}");
+ }
+ });
+ }
+
+ // Test the behavior of two components using factories of each other.
+ @Test
+ // Skip the test, as it causes deadlock.
+ //@Ignore
+ public void interleavingFactories()
+ throws Exception
+ {
+ multiThreadedTest(new TestThread() {
+ @Override
+ public void runTest() throws Exception
+ {
+ FactoryLockTest.this.getValue("knit(purl)",
"#{factoryLock.knitPurl}");
+ }
+ },
+
+ 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 {
+ new ComponentTest() {
+ @Override
+ protected void testComponents() throws Exception {
+ assertEquals(expected, invokeMethod(el));
+ }
+ }.run();
+ }
+
+ private void getValue(final String expected, final String el) throws Exception {
+ new ComponentTest() {
+ @Override
+ protected void testComponents() throws Exception {
+ assertEquals(expected, getValue(el));
+ }
+ }.run();
+ }
+
+ // Mostly the same as FactoryLockAction, except not a SFSB
+ @SuppressWarnings("serial")
+ @Scope(ScopeType.SESSION)
+ @Name("seamSynchronizedFactoryLock.test")
+ @Synchronized(timeout=3000)
+ 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";
+ }
+ }
+
+
+ @Name("factoryLock.testProducer")
+ public static class TestProducer {
+ @Factory(value="factoryLock.foo", scope=ScopeType.SESSION)
+ public String getFoo() {
+ 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";
+ }
+ }
+}
Added:
branches/community/Seam_2_3/seam-integration-tests/src/test/java/org/jboss/seam/test/integration/synchronization/SFSBSynchronizationTest.java
===================================================================
---
branches/community/Seam_2_3/seam-integration-tests/src/test/java/org/jboss/seam/test/integration/synchronization/SFSBSynchronizationTest.java
(rev 0)
+++
branches/community/Seam_2_3/seam-integration-tests/src/test/java/org/jboss/seam/test/integration/synchronization/SFSBSynchronizationTest.java 2012-08-23
11:30:44 UTC (rev 15068)
@@ -0,0 +1,107 @@
+package org.jboss.seam.test.integration.synchronization;
+
+import java.net.URL;
+import java.net.URLConnection;
+
+import org.apache.commons.io.IOUtils;
+import org.jboss.arquillian.container.test.api.Deployment;
+import org.jboss.arquillian.container.test.api.OverProtocol;
+import org.jboss.arquillian.container.test.api.RunAsClient;
+import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.arquillian.test.api.ArquillianResource;
+import org.jboss.seam.test.integration.Deployments;
+import org.jboss.shrinkwrap.api.Archive;
+import org.jboss.shrinkwrap.api.asset.StringAsset;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+@RunAsClient
+(a)RunWith(Arquillian.class)
+public class SFSBSynchronizationTest
+{
+ @Deployment(name="SFSBSynchronizationTest")
+ @OverProtocol("Servlet 3.0")
+ public static Archive<?> createDeployment()
+ {
+ // This is a client test, use a real (non-mocked) Seam deployment
+ return Deployments.realSeamDeployment()
+ .addClasses(TestAction.class, TestLocal.class)
+ .addAsWebResource(new StringAsset(
+ "<html
xmlns=\"http://www.w3.org/1999/xhtml\""
+
+ "
xmlns:s=\"http://jboss.org/schema/seam/taglib\""
+
+ "
xmlns:h=\"http://java.sun.com/jsf/html\"" +
+ "
xmlns:f=\"http://java.sun.com/jsf/core\">" +
+ "<h:head></h:head>" +
+ "<h:body>" +
+ "<h:outputText value=\"#{test.test1()} \"
/><h:outputText value=\"#{test.test2()}\" />" +
+ "</h:body>" +
+ "</html>"), "test.xhtml");
+ }
+
+ @ArquillianResource
+ private URL deploymentUrl;
+
+ private volatile boolean exceptionOccured = false;
+
+ private class ClientThread extends Thread {
+
+ private String cookie;
+ private URL url;
+
+ private ClientThread(URL url, String cookie) {
+ this.url = url;
+ this.cookie = cookie;
+ }
+
+ @Override
+ public void run()
+ {
+ try
+ {
+ // 10 iterations are enough to be very likely to reproduce the lock and takes
only 2 seconds
+ for (int i = 0; i < 10; ++i) {
+ URLConnection urlConn;
+ urlConn = url.openConnection();
+ urlConn.setRequestProperty("Cookie", cookie);
+ urlConn.connect();
+
+ String content = IOUtils.toString(urlConn.getInputStream());
+ assert content.contains("test1 test2");
+ }
+ }
+ catch (Throwable e)
+ {
+ e.printStackTrace();
+ exceptionOccured = true;
+ }
+ }
+ }
+
+ // JBPAPP-8869 (JBSEAM-4943)
+ @Test
+ public void synchronizationInterceptor()
+ throws Exception
+ {
+ System.out.println(deploymentUrl.toString());
+
+ // Initial request to get the session
+ URL testUrl = new URL(deploymentUrl.toString() + "/test.seam");
+ URLConnection urlConn = testUrl.openConnection();
+ urlConn.connect();
+
+ String cookie = urlConn.getHeaderField("Set-Cookie");
+ assert cookie != null;
+ assert cookie.startsWith("JSESSIONID=");
+
+ Thread thread1 = new ClientThread(testUrl, cookie);
+ Thread thread2 = new ClientThread(testUrl, cookie);
+
+ thread1.start();
+ thread2.start();
+
+ thread1.join();
+ thread2.join();
+
+ assert !exceptionOccured;
+ }
+}
Added:
branches/community/Seam_2_3/seam-integration-tests/src/test/java/org/jboss/seam/test/integration/synchronization/TestAction.java
===================================================================
---
branches/community/Seam_2_3/seam-integration-tests/src/test/java/org/jboss/seam/test/integration/synchronization/TestAction.java
(rev 0)
+++
branches/community/Seam_2_3/seam-integration-tests/src/test/java/org/jboss/seam/test/integration/synchronization/TestAction.java 2012-08-23
11:30:44 UTC (rev 15068)
@@ -0,0 +1,47 @@
+package org.jboss.seam.test.integration.synchronization;
+
+import javax.ejb.Remove;
+import javax.ejb.Stateful;
+
+import org.jboss.seam.ScopeType;
+import org.jboss.seam.annotations.JndiName;
+import org.jboss.seam.annotations.Name;
+import org.jboss.seam.annotations.Scope;
+import org.jboss.seam.annotations.Synchronized;
+
+@Stateful
+(a)Scope(ScopeType.SESSION)
+@Name("test")
+@JndiName("java:global/test/TestAction")
+@Synchronized(timeout=10000)
+public class TestAction implements TestLocal
+{
+ public String test1() {
+ try
+ {
+ Thread.sleep(100);
+ }
+
+ catch (InterruptedException e)
+ {
+ e.printStackTrace();
+ }
+ return "test1";
+ }
+
+ public String test2() {
+ try
+ {
+ Thread.sleep(100);
+ }
+
+ catch (InterruptedException e)
+ {
+ e.printStackTrace();
+ }
+ return "test2";
+ }
+
+ @Remove
+ public void remove() {}
+}
Added:
branches/community/Seam_2_3/seam-integration-tests/src/test/java/org/jboss/seam/test/integration/synchronization/TestLocal.java
===================================================================
---
branches/community/Seam_2_3/seam-integration-tests/src/test/java/org/jboss/seam/test/integration/synchronization/TestLocal.java
(rev 0)
+++
branches/community/Seam_2_3/seam-integration-tests/src/test/java/org/jboss/seam/test/integration/synchronization/TestLocal.java 2012-08-23
11:30:44 UTC (rev 15068)
@@ -0,0 +1,11 @@
+package org.jboss.seam.test.integration.synchronization;
+
+import javax.ejb.Local;
+
+@Local
+public interface TestLocal
+{
+ public String test1();
+ public String test2();
+ public void remove();
+}
\ No newline at end of file