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

weld-commits at lists.jboss.org weld-commits at lists.jboss.org
Mon May 24 11:47:00 EDT 2010


Author: pete.muir at jboss.org
Date: 2010-05-24 11:46:59 -0400 (Mon, 24 May 2010)
New Revision: 6294

Modified:
   cdi-tck/branches/1.0/impl/src/main/java/org/jboss/jsr299/tck/tests/context/request/ejb/EJBRequestContextTest.java
   cdi-tck/branches/1.0/impl/src/main/java/org/jboss/jsr299/tck/tests/context/request/ejb/FMS.java
   cdi-tck/branches/1.0/impl/src/main/java/org/jboss/jsr299/tck/tests/context/request/ejb/FMSModelIII.java
Log:
CDITCK-155, CDITCK-157

Modified: cdi-tck/branches/1.0/impl/src/main/java/org/jboss/jsr299/tck/tests/context/request/ejb/EJBRequestContextTest.java
===================================================================
--- cdi-tck/branches/1.0/impl/src/main/java/org/jboss/jsr299/tck/tests/context/request/ejb/EJBRequestContextTest.java	2010-05-24 15:06:33 UTC (rev 6293)
+++ cdi-tck/branches/1.0/impl/src/main/java/org/jboss/jsr299/tck/tests/context/request/ejb/EJBRequestContextTest.java	2010-05-24 15:46:59 UTC (rev 6294)
@@ -45,11 +45,20 @@
    @SpecAssertion(section = "6.7.1", id = "gc")
    public void testRequestScopeActiveDuringCallToEjbTimeoutMethod() throws Exception
    {
+      FMSModelIII.reset();
       FMS flightManagementSystem = getInstanceByType(FMS.class);
       flightManagementSystem.climb();
-      Thread.sleep(250);
+      waitForClimbed();
       assert flightManagementSystem.isRequestScopeActive();
    }
+   
+   private void waitForClimbed() throws Exception
+   {
+      for (int i = 0; !FMSModelIII.isClimbed() && i < 2000; i++)
+      {
+         Thread.sleep(10);
+      }
+   }
 
    /**
     * The request context is destroyed after the remote method invocation,
@@ -59,12 +68,22 @@
    @SpecAssertion(section = "6.7.1", id = "hc")
    public void testRequestScopeDestroyedAfterCallToEjbTimeoutMethod() throws Exception
    {
+      FMSModelIII.reset();
       FMS flightManagementSystem = getInstanceByType(FMS.class);
       flightManagementSystem.climb();
+      waitForClimbed();
       flightManagementSystem.descend();
-      Thread.sleep(250);
+      waitForDescended();
       assert !flightManagementSystem.isSameBean();
       assert SimpleRequestBean.isBeanDestroyed();
    }
+   
+   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/request/ejb/FMS.java
===================================================================
--- cdi-tck/branches/1.0/impl/src/main/java/org/jboss/jsr299/tck/tests/context/request/ejb/FMS.java	2010-05-24 15:06:33 UTC (rev 6293)
+++ cdi-tck/branches/1.0/impl/src/main/java/org/jboss/jsr299/tck/tests/context/request/ejb/FMS.java	2010-05-24 15:46:59 UTC (rev 6294)
@@ -21,17 +21,12 @@
 @Local
 public interface FMS
 {
-   public void turnLeft();
    
-   public void turnRight();
-   
    public void climb();
    
    public void descend();
    
    public boolean isRequestScopeActive();
-
-   public void setRequestScopeActive(boolean requestScopeActive);
    
    public boolean isSameBean();
 }

Modified: cdi-tck/branches/1.0/impl/src/main/java/org/jboss/jsr299/tck/tests/context/request/ejb/FMSModelIII.java
===================================================================
--- cdi-tck/branches/1.0/impl/src/main/java/org/jboss/jsr299/tck/tests/context/request/ejb/FMSModelIII.java	2010-05-24 15:06:33 UTC (rev 6293)
+++ cdi-tck/branches/1.0/impl/src/main/java/org/jboss/jsr299/tck/tests/context/request/ejb/FMSModelIII.java	2010-05-24 15:46:59 UTC (rev 6294)
@@ -22,6 +22,7 @@
 import javax.ejb.Timer;
 import javax.ejb.TimerService;
 import javax.enterprise.context.RequestScoped;
+import javax.enterprise.inject.Instance;
 import javax.enterprise.inject.spi.BeanManager;
 import javax.inject.Inject;
 
@@ -29,53 +30,62 @@
 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;
    
    @Inject
    private BeanManager beanManager;
+   
+   @Inject Instance<SimpleRequestBean> simpleRequestBean;
 
    private static boolean requestScopeActive = false;
    private static double beanId = 0.0d;
    private static boolean sameBean = false;
+   
+   private static boolean climbed;
+   private static boolean descended;
 
    public void climb()
    {
-      timerService.createTimer(200, "Climb command timeout");
+      timerService.createTimer(200, CLIMB_COMMAND);
    }
 
    public void descend()
    {
-      timerService.createTimer(100, "Descend command timeout");
+      timerService.createTimer(100, DESCEND_COMMAND);
+      // Resets
       beanId = 0.0d;
       sameBean = false;
    }
 
-   public void turnLeft()
-   {
-   }
-
-   public void turnRight()
-   {
-   }
-
    @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(RequestScoped.class).isActive())
       {
          requestScopeActive = true;
          if (beanId > 0.0)
          {
-            if (beanId == org.jboss.jsr299.tck.impl.OldSPIBridge.getInstanceByType(beanManager,SimpleRequestBean.class).getId())
+            if (beanId == simpleRequestBean.get().getId())
             {
                sameBean = true;
             }
          }
          else
          {
-            beanId = org.jboss.jsr299.tck.impl.OldSPIBridge.getInstanceByType(beanManager,SimpleRequestBean.class).getId();
+            beanId = simpleRequestBean.get().getId();
          }
       }
    }
@@ -84,15 +94,29 @@
    {
       return requestScopeActive;
    }
-
-   public void setRequestScopeActive(boolean requestScopeActive)
+   
+   public static void reset()
    {
-      FMSModelIII.requestScopeActive = requestScopeActive;
+      beanId = 0.0d;
+      climbed = false;
+      descended = false;
+      requestScopeActive = false;
+      sameBean = false;
    }
 
    public boolean isSameBean()
    {
       return sameBean;
    }
+   
+   public static boolean isClimbed()
+   {
+      return climbed;
+   }
+   
+   public static boolean isDescended()
+   {
+      return descended;
+   }
 
 }



More information about the weld-commits mailing list