Author: maschmid
Date: 2012-06-26 09:37:56 -0400 (Tue, 26 Jun 2012)
New Revision: 14953
Added:
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/resources/WEB-INF/real-web.xml
Modified:
branches/community/Seam_2_3/seam-integration-tests/pom.xml
branches/community/Seam_2_3/seam-integration-tests/src/test/java/org/jboss/seam/test/integration/Deployments.java
branches/community/Seam_2_3/seam-integration-tests/src/test/java/org/jboss/seam/test/integration/SFSBSynchronizationTest.java
Log:
add test for JBPAPP-8869 (JBSEAM-4943)
Modified: branches/community/Seam_2_3/seam-integration-tests/pom.xml
===================================================================
--- branches/community/Seam_2_3/seam-integration-tests/pom.xml 2012-06-26 10:57:58 UTC
(rev 14952)
+++ branches/community/Seam_2_3/seam-integration-tests/pom.xml 2012-06-26 13:37:56 UTC
(rev 14953)
@@ -146,6 +146,12 @@
<artifactId>validation-api</artifactId>
<scope>provided</scope>
</dependency>
+
+ <dependency>
+ <groupId>commons-io</groupId>
+ <artifactId>commons-io</artifactId>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<profiles>
Modified:
branches/community/Seam_2_3/seam-integration-tests/src/test/java/org/jboss/seam/test/integration/Deployments.java
===================================================================
---
branches/community/Seam_2_3/seam-integration-tests/src/test/java/org/jboss/seam/test/integration/Deployments.java 2012-06-26
10:57:58 UTC (rev 14952)
+++
branches/community/Seam_2_3/seam-integration-tests/src/test/java/org/jboss/seam/test/integration/Deployments.java 2012-06-26
13:37:56 UTC (rev 14953)
@@ -31,7 +31,32 @@
.addAsWebInfResource("WEB-INF/ejb-jar.xml",
"ejb-jar.xml")
.addAsWebInfResource("WEB-INF/jboss-seam-integration-tests-hornetq-jms.xml",
"jboss-seam-integration-tests-hornetq-jms.xml");
}
+
+ // Deployment that use the proper SeamListener instead of the MockSeamListener
+ public static WebArchive realSeamDeployment() {
+ return ShrinkWrap.create(ZipImporter.class, "test.war").importFrom(new
File("target/seam-integration-tests.war")).as(WebArchive.class)
+ .addAsWebInfResource(new StringAsset(
+ "<jboss-deployment-structure>" +
+ "<deployment>" +
+ "<dependencies>" +
+ "<module name=\"org.javassist\"/>" +
+ "<module name=\"org.dom4j\"/>" +
+ "</dependencies>" +
+ "</deployment>" +
+ "</jboss-deployment-structure>"),
"jboss-deployment-structure.xml")
+ .addAsResource("seam.properties")
+ .addAsResource("components.properties")
+ .addAsResource("messages_en.properties")
+ .addAsResource("META-INF/persistence.xml")
+ .addAsResource("hibernate.cfg.xml")
+ .addAsWebInfResource("WEB-INF/components.xml",
"components.xml")
+ .addAsWebInfResource("WEB-INF/pages.xml",
"pages.xml")
+ .addAsWebInfResource("WEB-INF/real-web.xml",
"web.xml")
+ .addAsWebInfResource("WEB-INF/ejb-jar.xml",
"ejb-jar.xml")
+
.addAsWebInfResource("WEB-INF/jboss-seam-integration-tests-hornetq-jms.xml",
"jboss-seam-integration-tests-hornetq-jms.xml");
+ }
+
public static WebArchive jbpmSeamDeployment() {
return ShrinkWrap.create(ZipImporter.class, "test.war").importFrom(new
File("target/seam-integration-tests.war")).as(WebArchive.class)
.addAsWebInfResource(new StringAsset(
Added:
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
(rev 0)
+++
branches/community/Seam_2_3/seam-integration-tests/src/test/java/org/jboss/seam/test/integration/FactoryLockTest.java 2012-06-26
13:37:56 UTC (rev 14953)
@@ -0,0 +1,148 @@
+package org.jboss.seam.test.integration;
+
+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.mock.JUnitSeamTest;
+import org.jboss.shrinkwrap.api.Archive;
+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);
+ }
+
+ // JBSEAM-4993
+ // The test starts two threads, one evaluates #{factoryLock.test.test()} and the other
#{factoryLock.testString} 200ms later
+ @Test
+ public void factoryLock()
+ throws Exception
+ {
+ exceptionOccured = false;
+ Thread thread1 = new Thread() {
+ @Override
+ public void run()
+ {
+ try
+ {
+ FactoryLockTest.this.factoryLockTestPart1();
+ }
+ catch (Throwable e)
+ {
+ e.printStackTrace();
+ FactoryLockTest.this.exceptionOccured = true;
+ }
+ }
+ };
+
+ Thread thread2 = new Thread() {
+ @Override
+ public void run()
+ {
+ try
+ {
+ FactoryLockTest.this.factoryLockTestPart2();
+ }
+ catch (Throwable e)
+ {
+ e.printStackTrace();
+ FactoryLockTest.this.exceptionOccured = true;
+ }
+ }
+ };
+
+ thread1.start();
+ thread2.start();
+
+ thread1.join();
+ thread2.join();
+
+ assert !exceptionOccured;
+ }
+
+ private void factoryLockTestPart1() throws Exception {
+ new ComponentTest() {
+ @Override
+ protected void testComponents() throws Exception {
+ assertEquals("test",
invokeMethod("#{factoryLock.test.test()}"));
+ }
+ }.run();
+ }
+
+ private void factoryLockTestPart2() throws Exception {
+ new ComponentTest() {
+ @Override
+ protected void testComponents() throws Exception {
+ Thread.sleep(200);
+ assertEquals("testString",
getValue("#{factoryLock.testString}"));
+ }
+ }.run();
+ }
+
+
+ @Local
+ public static interface FactoryLockLocal
+ {
+ public String getTestString();
+ public String test();
+ public void remove();
+ }
+
+
+ @Stateful
+ @Scope(ScopeType.SESSION)
+ @Name("factoryLock.test")
+ @JndiName("java:global/test/FactoryLockTest$FactoryLockAction")
+ public static class FactoryLockAction implements FactoryLockLocal
+ {
+ public String test() {
+ try
+ {
+ Thread.sleep(500);
+ }
+
+ catch (InterruptedException e)
+ {
+ e.printStackTrace();
+ }
+ Component.getInstance("factoryLock.foo", true);
+ return "test";
+ }
+
+ @Factory(value="factoryLock.testString", scope=ScopeType.EVENT)
+ public String getTestString() {
+ return "testString";
+ }
+ @Remove
+ public void remove() {}
+ }
+
+ @Name("factoryLock.testProducer")
+ public static class TestProducer {
+ @Factory(value="factoryLock.foo", scope=ScopeType.EVENT)
+ public String getFoo() {
+ return "foo";
+ }
+ }
+}
Modified:
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-06-26
10:57:58 UTC (rev 14952)
+++
branches/community/Seam_2_3/seam-integration-tests/src/test/java/org/jboss/seam/test/integration/SFSBSynchronizationTest.java 2012-06-26
13:37:56 UTC (rev 14953)
@@ -1,146 +1,161 @@
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.seam.Component;
+import org.jboss.arquillian.test.api.ArquillianResource;
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.mock.JUnitSeamTest;
+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;
-import static org.junit.Assert.assertEquals;
-
+@RunAsClient
@RunWith(Arquillian.class)
-public class SFSBSynchronizationTest extends JUnitSeamTest
+public class SFSBSynchronizationTest
{
- private volatile boolean exceptionOccured = false;
-
@Deployment(name="SFSBSynchronizationTest")
@OverProtocol("Servlet 3.0")
public static Archive<?> createDeployment()
{
- return Deployments.defaultSeamDeployment()
- .addClasses(FactoryLockAction.class, FactoryLockLocal.class,
TestProducer.class);
+ // 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");
}
- // JBSEAM-4993
- // The test starts two threads, one evaluates #{factoryLock.test.test()} and the other
#{factoryLock.testString} 200ms later
- @Test
- public void factoryLock()
- throws Exception
- {
- Thread thread1 = new Thread() {
- @Override
- public void run()
+ @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
{
- try
- {
- SFSBSynchronizationTest.this.factoryLockTestPart1();
+ // 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();
- SFSBSynchronizationTest.this.exceptionOccured = true;
- }
}
- };
-
- Thread thread2 = new Thread() {
- @Override
- public void run()
+ catch (Throwable e)
{
- try
- {
- SFSBSynchronizationTest.this.factoryLockTestPart2();
- }
- catch (Throwable e)
- {
- e.printStackTrace();
- SFSBSynchronizationTest.this.exceptionOccured = true;
- }
+ e.printStackTrace();
+ exceptionOccured = true;
}
- };
-
+ }
+ }
+
+ // JBPAPP-8869
+ @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;
}
- private void factoryLockTestPart1() throws Exception {
- new ComponentTest() {
- @Override
- protected void testComponents() throws Exception {
- assertEquals("test",
invokeMethod("#{factoryLock.test.test()}"));
- }
- }.run();
- }
-
- private void factoryLockTestPart2() throws Exception {
- new ComponentTest() {
- @Override
- protected void testComponents() throws Exception {
- Thread.sleep(200);
- assertEquals("testString",
getValue("#{factoryLock.testString}"));
- }
- }.run();
- }
-
@Local
- public static interface FactoryLockLocal
+ public static interface TestLocal
{
- public String getTestString();
- public String test();
+ public String test1();
+ public String test2();
public void remove();
}
@Stateful
@Scope(ScopeType.SESSION)
- @Name("factoryLock.test")
- @JndiName("java:global/test/SFSBSynchronizationTest$FactoryLockAction")
- public static class FactoryLockAction implements FactoryLockLocal
+ @Name("test")
+ @JndiName("java:global/test/SFSBSynchronizationTest$TestAction")
+ @Synchronized(timeout=10000)
+ public static class TestAction implements TestLocal
{
- public String test() {
+ public String test1() {
try
{
- Thread.sleep(500);
+ Thread.sleep(100);
}
+
catch (InterruptedException e)
{
e.printStackTrace();
}
- Component.getInstance("factoryLock.foo", true);
- return "test";
+ return "test1";
}
- @Factory(value="factoryLock.testString", scope=ScopeType.EVENT)
- public String getTestString() {
- return "testString";
+ public String test2() {
+ try
+ {
+ Thread.sleep(100);
+ }
+
+ catch (InterruptedException e)
+ {
+ e.printStackTrace();
+ }
+ return "test2";
}
-
+
@Remove
public void remove() {}
}
-
- @Name("factoryLock.testProducer")
- public static class TestProducer {
- @Factory(value="factoryLock.foo", scope=ScopeType.EVENT)
- public String getFoo() {
- return "foo";
- }
- }
}
Added:
branches/community/Seam_2_3/seam-integration-tests/src/test/resources/WEB-INF/real-web.xml
===================================================================
---
branches/community/Seam_2_3/seam-integration-tests/src/test/resources/WEB-INF/real-web.xml
(rev 0)
+++
branches/community/Seam_2_3/seam-integration-tests/src/test/resources/WEB-INF/real-web.xml 2012-06-26
13:37:56 UTC (rev 14953)
@@ -0,0 +1,56 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<web-app version="3.0"
+
xmlns="http://java.sun.com/xml/ns/javaee"
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
+
+ <listener>
+ <listener-class>org.jboss.seam.servlet.SeamListener</listener-class>
+ </listener>
+
+ <filter>
+ <filter-name>Seam Filter</filter-name>
+ <filter-class>org.jboss.seam.servlet.SeamFilter</filter-class>
+ </filter>
+
+ <filter-mapping>
+ <filter-name>Seam Filter</filter-name>
+ <url-pattern>/*</url-pattern>
+ </filter-mapping>
+
+ <servlet>
+ <servlet-name>Seam Resource Servlet</servlet-name>
+
<servlet-class>org.jboss.seam.servlet.SeamResourceServlet</servlet-class>
+ </servlet>
+
+ <servlet-mapping>
+ <servlet-name>Seam Resource Servlet</servlet-name>
+ <url-pattern>/seam/resource/*</url-pattern>
+ </servlet-mapping>
+
+ <!-- Faces Servlet -->
+
+ <servlet>
+ <servlet-name>Faces Servlet</servlet-name>
+ <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
+ <load-on-startup>1</load-on-startup>
+ </servlet>
+
+ <servlet-mapping>
+ <servlet-name>Faces Servlet</servlet-name>
+ <url-pattern>*.seam</url-pattern>
+ </servlet-mapping>
+
+ <!-- JSF parameters -->
+
+ <context-param>
+ <param-name>javax.faces.DEFAULT_SUFFIX</param-name>
+ <param-value>.xhtml</param-value>
+ </context-param>
+
+ <context-param>
+ <param-name>facelets.DEVELOPMENT</param-name>
+ <param-value>true</param-value>
+ </context-param>
+
+</web-app>