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_appli.java 4323 2004-03-09 13:17:05Z coqp $
023: * --------------------------------------------------------------------------
024: */
025:
026: package org.objectweb.jonas.stests.appli;
027:
028: import junit.framework.Test;
029: import junit.framework.TestSuite;
030: import javax.rmi.PortableRemoteObject;
031: import org.objectweb.jonas.stests.util.JTestCase;
032: import java.io.BufferedReader;
033: import java.io.InputStreamReader;
034:
035: /**
036: * Set of test with only 1 thread at a time.
037: */
038: public class F_appli extends JTestCase {
039:
040: protected static OrderEntryClerkHome home = null;
041:
042: protected static String oecName = "OrderEntryClerkHome";
043:
044: int nbThreads = 2;
045: int nbPlaceOrders = 1;
046: int nbOrderline = 3;
047:
048: public F_appli(String name) {
049: super (name);
050: }
051:
052: protected void setUp() throws Exception {
053: super .setUp();
054: if (home == null) {
055: useBeans("appli");
056: home = (OrderEntryClerkHome) PortableRemoteObject.narrow(
057: ictx.lookup(oecName), OrderEntryClerkHome.class);
058: }
059:
060: }
061:
062: protected void tearDown() throws Exception {
063: super .tearDown();
064:
065: }
066:
067: /*
068: * Test used for populating tables
069: */
070: public void testCreateAllTables() throws Exception {
071: OrderEntryClerk oecbean = null;
072: oecbean = home.create();
073: oecbean.createAllTables();
074: }
075:
076: public void test2placeOrder() throws Exception {
077: BufferedReader in = new BufferedReader(new InputStreamReader(
078: System.in));
079: OrderEntryClerk oecbean = null;
080: oecbean = home.create();
081: for (int i = 0; i < 100; i++) {
082: System.out.print(">>>>> ");
083: String readLine = in.readLine();
084: oecbean.setCustomer(new Integer(9));
085: oecbean.addOrderLine(new Integer(20), 24);
086: /**/
087: oecbean.addOrderLine(new Integer(10), 12);
088: oecbean.addOrderLine(new Integer(1), 1);
089: oecbean.addOrderLine(new Integer(2), 6);
090: /**/
091: String numorder = oecbean.placeOrder();
092: /**/
093: oecbean.setCustomer(new Integer(5));
094: oecbean.addOrderLine(new Integer(23), 2);
095: oecbean.addOrderLine(new Integer(13), 1);
096: oecbean.addOrderLine(new Integer(11), 7);
097: oecbean.addOrderLine(new Integer(22), 8);
098: numorder = oecbean.placeOrder();
099: /**/
100: }
101: }
102:
103: public void test5placeOrder() throws Exception {
104: OrderEntryClerk oecbean = null;
105: oecbean = home.create();
106: oecbean.setCustomer(new Integer(2));
107: oecbean.addOrderLine(new Integer(1), 24);
108: oecbean.addOrderLine(new Integer(2), 12);
109: oecbean.addOrderLine(new Integer(3), 1);
110: oecbean.addOrderLine(new Integer(4), 6);
111: String numorder = oecbean.placeOrder();
112: oecbean.setCustomer(new Integer(3));
113: oecbean.addOrderLine(new Integer(5), 4);
114: oecbean.addOrderLine(new Integer(6), 2);
115: numorder = oecbean.placeOrder();
116: oecbean.setCustomer(new Integer(4));
117: oecbean.addOrderLine(new Integer(7), 4);
118: oecbean.addOrderLine(new Integer(8), 2);
119: oecbean.addOrderLine(new Integer(9), 4);
120: oecbean.addOrderLine(new Integer(10), 2);
121: oecbean.addOrderLine(new Integer(9), 4);
122: oecbean.addOrderLine(new Integer(10), 2);
123: numorder = oecbean.placeOrder();
124: oecbean.setCustomer(new Integer(5));
125: oecbean.addOrderLine(new Integer(15), 4);
126: oecbean.addOrderLine(new Integer(16), 2);
127: oecbean.addOrderLine(new Integer(3), 5);
128: numorder = oecbean.placeOrder();
129: oecbean.setCustomer(new Integer(6));
130: oecbean.addOrderLine(new Integer(5), 4);
131: oecbean.addOrderLine(new Integer(26), 2);
132: oecbean.addOrderLine(new Integer(23), 5);
133: oecbean.addOrderLine(new Integer(5), 4);
134: oecbean.addOrderLine(new Integer(26), 2);
135: oecbean.addOrderLine(new Integer(23), 5);
136: numorder = oecbean.placeOrder();
137:
138: }
139:
140: public void test_2Threads_1Orders_3Orderlines() throws Exception {
141: applimulti(home, nbThreads, nbPlaceOrders, nbOrderline);
142: }
143:
144: public void test_4Threads_5Orders_4Orderlines() throws Exception {
145: int nbThreads = 4;
146: int nbPlaceOrders = 5;
147: int nbOrderline = 4;
148: applimulti(home, nbThreads, nbPlaceOrders, nbOrderline);
149: }
150:
151: public void test_10Threads_6Orders_10Orderlines() throws Exception {
152: int nbThreads = 10;
153: int nbPlaceOrders = 6;
154: int nbOrderline = 10;
155: applimulti(home, nbThreads, nbPlaceOrders, nbOrderline);
156: }
157:
158: /**
159: * Run a multithreaded client test. Common part to all test multi thread cases.
160: */
161: public void applimulti(OrderEntryClerkHome home, int threads,
162: int nbOrders, int nbLines) throws Exception {
163:
164: // Create and start all threads
165: A_thread[] t_thr = new A_thread[threads];
166: for (int i = 0; i < threads; i++) {
167: t_thr[i] = new A_thread(home, i, nbOrders, nbLines);
168: t_thr[i].start();
169: }
170:
171: // Wait end of all threads
172: for (int p = 0; p < threads; p++) {
173: t_thr[p].join();
174: }
175:
176: }
177:
178: public static Test suite() {
179: return new TestSuite(F_appli.class);
180: }
181:
182: public static void main(String args[]) {
183: String testtorun = null;
184: // Get args
185: for (int argn = 0; argn < args.length; argn++) {
186: String sarg = args[argn];
187: if (sarg.equals("-n")) {
188: testtorun = args[++argn];
189: }
190: }
191: if (testtorun == null) {
192: junit.textui.TestRunner.run(suite());
193: } else {
194: junit.textui.TestRunner.run(new F_appli(testtorun));
195: }
196: }
197:
198: }
|