001: /*
002: * JOnAS: Java(TM) Open Application Server
003: * Copyright (C) 1999 Bull S.A.
004: * Contact: jonas-team@objectweb.org
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
019: * USA
020: *
021: * --------------------------------------------------------------------------
022: * $Id: F_Worker.java 6515 2005-04-07 09:37:22Z durieuxp $
023: * --------------------------------------------------------------------------
024: */
025:
026: package org.objectweb.jonas.jtests.clients.jca15;
027:
028: import java.rmi.RemoteException;
029:
030: import javax.naming.NamingException;
031: import javax.rmi.PortableRemoteObject;
032:
033: import junit.framework.Test;
034: import junit.framework.TestSuite;
035:
036: import org.objectweb.jonas.jtests.beans.worker.Worker;
037: import org.objectweb.jonas.jtests.beans.worker.WorkerHome;
038: import org.objectweb.jonas.jtests.util.JTestCase;
039:
040: public class F_Worker extends JTestCase {
041:
042: private static String BEAN_HOME = "workerHome";
043: private static WorkerHome home = null;
044:
045: public F_Worker(String name) {
046: super (name);
047: }
048:
049: public WorkerHome getHome() {
050: if (home == null) {
051: try {
052: home = (WorkerHome) PortableRemoteObject.narrow(ictx
053: .lookup(BEAN_HOME), WorkerHome.class);
054: } catch (NamingException e) {
055: fail("Cannot get bean home");
056: }
057: }
058: return home;
059: }
060:
061: protected void setUp() {
062: super .setUp();
063: useBeans("worker", false);
064: }
065:
066: public void testDoWorkTx() throws Exception {
067: Worker w = getHome().create();
068: int count = 1;
069: w.doWorkInTx();
070: assertEquals("count", count, w.getwcount());
071: w.remove();
072: }
073:
074: public void testStartWorkTx() throws Exception {
075: Worker w = getHome().create();
076: int count = 1;
077: w.startWorkInTx();
078: assertEquals("count", count, w.getwcount());
079: w.remove();
080: }
081:
082: public void testScheduleWorkTx() throws Exception {
083: Worker w = getHome().create();
084: int count = 1;
085: w.scheduleWorkInTx();
086: assertEquals("count", count, w.getwcount());
087: w.remove();
088: }
089:
090: public void testDoWorkBasic() throws Exception {
091: Worker w = getHome().create();
092: int count = 1;
093: w.doWorks(count);
094: assertEquals("count", count, w.getwcount());
095: w.remove();
096: }
097:
098: public void testDo20Works() throws Exception {
099: Worker w = getHome().create();
100: int count = 20;
101: w.doWorks(count);
102: assertEquals("count", count, w.getwcount());
103: w.remove();
104: }
105:
106: public void testStartWorkBasic() throws Exception {
107: Worker w = getHome().create();
108: int count = 1;
109: w.startWorks(count);
110: sleep(500);
111: assertEquals("count", count, w.getwcount());
112: w.remove();
113: }
114:
115: public void testStart20Works() throws Exception {
116: Worker w = getHome().create();
117: int count = 20;
118: w.startWorks(count);
119: sleep(2000);
120: assertEquals("count", count, w.getwcount());
121: w.remove();
122: }
123:
124: public void testScheduleWorkBasic() throws Exception {
125: Worker w = getHome().create();
126: int count = 1;
127: w.scheduleWorks(count, 20000);
128: sleep(500);
129: assertEquals("count", count, w.getwcount());
130: assertEquals("accepted", count, w.getNotifyAccepted());
131: assertEquals("started", count, w.getNotifyStarted());
132: assertEquals("rejected", 0, w.getNotifyRejected());
133: assertEquals("completed", count, w.getNotifyCompleted());
134: w.remove();
135: }
136:
137: public void testScheduleWorkTimedout() throws Exception {
138: Worker w = getHome().create();
139: int count = 1;
140: w.scheduleWorks(count, 1L);
141: sleep(500);
142: assertEquals("count", 0, w.getwcount());
143: assertEquals("accepted", count, w.getNotifyAccepted());
144: assertEquals("started", 0, w.getNotifyStarted());
145: assertEquals("rejected", count, w.getNotifyRejected());
146: assertEquals("completed", 0, w.getNotifyCompleted());
147: w.remove();
148: }
149:
150: public void testSchedule20Works() throws Exception {
151: Worker w = getHome().create();
152: int count = 20;
153: w.scheduleWorks(count, 20000);
154: sleep(2000);
155: assertEquals("count", count, w.getwcount());
156: assertEquals("accepted", count, w.getNotifyAccepted());
157: assertEquals("started", count, w.getNotifyStarted());
158: assertEquals("rejected", 0, w.getNotifyRejected());
159: assertEquals("completed", count, w.getNotifyCompleted());
160: w.remove();
161: }
162:
163: public static Test suite() {
164: return new TestSuite(F_Worker.class);
165: }
166:
167: public static void main(String args[]) {
168: String testtorun = null;
169: // Get args
170: for (int argn = 0; argn < args.length; argn++) {
171: String s_arg = args[argn];
172: Integer i_arg;
173: if (s_arg.equals("-n")) {
174: testtorun = args[++argn];
175: }
176: }
177: if (testtorun == null) {
178: junit.textui.TestRunner.run(suite());
179: } else {
180: junit.textui.TestRunner.run(new F_Worker(testtorun));
181: }
182: }
183: }
|