KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > stests > appli > F_appli


1 /*
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 1999 Bull S.A.
4  * Contact: jonas-team@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA
20  *
21  * --------------------------------------------------------------------------
22  * $Id: F_appli.java,v 1.5 2004/03/09 13:17:04 coqp Exp $
23  * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.jonas.stests.appli;
27
28 import junit.framework.Test;
29 import junit.framework.TestSuite;
30 import javax.rmi.PortableRemoteObject JavaDoc;
31 import org.objectweb.jonas.stests.util.JTestCase;
32 import java.io.BufferedReader JavaDoc;
33 import java.io.InputStreamReader JavaDoc;
34
35 /**
36  * Set of test with only 1 thread at a time.
37  */

38 public class F_appli extends JTestCase {
39
40     protected static OrderEntryClerkHome home = null;
41  
42     protected static String JavaDoc oecName = "OrderEntryClerkHome";
43
44     int nbThreads = 2;
45     int nbPlaceOrders = 1;
46     int nbOrderline = 3;
47
48     public F_appli(String JavaDoc name) {
49         super(name);
50     }
51
52     protected void setUp() throws Exception JavaDoc {
53         super.setUp();
54         if (home == null) {
55             useBeans("appli");
56             home = (OrderEntryClerkHome) PortableRemoteObject.narrow(ictx.lookup(oecName),
57                                                              OrderEntryClerkHome.class);
58         }
59  
60     }
61
62     protected void tearDown() throws Exception JavaDoc {
63         super.tearDown();
64   
65     }
66
67     /*
68      * Test used for populating tables
69      */

70     public void testCreateAllTables() throws Exception JavaDoc {
71            OrderEntryClerk oecbean = null;
72            oecbean = home.create();
73            oecbean.createAllTables();
74     }
75                
76     public void test2placeOrder() throws Exception JavaDoc {
77         BufferedReader JavaDoc in = new BufferedReader JavaDoc(new InputStreamReader JavaDoc(System.in));
78         OrderEntryClerk oecbean = null;
79         oecbean = home.create();
80         for (int i = 0; i<100;i++) {
81             System.out.print(">>>>> ");
82             String JavaDoc readLine = in.readLine();
83             oecbean.setCustomer(new Integer JavaDoc(9));
84             oecbean.addOrderLine(new Integer JavaDoc(20),24);
85             /**/
86             oecbean.addOrderLine(new Integer JavaDoc(10),12);
87             oecbean.addOrderLine(new Integer JavaDoc(1),1);
88             oecbean.addOrderLine(new Integer JavaDoc(2),6);
89             /**/
90             String JavaDoc numorder = oecbean.placeOrder();
91             /**/
92             oecbean.setCustomer(new Integer JavaDoc(5));
93             oecbean.addOrderLine(new Integer JavaDoc(23),2);
94             oecbean.addOrderLine(new Integer JavaDoc(13),1);
95             oecbean.addOrderLine(new Integer JavaDoc(11),7);
96             oecbean.addOrderLine(new Integer JavaDoc(22),8);
97             numorder = oecbean.placeOrder();
98             /**/
99         }
100     }
101
102     public void test5placeOrder() throws Exception JavaDoc {
103         OrderEntryClerk oecbean = null;
104         oecbean = home.create();
105         oecbean.setCustomer(new Integer JavaDoc(2));
106         oecbean.addOrderLine(new Integer JavaDoc(1),24);
107         oecbean.addOrderLine(new Integer JavaDoc(2),12);
108         oecbean.addOrderLine(new Integer JavaDoc(3),1);
109         oecbean.addOrderLine(new Integer JavaDoc(4),6);
110         String JavaDoc numorder = oecbean.placeOrder();
111         oecbean.setCustomer(new Integer JavaDoc(3));
112         oecbean.addOrderLine(new Integer JavaDoc(5),4);
113         oecbean.addOrderLine(new Integer JavaDoc(6),2);
114         numorder = oecbean.placeOrder();
115         oecbean.setCustomer(new Integer JavaDoc(4));
116         oecbean.addOrderLine(new Integer JavaDoc(7),4);
117         oecbean.addOrderLine(new Integer JavaDoc(8),2);
118         oecbean.addOrderLine(new Integer JavaDoc(9),4);
119         oecbean.addOrderLine(new Integer JavaDoc(10),2);
120         oecbean.addOrderLine(new Integer JavaDoc(9),4);
121         oecbean.addOrderLine(new Integer JavaDoc(10),2);
122         numorder = oecbean.placeOrder();
123         oecbean.setCustomer(new Integer JavaDoc(5));
124         oecbean.addOrderLine(new Integer JavaDoc(15),4);
125         oecbean.addOrderLine(new Integer JavaDoc(16),2);
126         oecbean.addOrderLine(new Integer JavaDoc(3),5);
127         numorder = oecbean.placeOrder();
128         oecbean.setCustomer(new Integer JavaDoc(6));
129         oecbean.addOrderLine(new Integer JavaDoc(5),4);
130         oecbean.addOrderLine(new Integer JavaDoc(26),2);
131         oecbean.addOrderLine(new Integer JavaDoc(23),5);
132         oecbean.addOrderLine(new Integer JavaDoc(5),4);
133         oecbean.addOrderLine(new Integer JavaDoc(26),2);
134         oecbean.addOrderLine(new Integer JavaDoc(23),5);
135         numorder = oecbean.placeOrder();
136
137     }
138
139     public void test_2Threads_1Orders_3Orderlines() throws Exception JavaDoc {
140         applimulti(home, nbThreads, nbPlaceOrders, nbOrderline);
141     }
142
143     public void test_4Threads_5Orders_4Orderlines() throws Exception JavaDoc {
144         int nbThreads = 4;
145         int nbPlaceOrders = 5;
146         int nbOrderline = 4;
147         applimulti(home, nbThreads, nbPlaceOrders, nbOrderline);
148     }
149
150     public void test_10Threads_6Orders_10Orderlines() throws Exception JavaDoc {
151         int nbThreads = 10;
152         int nbPlaceOrders = 6;
153         int nbOrderline = 10;
154         applimulti(home, nbThreads, nbPlaceOrders, nbOrderline);
155     }
156
157     /**
158      * Run a multithreaded client test. Common part to all test multi thread cases.
159      */

160     public void applimulti( OrderEntryClerkHome home,
161                             int threads,
162                             int nbOrders,
163                             int nbLines) throws Exception JavaDoc {
164
165         // Create and start all threads
166
A_thread[] t_thr = new A_thread[threads];
167         for (int i = 0; i < threads; i++) {
168             t_thr[i] = new A_thread(home, i, nbOrders, nbLines);
169             t_thr[i].start();
170         }
171
172         // Wait end of all threads
173
for (int p = 0; p < threads; p++) {
174             t_thr[p].join();
175         }
176
177     
178     }
179
180     public static Test suite() {
181         return new TestSuite(F_appli.class);
182     }
183
184     public static void main (String JavaDoc args[]) {
185         String JavaDoc testtorun = null;
186         // Get args
187
for (int argn = 0; argn < args.length; argn++) {
188             String JavaDoc sarg = args[argn];
189             if (sarg.equals("-n")) {
190                 testtorun = args[++argn];
191             }
192         }
193         if (testtorun == null) {
194             junit.textui.TestRunner.run(suite());
195         } else {
196             junit.textui.TestRunner.run(new F_appli(testtorun));
197         }
198     }
199
200 }
201
Popular Tags