KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jacorb > trading > test > LoadTest


1 package org.jacorb.trading.test;
2
3 /**
4  * This class is a load test for a trader federation. It starts four traders,
5  * supplies them with two offers each and links every trader with every other.
6  * Then it starts several ImportThreads which randomly query the traders.
7  *
8  * @author Nicolas Noffke
9  */

10
11 import org.omg.CosTrading.*;
12 import org.omg.CosTrading.RegisterPackage.*;
13 import org.omg.CosTrading.LookupPackage.*;
14 import org.omg.CosTradingRepos.*;
15 import org.omg.CosTradingRepos.ServiceTypeRepositoryPackage.*;
16 import org.omg.CORBA.*;
17 import java.io.*;
18 //import java.util.*;
19

20 public class LoadTest {
21     private static final int THREADS = 2;
22     
23     public static void main(String JavaDoc[] args) {
24       if (args.length == 0){
25     System.out.println("Usage: LoadTest <iorfile-stem>");
26     System.exit(0);
27       }
28     
29         try{
30         // exec four independent traders
31
Runtime JavaDoc _rt = Runtime.getRuntime();
32         
33         new OutputForwarder(_rt.exec("ts " + args[0] + "1 -d db1"), "Trader1");
34         new OutputForwarder(_rt.exec("ts " + args[0] + "2 -d db2"), "Trader2");
35         new OutputForwarder(_rt.exec("ts " + args[0] + "3 -d db3"), "Trader3");
36         new OutputForwarder(_rt.exec("ts " + args[0] + "4 -d db4"), "Trader4");
37
38         System.out.println("Press any key when all four Traders are ready");
39         System.in.read();
40
41         //set up ORB
42
org.omg.CORBA.ORB JavaDoc _orb = org.omg.CORBA.ORB.init(args, null);
43
44         // get lookup interfaces
45
Lookup[] _lookup = new Lookup[4];
46         
47         BufferedReader in = new BufferedReader(new FileReader(new File(args[0] + "1")));
48         String JavaDoc ref = in.readLine();
49         in.close();
50         _lookup[0] = LookupHelper.narrow(_orb.string_to_object(ref));
51         Link _link1 = LinkHelper.narrow(_lookup[0].link_if());
52         ServiceTypeRepository _repos1 = ServiceTypeRepositoryHelper.narrow(_lookup[0].type_repos());
53         Register _reg1 = RegisterHelper.narrow(_lookup[0].register_if());
54
55
56         in = new BufferedReader(new FileReader(new File(args[0] + "2")));
57         ref = in.readLine();
58         in.close();
59          _lookup[1] = LookupHelper.narrow(_orb.string_to_object(ref));
60         Link _link2 = LinkHelper.narrow(_lookup[1].link_if());
61         ServiceTypeRepository _repos2 = ServiceTypeRepositoryHelper.narrow(_lookup[1].type_repos());
62         Register _reg2 = RegisterHelper.narrow(_lookup[1].register_if());
63
64
65         in = new BufferedReader(new FileReader(new File(args[0] + "3")));
66         ref = in.readLine();
67         in.close();
68          _lookup[2] = LookupHelper.narrow(_orb.string_to_object(ref));
69         Link _link3 = LinkHelper.narrow(_lookup[2].link_if());
70         ServiceTypeRepository _repos3 = ServiceTypeRepositoryHelper.narrow(_lookup[2].type_repos());
71         Register _reg3 = RegisterHelper.narrow(_lookup[2].register_if());
72
73
74         in = new BufferedReader(new FileReader(new File(args[0] + "4")));
75         ref = in.readLine();
76         in.close();
77          _lookup[3] = LookupHelper.narrow(_orb.string_to_object(ref));
78         Link _link4 = LinkHelper.narrow(_lookup[3].link_if());
79         ServiceTypeRepository _repos4 = ServiceTypeRepositoryHelper.narrow(_lookup[3].type_repos());
80         Register _reg4 = RegisterHelper.narrow(_lookup[3].register_if());
81
82
83         //build up properties for exporting type
84
PropStruct[] _props = new PropStruct[2];
85         _props[0] = new PropStruct();
86         _props[0].name = "Art";
87         _props[0].value_type = _orb.get_primitive_tc(TCKind.tk_string);
88         _props[0].mode = PropertyMode.PROP_MANDATORY;
89         
90         _props[1] = new PropStruct();
91         _props[1].name = "Preis";
92         _props[1].value_type = _orb.get_primitive_tc(TCKind.tk_string);
93         _props[1].mode = PropertyMode.PROP_MANDATORY;
94           
95         //export the type
96
_repos1.add_type("Orchideen", "IDL:Orchid:0.1", _props, new String JavaDoc[0]);
97         _repos2.add_type("Orchideen", "IDL:Orchid:0.1", _props, new String JavaDoc[0]);
98         _repos3.add_type("Orchideen", "IDL:Orchid:0.1", _props, new String JavaDoc[0]);
99         _repos4.add_type("Orchideen", "IDL:Orchid:0.1", _props, new String JavaDoc[0]);
100         
101         
102         //build and export offers
103
String JavaDoc[] types;
104         SpecifiedServiceTypes whichTypes = new SpecifiedServiceTypes();
105         whichTypes.__default();
106         types = _repos1.list_types(whichTypes);
107             
108         Property[] _prop = new Property[2];
109         _prop[0] = new Property();
110         _prop[0].name = "Art";
111         _prop[0].value = _orb.create_any();
112         _prop[0].value.insert_string("1");
113         
114         _prop[1] = new Property();
115         _prop[1].name = "Preis";
116         _prop[1].value = _orb.create_any();
117         _prop[1].value.insert_string("8");
118         
119         String JavaDoc id = _reg1.export(_reg1, "Orchideen", _prop);
120         System.out.println("Offer id = " + id);
121
122         _prop[0].name = "Art";
123         _prop[0].value = _orb.create_any();
124         _prop[0].value.insert_string("2");
125
126         _prop[1].name = "Preis";
127         _prop[1].value = _orb.create_any();
128         _prop[1].value.insert_string("6");
129                 
130         id = _reg1.export(_reg1, "Orchideen", _prop);
131         System.out.println("Offer id = " + id);
132         
133         //
134
_prop[0].value.insert_string("3");
135         _prop[1].value.insert_string("8");
136         id = _reg2.export(_reg2, "Orchideen", _prop);
137         System.out.println("Offer id = " + id);
138
139         _prop[0].value.insert_string("4");
140         _prop[1].value.insert_string("6");
141         id = _reg2.export(_reg2, "Orchideen", _prop);
142         System.out.println("Offer id = " + id);
143
144         //
145
_prop[0].value.insert_string("5");
146         _prop[1].value.insert_string("8");
147         id = _reg3.export(_reg3, "Orchideen", _prop);
148         System.out.println("Offer id = " + id);
149
150         _prop[0].value.insert_string("6");
151         _prop[1].value.insert_string("6");
152         id = _reg3.export(_reg3, "Orchideen", _prop);
153         System.out.println("Offer id = " + id);
154
155         //
156
_prop[0].value.insert_string("7");
157         _prop[1].value.insert_string("8");
158         id = _reg4.export(_reg4, "Orchideen", _prop);
159         System.out.println("Offer id = " + id);
160
161         _prop[0].value.insert_string("0");
162         _prop[1].value.insert_string("6");
163         id = _reg4.export(_reg4, "Orchideen", _prop);
164         System.out.println("Offer id = " + id);
165
166         //link traders
167
_link1.add_link("link1", _lookup[1], FollowOption.always, FollowOption.always);
168         _link1.add_link("link2", _lookup[2], FollowOption.always, FollowOption.always);
169         _link1.add_link("link3", _lookup[3], FollowOption.always, FollowOption.always);
170         
171         _link2.add_link("link1", _lookup[0], FollowOption.always, FollowOption.always);
172         _link2.add_link("link2", _lookup[2], FollowOption.always, FollowOption.always);
173         _link2.add_link("link3", _lookup[3], FollowOption.always, FollowOption.always);
174         
175         _link3.add_link("link1", _lookup[1], FollowOption.always, FollowOption.always);
176         _link3.add_link("link2", _lookup[0], FollowOption.always, FollowOption.always);
177         _link3.add_link("link3", _lookup[3], FollowOption.always, FollowOption.always);
178         
179         _link4.add_link("link1", _lookup[0], FollowOption.always, FollowOption.always);
180         _link4.add_link("link2", _lookup[2], FollowOption.always, FollowOption.always);
181         _link4.add_link("link3", _lookup[1], FollowOption.always, FollowOption.always);
182         
183
184         // run query threads
185
for (int i = 0; i < THREADS; i++)
186          new ImportThread("" + i, _lookup, types[0], _orb);
187     }
188     catch (Exception JavaDoc e){
189         e.printStackTrace();
190     }
191     }
192     
193 } // LoadTest
194

195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
Popular Tags