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;
19 $redirection_enabled = 0;
23 my $server = PerlACE
::TestTarget
::create_target
(1) || die "Create target 1 failed\n";
24 my $client = PerlACE
::TestTarget
::create_target
(2) || die "Create target 2 failed\n";
27 # Variables for command-line arguments to client and server
29 my $hostname = $server->HostName ();
31 my $ns_orb_port1 = 10001 + $server->RandomPort ();
32 my $ns_orb_port2 = 10002 + $server->RandomPort ();
34 my $ns_endpoint1 = "iiop://$hostname:$ns_orb_port1";
35 my $ns_endpoint2 = "iiop://$hostname:$ns_orb_port2";
37 # References to primary naming service only
38 my $primary_default_init_ref = "-ORBDefaultInitRef corbaloc:iiop:$hostname:$ns_orb_port1";
40 # References to backup naming service only
41 my $backup_default_init_ref = "-ORBDefaultInitRef corbaloc:iiop:$hostname:$ns_orb_port2";
43 ## Allow the user to determine where the persistence file will be located
44 ## just in case the current directory is not suitable for locking.
45 ## We can't change the name of the persistence file because that is not
46 ## sufficient to work around locking problems for Tru64 when the current
47 ## directory is NFS mounted from a system that does not properly support
49 foreach my $possible ($ENV{TMPDIR
}, $ENV{TEMP
}, $ENV{TMP
}) {
50 if (defined $possible && -d
$possible) {
51 if (chdir($possible)) {
58 my $POSITIVE_TEST_RESULT = 0;
59 my $NEGATIVE_TEST_RESULT = 1;
61 my $NSGROUP = $client->CreateProcess ("$ENV{ACE_ROOT}/bin/tao_nsgroup");
62 my $NSLIST = $client->CreateProcess ("$ENV{ACE_ROOT}/bin/tao_nslist");
63 my $NSADD = $client->CreateProcess ("$ENV{ACE_ROOT}/bin/tao_nsadd");
64 my $NSDEL = $client->CreateProcess ("$ENV{ACE_ROOT}/bin/tao_nsdel");
68 my $file_name = shift;
69 if (-s
$file_name ) # size of file is greater than zero
71 open TESTFILE
, $file_name or die "Couldn't open file: $!";
72 my @teststring = <TESTFILE
>; # read in all of the file
73 print STDERR
"\n@teststring\n";
80 open (OLDOUT
, ">&", \
*STDOUT
) or die "Can't dup STDOUT: $!";
81 open (OLDERR
, ">&", \
*STDERR
) or die "Can't dup STDERR: $!";
82 open STDERR
, '>', $client_stderr_file;
83 open STDOUT
, '>', $client_stdout_file;
88 open (STDERR
, ">&OLDERR") or die "Can't dup OLDERR: $!";
89 open (STDOUT
, ">&OLDOUT") or die "Can't dup OLDOUT: $!";
95 my $expected_test_result = shift;
97 my $arglist = "$args";
99 $NSGROUP->Arguments ($arglist);
101 if ($redirection_enabled) {
105 my $nsgroup_status = $NSGROUP->SpawnWaitKill ($client->ProcessStartWaitInterval());
107 if ($redirection_enabled) {
111 if ($nsgroup_status != $expected_test_result) {
112 my $time = localtime;
113 print STDERR
"ERROR: nsgroup returned $nsgroup_status at $time\n";
114 if ($redirection_enabled) {
115 cat_file
($client_stderr_file);
116 cat_file
($client_stdout_file);
125 my $expected_test_result = shift;
127 $NSLIST->Arguments ($args);
129 if ($redirection_enabled) {
133 #tao_nslist --ns file://ns.ior
134 my $nslist_status = $NSLIST->SpawnWaitKill ($client->ProcessStartWaitInterval());
136 if ($redirection_enabled) {
140 if ($nslist_status != $expected_test_result) {
141 my $time = localtime;
142 print STDERR
"ERROR: nslist returned $nslist_status at $time\n";
143 if ($redirection_enabled) {
144 cat_file
($client_stderr_file);
145 cat_file
($client_stdout_file);
154 my $expected_test_result = shift;
156 $NSADD->Arguments ($args);
158 if ($redirection_enabled) {
162 #tao_nsadd --ns file://ns.ior --name iso --ctx
163 my $nsadd_status = $NSADD->SpawnWaitKill ($client->ProcessStartWaitInterval());
165 if ($redirection_enabled) {
169 if ($nsadd_status != $expected_test_result) {
170 my $time = localtime;
171 print STDERR
"ERROR: nsadd returned $nsadd_status at $time\n";
172 if ($redirection_enabled) {
173 cat_file
($client_stderr_file);
174 cat_file
($client_stdout_file);
183 my $expected_test_result = shift;
185 $NSDEL->Arguments ($args);
187 if ($redirection_enabled) {
191 #tao_nsdel --ns file://ns.ior --name iso --destroy
192 my $nsdel_status = $NSDEL->SpawnWaitKill ($client->ProcessStartWaitInterval());
194 if ($redirection_enabled) {
198 if ($nsdel_status != $expected_test_result) {
199 my $time = localtime;
200 print STDERR
"ERROR: nsdel returned $nsdel_status at $time\n";
201 if ($redirection_enabled) {
202 cat_file
($client_stderr_file);
203 cat_file
($client_stdout_file);
209 sub clean_persistence_dir
($$)
212 my $directory_name = shift;
214 chdir $directory_name;
215 opendir(THISDIR
, ".");
216 @allfiles = grep(!/^\.\.?$/, readdir(THISDIR
));
218 foreach $tmp (@allfiles){
219 $target->DeleteFile ($tmp);
224 # Make sure that the directory to use to hold the naming contexts exists
226 sub init_naming_context_directory
($$)
229 my $directory_name = shift;
231 if ( ! -d
$directory_name ) {
232 mkdir ($directory_name, 0777);
234 clean_persistence_dir
($target, $directory_name);
238 my $name_dir = "NameService";
239 my $group_dir = "GroupService";
240 my $ns_replica_primary_iorfile = "$name_dir/ns_replica_primary.ior";
241 my $ns_multi_iorfile = "ns_multi.ior";
242 my $nm_multi_iorfile = "nm_multi.ior";
243 my $ns_primary_iorfile = "ns_primary.ior";
244 my $nm_primary_iorfile = "nm_primary.ior";
245 my $ns_backup_iorfile = "ns_backup.ior";
246 my $nm_backup_iorfile = "nm_backup.ior";
247 my $stderr_file = "test.err";
248 my $stdout_file = "test.out";
250 ################################################################################
251 # setup END block to cleanup after exit call
252 ################################################################################
255 $server->DeleteFile ($ns_replica_primary_iorfile);
257 $server->DeleteFile ($ns_multi_iorfile);
258 $server->DeleteFile ($nm_multi_iorfile);
259 $server->DeleteFile ($ns_primary_iorfile);
260 $server->DeleteFile ($nm_primary_iorfile);
261 $server->DeleteFile ($ns_backup_iorfile);
262 $server->DeleteFile ($nm_backup_iorfile);
264 $client->DeleteFile ($ns_primary_iorfile);
265 $client->DeleteFile ($nm_primary_iorfile);
266 $client->DeleteFile ($ns_backup_iorfile);
267 $client->DeleteFile ($nm_backup_iorfile);
268 $client->DeleteFile ($stdout_file);
269 $client->DeleteFile ($stderr_file);
271 if ( -d
$name_dir ) {
272 print STDERR
"INFO: removing <$name_dir>\n";
273 clean_persistence_dir
($server, $name_dir);
277 if ( -d
$group_dir ) {
278 print STDERR
"INFO: removing <$group_dir>\n";
279 clean_persistence_dir
($server, $group_dir);
284 ################################################################################
285 # Validate that a client can seamlessly invoke naming operations on either
287 ################################################################################
288 sub redundant_equivalency_test
()
290 my $previous_status = $status;
293 print_msg
("Redundant Equivalency Test");
295 init_naming_context_directory
($server, $name_dir);
296 init_naming_context_directory
($server, $group_dir);
298 # The file that is written by the primary when ready to start backup
299 my $server_primary_iorfile = $server->LocalFile ($ns_replica_primary_iorfile);
300 my $server_ns_multi_iorfile = $server->LocalFile ($ns_multi_iorfile);
301 my $server_nm_multi_iorfile = $server->LocalFile ($nm_multi_iorfile);
303 my $server_ns_primary_iorfile = $server->LocalFile ($ns_primary_iorfile);
304 my $server_nm_primary_iorfile = $server->LocalFile ($nm_primary_iorfile);
305 my $server_ns_backup_iorfile = $server->LocalFile ($ns_backup_iorfile);
306 my $server_nm_backup_iorfile = $server->LocalFile ($nm_backup_iorfile);
308 my $client_ns_primary_iorfile = $client->LocalFile ($ns_primary_iorfile);
309 my $client_nm_primary_iorfile = $client->LocalFile ($nm_primary_iorfile);
310 my $client_ns_backup_iorfile = $client->LocalFile ($ns_backup_iorfile);
311 my $client_nm_backup_iorfile = $client->LocalFile ($nm_backup_iorfile);
313 my $client_stdout_file = $client->LocalFile ($stdout_file);
314 my $client_stderr_file = $client->LocalFile ($stderr_file);
316 my $tao_ft_naming = "$ENV{TAO_ROOT}/orbsvcs/FT_Naming_Service/tao_ft_naming";
318 # Run two Naming Servers
319 my $ns1_args = "--primary ".
320 "-ORBDebugLevel $debug_level " .
321 "-ORBListenEndPoints $ns_endpoint1 ".
322 "-o $server_ns_primary_iorfile ".
323 "-h $server_nm_primary_iorfile ".
327 my $ns2_args = "--backup ".
328 "-ORBDebugLevel $debug_level " .
329 "-ORBListenEndPoints $ns_endpoint2 ".
330 "-o $server_ns_backup_iorfile ".
331 "-h $server_nm_backup_iorfile ".
332 "-c $server_ns_multi_iorfile ".
333 "-g $server_nm_multi_iorfile ".
337 my $client_args = "--equivalence " .
338 "-ORBDebugLevel $debug_level " .
339 "-p file://$client_ns_primary_iorfile " .
340 "-q file://$client_ns_backup_iorfile " .
341 "-r file://$client_nm_primary_iorfile " .
342 "-s file://$client_nm_backup_iorfile " .
346 my $client_prog = "client";
348 $NS1 = $server->CreateProcess ($tao_ft_naming, $ns1_args);
349 $NS2 = $server->CreateProcess ($tao_ft_naming, $ns2_args);
350 $CL = $client->CreateProcess ($client_prog, $client_args);
352 $server->DeleteFile ($ns_primary_iorfile);
354 if ($server->WaitForFileTimed ($ns_primary_iorfile,
355 $server->ProcessStartWaitInterval()) == -1) {
356 print STDERR
"ERROR: cannot find file <$server_primary_iorfile>\n";
357 $NS1->Kill (); $NS1->TimedWait (1);
361 $server->DeleteFile ($ns_multi_iorfile);
363 if ($server->WaitForFileTimed ($ns_multi_iorfile,
364 $server->ProcessStartWaitInterval()) == -1) {
365 print STDERR
"ERROR: cannot find file <$server_ns_multi_iorfile>\n";
366 $NS2->Kill (); $NS2->TimedWait (1);
367 $NS1->Kill (); $NS1->TimedWait (1);
371 print_msg
("INFO: Starting the client");
372 $client_status = $CL->SpawnWaitKill ($client->ProcessStartWaitInterval()+5);
373 if ($client_status != 0) {
374 print STDERR
"ERROR: client returned $client_status\n";
379 $server_status = $NS2->TerminateWaitKill ($server->ProcessStopWaitInterval());
380 if ($server_status != 0) {
381 print STDERR
"ERROR: server 2 returned $server_status\n";
385 $server_status = $NS1->TerminateWaitKill ($server->ProcessStopWaitInterval());
386 if ($server_status != 0) {
387 print STDERR
"ERROR: server 1 returned $server_status\n";
391 if ( $status == 0 ) {
392 $status = $previous_status;
401 my $bar = "===============================================================================";
402 print STDERR
"\n\n$bar\n$msg\n$bar\n";
407 my $test_result = shift;
408 my $test_name = shift;
410 if ( 0 == $test_result ) {
411 print_msg
("$test_name: SUCCESS");
413 print_msg
("$test_name: ERROR");
417 my $result = redundant_equivalency_test
();
418 show_result
($result, "Redundant Equivalency Test");