1 22 package org.jboss.test.tm.ejb; 23 24 import javax.ejb.EJBException ; 25 import javax.naming.InitialContext ; 26 import javax.transaction.Status ; 27 import javax.transaction.TransactionManager ; 28 29 import org.jboss.test.util.ejb.SessionSupport; 30 31 public class TxTimeoutBean extends SessionSupport 32 { 33 34 private static final long serialVersionUID = -6750278789142406435L; 35 36 public void ejbCreate() 37 { 38 } 39 40 43 public void testDefaultTimeout() 44 { 45 try 46 { 47 Thread.sleep(12000); 48 } 49 catch (Exception ignored) 50 { 51 log.debug("Ignored", ignored); 52 } 53 if (getTxStatus() != Status.STATUS_MARKED_ROLLBACK) 54 throw new EJBException ("Should be marked rolled back " + getTxStatus()); 55 } 56 57 60 public void testOverriddenTimeoutExpires() 61 { 62 try 63 { 64 Thread.sleep(7000); 65 } 66 catch (Exception ignored) 67 { 68 log.debug("Ignored", ignored); 69 } 70 if (getTxStatus() != Status.STATUS_MARKED_ROLLBACK) 71 throw new EJBException ("Should be marked rolled back " + getTxStatus()); 72 } 73 74 77 public void testOverriddenTimeoutDoesNotExpire() 78 { 79 try 80 { 81 Thread.sleep(12000); 82 } 83 catch (Exception e) 84 { 85 throw new EJBException (e); 86 } 87 if (getTxStatus() != Status.STATUS_ACTIVE) 88 throw new EJBException ("Should be active " + getTxStatus()); 89 } 90 91 private int getTxStatus() 92 { 93 try 94 { 95 InitialContext ctx = new InitialContext (); 96 TransactionManager tm = (TransactionManager ) ctx.lookup("java:/TransactionManager"); 97 return tm.getStatus(); 98 } 99 catch (Exception e) 100 { 101 throw new EJBException (e); 102 } 103 } 104 } 105 | Popular Tags |