1 25 26 package org.objectweb.jonas.stests.appli; 27 28 import junit.framework.Test; 29 import junit.framework.TestSuite; 30 import javax.rmi.PortableRemoteObject ; 31 import org.objectweb.jonas.stests.util.JTestCase; 32 import java.io.BufferedReader ; 33 import java.io.InputStreamReader ; 34 35 38 public class F_appli extends JTestCase { 39 40 protected static OrderEntryClerkHome home = null; 41 42 protected static String oecName = "OrderEntryClerkHome"; 43 44 int nbThreads = 2; 45 int nbPlaceOrders = 1; 46 int nbOrderline = 3; 47 48 public F_appli(String name) { 49 super(name); 50 } 51 52 protected void setUp() throws Exception { 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 { 63 super.tearDown(); 64 65 } 66 67 70 public void testCreateAllTables() throws Exception { 71 OrderEntryClerk oecbean = null; 72 oecbean = home.create(); 73 oecbean.createAllTables(); 74 } 75 76 public void test2placeOrder() throws Exception { 77 BufferedReader in = new BufferedReader (new InputStreamReader (System.in)); 78 OrderEntryClerk oecbean = null; 79 oecbean = home.create(); 80 for (int i = 0; i<100;i++) { 81 System.out.print(">>>>> "); 82 String readLine = in.readLine(); 83 oecbean.setCustomer(new Integer (9)); 84 oecbean.addOrderLine(new Integer (20),24); 85 86 oecbean.addOrderLine(new Integer (10),12); 87 oecbean.addOrderLine(new Integer (1),1); 88 oecbean.addOrderLine(new Integer (2),6); 89 90 String numorder = oecbean.placeOrder(); 91 92 oecbean.setCustomer(new Integer (5)); 93 oecbean.addOrderLine(new Integer (23),2); 94 oecbean.addOrderLine(new Integer (13),1); 95 oecbean.addOrderLine(new Integer (11),7); 96 oecbean.addOrderLine(new Integer (22),8); 97 numorder = oecbean.placeOrder(); 98 99 } 100 } 101 102 public void test5placeOrder() throws Exception { 103 OrderEntryClerk oecbean = null; 104 oecbean = home.create(); 105 oecbean.setCustomer(new Integer (2)); 106 oecbean.addOrderLine(new Integer (1),24); 107 oecbean.addOrderLine(new Integer (2),12); 108 oecbean.addOrderLine(new Integer (3),1); 109 oecbean.addOrderLine(new Integer (4),6); 110 String numorder = oecbean.placeOrder(); 111 oecbean.setCustomer(new Integer (3)); 112 oecbean.addOrderLine(new Integer (5),4); 113 oecbean.addOrderLine(new Integer (6),2); 114 numorder = oecbean.placeOrder(); 115 oecbean.setCustomer(new Integer (4)); 116 oecbean.addOrderLine(new Integer (7),4); 117 oecbean.addOrderLine(new Integer (8),2); 118 oecbean.addOrderLine(new Integer (9),4); 119 oecbean.addOrderLine(new Integer (10),2); 120 oecbean.addOrderLine(new Integer (9),4); 121 oecbean.addOrderLine(new Integer (10),2); 122 numorder = oecbean.placeOrder(); 123 oecbean.setCustomer(new Integer (5)); 124 oecbean.addOrderLine(new Integer (15),4); 125 oecbean.addOrderLine(new Integer (16),2); 126 oecbean.addOrderLine(new Integer (3),5); 127 numorder = oecbean.placeOrder(); 128 oecbean.setCustomer(new Integer (6)); 129 oecbean.addOrderLine(new Integer (5),4); 130 oecbean.addOrderLine(new Integer (26),2); 131 oecbean.addOrderLine(new Integer (23),5); 132 oecbean.addOrderLine(new Integer (5),4); 133 oecbean.addOrderLine(new Integer (26),2); 134 oecbean.addOrderLine(new Integer (23),5); 135 numorder = oecbean.placeOrder(); 136 137 } 138 139 public void test_2Threads_1Orders_3Orderlines() throws Exception { 140 applimulti(home, nbThreads, nbPlaceOrders, nbOrderline); 141 } 142 143 public void test_4Threads_5Orders_4Orderlines() throws Exception { 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 { 151 int nbThreads = 10; 152 int nbPlaceOrders = 6; 153 int nbOrderline = 10; 154 applimulti(home, nbThreads, nbPlaceOrders, nbOrderline); 155 } 156 157 160 public void applimulti( OrderEntryClerkHome home, 161 int threads, 162 int nbOrders, 163 int nbLines) throws Exception { 164 165 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 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 args[]) { 185 String testtorun = null; 186 for (int argn = 0; argn < args.length; argn++) { 188 String 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 |