KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > tm > ejb > TxTimeoutBean


1 /*
2 * JBoss, Home of Professional Open Source
3 * Copyright 2005, JBoss Inc., and individual contributors as indicated
4 * by the @authors tag. See the copyright.txt in the distribution for a
5 * full listing of individual contributors.
6 *
7 * This is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation; either version 2.1 of
10 * the License, or (at your option) any later version.
11 *
12 * This software is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this software; if not, write to the Free
19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 */

22 package org.jboss.test.tm.ejb;
23
24 import javax.ejb.EJBException JavaDoc;
25 import javax.naming.InitialContext JavaDoc;
26 import javax.transaction.Status JavaDoc;
27 import javax.transaction.TransactionManager JavaDoc;
28
29 import org.jboss.test.util.ejb.SessionSupport;
30
31 public class TxTimeoutBean extends SessionSupport
32 {
33    /** The serialVersionUID */
34    private static final long serialVersionUID = -6750278789142406435L;
35
36    public void ejbCreate()
37    {
38    }
39    
40    /**
41     * The harness should have set the default timeout to 10 secs
42     */

43    public void testDefaultTimeout()
44    {
45       try
46       {
47          Thread.sleep(12000);
48       }
49       catch (Exception JavaDoc ignored)
50       {
51          log.debug("Ignored", ignored);
52       }
53       if (getTxStatus() != Status.STATUS_MARKED_ROLLBACK)
54          throw new EJBException JavaDoc("Should be marked rolled back " + getTxStatus());
55    }
56
57    /**
58     * This method's timeout should be 5 secs
59     */

60    public void testOverriddenTimeoutExpires()
61    {
62       try
63       {
64          Thread.sleep(7000);
65       }
66       catch (Exception JavaDoc ignored)
67       {
68          log.debug("Ignored", ignored);
69       }
70       if (getTxStatus() != Status.STATUS_MARKED_ROLLBACK)
71          throw new EJBException JavaDoc("Should be marked rolled back " + getTxStatus());
72    }
73
74    /**
75     * This method's timeout should be 20 secs
76     */

77    public void testOverriddenTimeoutDoesNotExpire()
78    {
79       try
80       {
81          Thread.sleep(12000);
82       }
83       catch (Exception JavaDoc e)
84       {
85          throw new EJBException JavaDoc(e);
86       }
87       if (getTxStatus() != Status.STATUS_ACTIVE)
88          throw new EJBException JavaDoc("Should be active " + getTxStatus());
89    }
90    
91    private int getTxStatus()
92    {
93       try
94       {
95          InitialContext JavaDoc ctx = new InitialContext JavaDoc();
96          TransactionManager JavaDoc tm = (TransactionManager JavaDoc) ctx.lookup("java:/TransactionManager");
97          return tm.getStatus();
98       }
99       catch (Exception JavaDoc e)
100       {
101          throw new EJBException JavaDoc(e);
102       }
103    }
104 }
105
Popular Tags