[seam-commits] Seam SVN: r14952 - branches/community/Seam_2_3/seam-integration-tests/src/test/java/org/jboss/seam/test/integration.

seam-commits at lists.jboss.org seam-commits at lists.jboss.org
Tue Jun 26 06:57:59 EDT 2012


Author: maschmid
Date: 2012-06-26 06:57:58 -0400 (Tue, 26 Jun 2012)
New Revision: 14952

Added:
   branches/community/Seam_2_3/seam-integration-tests/src/test/java/org/jboss/seam/test/integration/SFSBSynchronizationTest.java
Log:
Integration test for JBSEAM-4993


Added: 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	                        (rev 0)
+++ 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)
@@ -0,0 +1,146 @@
+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;
+
+ at RunWith(Arquillian.class)
+public class SFSBSynchronizationTest extends JUnitSeamTest
+{
+   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);
+   }
+   
+   // 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()
+         {
+            try
+            {
+               SFSBSynchronizationTest.this.factoryLockTestPart1();
+            }
+            catch (Throwable e)
+            {
+               e.printStackTrace();
+               SFSBSynchronizationTest.this.exceptionOccured = true;
+            }
+         }
+      };
+
+      Thread thread2 = new Thread() {
+         @Override
+         public void run()
+         {
+            try
+            {
+               SFSBSynchronizationTest.this.factoryLockTestPart2();
+            }
+            catch (Throwable e)
+            {
+               e.printStackTrace();
+               SFSBSynchronizationTest.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/SFSBSynchronizationTest$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";
+      }
+   }
+}



More information about the seam-commits mailing list