[jboss-cvs] JBossAS SVN: r63571 - branches/Branch_4_2/testsuite/src/main/org/jboss/test/tm/ejb.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue Jun 19 09:17:05 EDT 2007


Author: dimitris at jboss.org
Date: 2007-06-19 09:17:05 -0400 (Tue, 19 Jun 2007)
New Revision: 63571

Modified:
   branches/Branch_4_2/testsuite/src/main/org/jboss/test/tm/ejb/TxTimeoutBean.java
Log:
make the test more robust with timing issues

Modified: branches/Branch_4_2/testsuite/src/main/org/jboss/test/tm/ejb/TxTimeoutBean.java
===================================================================
--- branches/Branch_4_2/testsuite/src/main/org/jboss/test/tm/ejb/TxTimeoutBean.java	2007-06-19 11:22:21 UTC (rev 63570)
+++ branches/Branch_4_2/testsuite/src/main/org/jboss/test/tm/ejb/TxTimeoutBean.java	2007-06-19 13:17:05 UTC (rev 63571)
@@ -27,7 +27,11 @@
 import javax.transaction.TransactionManager;
 
 import org.jboss.test.util.ejb.SessionSupport;
+import org.jboss.tm.TxUtils;
 
+/**
+ * @version $Revision:$
+ */
 public class TxTimeoutBean extends SessionSupport
 {
    /** The serialVersionUID */
@@ -42,16 +46,10 @@
     */
    public void testDefaultTimeout()
    {
-      try
-      {
-         Thread.sleep(12000);
-      }
-      catch (Exception ignored)
-      {
-         log.debug("Ignored", ignored);
-      }
-      if (getTxStatus() != Status.STATUS_MARKED_ROLLBACK)
-         throw new EJBException("Should be marked rolled back " + getTxStatus());
+      sleep(12000, false);
+      int status = getTxStatus();
+      if (status != Status.STATUS_MARKED_ROLLBACK)
+         throw new EJBException("Should be marked rolled back: " + TxUtils.getStatusAsString(status));
    }
 
    /**
@@ -59,16 +57,19 @@
     */
    public void testOverriddenTimeoutExpires()
    {
-      try
+      sleep(7000, false);
+      int status = getTxStatus();
+      log.info("testOverriddenTimeoutExpires: " + TxUtils.getStatusAsString(status));
+      if (TxUtils.isRollback(status) == false)
       {
-         Thread.sleep(8000);
+         // give it a second chance
+         sleep(2000, false);
+         status = getTxStatus();
+         log.info("testOverriddenTimeoutExpires: " + TxUtils.getStatusAsString(status));
+         
+         if (TxUtils.isRollback(status) == false)
+            throw new EJBException("Should be marked rolled back: " + TxUtils.getStatusAsString(status));         
       }
-      catch (Exception ignored)
-      {
-         log.debug("Ignored", ignored);
-      }
-      if (getTxStatus() != Status.STATUS_MARKED_ROLLBACK)
-         throw new EJBException("Should be marked rolled back " + getTxStatus());
    }
 
    /**
@@ -76,29 +77,38 @@
     */
    public void testOverriddenTimeoutDoesNotExpire()
    {
+      sleep(12000, true);
+      int status = getTxStatus();
+      if (status != Status.STATUS_ACTIVE)
+         throw new EJBException("Should be active: " + TxUtils.getStatusAsString(status));
+   }
+   
+   private int getTxStatus()
+   {
       try
       {
-         Thread.sleep(12000);
+         InitialContext ctx = new InitialContext();
+         TransactionManager tm = (TransactionManager) ctx.lookup("java:/TransactionManager");
+         return tm.getStatus();
       }
       catch (Exception e)
       {
          throw new EJBException(e);
       }
-      if (getTxStatus() != Status.STATUS_ACTIVE)
-         throw new EJBException("Should be active " + getTxStatus());
    }
    
-   private int getTxStatus()
+   private void sleep(int timeout, boolean throwEJBException)
    {
       try
       {
-         InitialContext ctx = new InitialContext();
-         TransactionManager tm = (TransactionManager) ctx.lookup("java:/TransactionManager");
-         return tm.getStatus();
+         Thread.sleep(timeout);
       }
       catch (Exception e)
       {
-         throw new EJBException(e);
+         if (throwEJBException)
+            throw new EJBException(e);
+         else
+            log.debug("Ignored", e);
       }
    }
 }




More information about the jboss-cvs-commits mailing list