1 eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}'
2 & eval 'exec perl -S $0 $argv:q'
7 # 1. Register server as MANUAL start
8 # 2. Start server via tao_imr, it writes IOR and exits
9 # 3. Run client using IOR which should fail
10 # 4. Update server as NORMAL start
11 # 5. Start server via tao_imr which should succeed
13 ###############################################################################
14 use lib
"$ENV{ACE_ROOT}/bin";
15 use PerlACE
::TestTarget
;
25 for (my $i = 0; $i <= $#ARGV; $i++) {
26 if ($ARGV[$i] eq '-debug') {
29 elsif ($ARGV[$i] eq '-cd') {
33 elsif ($ARGV[$i] eq '-kill') {
45 my $imr = PerlACE
::TestTarget
::create_target
(++$tgt_num) || die "Create target $tgt_num failed\n";
46 my $replica_imr = PerlACE
::TestTarget
::create_target
(++$tgt_num) || die "Create target $tgt_num failed\n";
47 my $act = PerlACE
::TestTarget
::create_target
(++$tgt_num) || die "Create target $tgt_num failed\n";
48 my $ti = PerlACE
::TestTarget
::create_target
(++$tgt_num) || die "Create target $tgt_num failed\n";
49 my $srv = PerlACE
::TestTarget
::create_target
(++$tgt_num) || die "Create target $tgt_num failed\n";
50 my $clt = PerlACE
::TestTarget
::create_target
(++$tgt_num) || die "Create target $tgt_num failed\n";
52 my $port = 10001 + $imr->RandomPort ();
53 my $rport = $port + 1;
55 my $imriorfile = "imr_locator.ior";
56 my $actiorfile = "imr_activator.ior";
57 my $primaryiorfile = "ImR_ReplicaPrimary.ior";
58 my $backupiorfile = "ImR_ReplicaBackup.ior";
59 my $srviorfile = "test.ior";
60 my $persistfile = "persist.xml";
62 my $imr_imriorfile = $imr->LocalFile ($imriorfile);
63 my $imr_persistfile = $imr->LocalFile ($persistfile);
64 my $act_imriorfile = $act->LocalFile ($imriorfile);
65 my $ti_imriorfile = $ti->LocalFile ($imriorfile);
66 my $srv_imriorfile = $srv->LocalFile ($imriorfile);
67 my $act_actiorfile = $act->LocalFile ($actiorfile);
68 my $srv_srviorfile = $srv->LocalFile ($srviorfile);
69 my $clt_srviorfile = $clt->LocalFile ($srviorfile);
71 my $ti_initref = "-ORBInitRef ImplRepoService=file://$ti_imriorfile";
72 my $act_initref = "-ORBInitRef ImplRepoService=file://$act_imriorfile";
74 $IMR = $imr->CreateProcess ("$ENV{TAO_ROOT}/orbsvcs/ImplRepo_Service/tao_imr_locator");
75 $RIMR = $replica_imr->CreateProcess ("$ENV{TAO_ROOT}/orbsvcs/ImplRepo_Service/tao_imr_locator");
76 $ACT = $act->CreateProcess ("$ENV{TAO_ROOT}/orbsvcs/ImplRepo_Service/tao_imr_activator");
77 $TI = $ti->CreateProcess ("$ENV{ACE_ROOT}/bin/tao_imr");
78 $SRV = $srv->CreateProcess ("server");
79 $CLT = $clt->CreateProcess ("client");
81 my $server_cmd = $act->LocalFile ($SRV->Executable());
83 my $imrlogfile = "imr.log";
84 my $rimrlogfile = "replica_imr.log";
85 my $actlogfile = "act.log";
86 my $cltlogfile = "client.log";
87 my $srvlogfile = "server.log";
89 my $imr_imrlogfile = $imr->LocalFile ($imrlogfile);
90 my $act_actlogfile = $act->LocalFile ($actlogfile);
92 my $stdout_file = "test.out";
93 my $stderr_file = "test.err";
94 my $ti_stdout_file = $ti->LocalFile ($stdout_file);
95 my $ti_stderr_file = $ti->LocalFile ($stderr_file);
100 if ($logs_too == 1) {
101 $imr->DeleteFile ($imrlogfile);
102 $replica_imr->DeleteFile ($rimrlogfile);
103 $act->DeleteFile ($actlogfile);
104 $clt->DeleteFile ($cltlogfile);
105 $srv->DeleteFile ($srvlogfile);
107 $imr->DeleteFile ($imriorfile);
108 $imr->DeleteFile ($persistfile);
109 $replica_imr->DeleteFile ($replica_imrlogfile);
110 $act->DeleteFile ($imriorfile);
111 $ti->DeleteFile ($imriorfile);
112 $ti->DeleteFile ($replica_imriorfile);
113 $srv->DeleteFile ($imriorfile);
114 $act->DeleteFile ($actiorfile);
116 $ti->DeleteFile ($stdout_file);
117 $ti->DeleteFile ($stderr_file);
119 cleanup_replication
('.');
122 # Clean up after exit call
128 sub cleanup_replication
131 if (!defined($dir)) {
135 my $listings = "$dir/imr_listing.xml";
137 if (open FILE
, "<$listings") {
139 if ($_ =~ /fname="([^"]+)"?/) {
141 my $file = "$dir/$1";
142 print "deleting $file\n" if ($debuglevel > 0);
143 $imr->DeleteFile ($file);
144 $imr->DeleteFile ($file . ".bak");
150 # If the primary listings file has been corrupt then perform the
151 # deletions from the backup file.
154 if (open FILE
, "<$listings" . ".bak") {
156 if ($_ =~ /fname="([^"]+)"?/) {
157 my $file = "$dir/$1";
158 print "deleting $file\n" if ($debuglevel > 0);
159 $imr->DeleteFile ($file);
160 $imr->DeleteFile ($file . ".bak");
166 print "deleting $listings\n" if ($debuglevel > 0);
167 $imr->DeleteFile ("$listings");
168 $imr->DeleteFile ("$listings" . ".bak");
169 $imr->DeleteFile ("$dir/$primaryiorfile");
170 $imr->DeleteFile ("$dir/$backupiorfile");
175 open(OLDOUT
, ">&", \
*STDOUT
) or die "Can't dup STDOUT: $!";
176 open(OLDERR
, ">&", \
*STDERR
) or die "Can't dup STDERR: $!";
177 open STDERR
, '>', $ti_stderr_file;
178 open STDOUT
, '>', $ti_stdout_file;
183 open(STDERR
, ">&OLDERR") or die "Can't dup OLDERR: $!";
184 open(STDOUT
, ">&OLDOUT") or die "Can't dup OLDOUT: $!";
190 print STDERR
"ERROR: $msg\n" if (length ($msg) > 0);
191 $ACT->Kill (); $ACT->TimedWait (1);
192 $IMR->Kill (); $IMR->TimedWait (1);
193 $RIMR->Kill (); $RIMR->TimedWait (1);
199 print "Killing primary ImR\n";
200 $IMR->Kill (); $IMR->TimedWait (1);
206 open (FILE
, "server.pid") or die "Can't open server.pid: $!";
210 $server_pid = $pid if ($server_pid == 0);
219 print "signal $sig to server $server_pid\n";
220 kill ($sig, $server_pid);
226 my $debugbase = "-ORBDebugLevel $debuglevel " .
227 "-ORBVerboseLogging 1 -ORBLogFile ";
228 my $actargs = "-d $debuglevel -l -o $act_actiorfile $act_initref -ORBListenEndpoints iiop://127.0.0.1:";
230 my $imrargs = " -d $debuglevel -i -v 1000 " .
231 "--directory . --primary " .
232 "-ORBListenEndpoints iiop://127.0.0.1:$port";
234 my $rimrargs = " -d $debuglevel -i -v 1000 -o $imr_imriorfile " .
235 "--directory . --backup " .
236 "-ORBListenEndpoints iiop://127.0.0.1:$rport";
238 if ($debuglevel > 0) {
239 $imrargs .= " $debugbase $imrlogfile";
240 $rimrargs .= " $debugbase $rimrlogfile";
241 $actargs .= " $debugbase $actlogfile";
244 print "imr args = \"$imrargs\"\n" if ($debuglevel > 0);
245 print "replica imr args = \"$rimrargs\"\n" if ($debuglevel > 0);
246 print "act args = \"$actargs\"\n" if ($debuglevel > 0);
248 $IMR->Arguments ($imrargs);
249 $RIMR->Arguments ($rimrargs);
250 $ACT->Arguments ($actargs);
252 ##### Start ImplRepo #####
253 $IMR_status = $IMR->Spawn ();
254 if ($IMR_status != 0) {
255 print STDERR
"ERROR: ImplRepo Service returned $IMR_status\n";
258 if ($imr->WaitForFileTimed ($primaryiorfile, $imr->ProcessStartWaitInterval()) == -1) {
259 print STDERR
"ERROR: cannot find file <$primaryiorfile>\n";
260 $IMR->Kill (); $IMR->TimedWait (1);
265 $IMR_status = $RIMR->Spawn ();
266 if ($IMR_status != 0) {
267 print STDERR
"ERROR: replica ImplRepo Service returned $IMR_status\n";
268 $IMR->Kill (); $IMR->TimedWait (1);
271 if ($imr->WaitForFileTimed ($imriorfile, $imr->ProcessStartWaitInterval()) == -1) {
272 print STDERR
"ERROR: cannot find file <$imr_imriorfile>\n";
273 $IMR->Kill (); $IMR->TimedWait (1);
274 $RIMR->Kill (); $RIMR->TimedWait (1);
278 if ($imr->GetFile ($imriorfile) == -1) {
279 print STDERR
"ERROR: cannot retrieve file <$imr_imriorfile>\n";
280 $IMR->Kill (); $IMR->TimedWait (1);
283 if ($act->PutFile ($imriorfile) == -1) {
284 print STDERR
"ERROR: cannot set file <$act_imriorfile>\n";
285 $IMR->Kill (); $IMR->TimedWait (1);
288 if ($ti->PutFile ($imriorfile) == -1) {
289 print STDERR
"ERROR: cannot set file <$ti_imriorfile>\n";
290 $IMR->Kill (); $IMR->TimedWait (1);
293 if ($srv->PutFile ($imriorfile) == -1) {
294 print STDERR
"ERROR: cannot set file <$srv_imriorfile>\n";
295 $IMR->Kill (); $IMR->TimedWait (1);
299 $ACT_status = $ACT->Spawn ();
300 if ($ACT_status != 0) {
301 print STDERR
"ERROR: ImR Activator returned $ACT_status\n";
304 if ($act->WaitForFileTimed ($actiorfile,$act->ProcessStartWaitInterval()) == -1) {
305 return kill_imr
("cannot find file <$act_imriorfile>");
312 if ($srv->GetFile ($srviorfile) == -1) {
313 print STDERR
"ERROR: cannot retrieve file <$srv_srviorfile>\n";
316 if ($clt->PutFile ($srviorfile) == -1) {
317 print STDERR
"ERROR: cannot set file <$clt_srviorfile>\n";
321 my $args = "-k file://$srviorfile";
322 $args .= " -ORBDebuglevel $cltdbg -ORBVerboseLogging 1 -ORBLogFile $cltlogfile" if ($debuglevel > 0);
324 print "running client $args\n";
326 $CLT->Arguments ($args);
327 if ($CLT->Spawn () == -1) {
328 print STDERR
"ERROR: client failed\n";
336 if (launch_client
() == 0) {
337 if ($CLT->WaitKill ($clt->ProcessStartWaitInterval() + 120) == -1) {
338 print STDERR
"ERROR: client failed\n";
349 my $obj_name = "manual_test";
350 print "invoking ti cmd $cmd $obj_name $cmdargs\n" if ($debuglevel > 0);
351 $TI->Arguments ("$ti_initref $cmd $obj_name $cmdargs");
352 $TI_status = $TI->SpawnWaitKill ($ti->ProcessStartWaitInterval());
353 if ($TI_status != 0 && $TI_status != 4) {
354 return kill_imr
("tao_imr $cmd $obj_name returned $TI_status");
358 sub list_active_servers
360 my $list_options = shift;
361 my $start_time = time();
362 $TI->Arguments ("$ti_initref list $list_options");
363 # Redirect output so we can count number of lines in output
365 $TI_status = $TI->SpawnWaitKill ($ti->ProcessStartWaitInterval());
366 my $list_time = time() - $start_time;
368 if ($TI_status != 0) {
369 kill_imr
("tao_imr list returned $TI_status");
372 open (FILE
, $stderr_file) or die "Can't open $stderr_file: $!";
379 print STDERR
"List took $list_time seconds.\n";
380 return $active_servers;
385 print "Running manual start test.\n";
387 my $start_time = time();
389 if (start_imr
(1) != 0) {
393 my $cmdline = $server_cmd . " -o $srviorfile -ORBUseIMR 1 $act_initref "
394 # . "-ORBDebuglevel 10 -ORBVerboseLogging 1 -ORBLogFile srv.log "
395 . "-ORBListenEndpoints iiop://127.0.0.1:";
397 if (do_ti_command
("add", "-a MANUAL -c \"$cmdline\"") != 0) {
401 if (do_ti_command
("start") != 0) {
405 # print STDERR "=== kill ImR Locator\n";
406 # $IMR_status = $IMR->TerminateWaitKill ($imr->ProcessStopWaitInterval());
407 # $imr->DeleteFile ($imriorfile);
411 # print STDERR "=== restart ImR Locator\n";
412 # $IMR_status = $IMR->Spawn ();
413 # if ($IMR_status != 0) {
414 # print STDERR "ERROR: ImplRepo Service returned $IMR_status\n";
417 # if ($imr->WaitForFileTimed ($imriorfile,$imr->ProcessStartWaitInterval()) == -1) {
418 # print STDERR "ERROR: cannot find file <$imr_imriorfile>\n";
419 # $IMR->Kill (); $IMR->TimedWait (1);
424 print "starting client\n";
426 if (launch_client
() != 0) {
429 print "******waiting for client exit\n";
430 if ($CLT->WaitKill ($clt->ProcessStartWaitInterval() + 120) == -1) {
431 print STDERR
"ERROR: client failed\n";
434 print "******client done\n";
436 if (do_ti_command
("update", "-a NORMAL -c \"$cmdline\"") != 0) {
440 if (do_ti_command
("start") != 0) {
447 my $test_time = time() - $start_time;
449 print "\nFinished. The test took $test_time seconds.\n";
456 print "Usage: run_test.pl [-debug] [-cd n]\n";
457 print " -debug enables ImR debugging\n";
458 print " -cd n sets client debug level to n (default 1)\n";
461 ###############################################################################
462 ###############################################################################
466 $ret = manual_test
();