[jboss-cvs] JBossAS SVN: r64465 - in trunk/ejb3/src/test/org/jboss/ejb3/test/ejbthree1020: unit and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Aug 6 07:52:48 EDT 2007


Author: wolfc
Date: 2007-08-06 07:52:48 -0400 (Mon, 06 Aug 2007)
New Revision: 64465

Modified:
   trunk/ejb3/src/test/org/jboss/ejb3/test/ejbthree1020/MyStateful.java
   trunk/ejb3/src/test/org/jboss/ejb3/test/ejbthree1020/MyStatefulBean.java
   trunk/ejb3/src/test/org/jboss/ejb3/test/ejbthree1020/unit/EjbContextCheckTestCase.java
Log:
EJBTHREE-1020: fixed unit test

Modified: trunk/ejb3/src/test/org/jboss/ejb3/test/ejbthree1020/MyStateful.java
===================================================================
--- trunk/ejb3/src/test/org/jboss/ejb3/test/ejbthree1020/MyStateful.java	2007-08-06 11:39:45 UTC (rev 64464)
+++ trunk/ejb3/src/test/org/jboss/ejb3/test/ejbthree1020/MyStateful.java	2007-08-06 11:52:48 UTC (rev 64465)
@@ -28,7 +28,7 @@
  * Comment
  *
  * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
- * @version $Revision: $
+ * @version $Revision$
  */
 @Remote
 public interface MyStateful
@@ -38,7 +38,7 @@
    
    int getId();
    
-   void method1(int expectedId);
+   MyStateful[] method1(int expectedId);
    
-   void method2(int expectedId);
+   MyStateful method2(int expectedId);
 }

Modified: trunk/ejb3/src/test/org/jboss/ejb3/test/ejbthree1020/MyStatefulBean.java
===================================================================
--- trunk/ejb3/src/test/org/jboss/ejb3/test/ejbthree1020/MyStatefulBean.java	2007-08-06 11:39:45 UTC (rev 64464)
+++ trunk/ejb3/src/test/org/jboss/ejb3/test/ejbthree1020/MyStatefulBean.java	2007-08-06 11:52:48 UTC (rev 64465)
@@ -31,7 +31,7 @@
  * Comment
  *
  * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
- * @version $Revision: $
+ * @version $Revision$
  */
 @Stateful
 public class MyStatefulBean implements MyStateful
@@ -51,22 +51,30 @@
       return id;
    }
    
-   public void method1(int expectedId)
+   public MyStateful[] method1(int expectedId)
    {
+      if(expectedId != id)
+         throw new RuntimeException("ids don't match");
+      
       try
       {
+         MyStateful bos[] = new MyStateful[2];
+         
          SessionContext ctx1 = (SessionContext) new InitialContext().lookup("java:comp/EJBContext");
-         if(expectedId != ctx1.getBusinessObject(MyStateful.class).getId())
-            throw new RuntimeException("ids on first check don't match");
+         bos[0] = ctx1.getBusinessObject(MyStateful.class);
          
-         lock.wait(5000);
+         synchronized(lock)
+         {
+            lock.wait(5000);
+         }
          
          SessionContext ctx2 = (SessionContext) new InitialContext().lookup("java:comp/EJBContext");
-         if(expectedId != ctx2.getBusinessObject(MyStateful.class).getId())
-            throw new RuntimeException("ids on second check don't match");
+         bos[1] = ctx2.getBusinessObject(MyStateful.class);
          
          System.out.println("ctx1 = " + ctx1);
          System.out.println("ctx2 = " + ctx2);
+         
+         return bos;
       }
       catch (NamingException e)
       {
@@ -78,15 +86,22 @@
       }
    }
    
-   public void method2(int expectedId)
+   public MyStateful method2(int expectedId)
    {
+      if(expectedId != id)
+         throw new RuntimeException("ids don't match");
+      
       try
       {
          SessionContext ctx1 = (SessionContext) new InitialContext().lookup("java:comp/EJBContext");
-         if(expectedId != ctx1.getBusinessObject(MyStateful.class).getId())
-            throw new RuntimeException("ids on check don't match");
+         MyStateful bo = ctx1.getBusinessObject(MyStateful.class);
          
-         lock.notify();
+         synchronized (lock)
+         {
+            lock.notify();
+         }
+         
+         return bo;
       }
       catch(NamingException e)
       {

Modified: trunk/ejb3/src/test/org/jboss/ejb3/test/ejbthree1020/unit/EjbContextCheckTestCase.java
===================================================================
--- trunk/ejb3/src/test/org/jboss/ejb3/test/ejbthree1020/unit/EjbContextCheckTestCase.java	2007-08-06 11:39:45 UTC (rev 64464)
+++ trunk/ejb3/src/test/org/jboss/ejb3/test/ejbthree1020/unit/EjbContextCheckTestCase.java	2007-08-06 11:52:48 UTC (rev 64465)
@@ -21,6 +21,8 @@
  */
 package org.jboss.ejb3.test.ejbthree1020.unit;
 
+import java.lang.Thread.UncaughtExceptionHandler;
+
 import junit.framework.Test;
 
 import org.jboss.ejb3.test.ejbthree1020.MyStateful;
@@ -34,6 +36,22 @@
  */
 public class EjbContextCheckTestCase extends JBossTestCase
 {
+   private static class MyUncaughtExceptionHandler implements UncaughtExceptionHandler
+   {
+      private Throwable uncaught;
+      
+      Throwable getUncaughtException()
+      {
+         return uncaught;
+      }
+      
+      public void uncaughtException(Thread t, Throwable e)
+      {
+         e.printStackTrace();
+         this.uncaught = e;
+      }
+   }
+   
    public EjbContextCheckTestCase(String name)
    {
       super(name);
@@ -52,21 +70,29 @@
       MyStateful bean2 = lookupBean();
       bean2.create(2);
       
+      MyUncaughtExceptionHandler handler = new MyUncaughtExceptionHandler();
       Thread thread = new Thread()
       {
          @Override
          public void run()
          {
-            bean1.method1(1);
+            MyStateful beans[] = bean1.method1(1);
+            for(MyStateful bean : beans)
+            {
+               assertEquals(1, bean.getId());
+            }
          }
       };
+      thread.setUncaughtExceptionHandler(handler);
       thread.start();
       
       Thread.sleep(1000);
       
-      bean2.method2(2);
+      MyStateful bean = bean2.method2(2);
+      assertEquals(2, bean.getId());
       
       thread.join(5000);
+      assertNull(handler.getUncaughtException());
    }
    
    public static Test suite() throws Exception




More information about the jboss-cvs-commits mailing list