1 eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}'
2 & eval 'exec perl -S $0 $argv:q'
7 ###############################################################################
8 use lib
"$ENV{ACE_ROOT}/bin";
9 use PerlACE
::TestTarget
;
12 my $debug_level = '0';
13 my $imr_debug_level = '1';
15 # Allow for manually launching ImplRepo for debugging purposes.
18 my $clients_count = 6;
19 my $secs_between_clients = 1;
20 my $server_init_delay = 1;
21 my $server_reply_delay = 0;
22 my $rt_timeout_msecs = 0;
25 my $activationmode = "normal";
26 my $shutdownserver = 0;
29 for (my $i = 0; $i <= $#ARGV; $i++) {
30 if ($ARGV[$i] eq '-debug') {
34 elsif ($ARGV[$i] eq "-imrdebug") {
36 $imr_debug_level = $ARGV[$i];
38 elsif ($ARGV[$i] eq "-activationmode") {
40 $activationmode = $ARGV[$i];
42 elsif ($ARGV[$i] eq "-clients") {
44 $clients_count = $ARGV[$i];
46 elsif ($ARGV[$i] eq "-rt_timeout") {
48 $rt_timeout_msecs = $ARGV[$i];
50 elsif ($ARGV[$i] eq "-secs_between_clients") {
52 $secs_between_clients = $ARGV[$i];
54 elsif ($ARGV[$i] eq "-server_init_delay") {
56 $server_init_delay = $ARGV[$i];
58 elsif ($ARGV[$i] eq "-server_reply_delay") {
60 $server_reply_delay = $ARGV[$i];
62 elsif ($ARGV[$i] eq "-rt_timeout") {
64 $rt_timeout_msecs = $ARGV[$i];
66 elsif ($ARGV[$i] eq "-max_rt_tries") {
68 $max_rt_tries = $ARGV[$i];
70 elsif ($ARGV[$i] eq "-no_imr") {
73 elsif ($ARGV[$i] eq "-asynch") {
74 $asynch_loc = "--use_dsi";
84 my $imr = PerlACE
::TestTarget
::create_target
(++$tgt_num) || die "Create target $tgt_num failed\n";
85 my $act = PerlACE
::TestTarget
::create_target
(++$tgt_num) || die "Create target $tgt_num failed\n";
86 my $ti = PerlACE
::TestTarget
::create_target
(++$tgt_num) || die "Create target $tgt_num failed\n";
87 my $srv = PerlACE
::TestTarget
::create_target
(++$tgt_num) || die "Create target $tgt_num failed\n";
89 for(my $i = 0; $i < $clients_count; $i++) {
90 push (@cli, PerlACE
::TestTarget
::create_target
(++$tgt_num)) || die "Create target $tgt_num failed\n";
93 my $refstyle = " -ORBobjrefstyle URL";
97 my $objprefix = "TestObject";
98 my $client_wait_time = 10;
100 $imriorfile = "imr_locator.ior";
101 $actiorfile = "imr_activator.ior";
102 $persistxml = "persist.xml";
103 $persistdat = "persist.dat";
105 my $imr_imriorfile = $imr->LocalFile ($imriorfile);
106 my $act_imriorfile = $act->LocalFile ($imriorfile);
107 my $ti_imriorfile = $ti->LocalFile ($imriorfile);
108 my $srv_imriorfile = $srv->LocalFile ($imriorfile);
109 my $act_actiorfile = $act->LocalFile ($actiorfile);
110 my $imr_persistxml = $imr->LocalFile ($persistxml);
111 my $imr_persistdat = $imr->LocalFile ($persistdat);
113 $IMR = $imr->CreateProcess ("$ENV{TAO_ROOT}/orbsvcs/ImplRepo_Service/tao_imr_locator");
114 $ACT = $act->CreateProcess ("$ENV{TAO_ROOT}/orbsvcs/ImplRepo_Service/tao_imr_activator");
115 $TI = $ti->CreateProcess ("$ENV{ACE_ROOT}/bin/tao_imr");
116 $SRV = $srv->CreateProcess ("server");
117 my $server_cmd = $SRV->Executable();
118 my $srv_server_cmd = $imr->LocalFile ($server_cmd);
121 for(my $i = 0; $i < $clients_count; $i++) {
122 push (@CLI, $cli[$i]->CreateProcess ("client"));
124 # Make sure the files are gone, so we can wait on them.
126 $imr->DeleteFile ($imriorfile);
127 $act->DeleteFile ($imriorfile);
128 $ti->DeleteFile ($imriorfile);
129 $srv->DeleteFile ($imriorfile);
131 $act->DeleteFile ($actiorfile);
132 $imr->DeleteFile ($persistxml);
133 $imr->DeleteFile ($persistdat);
135 sub scale_clients_test
137 print "Running scale_clients test with $clients_count clients.\n";
140 my $start_time = time();
142 if ($activationmode eq "per_client") {
146 $IMR->Arguments ("-d $imr_debug_level -o $imr_imriorfile -orbendpoint iiop://:$port $asynch_loc -ORBDebugLevel $debug_level");
149 print STDERR
"IMR assumed to be manually launched in way that is ".
150 "compatible with:\n";
151 print STDERR
$IMR->CommandLine () . "\n";
153 print ">>> " . $IMR->CommandLine () . "\n";
155 ##### Start ImplRepo #####
156 $IMR_status = $IMR->Spawn ();
157 if ($IMR_status != 0) {
158 print STDERR
"ERROR: ImplRepo Service returned $IMR_status\n";
161 if ($imr->WaitForFileTimed ($imriorfile, $imr->ProcessStartWaitInterval()) == -1) {
162 print STDERR
"ERROR: cannot find file <$imr_imriorfile>\n";
163 $IMR->Kill (); $IMR->TimedWait (1);
167 if ($imr->GetFile ($imriorfile) == -1) {
168 print STDERR
"ERROR: cannot retrieve file <$imr_imriorfile>\n";
169 $IMR->Kill (); $IMR->TimedWait (1);
174 if ($act->PutFile ($imriorfile) == -1) {
175 print STDERR
"ERROR: cannot set file <$act_imriorfile>\n";
176 $IMR->Kill (); $IMR->TimedWait (1);
179 if ($ti->PutFile ($imriorfile) == -1) {
180 print STDERR
"ERROR: cannot set file <$ti_imriorfile>\n";
181 $IMR->Kill (); $IMR->TimedWait (1);
184 if ($srv->PutFile ($imriorfile) == -1) {
185 print STDERR
"ERROR: cannot set file <$srv_imriorfile>\n";
186 $IMR->Kill (); $IMR->TimedWait (1);
190 $ACT->Arguments ("-d $imr_debug_level -o $act_actiorfile -ORBInitRef ImplRepoService=file://$act_imriorfile");
191 print ">>> " . $ACT->CommandLine () . "\n";
193 $ACT_status = $ACT->Spawn ();
194 if ($ACT_status != 0) {
195 print STDERR
"ERROR: ImR Activator returned $ACT_status\n";
198 if ($act->WaitForFileTimed ($actiorfile,$act->ProcessStartWaitInterval()) == -1) {
199 print STDERR
"ERROR: cannot find file <$act_imriorfile>\n";
200 $ACT->Kill (); $ACT->TimedWait (1);
201 $IMR->Kill (); $IMR->TimedWait (1);
205 # In a per client mode each server should get one request, in all other
206 # modes the server gets a request for each client started
207 $expected_requests = $clients_count;
208 if ($activationmode eq "per_client") {
209 $expected_requests = 1;
212 ##### Add server to activator #####
213 my $status_file_name = $objprefix . ".status";
214 my $srv_status_file = $srv->LocalFile ($status_file_name);
215 $srv->DeleteFile ($srv_status_file);
217 $TI->Arguments ("-ORBInitRef ImplRepoService=file://$ti_imriorfile ".
218 "add $objprefix" . " -a $activationmode -c \"".
219 $srv_server_cmd . " ".
220 "-ORBUseIMR 1 -d $server_init_delay -n $expected_requests ".
221 "-ORBInitRef ImplRepoService=file://$imr_imriorfile\"");
223 print ">>> " . $TI->CommandLine () . "\n";
224 $TI_status = $TI->SpawnWaitKill ($ti->ProcessStartWaitInterval());
225 if ($TI_status != 0) {
226 print STDERR
"ERROR: tao_imr returned $TI_status\n";
227 $ACT->Kill (); $ACT->TimedWait (1);
228 $IMR->Kill (); $IMR->TimedWait (1);
232 # Why is this sleep needed?
235 ##### Run clients #####
236 for(my $i = 0; $i < $clients_count; $i++ ) {
237 # Make sure server has started by looking for its status file
239 $CLI[$i]->Arguments ("-ORBInitRef Test=corbaloc::localhost:$port/$objprefix" .
240 " -d $server_reply_delay".
241 " -x $shutdownserver " .
242 " -r $rt_timeout_msecs".
243 " -m $max_rt_tries");
244 print ">>> " . $CLI[$i]->CommandLine () . "\n";
245 $CLI_status = $CLI[$i]->Spawn ();
246 if ($CLI_status != 0) {
247 print STDERR
"ERROR: client returned $CLI_status during spawn\n";
251 sleep($secs_between_clients);
254 sleep (server_request_delay
);
256 ##### Stop clients #####
257 print STDERR
"Waiting for clients to stop\n";
258 for(my $i = 0; $i < $clients_count; $i++ ) {
259 my $CLI_status = $CLI[$i]->WaitKill ($cli[$i]->ProcessStartWaitInterval() + $server_init_delay + $server_reply_delay);
260 if ($CLI_status != 0) {
261 print STDERR
"ERROR: Client $i returned $CLI_status\n";
266 ##### Shutdown server #####
267 my $status_file_name = $objprefix . ".status";
268 $srv->DeleteFile ($status_file_name);
270 # Shutting down any server object within the server will shutdown the whole server
271 # This can not be done with per client activation mode
272 if ($activationmode ne "per_client") {
273 $TI->Arguments ("-ORBInitRef ImplRepoService=file://$ti_imriorfile shutdown $objprefix");
274 print ">>> " . $TI->CommandLine () . "\n";
275 $TI_status = $TI->SpawnWaitKill ($ti->ProcessStartWaitInterval());
276 if ($TI_status != 0) {
277 print STDERR
"ERROR: tao_imr shutdown returned $TI_status\n";
282 my $ACT_status = $ACT->TerminateWaitKill ($act->ProcessStopWaitInterval());
283 if ($ACT_status != 0) {
284 print STDERR
"ERROR: IMR Activator returned $ACT_status\n";
289 my $IMR_status = $IMR->TerminateWaitKill ($imr->ProcessStopWaitInterval());
290 if ($IMR_status != 0) {
291 print STDERR
"ERROR: IMR returned $IMR_status\n";
296 my $test_time = time() - $start_time;
298 print "\nFinished. The test took $test_time seconds.\n";
304 print "Usage: run_test.pl ".
305 "[-clients <num=$clients_count>] ".
306 "[-secs_between_clients <seconds=$secs_between_clients>] ".
307 "[-server_init_delay <seconds=$server_init_delay>] ".
308 "[-server_reply_delay <seconds=$server_reply_delay] ".
309 "[-rt_timeout <round-trip-timeout-msecs=$rt_timeout_msecs>] ".
310 "[-max_rt_tries <max-client-requests=$max_rt_tries>] ".
312 "[-imrdebug <level=$imr_debug_level>]" .
313 "[-activationmode <activationmode=$activationmode]" .
317 ###############################################################################
318 ###############################################################################
320 my $ret = scale_clients_test
();
323 $imr->DeleteFile ($imriorfile);
324 $act->DeleteFile ($imriorfile);
325 $ti->DeleteFile ($imriorfile);
326 $srv->DeleteFile ($imriorfile);
328 $act->DeleteFile ($actiorfile);
329 $imr->DeleteFile ($persistxml);
330 $imr->DeleteFile ($persistdat);