[weld-commits] Weld SVN: r6296 - cdi-tck/branches/1.0/impl/src/main/java/org/jboss/jsr299/tck/tests/context/application/ejb.

weld-commits at lists.jboss.org weld-commits at lists.jboss.org
Mon May 24 12:07:50 EDT 2010


Author: pete.muir at jboss.org
Date: 2010-05-24 12:07:50 -0400 (Mon, 24 May 2010)
New Revision: 6296

Modified:
   cdi-tck/branches/1.0/impl/src/main/java/org/jboss/jsr299/tck/tests/context/application/ejb/ApplicationContextSharedTest.java
   cdi-tck/branches/1.0/impl/src/main/java/org/jboss/jsr299/tck/tests/context/application/ejb/FMSModelIII.java
Log:
CDITCK-156

Modified: cdi-tck/branches/1.0/impl/src/main/java/org/jboss/jsr299/tck/tests/context/application/ejb/ApplicationContextSharedTest.java
===================================================================
--- cdi-tck/branches/1.0/impl/src/main/java/org/jboss/jsr299/tck/tests/context/application/ejb/ApplicationContextSharedTest.java	2010-05-24 16:07:29 UTC (rev 6295)
+++ cdi-tck/branches/1.0/impl/src/main/java/org/jboss/jsr299/tck/tests/context/application/ejb/ApplicationContextSharedTest.java	2010-05-24 16:07:50 UTC (rev 6296)
@@ -41,21 +41,40 @@
    @SpecAssertion(section = "6.7.3", id = "e")
    public void testApplicationContextShared() throws Exception
    {
+      FMSModelIII.reset();
       FMS flightManagementSystem = getInstanceByType(FMS.class);
       flightManagementSystem.climb();
+      waitForClimbed();
       flightManagementSystem.descend();
-      Thread.sleep(250);
+      waitForDescended();
       assert flightManagementSystem.isSameBean();
    }
    
+   private void waitForClimbed() throws Exception
+   {
+      for (int i = 0; !FMSModelIII.isClimbed() && i < 2000; i++)
+      {
+         Thread.sleep(10);
+      }
+   }
+   
    @Test(groups = { "contexts", "ejb3", "integration" })
    @SpecAssertion(section = "6.7.3", id = "dc")
    public void testApplicationScopeActiveDuringCallToEjbTimeoutMethod() throws Exception
    {
+      FMSModelIII.reset();
       FMS flightManagementSystem = getInstanceByType(FMS.class);
       flightManagementSystem.climb();
-      Thread.sleep(250);
+      waitForClimbed();
       assert flightManagementSystem.isApplicationScopeActive();
    }
+   
+   private void waitForDescended() throws Exception
+   {
+      for (int i = 0; !FMSModelIII.isDescended() && i < 2000; i++)
+      {
+         Thread.sleep(10);
+      }
+   }
 
 }

Modified: cdi-tck/branches/1.0/impl/src/main/java/org/jboss/jsr299/tck/tests/context/application/ejb/FMSModelIII.java
===================================================================
--- cdi-tck/branches/1.0/impl/src/main/java/org/jboss/jsr299/tck/tests/context/application/ejb/FMSModelIII.java	2010-05-24 16:07:29 UTC (rev 6295)
+++ cdi-tck/branches/1.0/impl/src/main/java/org/jboss/jsr299/tck/tests/context/application/ejb/FMSModelIII.java	2010-05-24 16:07:50 UTC (rev 6296)
@@ -30,6 +30,9 @@
 public class FMSModelIII implements FMS
 {
    private static final long serialVersionUID = 1L;
+   
+   private static final String CLIMB_COMMAND = "ClimbCommand";
+   private static final String DESCEND_COMMAND = "DescendCommand";
 
    @Resource
    private TimerService timerService;
@@ -44,46 +47,30 @@
    private static volatile double beanId = 0.0d;
    private static volatile boolean sameBean = false;
    
-   private static volatile int climbState;
-   private static volatile int descendState;
+   private static boolean climbed;
+   private static boolean descended;
 
    public void climb() throws Exception
    {
-      climbState = 0;
-      timerService.createTimer(200, "Climb command timeout");
-      long timestamp = System.currentTimeMillis();
-      // Wait for the timer
-      while (climbState == 0)
-      {
-         // but don't wait more than 10s so we don't just hang!
-         if (System.currentTimeMillis() > timestamp + 10000)
-         {
-            return;
-         }
-         Thread.sleep(1);
-      }
+      timerService.createTimer(200, CLIMB_COMMAND);
    }
 
    public void descend() throws Exception
    {
-      descendState = 0;
-      timerService.createTimer(100, "Descend command timeout");
-      long timestamp = System.currentTimeMillis();
-      // Wait for the timer
-      while (descendState == 0)
-      {
-         // but don't wait more than 10s so we don't just hang!
-         if (System.currentTimeMillis() > timestamp + 10000)
-         {
-            return;
-         }
-         Thread.sleep(1);
-      }
+      timerService.createTimer(100, DESCEND_COMMAND);
    }
 
    @Timeout
    public void timeout(Timer timer)
    {
+      if (timer.getInfo().equals(CLIMB_COMMAND))
+      {
+         climbed = true;
+      }
+      if (timer.getInfo().equals(DESCEND_COMMAND))
+      {
+         descended = true;
+      }
       if (beanManager.getContext(ApplicationScoped.class).isActive())
       {
          applicationScopeActive = true;
@@ -99,8 +86,6 @@
             beanId = simpleApplicationBeanInstance.get().getId();
          }
       }
-      climbState = 1;
-      descendState = 1;
    }
 
    public boolean isApplicationScopeActive()
@@ -112,5 +97,24 @@
    {
       return sameBean;
    }
+   
+   public static boolean isClimbed()
+   {
+      return climbed;
+   }
+   
+   public static boolean isDescended()
+   {
+      return descended;
+   }
+   
+   public static void reset()
+   {
+      beanId = 0.0d;
+      climbed = false;
+      descended = false;
+      applicationScopeActive = false;
+      sameBean = false;
+   }
 
 }



More information about the weld-commits mailing list