KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > ejb3 > test > cache > unit > StatefulUnitTestCase


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.ejb3.test.cache.unit;
23
24 import javax.management.MBeanServerConnection JavaDoc;
25 import javax.management.ObjectName JavaDoc;
26 import org.jboss.ejb3.test.cache.SimpleStatefulRemote;
27 import org.jboss.ejb3.test.cache.StatefulRemote;
28 import org.jboss.test.JBossTestCase;
29 import junit.framework.Test;
30
31 /**
32  * Sample client for the jboss container.
33  *
34  * @author <a HREF="mailto:bill@burkecentral.com">Bill Burke</a>
35  * @version $Id: StatefulUnitTestCase.java 58110 2006-11-04 08:34:21Z scott.stark@jboss.org $
36  */

37
38 public class StatefulUnitTestCase
39 extends JBossTestCase
40 {
41    org.jboss.logging.Logger log = getLog();
42
43    static boolean deployed = false;
44    static int test = 0;
45
46    public StatefulUnitTestCase(String JavaDoc name)
47    {
48
49       super(name);
50
51    }
52
53    public void testStateful() throws Exception JavaDoc
54    {
55       StatefulRemote remote = (StatefulRemote) getInitialContext().lookup("StatefulBean/remote");
56       remote.reset();
57       remote.setState("hello");
58       Thread.sleep(11000);
59       assertEquals("hello", remote.getState());
60       assertTrue(remote.getPostActivate());
61       assertTrue(remote.getPrePassivate());
62       remote.done(); // remove this
63
}
64
65    public void testStatefulLongRunning() throws Exception JavaDoc
66    {
67       StatefulRemote remote = (StatefulRemote) getInitialContext().lookup("StatefulBean/remote");
68       remote.reset();
69       remote.setState("hello");
70       remote.longRunning();
71       // It is in use so not yet passivated
72
assertFalse(remote.getPrePassivate());
73       Thread.sleep(11000);
74       // Now it will be.
75
assertEquals("hello", remote.getState());
76       assertTrue(remote.getPostActivate());
77       assertTrue(remote.getPrePassivate());
78       remote.done(); // remove this
79
}
80
81    public void testSimpleStatefulLongRunning() throws Exception JavaDoc
82    {
83       SimpleStatefulRemote remote = (SimpleStatefulRemote) getInitialContext().lookup("SimpleStatefulBean/remote");
84       remote.reset();
85       remote.setState("hello");
86       remote.longRunning();
87       assertEquals("hello", remote.getState());
88       assertTrue(remote.getPostActivate());
89       assertTrue(remote.getPrePassivate());
90    }
91
92    public void testSimpleStateful() throws Exception JavaDoc
93    {
94       SimpleStatefulRemote remote = (SimpleStatefulRemote) getInitialContext().lookup("SimpleStatefulBean/remote");
95       remote.reset();
96       remote.setState("hello");
97       Thread.sleep(5000);
98       assertEquals("hello", remote.getState());
99       assertTrue(remote.getPostActivate());
100       assertTrue(remote.getPrePassivate());
101    }
102
103    public void testSimpleLocal() throws Exception JavaDoc
104    {
105        MBeanServerConnection JavaDoc server = getServer();
106       ObjectName JavaDoc testerName = new ObjectName JavaDoc("jboss.ejb3:service=Tester,test=cache");
107       Object JavaDoc[] params = {};
108       String JavaDoc[] sig = {};
109       server.invoke(testerName, "testSimpleLocal", params, sig);
110    }
111
112    public void testBench() throws Exception JavaDoc
113    {
114       StatefulRemote remote = (StatefulRemote) getInitialContext().lookup("StatefulBean/remote");
115       System.out.println("bench: " + remote.bench(1000));
116       remote.done(); // remove this
117
}
118
119    public void testBenchSimple() throws Exception JavaDoc
120    {
121       SimpleStatefulRemote remote = (SimpleStatefulRemote) getInitialContext().lookup("SimpleStatefulBean/remote");
122       System.out.println("simple bench: " + remote.bench(1000));
123
124    }
125
126    public static Test suite() throws Exception JavaDoc
127    {
128       return getDeploySetup(StatefulUnitTestCase.class, "testejb3-statefulcache-service.xml, cache-test.jar, cache-test.sar");
129    }
130
131 }
132
Popular Tags