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
;
13 #$ENV{ACE_TEST_VERBOSE} = "1";
15 my $startdir = getcwd
();
16 my $debug_level = '0';
17 my $redirection_enabled = 0;
23 if ($i eq '-verbose') {
24 $redirection_enabled = 0;
28 my $server = PerlACE
::TestTarget
::create_target
(1) || die "Create target 1 failed\n";
29 my $client = PerlACE
::TestTarget
::create_target
(2) || die "Create target 2 failed\n";
30 my $server2 = PerlACE
::TestTarget
::create_target
(3) || die "Create target 3 failed\n";
32 # Variables for command-line arguments to client and server
35 my $stdout_file = "test.out";
36 my $stderr_file = "test.err";
37 my $client_stdout_file = $client->LocalFile ($stdout_file);
38 my $client_stderr_file = $client->LocalFile ($stderr_file);
39 my $client_member_file = "member.dat";
42 my $POSITIVE_TEST_RESULT = 0;
43 my $NEGATIVE_TEST_RESULT = 1;
45 my $NSGROUP = $client->CreateProcess ("$ENV{ACE_ROOT}/bin/tao_nsgroup");
46 my $NSLIST = $client->CreateProcess ("$ENV{ACE_ROOT}/bin/tao_nslist");
47 my $NSADD = $client->CreateProcess ("$ENV{ACE_ROOT}/bin/tao_nsadd");
48 my $NSDEL = $client->CreateProcess ("$ENV{ACE_ROOT}/bin/tao_nsdel");
50 ## Allow the user to determine where the persistence file will be located
51 ## just in case the current directory is not suitable for locking.
52 ## We can't change the name of the persistence file because that is not
53 ## sufficient to work around locking problems for Tru64 when the current
54 ## directory is NFS mounted from a system that does not properly support
56 foreach my $possible ($ENV{TMPDIR
}, $ENV{TEMP
}, $ENV{TMP
}) {
57 if (defined $possible && -d
$possible) {
58 if (chdir($possible)) {
66 my $file_name = shift;
67 if (-s
$file_name ) # size of file is greater than zero
69 open TESTFILE
, $file_name or die "Couldn't open file: $!";
70 my @teststring = <TESTFILE
>; # read in all of the file
71 print STDERR
"\n@teststring\n";
78 open (OLDOUT
, ">&", \
*STDOUT
) or die "Can't dup STDOUT: $!";
79 open (OLDERR
, ">&", \
*STDERR
) or die "Can't dup STDERR: $!";
80 open STDERR
, '>', $client_stderr_file;
81 open STDOUT
, '>', $client_stdout_file;
86 open (STDERR
, ">&OLDERR") or die "Can't dup OLDERR: $!";
87 open (STDOUT
, ">&OLDOUT") or die "Can't dup OLDOUT: $!";
90 sub compare_file_with_backup
($)
93 my $backup = $file . ".bak";
95 print STDERR
"ERROR: Backup file $backup does not exist\n";
98 my $result = compare
($file, $backup);
100 print STDERR
"ERROR: Backup file $backup does not agree with $file\n";
108 my $expected_test_result = shift;
110 my $arglist = "$args";
112 $NSGROUP->Arguments ($arglist);
114 if ($redirection_enabled) {
118 my $nsgroup_status = $NSGROUP->SpawnWaitKill ($client->ProcessStartWaitInterval());
120 if ($redirection_enabled) {
124 if ($nsgroup_status != $expected_test_result) {
125 my $time = localtime;
126 print STDERR
"ERROR: nsgroup returned $nsgroup_status at $time\n";
127 if ($redirection_enabled) {
128 cat_file
($client_stderr_file);
129 cat_file
($client_stdout_file);
138 my $expected_test_result = shift;
140 $NSLIST->Arguments ($args);
142 if ($redirection_enabled) {
146 #tao_nslist --ns file://ns.ior
147 my $nslist_status = $NSLIST->SpawnWaitKill ($client->ProcessStartWaitInterval());
149 if ($redirection_enabled) {
153 if ($nslist_status != $expected_test_result) {
154 my $time = localtime;
155 print STDERR
"ERROR: nslist returned $nslist_status at $time\n";
156 if ($redirection_enabled) {
157 cat_file
($client_stderr_file);
158 cat_file
($client_stdout_file);
167 my $expected_test_result = shift;
169 $NSADD->Arguments ($args);
171 if ($redirection_enabled) {
175 #tao_nsadd --ns file://ns.ior --name iso --ctx
176 my $nsadd_status = $NSADD->SpawnWaitKill ($client->ProcessStartWaitInterval());
178 if ($redirection_enabled) {
182 if ($nsadd_status != $expected_test_result) {
183 my $time = localtime;
184 print STDERR
"ERROR: nsadd returned $nsadd_status at $time\n";
185 if ($redirection_enabled) {
186 cat_file
($client_stderr_file);
187 cat_file
($client_stdout_file);
196 my $expected_test_result = shift;
198 $NSDEL->Arguments ($args);
200 if ($redirection_enabled) {
204 #tao_nsdel --ns file://ns.ior --name iso --destroy
205 my $nsdel_status = $NSDEL->SpawnWaitKill ($client->ProcessStartWaitInterval());
207 if ($redirection_enabled) {
211 if ($nsdel_status != $expected_test_result) {
212 my $time = localtime;
213 print STDERR
"ERROR: nsdel returned $nsdel_status at $time\n";
214 if ($redirection_enabled) {
215 cat_file
($client_stderr_file);
216 cat_file
($client_stdout_file);
222 sub clean_persistence_dir
($$)
225 my $directory_name = shift;
227 chdir $directory_name;
228 opendir(THISDIR
, ".");
229 @allfiles = grep(!/^\.\.?$/, readdir(THISDIR
));
231 foreach $tmp (@allfiles){
232 $target->DeleteFile ($tmp);
237 # Make sure that the directory to use to hold the naming contexts exists
239 sub init_persistence_dir
($$)
242 my $directory_name = shift;
244 if ( ! -d
$directory_name ) {
245 mkdir ($directory_name, 0777);
247 clean_persistence_dir
($target, $directory_name);
251 my $name_dir = "NameService";
252 my $group_dir = "GroupService";
253 my $nm_iorfile = "nm.ior";
254 my $ns_iorfile = "ns.ior";
255 my $sv_iorfile = "obj.ior";
256 my $sv_statusfile = "server.status";
258 my $ns_ref = "--ns file://$ns_iorfile";
259 my $sv2_iorfile = $server2->LocalFile ($sv_iorfile);
260 my $sv2_statusfile = $server2->LocalFile ($sv_statusfile);
265 ################################################################################
266 # setup END block to cleanup after exit call
267 ################################################################################
270 $server->DeleteFile ($ns_iorfile);
271 $server->DeleteFile ($nm_iorfile);
272 $client->DeleteFile ($nm_iorfile);
273 $client->DeleteFile ($stdout_file);
274 $client->DeleteFile ($stderr_file);
275 $client->DeleteFile ($client_member_file);
276 $server2->DeleteFile($sv_iorfile);
277 $server2->DeleteFile($sv_statusfile);
279 if ( -d
$name_dir ) {
280 print STDERR
"INFO: removing <$name_dir>\n";
281 clean_persistence_dir
($server, $name_dir);
285 if ( -d
$group_dir ) {
286 print STDERR
"INFO: removing <$group_dir>\n";
287 clean_persistence_dir
($server, $group_dir);
292 ################################################################################
293 # Validate that repository data written by the name service is available upon
295 ################################################################################
296 sub persistence_test
()
298 my $previous_status = $status;
301 my $hostname = $server->HostName ();
302 my $ns_orb_port1 = 10001 + $server->RandomPort ();
303 my $ns_endpoint1 = "iiop://$hostname:$ns_orb_port1";
304 my $default_init_ref = "-ORBDefaultInitRef corbaloc:iiop:$hostname:$ns_orb_port1";
305 my $client_nm_iorfile = $client->LocalFile ($nm_iorfile);
307 print_msg
("Persistence Test");
308 init_persistence_dir
($server, $name_dir);
309 init_persistence_dir
($server, $group_dir);
311 my $ns_args = "-ORBListenEndPoints $ns_endpoint1 ".
312 "-ORBDebugLevel $debug_level " .
318 my $tao_ft_naming = "$ENV{TAO_ROOT}/orbsvcs/FT_Naming_Service/tao_ft_naming";
320 my $client1_args = "--persistence " .
322 "-ORBDebugLevel $debug_level " .
323 "-p corbaloc:iiop:$hostname:$ns_orb_port1/NameService " .
324 "-r corbaloc:iiop:$hostname:$ns_orb_port1/NamingManager " .
328 my $client2_args = "--persistence " .
330 "-ORBDebugLevel $debug_level " .
331 "-p corbaloc:iiop:$hostname:$ns_orb_port1/NameService " .
332 "-r corbaloc:iiop:$hostname:$ns_orb_port1/NamingManager " .
336 my $client_prog = "$startdir/client";
339 ##1. Run one instance of tao_ft_naming service
340 $NS1 = $server->CreateProcess ($tao_ft_naming, $ns_args);
341 $CL1 = $client->CreateProcess ($client_prog, $client1_args);
342 $CL2 = $client->CreateProcess ($client_prog, $client2_args);
345 my $server2_args = "-ORBdebuglevel $debug_level " .
346 "$default_init_ref ".
349 $SV2 = $server2->CreateProcess ("$startdir/server", $server2_args);
351 $server->DeleteFile ($ns_iorfile);
353 if ($server->WaitForFileTimed ($ns_iorfile,
354 $server->ProcessStartWaitInterval()) == -1) {
355 print STDERR
"ERROR: cannot find file <$ns_iorfile>\n";
356 $NS1->Kill (); $NS1->TimedWait (1);
360 ##2. Create new contexts and new object groups
361 print_msg
("INFO: starting test server");
362 $server_status = $SV2->Spawn ();
363 if ($server_status != 0) {
364 print STDERR
"ERROR: server returned $server_status\n";
367 if ($server2->WaitForFileTimed ($sv_statusfile,
368 $server2->ProcessStartWaitInterval()) == -1) {
369 print STDERR
"ERROR: cannot find file <$sv_statusfile>\n";
370 $SV2->Kill (); $SV2->TimedWait (1);
374 ##3. Creation additional contexts and object groups and verify
375 print_msg
("INFO: Starting client1");
376 $client_status = $CL1->SpawnWaitKill ($client->ProcessStartWaitInterval());
377 if ($client_status != 0) {
378 print STDERR
"ERROR: client1 returned $client_status\n";
382 ##4. Kill the tao_ft_naming server
383 print_msg
("Kill the tao_ft_naming server");
384 $server_status = $NS1->TerminateWaitKill ($server->ProcessStopWaitInterval());
385 if ($server_status != 0) {
386 print STDERR
"ERROR: server 1 returned $server_status\n";
390 ##5. Start a new instance of the tao_ft_naming server
391 print_msg
("Start a new instance of the tao_ft_naming server");
392 $server->DeleteFile ($ns_iorfile);
394 if ($server->WaitForFileTimed ($ns_iorfile,
395 $server->ProcessStartWaitInterval()) == -1) {
396 print STDERR
"ERROR: cannot find file <$ns_iorfile>\n";
397 $NS1->Kill (); $NS1->TimedWait (1);
401 ##6. Verify the new name, object group and member are in the tao_ft_naming repository.
402 print_msg
("Verify the new name, object group and member are in the tao_ft_naming repository");
403 print_msg
("INFO: Starting client2");
404 $client_status = $CL2->SpawnWaitKill ($client->ProcessStartWaitInterval());
405 if ($client_status != 0) {
406 print STDERR
"ERROR: client2 returned $client_status\n";
410 print_msg
("INFO: terminating test server");
411 $server_status = $SV2->TerminateWaitKill ($server2->ProcessStopWaitInterval());
412 if ($server_status != 0) {
413 print STDERR
"ERROR: server returned $server_status\n";
417 $server_status = $NS1->TerminateWaitKill ($server->ProcessStopWaitInterval());
418 if ($server_status != 0) {
419 print STDERR
"ERROR: server 1 returned $server_status\n";
423 if ( $status == 0 ) {
424 $status = $previous_status;
430 ################################################################################
431 # Validate that when a corrupt persistent file is read that the contents of the
432 # backup file is used instead.
433 ################################################################################
434 sub backup_restore_test
()
437 my $num_child_contexts = 8;
438 my $num_object_groups = 1;
440 my $previous_status = $status;
443 my $hostname = $server->HostName ();
444 my $ns_orb_port1 = 10001 + $server->RandomPort ();
445 my $ns_endpoint1 = "iiop://$hostname:$ns_orb_port1";
446 my $default_init_ref = "-ORBDefaultInitRef corbaloc:iiop:$hostname:$ns_orb_port1";
447 my $client_nm_iorfile = $client->LocalFile ($nm_iorfile);
449 print_msg
("Backup/Restore Test");
450 init_persistence_dir
($server, $name_dir);
451 init_persistence_dir
($server, $group_dir);
453 my $ns_args = "-ORBListenEndPoints $ns_endpoint1 ".
454 "-ORBDebugLevel $debug_level " .
460 my $tao_ft_naming = "$ENV{TAO_ROOT}/orbsvcs/FT_Naming_Service/tao_ft_naming";
462 my $client1_args = "--persistence " .
464 "-ORBDebugLevel $debug_level " .
465 "-p corbaloc:iiop:$hostname:$ns_orb_port1/NameService " .
466 "-r corbaloc:iiop:$hostname:$ns_orb_port1/NamingManager " .
470 my $client2_args = "--persistence " .
472 "-ORBDebugLevel $debug_level " .
473 "-p corbaloc:iiop:$hostname:$ns_orb_port1/NameService " .
474 "-r corbaloc:iiop:$hostname:$ns_orb_port1/NamingManager " .
478 my $client_prog = "$startdir/client";
481 ##1. Run one instance of tao_ft_naming service
482 $NS1 = $server->CreateProcess ($tao_ft_naming, $ns_args);
483 $CL1 = $client->CreateProcess ($client_prog, $client1_args);
484 $CL2 = $client->CreateProcess ($client_prog, $client2_args);
487 my $server2_args = "-ORBdebuglevel $debug_level " .
488 "$default_init_ref ".
491 $SV2 = $server2->CreateProcess ("$startdir/server", $server2_args);
493 $server->DeleteFile ($ns_iorfile);
495 if ($server->WaitForFileTimed ($ns_iorfile,
496 $server->ProcessStartWaitInterval()) == -1) {
497 print STDERR
"ERROR: cannot find file <$ns_iorfile>\n";
498 $NS1->Kill (); $NS1->TimedWait (1);
502 ##2. Create new contexts and new object groups
503 print_msg
("INFO: starting test server");
504 $server_status = $SV2->Spawn ();
505 if ($server_status != 0) {
506 print STDERR
"ERROR: server returned $server_status\n";
509 if ($server2->WaitForFileTimed ($sv_statusfile,
510 $server2->ProcessStartWaitInterval()) == -1) {
511 print STDERR
"ERROR: cannot find file <$sv_statusfile>\n";
512 $SV2->Kill (); $SV2->TimedWait (1);
516 ##3. Creation additional contexts and object groups and verify
517 print_msg
("INFO: Starting client1");
518 $client_status = $CL1->SpawnWaitKill ($client->ProcessStartWaitInterval());
519 if ($client_status != 0) {
520 print STDERR
"ERROR: client1 returned $client_status\n";
524 ##4. Kill the tao_ft_naming server
525 print_msg
("Kill the tao_ft_naming server");
526 $server_status = $NS1->TerminateWaitKill ($server->ProcessStopWaitInterval());
527 if ($server_status != 0) {
528 print STDERR
"ERROR: server 1 returned $server_status\n";
532 ##5. Verify that backup files are created
534 print_msg
("Verifying naming context backup files");
535 $file = $name_dir . "/NameService";
536 if (compare_file_with_backup
($file) != 0) {
539 for ($i = 0; $i < $num_child_contexts; $i++) {
540 $file = $name_dir . "/NameService_$i";
541 if (compare_file_with_backup
($file) != 0) {
546 print_msg
("Verifying object group backup files");
547 $file = $group_dir . "/ObjectGroup_global";
548 if (compare_file_with_backup
($file) != 0) {
551 for ($i = 0; $i < $num_object_groups; $i++) {
552 $file = $group_dir . "/ObjectGroup_$i";
553 if (compare_file_with_backup
($file) != 0) {
558 ##6. Replace some of the data files with corrupt files
559 print_msg
("Replace data files with corrupt files");
560 my $corrupt_data_dir = $startdir . "/corrupt_data/";
562 my $corrupt_name_dir = $corrupt_data_dir . $name_dir . "/";
563 opendir(NAMEDIR
, $corrupt_name_dir);
564 @allfiles = grep(/^NameService/, readdir(NAMEDIR
));
566 foreach $file (@allfiles) {
567 copy
($corrupt_name_dir . $file, $name_dir . "/" . $file) or die "Copy failed: $!\n";
570 my $corrupt_group_dir = $corrupt_data_dir . $group_dir . "/";
571 opendir(GROUPDIR
, $corrupt_group_dir);
572 @allfiles = grep(/^ObjectGroup/, readdir(GROUPDIR
));
574 foreach $file (@allfiles) {
575 copy
($corrupt_group_dir . $file, $group_dir . "/" . $file) or die "Copy failed: $!\n";
578 ##7. Start a new instance of the tao_ft_naming server
579 print_msg
("Start a new instance of the tao_ft_naming server and then running client 2");
580 $server->DeleteFile ($ns_iorfile);
581 # Redirect output so that expected error messages are not interpreted as
582 # test failure and rely instead of return status.
584 my $restore_status = 0;
586 if ($server->WaitForFileTimed ($ns_iorfile,
587 $server->ProcessStartWaitInterval()) == -1) {
588 print STDERR
"ERROR: cannot find file <$ns_iorfile>\n";
589 $NS1->Kill (); $NS1->TimedWait (1);
594 ##8. Verify the new name, object group and member are in the tao_ft_naming repository.
595 print_msg
("Verify the backup files are used when the corrupt files are read");
596 print_msg
("INFO: Starting client2");
597 $client_status = $CL2->SpawnWaitKill ($client->ProcessStartWaitInterval());
599 if ($client_status != 0) {
600 print STDERR
"ERROR: client2 returned $client_status\n";
605 if ($restore_status == 1) {
606 cat_file
($client_stderr_file);
607 cat_file
($client_stdout_file);
610 print_msg
("INFO: terminating test server");
611 $server_status = $SV2->TerminateWaitKill ($server2->ProcessStopWaitInterval());
612 if ($server_status != 0) {
613 print STDERR
"ERROR: server returned $server_status\n";
617 $server_status = $NS1->TerminateWaitKill ($server->ProcessStopWaitInterval());
618 if ($server_status != 0) {
619 print STDERR
"ERROR: server 1 returned $server_status\n";
623 if ( $status == 0 ) {
624 $status = $previous_status;
633 my $bar = "===============================================================================";
634 print STDERR
"\n\n$bar\n$msg\n$bar\n";
639 my $test_result = shift;
640 my $test_name = shift;
642 if ( 0 == $test_result ) {
643 print_msg
("$test_name: SUCCESS");
645 print_msg
("$test_name: ERROR");
649 my $result = persistence_test
();
650 my $result = backup_restore_test
();
652 show_result
($result, "Persistence Test");