1 eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}'
2 & eval 'exec perl -S $0 $argv:q'
7 use lib
"$ENV{ACE_ROOT}/bin";
8 use PerlACE
::TestTarget
;
11 #$ENV{ACE_TEST_VERBOSE} = "1";
13 my $debug_level = '0';
14 my $redirection_enabled = 0;
20 if ($i eq '-verbose') {
21 $redirection_enabled = 0;
25 my $server = PerlACE
::TestTarget
::create_target
(1) || die "Create target 1 failed\n";
26 my $client = PerlACE
::TestTarget
::create_target
(2) || die "Create target 2 failed\n";
29 # Variables for command-line arguments to client and server
31 my $hostname = $server->HostName ();
34 my $ns_orb_port1 = 10001 + $server->RandomPort ();
35 my $ns_orb_port2 = 10002 + $server->RandomPort ();
37 my $ns_endpoint1 = "iiop://$hostname:$ns_orb_port1";
38 my $ns_endpoint2 = "iiop://$hostname:$ns_orb_port2";
42 # References to both naming services
43 my $default_init_ref = "-ORBDefaultInitRef corbaloc:iiop:$hostname:$ns_orb_port1,iiop:$hostname:$ns_orb_port2";
45 # References to primary naming service only
46 my $primary_default_init_ref = "-ORBDefaultInitRef corbaloc:iiop:$hostname:$ns_orb_port1";
48 # References to backup naming service only
49 my $backup_default_init_ref = "-ORBDefaultInitRef corbaloc:iiop:$hostname:$ns_orb_port2";
51 ## Allow the user to determine where the persistence file will be located
52 ## just in case the current directory is not suitable for locking.
53 ## We can't change the name of the persistence file because that is not
54 ## sufficient to work around locking problems for Tru64 when the current
55 ## directory is NFS mounted from a system that does not properly support
57 foreach my $possible ($ENV{TMPDIR
}, $ENV{TEMP
}, $ENV{TMP
}) {
58 if (defined $possible && -d
$possible) {
59 if (chdir($possible)) {
66 my $POSITIVE_TEST_RESULT = 0;
67 my $NEGATIVE_TEST_RESULT = 1;
69 my $NSGROUP = $client->CreateProcess ("$ENV{ACE_ROOT}/bin/tao_nsgroup");
70 my $NSLIST = $client->CreateProcess ("$ENV{ACE_ROOT}/bin/tao_nslist");
71 my $NSADD = $client->CreateProcess ("$ENV{ACE_ROOT}/bin/tao_nsadd");
72 my $NSDEL = $client->CreateProcess ("$ENV{ACE_ROOT}/bin/tao_nsdel");
76 my $file_name = shift;
77 if (-s
$file_name ) # size of file is greater than zero
79 open TESTFILE
, $file_name or die "Couldn't open file: $!";
80 my @teststring = <TESTFILE
>; # read in all of the file
81 print STDERR
"\n@teststring\n";
88 open (OLDOUT
, ">&", \
*STDOUT
) or die "Can't dup STDOUT: $!";
89 open (OLDERR
, ">&", \
*STDERR
) or die "Can't dup STDERR: $!";
90 open STDERR
, '>', $client_stderr_file;
91 open STDOUT
, '>', $client_stdout_file;
96 open (STDERR
, ">&OLDERR") or die "Can't dup OLDERR: $!";
97 open (STDOUT
, ">&OLDOUT") or die "Can't dup OLDOUT: $!";
103 my $expected_test_result = shift;
105 my $arglist = "$args";
107 $NSGROUP->Arguments ($arglist);
109 if ($redirection_enabled) {
113 my $nsgroup_status = $NSGROUP->SpawnWaitKill ($client->ProcessStartWaitInterval());
115 if ($redirection_enabled) {
119 if ($nsgroup_status != $expected_test_result) {
120 my $time = localtime;
121 print STDERR
"ERROR: nsgroup returned $nsgroup_status at $time\n";
122 if ($redirection_enabled) {
123 cat_file
($client_stderr_file);
124 cat_file
($client_stdout_file);
133 my $expected_test_result = shift;
135 $NSLIST->Arguments ($args);
137 if ($redirection_enabled) {
141 #tao_nslist --ns file://ns.ior
142 my $nslist_status = $NSLIST->SpawnWaitKill ($client->ProcessStartWaitInterval());
144 if ($redirection_enabled) {
148 if ($nslist_status != $expected_test_result) {
149 my $time = localtime;
150 print STDERR
"ERROR: nslist returned $nslist_status at $time\n";
151 if ($redirection_enabled) {
152 cat_file
($client_stderr_file);
153 cat_file
($client_stdout_file);
162 my $expected_test_result = shift;
164 $NSADD->Arguments ($args);
166 if ($redirection_enabled) {
170 #tao_nsadd --ns file://ns.ior --name iso --ctx
171 my $nsadd_status = $NSADD->SpawnWaitKill ($client->ProcessStartWaitInterval());
173 if ($redirection_enabled) {
177 if ($nsadd_status != $expected_test_result) {
178 my $time = localtime;
179 print STDERR
"ERROR: nsadd returned $nsadd_status at $time\n";
180 if ($redirection_enabled) {
181 cat_file
($client_stderr_file);
182 cat_file
($client_stdout_file);
191 my $expected_test_result = shift;
193 $NSDEL->Arguments ($args);
195 if ($redirection_enabled) {
199 #tao_nsdel --ns file://ns.ior --name iso --destroy
200 my $nsdel_status = $NSDEL->SpawnWaitKill ($client->ProcessStartWaitInterval());
202 if ($redirection_enabled) {
206 if ($nsdel_status != $expected_test_result) {
207 my $time = localtime;
208 print STDERR
"ERROR: nsdel returned $nsdel_status at $time\n";
209 if ($redirection_enabled) {
210 cat_file
($client_stderr_file);
211 cat_file
($client_stdout_file);
217 sub clean_persistence_dir
($$)
220 my $directory_name = shift;
221 chdir $directory_name;
222 opendir(THISDIR
, ".");
223 @allfiles = grep(!/^\.\.?$/, readdir(THISDIR
));
225 foreach $tmp (@allfiles){
226 $target->DeleteFile ($tmp);
231 # Make sure that the directory to use to hold the naming contexts exists
233 sub init_naming_context_directory
($$)
236 my $directory_name = shift;
238 if ( ! -d
$directory_name ) {
239 mkdir ($directory_name, 0777);
241 clean_persistence_dir
($target, $directory_name);
245 my $name_dir = "NameService";
246 my $group_dir = "GroupService";
247 my $primary_iorfile = "$name_dir/ns_replica_primary.ior";
248 my $nm_iorfile = "nm.ior";
249 my $ns_iorfile = "ns.ior";
250 my $stderr_file = "test.err";
251 my $stdout_file = "test.out";
253 ################################################################################
254 # setup END block to cleanup after exit call
255 ################################################################################
258 $server->DeleteFile($primary_iorfile);
259 $server->DeleteFile($nm_iorfile);
260 $server->DeleteFile($ns_iorfile);
261 $client->DeleteFile ($stdout_file);
262 $client->DeleteFile ($stderr_file);
264 if ( -d
$name_dir ) {
265 print STDERR
"INFO: removing <$name_dir>\n";
266 clean_persistence_dir
($server, $name_dir);
270 if ( -d
$group_dir ) {
271 print STDERR
"INFO: removing <$group_dir>\n";
272 clean_persistence_dir
($server, $group_dir);
278 ################################################################################
279 # Validate that a client can seamlessly connect to the alternate server of a
280 # server naming server pair after the other server has been terminated.
281 ################################################################################
284 my $previous_status = $status;
287 # The file that is written by the primary when ready to start backup
288 my $server_primary_iorfile = $server->LocalFile ($primary_iorfile);
289 my $server_nm_iorfile = $server->LocalFile ($nm_iorfile);
290 my $server_ns_iorfile = $server->LocalFile ($ns_iorfile);
291 my $client_stdout_file = $client->LocalFile ($stdout_file);
292 my $client_stderr_file = $client->LocalFile ($stderr_file);
294 print_msg
("Failover Test");
295 init_naming_context_directory
($server, $name_dir);
296 init_naming_context_directory
($server, $group_dir);
298 # Run two Naming Servers
299 my $ns1_args = "--primary ".
300 "-ORBDebugLevel $debug_level ".
301 "-ORBListenEndPoints $ns_endpoint1 ".
306 my $ns2_args = "--backup ".
307 "-ORBDebugLevel $debug_level ".
308 "-ORBListenEndPoints $ns_endpoint2 ".
309 "-c $server_ns_iorfile ".
310 "-g $server_nm_iorfile ".
315 my $tao_ft_naming = "$ENV{TAO_ROOT}/orbsvcs/FT_Naming_Service/tao_ft_naming";
317 my $client_args = "--failover " .
318 "-ORBDebugLevel $debug_level " .
319 "-p file://$server_ns_iorfile " .
320 "-r file://$server_nm_iorfile " .
324 my $client_prog = "client";
326 print STDERR
"$tao_ft_naming $ns1_args\n";
327 print STDERR
"$tao_ft_naming $ns2_args\n";
329 $NS1 = $server->CreateProcess ($tao_ft_naming, $ns1_args);
330 $NS2 = $server->CreateProcess ($tao_ft_naming, $ns2_args);
331 $CL = $client->CreateProcess ($client_prog, $client_args);
333 $server->DeleteFile ($primary_iorfile);
334 $server->DeleteFile ($ns_iorfile);
335 $server->DeleteFile ($nm_iorfile);
337 print_msg
("INFO: Starting the primary");
339 if ($server->WaitForFileTimed ($primary_iorfile,
340 $server->ProcessStartWaitInterval()) == -1) {
341 print STDERR
"ERROR: cannot find file <$server_primary_iorfile>\n";
342 $NS1->Kill (); $NS1->TimedWait (1);
346 print_msg
("INFO: Starting the backup");
348 if ($server->WaitForFileTimed ($ns_iorfile,
349 $server->ProcessStartWaitInterval()) == -1) {
350 print STDERR
"ERROR: cannot find file <$server_ns_iorfile>\n";
351 $NS2->Kill (); $NS2->TimedWait (1);
352 $NS1->Kill (); $NS1->TimedWait (1);
356 print_msg
("INFO: Starting the client");
359 $server_status = $NS1->TerminateWaitKill ($server->ProcessStopWaitInterval());
360 if ($server_status != 0) {
361 print STDERR
"ERROR: server 1 returned $server_status\n";
365 print_msg
("INFO: restart primary server");
370 $client_status = $CL->TerminateWaitKill ($client->ProcessStopWaitInterval());
371 if ($client_status != 0) {
372 print STDERR
"ERROR: client returned $client_status\n";
376 $server_status = $NS2->TerminateWaitKill ($server->ProcessStopWaitInterval());
377 if ($server_status != 0) {
378 print STDERR
"ERROR: server 2 returned $server_status\n";
382 $server_status = $NS1->TerminateWaitKill ($server->ProcessStopWaitInterval());
383 if ($server_status != 0) {
384 print STDERR
"ERROR: server 1 returned $server_status\n";
388 if ( $status == 0 ) {
389 $status = $previous_status;
398 my $bar = "===============================================================================";
399 print STDERR
"\n\n$bar\n$msg\n$bar\n";
404 my $test_result = shift;
405 my $test_name = shift;
407 if ( 0 == $test_result ) {
408 print_msg
("$test_name: SUCCESS");
410 print_msg
("$test_name: ERROR");
414 my $result = failover_test
();
415 show_result
($result, "Failover Test");