1 //=============================================================================
5 * This class implements a CORBA test client for the Fault Tolerant Naming Service.
7 * @author Rich Seibel <seibel_r@ociweb.com>
8 * @author Phillip LaBanca <labancap@ociweb.com>
10 //=============================================================================
13 #include "test_objectS.h"
14 #include "orbsvcs/CosNamingC.h"
15 #include "orbsvcs/FT_NamingManagerC.h"
16 #include "orbsvcs/Naming/Naming_Server.h"
17 #include "tao/debug.h"
19 #include "ace/Get_Opt.h"
20 #include "ace/OS_NS_stdio.h"
21 #include "ace/OS_NS_unistd.h"
22 #include "orbsvcs/Naming/FaultTolerant/nsgroup_svc.h"
26 #if defined (_MSC_VER)
27 # pragma warning (disable : 4250)
30 //==============================================================================
32 //==============================================================================
33 class My_Test_Object
:
34 public virtual POA_Test_Object
37 My_Test_Object (CORBA::Short id
= 0);
43 // = Interface implementation accessor methods.
45 void id (CORBA::Short id
);
55 My_Test_Object::My_Test_Object (CORBA::Short id
)
60 My_Test_Object::~My_Test_Object ()
71 My_Test_Object::id (CORBA::Short id
)
76 //==============================================================================
78 //==============================================================================
79 /// Failover Name Test
81 do_failover_name_test (
82 CORBA::ORB_ptr theOrb
,
88 /// Failover ObjectGroup Test
90 do_failover_objectgroup_test (
91 CORBA::ORB_ptr theOrb
,
97 //==============================================================================
99 //==============================================================================
100 /// Persistence Name Test
102 do_persistence_name_test (
103 CORBA::ORB_ptr theOrb
,
110 /// Persistence ObjectGroup Test
112 do_persistence_objectgroup_test (
113 CORBA::ORB_ptr theOrb
,
120 //==============================================================================
122 //==============================================================================
123 /// Equivalence Name Test
125 do_equivalence_name_test (
126 CORBA::ORB_ptr theOrb
,
133 /// Equivalence ObjectGroup Test
135 do_equivalence_objectgroup_test (
136 CORBA::ORB_ptr theOrb
,
144 //==============================================================================
146 //==============================================================================
148 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
150 const int RC_SUCCESS
= 0;
151 const int RC_ERROR
= 1;
159 ACE_TCHAR
*ns1ref
= 0;
160 ACE_TCHAR
*ns2ref
= 0;
162 ACE_TCHAR
*nm1ref
= 0;
163 ACE_TCHAR
*nm2ref
= 0;
169 } fault_tolerant_test
;
170 fault_tolerant_test test_type
= TT_FAILOVER
;
176 } fault_tolerant_test_phase
;
177 fault_tolerant_test_phase test_phase
= TT_INIT
;
179 //////////////////////////////////////////////////////////////////////////////
181 //////////////////////////////////////////////////////////////////////////////
182 // -b <breadth of context tree>
183 // -d <depth of context tree>
184 // -o <breadth of object tree>
185 //////////////////////////////////////////////////////////////////////////////
187 //////////////////////////////////////////////////////////////////////////////
188 // -p <ior of first name server>
189 // -q <ior of second name server>
190 // -r <ior of first naming service>
191 // -s <ior of second naming service>
192 // --failover run fault tolerant failover test
193 // --persistence run fault tolerant persistence test
194 // --equivalence run fault tolerant equivalence test
195 //////////////////////////////////////////////////////////////////////////////
196 // required with persistance
197 //////////////////////////////////////////////////////////////////////////////
198 // --create run creation test phase
199 // --validate run validation test phase
204 CORBA::ORB_var orb
= CORBA::ORB_init(argc
, argv
);
206 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT ("b:d:o:p:q:r:s:"));
209 get_opts
.long_option (ACE_TEXT ("failover"), ACE_Get_Opt::NO_ARG
);
210 get_opts
.long_option (ACE_TEXT ("persistence"), ACE_Get_Opt::NO_ARG
);
211 get_opts
.long_option (ACE_TEXT ("equivalence"), ACE_Get_Opt::NO_ARG
);
212 get_opts
.long_option (ACE_TEXT ("create"), ACE_Get_Opt::NO_ARG
);
213 get_opts
.long_option (ACE_TEXT ("validate"), ACE_Get_Opt::NO_ARG
);
215 while ((c
= get_opts ()) != -1)
219 i
= ACE_OS::atoi(get_opts
.opt_arg ());
223 ACE_TEXT ("Invalid breadth, must be 2 or more\n")));
224 ACE_OS::exit(RC_ERROR
);
229 i
= ACE_OS::atoi(get_opts
.opt_arg ());
233 ACE_TEXT ("Invalid depth, must be 2 or more\n")));
234 ACE_OS::exit(RC_ERROR
);
239 i
= ACE_OS::atoi(get_opts
.opt_arg ());
243 ACE_TEXT ("Invalid breadth, must be 2 or more\n")));
244 ACE_OS::exit(RC_ERROR
);
249 ns1ref
= get_opts
.opt_arg ();
252 ns2ref
= get_opts
.opt_arg ();
255 nm1ref
= get_opts
.opt_arg ();
258 nm2ref
= get_opts
.opt_arg ();
260 case 0: // A long option was found
262 const ACE_TCHAR
* long_option
= get_opts
.long_option ();
263 if (ACE_OS::strcmp (long_option
,
264 ACE_TEXT ("failover")) == 0)
266 test_type
= TT_FAILOVER
;
268 else if (ACE_OS::strcmp (long_option
,
269 ACE_TEXT ("persistence")) == 0)
271 test_type
= TT_PERSISTENCE
;
273 else if (ACE_OS::strcmp (long_option
,
274 ACE_TEXT ("equivalence")) == 0)
276 test_type
= TT_EQUIVALENCE
;
278 else if (ACE_OS::strcmp (long_option
,
279 ACE_TEXT ("create")) == 0)
281 test_phase
= TT_CREATE
;
283 else if (ACE_OS::strcmp (long_option
,
284 ACE_TEXT ("validate")) == 0)
286 test_phase
= TT_VALIDATE
;
292 ACE_ERROR_RETURN ((LM_ERROR
,
293 ACE_TEXT ("Argument %c \n usage: %s")
294 ACE_TEXT (" [-b <breadth of context tree>]")
295 ACE_TEXT (" [-d <depth of context tree>]")
296 ACE_TEXT (" [-o <breadth of object tree>]")
297 ACE_TEXT (" -p <ior of first name server>")
298 ACE_TEXT (" -q <ior of second name server>")
299 ACE_TEXT (" -r <ior of first naming server>")
300 ACE_TEXT (" -s <ior of second naming server>")
308 if( RC_SUCCESS
!= do_failover_name_test (
315 ACE_DEBUG ((LM_DEBUG
,
316 ACE_TEXT ("ERROR: Failover Name Test Failed\n")));
319 ACE_DEBUG ((LM_DEBUG
,
320 ACE_TEXT ("INFO: Failover Name Test OK\n")));
323 if( RC_SUCCESS
!= do_failover_objectgroup_test (
330 ACE_DEBUG ((LM_DEBUG
,
331 ACE_TEXT ("ERROR: Failover ObjectGroup ")
332 ACE_TEXT ("Test Failed\n")));
335 ACE_DEBUG ((LM_DEBUG
,
336 ACE_TEXT ("INFO: Failover ObjectGroup Test OK\n")));
345 if (RC_SUCCESS
!= do_persistence_name_test (
353 ACE_DEBUG ((LM_DEBUG
,
354 ACE_TEXT ("ERROR: Persistence Creation Name ")
355 ACE_TEXT ("Test Failed\n")));
358 ACE_DEBUG ((LM_DEBUG
,
359 ACE_TEXT ("INFO: Persistence Creation Name ")
360 ACE_TEXT ("Test OK\n")));
362 if (RC_SUCCESS
!= do_persistence_objectgroup_test(
370 ACE_DEBUG ((LM_DEBUG
,
371 ACE_TEXT ("ERROR: Persistence Creation ObjectGroup ")
372 ACE_TEXT ("Test Failed\n")));
375 ACE_DEBUG ((LM_DEBUG
,
376 ACE_TEXT ("INFO: Persistence Creation ObjectGroup ")
377 ACE_TEXT ("Test OK\n")));
382 if (RC_SUCCESS
!= do_persistence_name_test (
390 ACE_DEBUG ((LM_DEBUG
,
391 ACE_TEXT ("ERROR: Persistence Validation ")
392 ACE_TEXT ("Name Test Failed\n")));
395 ACE_DEBUG ((LM_DEBUG
,
396 ACE_TEXT ("INFO: Persistence Validation ")
397 ACE_TEXT ("Name Test OK\n")));
400 if (RC_SUCCESS
!= do_persistence_objectgroup_test (
408 ACE_DEBUG ((LM_DEBUG
,
409 ACE_TEXT ("ERROR: Persistence Validation ")
410 ACE_TEXT ("ObjectGroup Test Failed\n")));
413 ACE_DEBUG ((LM_DEBUG
,
414 ACE_TEXT ("INFO: Persistence Validation ")
415 ACE_TEXT ("ObjectGroup Test OK\n")));
421 ACE_DEBUG ((LM_DEBUG
,
422 ACE_TEXT ("ERROR: Missing Required Persistence ")
423 ACE_TEXT ("Argument [--create|--validate] \n")));
431 if (RC_SUCCESS
!= do_equivalence_name_test (
439 ACE_DEBUG ((LM_DEBUG
,
440 ACE_TEXT ("ERROR: Equivalence Name Test\n")));
443 ACE_DEBUG ((LM_DEBUG
,
444 ACE_TEXT ("INFO: Equivalence Name Test OK\n")));
447 if (RC_SUCCESS
!= do_equivalence_objectgroup_test(
455 ACE_DEBUG ((LM_DEBUG
,
456 ACE_TEXT ("ERROR: Equivalence ObjectGroup Test\n")));
459 ACE_DEBUG ((LM_DEBUG
,
460 ACE_TEXT ("INFO: Equivalence ObjectGroup Test OK\n")));
465 catch (const CORBA::Exception
& ex
)
467 ex
._tao_print_exception (
468 ACE_TEXT ("ERROR: Unable to resolve name servers"));
476 //==============================================================================
478 //==============================================================================
479 /// Failover Name Test
481 do_failover_name_test (
482 CORBA::ORB_ptr theOrb
,
488 const int RC_SUCCESS
= 0;
489 const int RC_ERROR
= -1;
490 CosNaming::NamingContext_var root_context_1
;
494 CORBA::ORB_var orb
= CORBA::ORB::_duplicate(theOrb
);
496 if (CORBA::is_nil (orb
.in ()))
498 ACE_ERROR_RETURN (( LM_ERROR
,
499 ACE_TEXT ("ERROR: invalid orb\n")),
503 if (CORBA::is_nil (ns1ref
))
505 ACE_ERROR_RETURN (( LM_ERROR
,
506 ACE_TEXT ("ERROR: invalid ns1\n")),
510 CORBA::Object_var ns1obj
=
511 orb
->string_to_object (ACE_TEXT_ALWAYS_CHAR (ns1ref
));
513 if (CORBA::is_nil (ns1obj
.in ()))
515 ACE_ERROR_RETURN (( LM_ERROR
,
516 ACE_TEXT ("ERROR: invalid ior <%s>\n"),ns1ref
),
520 root_context_1
= CosNaming::NamingContext::_narrow (ns1obj
.in ());
522 if (CORBA::is_nil (root_context_1
.in ()))
524 ACE_ERROR_RETURN (( LM_ERROR
,
525 ACE_TEXT ("ERROR: invalid ior <%s>\n"),ns1ref
),
530 catch (const CORBA::Exception
& ex
)
532 ex
._tao_print_exception (
533 ACE_TEXT ("ERROR: Unable to resolve name servers"));
537 // Create a bunch of objects in one context
538 // Note: strings to the naming service must be char, not wchar
541 // Bind one context level under root.
542 CosNaming::Name level1
;
544 level1
[0].id
= CORBA::string_dup ("level1_context");
545 CosNaming::NamingContext_var level1_context
;
546 level1_context
= root_context_1
->bind_new_context (level1
);
547 ACE_OS::thr_yield ();
549 for (i
=0; i
<o_breadth
; i
++)
551 // Instantiate a dummy object and bind it under the new context.
552 My_Test_Object
*impl1
= new My_Test_Object (i
+1);
553 Test_Object_var obj1
= impl1
->_this ();
555 impl1
->_remove_ref ();
560 ACE_OS::sprintf (wide_name
, "obj_%d", i
);
561 level1
[1].id
= CORBA::string_dup (wide_name
);
563 root_context_1
->bind (level1
, obj1
.in ());
564 ACE_OS::thr_yield ();
566 // See if the newly bound object is available in the
569 CORBA::Object_var obj1_on_replica
= root_context_1
->resolve (level1
);
571 catch (const CosNaming::NamingContext::NotFound
& ex
)
573 ex
._tao_print_exception (
574 ACE_TEXT ("INFO: Unable to resolve object from replica. Sleeping for a second.\n"));
576 // Give it a second to be processed
581 CORBA::Object_var obj1_on_replica
=
582 root_context_1
->resolve (level1
);
584 // We did find the object on the replica, but only after a wait.
585 // This would be caused by a race condition to access the variable.
586 ACE_ERROR ((LM_ERROR
,
587 ACE_TEXT ("INFO: Object appeared after a short ")
588 ACE_TEXT ("wait.\n")));
590 catch (const CosNaming::NamingContext::NotFound
& second_ex
)
592 second_ex
._tao_print_exception (
593 ACE_TEXT ("ERROR: It really is not there. Failing...\n"));
599 catch (const CORBA::Exception
& ex
)
601 ex
._tao_print_exception (
602 ACE_TEXT ("ERROR: Unable to create a lot of objects"));
606 // Create a deep context tree
609 CosNaming::NamingContext_var next_context
= root_context_1
;
610 for (i
=0; i
<c_depth
; i
++)
612 // Bind level1 context under root.
613 CosNaming::Name deep
;
616 ACE_OS::sprintf (deep_name
, "deep_%d", i
);
617 deep
[0].id
= CORBA::string_dup (deep_name
);
618 CosNaming::NamingContext_var deep_context
;
619 deep_context
= next_context
->bind_new_context (deep
);
620 ACE_OS::thr_yield ();
621 next_context
= deep_context
;
624 catch (const CORBA::Exception
& ex
)
626 ex
._tao_print_exception (
627 ACE_TEXT ("ERROR: Unable to create deep context"));
631 // Create a wide context tree
634 for (i
=0; i
<c_breadth
; i
++)
636 // Bind all level of context under root.
637 CosNaming::Name wide
;
640 ACE_OS::sprintf (wide_name
, "wide_%d", i
);
641 wide
[0].id
= CORBA::string_dup (wide_name
);
642 CosNaming::NamingContext_var wide_context
;
643 wide_context
= root_context_1
->bind_new_context (wide
);
644 ACE_OS::thr_yield ();
647 // Check if the new context is available in the replica
648 CORBA::Object_var obj1_on_replica
= root_context_1
->resolve (wide
);
649 // Make sure it is a context
650 CosNaming::NamingContext_var nc
=
651 CosNaming::NamingContext::_narrow (obj1_on_replica
.in ());
653 catch (const CosNaming::NamingContext::NotFound
&)
655 ACE_DEBUG ((LM_DEBUG
,
656 ACE_TEXT ("INFO: Unable to resolve wide context object from ")
657 ACE_TEXT ("replica. Sleeping for a second.\n")));
661 // Try again to see if it just was a race condition
663 CORBA::Object_var obj1_on_replica
= root_context_1
->resolve (wide
);
664 // We did find the object on the replica, but only after a wait.
665 // This would be caused by a race condition to access the variable.
666 ACE_ERROR (( LM_ERROR
,
667 ACE_TEXT ("INFO: Object appeared after a short ")
668 ACE_TEXT ("wait.\n")));
670 catch (const CosNaming::NamingContext::NotFound
& second_ex
)
672 second_ex
._tao_print_exception (
673 ACE_TEXT ("ERROR: It really is not there. Failing...\n"));
679 catch (const CORBA::Exception
& ex
)
681 ex
._tao_print_exception (
682 ACE_TEXT ("ERROR: Unable to create wide context"));
686 // Delete three selected things, one from each tree
688 // Remove the second to last object from the Naming Context
689 CosNaming::Name wide1
;
691 wide1
[0].id
= CORBA::string_dup ("level1_context");
693 ACE_OS::sprintf (wide_name
, "obj_%d", o_breadth
-2);
694 wide1
[1].id
= CORBA::string_dup (wide_name
);
695 root_context_1
->unbind (wide1
);
696 ACE_OS::thr_yield ();
698 bool retried
= false;
699 // Make sure it is gone from the replica
701 CORBA::Object_var obj1_on_replica
= root_context_1
->resolve (wide1
);
703 // An exception should be thrown by the above or
704 // there is an error. This means the replica did
705 // not register the loss of the context.
706 ACE_ERROR ((LM_ERROR
,
707 ACE_TEXT ("INFO: Unbound deep context not removed from ")
708 ACE_TEXT ("replica. Trying again...\n")));
709 retried
= true; // Mark this so it can be reported in catch block.
711 obj1_on_replica
= root_context_1
->resolve (wide1
);
713 ACE_ERROR_RETURN (( LM_ERROR
,
714 ACE_TEXT ("ERROR: Unbound context not removed from ")
715 ACE_TEXT ("on retry\n")),
718 catch (const CosNaming::NamingContext::NotFound
&)
720 // Not on replica --- as it should be.
721 if (retried
) // Was found on the retry
722 ACE_ERROR (( LM_ERROR
,
723 ACE_TEXT ("INFO: Was removed after short wait.\n")));
726 // Remove the second to last context from the wide root Naming Context
727 CosNaming::Name wide2
;
729 ACE_OS::sprintf (wide_name
, "wide_%d", c_breadth
-2);
730 wide2
[0].id
= CORBA::string_dup (wide_name
);
732 CORBA::Object_var result_obj_ref
= root_context_1
->resolve (wide2
);
734 CosNaming::NamingContext_var result_object
=
735 CosNaming::NamingContext::_narrow (result_obj_ref
.in ());
737 if (CORBA::is_nil (result_object
.in ()))
739 ACE_ERROR_RETURN ((LM_ERROR
,
740 ACE_TEXT ("ERROR: Problems with resolving wide context ")
741 ACE_TEXT ("- nil object ref.\n")),
745 result_object
->destroy();
746 root_context_1
->unbind (wide2
);
747 ACE_OS::thr_yield ();
749 // Remove the last context from the deep Naming Context
750 CosNaming::Name deep
;
751 deep
.length (c_depth
);
754 for (i
=0; i
<c_depth
; i
++)
756 ACE_OS::sprintf (deep_name
, "deep_%d", i
);
757 deep
[i
].id
= CORBA::string_dup (deep_name
);
760 result_obj_ref
= root_context_1
->resolve (deep
);
762 result_object
= CosNaming::NamingContext::_narrow (result_obj_ref
.in ());
763 if (CORBA::is_nil (result_object
.in ()))
765 ACE_ERROR_RETURN ((LM_ERROR
,
766 ACE_TEXT ("ERROR: Problems with resolving deep context ")
767 ACE_TEXT ("- nil object ref.\n")),
771 result_object
->destroy();
772 root_context_1
->unbind (deep
);
773 ACE_OS::thr_yield ();
776 // Make sure it is gone from the replica
778 CORBA::Object_var obj1_on_replica
= root_context_1
->resolve (deep
);
780 // An exception should be thrown by the above or
781 // there is an error. This means the replica did
782 // not register the loss of the context.
783 ACE_ERROR (( LM_ERROR
,
784 ACE_TEXT ("INFO: Unbound deep context not removed from ")
785 ACE_TEXT ("replica. Trying again...\n")));
787 retried
= true; // Mark this so it can be reported in catch block.
788 obj1_on_replica
= root_context_1
->resolve (deep
);
790 ACE_ERROR_RETURN ((LM_ERROR
,
791 ACE_TEXT ("ERROR: Unbound context not removed from ")
792 ACE_TEXT ("on retry\n")),
795 catch (const CosNaming::NamingContext::NotFound
&)
797 // Not on replica --- as it should be.
798 if (retried
) // Was found on the retry
799 ACE_ERROR (( LM_ERROR
,
800 ACE_TEXT ("INFO: Was removed after short wait.\n")));
803 catch (const CORBA::Exception
& ex
)
805 ex
._tao_print_exception (
806 ACE_TEXT ("ERROR: Unable to delete objects"));
810 // Now use the other name server to access 3 objects next to the
811 // deleted objects and the 3 deleted objects
814 // Access the last object from the Naming Context
815 CosNaming::Name wide
;
817 wide
[0].id
= CORBA::string_dup ("level1_context");
819 ACE_OS::sprintf (wide_name
, "obj_%d", o_breadth
-1);
820 wide
[1].id
= CORBA::string_dup (wide_name
);
821 CORBA::Object_var result_obj_ref
= root_context_1
->resolve (wide
);
822 Test_Object_var result_object
= Test_Object::_narrow (result_obj_ref
.in ());
823 if (CORBA::is_nil (result_object
.in ()))
825 ACE_ERROR_RETURN ((LM_ERROR
,
826 ACE_TEXT ("ERROR: Problems with resolving object from ")
827 ACE_TEXT ("redundant server - nil object ref.\n")),
831 catch (const CORBA::Exception
& ex
)
833 ex
._tao_print_exception (
834 ACE_TEXT ("ERROR: Unable to resolve object from redundant server"));
840 // Access the deleted second to last object from the Naming Context
841 CosNaming::Name wide
;
843 wide
[0].id
= CORBA::string_dup ("level1_context");
845 ACE_OS::sprintf (wide_name
, "obj_%d", o_breadth
-2);
846 wide
[1].id
= CORBA::string_dup (wide_name
);
848 CORBA::Object_var result_obj_ref
= root_context_1
->resolve (wide
);
850 ACE_ERROR_RETURN ((LM_ERROR
,
851 ACE_TEXT ("ERROR: Problems with resolving object from ")
852 ACE_TEXT ("redundant server - deleted object found.\n")),
855 catch (const CosNaming::NamingContext::NotFound
& ex
)
857 // expect exception since the context was deleted.
858 // Make sure the right exception reason is provided.
859 if (ex
.why
!= CosNaming::NamingContext::missing_node
)
861 ACE_ERROR_RETURN ((LM_ERROR
,
862 ACE_TEXT ("ERROR: Wrong exception returned during resolve.\n")),
866 catch (const CORBA::Exception
& ex
)
868 ex
._tao_print_exception (
869 ACE_TEXT ("ERROR: Wrong exception type returned from resolve.\n"));
875 // Access the last context from the wide Naming Context
876 CosNaming::Name wide
;
879 ACE_OS::sprintf (wide_name
, "wide_%d", c_breadth
-1);
880 wide
[0].id
= CORBA::string_dup (wide_name
);
882 CORBA::Object_var result_obj_ref
= root_context_1
->resolve (wide
);
884 CosNaming::NamingContext_var result_object
=
885 CosNaming::NamingContext::_narrow (result_obj_ref
.in ());
887 if (CORBA::is_nil (result_object
.in ()))
889 ACE_ERROR_RETURN (( LM_ERROR
,
890 ACE_TEXT ("ERROR: Problems with resolving wide context from ")
891 ACE_TEXT ("redundant server - nil object ref.\n")),
895 catch (const CosNaming::NamingContext::NotFound
&)
897 // Expected exception
899 catch (const CORBA::Exception
& ex
)
901 ex
._tao_print_exception ( ACE_TEXT ("ERROR: Unexpected Exception received.\n"));
907 // Access the deleted second to last object from the Naming Context
908 CosNaming::Name wide
;
911 ACE_OS::sprintf (wide_name
, "wide_%d", c_breadth
-2);
912 wide
[0].id
= CORBA::string_dup (wide_name
);
914 CORBA::Object_var result_obj_ref
= root_context_1
->resolve (wide
);
916 ACE_ERROR_RETURN ((LM_ERROR
,
917 ACE_TEXT ("ERROR: Problems with resolving wide context from ")
918 ACE_TEXT ("redundant server - deleted object found.\n")),
921 catch (const CosNaming::NamingContext::NotFound
&)
923 // Expected exception
925 catch (const CORBA::Exception
& ex
)
927 ex
._tao_print_exception ( ACE_TEXT ("ERROR: Unexpected Exception received.\n"));
933 // Access the deleted last context from the deep Naming Context
934 CosNaming::Name deep
;
935 deep
.length (c_depth
);
937 for (i
=0; i
<c_depth
; i
++)
939 ACE_OS::sprintf (deep_name
, "deep_%d", i
);
940 deep
[i
].id
= CORBA::string_dup (deep_name
);
943 CORBA::Object_var result_obj_ref
= root_context_1
->resolve (deep
);
945 ACE_ERROR_RETURN ((LM_ERROR
,
946 ACE_TEXT ("ERROR: Problems with resolving deep context from ")
947 ACE_TEXT ("redundant server - deleted object found.\n")),
950 catch (const CosNaming::NamingContext::NotFound
&)
952 // Expected exception
954 catch (const CORBA::Exception
& ex
)
956 ex
._tao_print_exception (
957 ACE_TEXT ("ERROR: Unexpected Exception received resolving ")
958 ACE_TEXT ("deep cxt from redundant server.\n"));
964 // Access the second to last object from the Naming Context
965 CosNaming::Name deep
;
966 deep
.length (c_depth
-1);
968 for (i
=0; i
<c_depth
-1; i
++)
970 ACE_OS::sprintf (deep_name
, "deep_%d", i
);
971 deep
[i
].id
= CORBA::string_dup (deep_name
);
974 CORBA::Object_var result_obj_ref
=
975 root_context_1
->resolve (deep
);
977 CosNaming::NamingContext_var result_object
=
978 CosNaming::NamingContext::_narrow (result_obj_ref
.in ());
980 if (CORBA::is_nil (result_object
.in ()))
982 ACE_ERROR_RETURN ((LM_ERROR
,
983 ACE_TEXT ("ERROR: Problems with resolving deep context from ")
984 ACE_TEXT ("redundant server - nil object ref.\n")),
988 catch (const CORBA::Exception
& ex
)
990 ex
._tao_print_exception (
991 ACE_TEXT ("ERROR: Unable to resolve deep context from redundant server"));
998 /// Failover ObjectGroup Test
1000 do_failover_objectgroup_test (
1001 CORBA::ORB_ptr theOrb
,
1007 ACE_UNUSED_ARG (c_breadth
);
1008 ACE_UNUSED_ARG (c_depth
);
1009 ACE_UNUSED_ARG (o_breadth
);
1011 const int RC_SUCCESS
= 0;
1012 const int RC_ERROR
= -1;
1014 FT_Naming::NamingManager_var naming_manager_1
;
1017 CORBA::ORB_var orb
= CORBA::ORB::_duplicate(theOrb
);
1018 if (CORBA::is_nil (orb
.in ()))
1020 ACE_ERROR_RETURN (( LM_ERROR
,
1021 ACE_TEXT ("ERROR: invalid orb\n")),
1025 if (CORBA::is_nil (nm1ref
))
1027 ACE_ERROR_RETURN (( LM_ERROR
,
1028 ACE_TEXT ("ERROR: invalid nm1\n")),
1032 ACE_DEBUG ((LM_DEBUG
, ACE_TEXT ("INFO: nm1ref: %s\n"), nm1ref
));
1034 CORBA::Object_var nm1obj
=
1035 orb
->string_to_object (ACE_TEXT_ALWAYS_CHAR (nm1ref
));
1037 if (CORBA::is_nil (nm1obj
.in ()))
1039 ACE_ERROR_RETURN (( LM_ERROR
,
1040 ACE_TEXT ("ERROR: invalid ior <%s>\n"),nm1ref
),
1044 naming_manager_1
= FT_Naming::NamingManager::_narrow (nm1obj
.in ());
1045 if (CORBA::is_nil (naming_manager_1
.in ()))
1047 ACE_ERROR_RETURN (( LM_ERROR
,
1048 ACE_TEXT ("ERROR: invalid ior <%s>\n"),nm1ref
),
1054 if (RC_SUCCESS
!= svc
.set_orb (theOrb
))
1056 ACE_ERROR_RETURN (( LM_ERROR
,
1057 ACE_TEXT ("ERROR: invalid orb\n")),
1061 if (RC_SUCCESS
!= svc
.set_naming_manager (naming_manager_1
.in ()))
1063 ACE_ERROR_RETURN (( LM_ERROR
,
1064 ACE_TEXT ("ERROR: invalid ior <%s>\n"),nm1ref
),
1069 const ACE_TCHAR
* test_group
= ACE_TEXT ("test_group");
1070 const ACE_TCHAR
* policy
= ACE_TEXT ("round");
1072 if (RC_SUCCESS
!= svc
.group_create (test_group
, policy
))
1074 ACE_ERROR_RETURN (( LM_ERROR
,
1075 ACE_TEXT ("ERROR: unable to create %s\n"),test_group
),
1079 if (false == svc
.group_exist(test_group
))
1081 ACE_ERROR_RETURN (( LM_ERROR
,
1082 ACE_TEXT ("ERROR: Object Group Not Found In Repository\n")),
1085 ACE_DEBUG (( LM_DEBUG
,
1086 ACE_TEXT ("INFO: Object Group Found In Repository\n")));
1091 catch (const CORBA::Exception
& ex
)
1093 ex
._tao_print_exception (
1094 ACE_TEXT ("ERROR: Unable to resolve name manager servers"));
1102 //==============================================================================
1104 //==============================================================================
1105 /// Persistence Name Test
1107 do_persistence_name_test (
1108 CORBA::ORB_ptr theOrb
,
1115 const int RC_ERROR
= -1;
1116 const int RC_SUCCESS
= 0;
1117 CosNaming::NamingContext_var root_context_1
;
1121 CORBA::ORB_var orb
= CORBA::ORB::_duplicate(theOrb
);
1123 if (CORBA::is_nil (orb
.in () ))
1125 ACE_ERROR_RETURN (( LM_ERROR
,
1126 ACE_TEXT ("ERROR: invalid orb\n")),
1130 if (CORBA::is_nil (ns1ref
))
1132 ACE_ERROR_RETURN (( LM_ERROR
,
1133 ACE_TEXT ("ERROR: invalid ns1\n")),
1137 CORBA::Object_var ns1obj
=
1138 orb
->string_to_object (ACE_TEXT_ALWAYS_CHAR (ns1ref
));
1140 if (CORBA::is_nil (ns1obj
.in ()))
1142 ACE_ERROR_RETURN (( LM_ERROR
,
1143 ACE_TEXT ("ERROR: invalid ior <%s>\n"),ns1ref
),
1147 root_context_1
= CosNaming::NamingContext::_narrow (ns1obj
.in ());
1149 if (CORBA::is_nil (root_context_1
.in ()))
1151 ACE_ERROR_RETURN (( LM_ERROR
,
1152 ACE_TEXT ("ERROR: invalid ior <%s>\n"),ns1ref
),
1156 catch (const CORBA::Exception
& ex
)
1158 ex
._tao_print_exception (ACE_TEXT ("ERROR: Unable to resolve name servers"));
1162 // Create a bunch of objects in one context
1163 // Note: strings to the naming service must be char, not wchar
1166 // Bind one context level under root.
1167 CosNaming::Name level1
;
1169 level1
[0].id
= CORBA::string_dup ("level1_context");
1171 if( false == validate_only
) {
1172 CosNaming::NamingContext_var level1_context
;
1173 level1_context
= root_context_1
->bind_new_context (level1
);
1174 ACE_OS::thr_yield ();
1177 for (i
=0; i
<o_breadth
; i
++)
1179 // Instantiate a dummy object and bind it under the new context.
1180 My_Test_Object
*impl1
= new My_Test_Object (i
+1);
1181 Test_Object_var obj1
= impl1
->_this ();
1182 impl1
->_remove_ref ();
1186 ACE_OS::sprintf (wide_name
, "obj_%d", i
);
1187 level1
[1].id
= CORBA::string_dup (wide_name
);
1189 if( false == validate_only
) {
1190 root_context_1
->bind (level1
, obj1
.in ());
1191 ACE_OS::thr_yield ();
1195 // See if the newly bound object is available in the repository
1197 CORBA::Object_var obj1_on_replica
= root_context_1
->resolve (level1
);
1199 catch (const CosNaming::NamingContext::NotFound
& ex
)
1201 ex
._tao_print_exception (
1202 ACE_TEXT ("ERROR: Unable to resolve object from repository. Sleeping for a second.\n"));
1208 CORBA::Object_var obj1_on_replica
= root_context_1
->resolve (level1
);
1209 // We did find the object on the repository, but only after a wait.
1210 // This would be caused by a race condition to access the variable.
1211 ACE_ERROR ((LM_ERROR
,
1212 ACE_TEXT ("INFO: Object appeared after a short wait.\n")));
1214 catch (const CosNaming::NamingContext::NotFound
& second_ex
)
1216 second_ex
._tao_print_exception (
1217 ACE_TEXT ("ERROR: It really is not there. Failing...\n"));
1223 catch (const CORBA::Exception
& ex
)
1225 ex
._tao_print_exception (
1226 ACE_TEXT ("ERROR: Unable to create or validate a lot of objects"));
1231 if( false == validate_only
) {
1232 // Create a deep context tree
1235 CosNaming::NamingContext_var next_context
= root_context_1
;
1236 for (i
=0; i
<c_depth
; i
++)
1238 // Bind level1 context under root.
1239 CosNaming::Name deep
;
1242 ACE_OS::sprintf (deep_name
, "deep_%d", i
);
1243 deep
[0].id
= CORBA::string_dup (deep_name
);
1245 CosNaming::NamingContext_var deep_context
;
1246 deep_context
= next_context
->bind_new_context (deep
);
1247 ACE_OS::thr_yield ();
1248 next_context
= deep_context
;
1251 catch (const CORBA::Exception
& ex
)
1253 ex
._tao_print_exception (ACE_TEXT ("ERROR: Unable to create deep context"));
1258 // Create a wide context tree
1261 for (i
=0; i
<c_breadth
; i
++)
1263 // Bind all level of context under root.
1264 CosNaming::Name wide
;
1267 ACE_OS::sprintf (wide_name
, "wide_%d", i
);
1268 wide
[0].id
= CORBA::string_dup (wide_name
);
1270 if( false == validate_only
) {
1271 CosNaming::NamingContext_var wide_context
;
1272 wide_context
= root_context_1
->bind_new_context (wide
);
1273 ACE_OS::thr_yield ();
1277 // Check if the new context is available in the repository
1278 CORBA::Object_var obj1_on_replica
=
1279 root_context_1
->resolve (wide
);
1281 // Make sure it is a context
1282 CosNaming::NamingContext_var nc
=
1283 CosNaming::NamingContext::_narrow (obj1_on_replica
.in ());
1285 catch (const CosNaming::NamingContext::NotFound
&)
1287 ACE_DEBUG ((LM_DEBUG
,
1288 ACE_TEXT ("INFO: Unable to resolve wide context object from ")
1289 ACE_TEXT ("repository. Sleeping for a second.\n")));
1293 // Try again to see if it just was a race condition
1295 CORBA::Object_var obj1_on_replica
= root_context_1
->resolve (wide
);
1296 // We did find the object on the replica, but only after a wait.
1297 // This would be caused by a race condition to access the variable.
1298 ACE_ERROR (( LM_ERROR
,
1299 ACE_TEXT ("INFO: Object appeared after a short ")
1300 ACE_TEXT ("wait.\n")));
1302 catch (const CosNaming::NamingContext::NotFound
& second_ex
)
1304 second_ex
._tao_print_exception (
1305 ACE_TEXT ("ERROR: It really is not there. Failing...\n"));
1311 catch (const CORBA::Exception
& ex
)
1313 ex
._tao_print_exception (
1314 ACE_TEXT ("ERROR: Unable to create or validate wide context"));
1322 /// Persistence ObjectGroup Test
1324 do_persistence_objectgroup_test (
1325 CORBA::ORB_ptr theOrb
,
1332 ACE_UNUSED_ARG (c_breadth
);
1333 ACE_UNUSED_ARG (c_depth
);
1334 ACE_UNUSED_ARG (o_breadth
);
1336 const int RC_ERROR
= -1;
1337 const int RC_SUCCESS
= 0;
1339 FT_Naming::NamingManager_var naming_manager_1
;
1342 CORBA::ORB_var orb
= CORBA::ORB::_duplicate(theOrb
);
1344 if (CORBA::is_nil (orb
.in ()))
1346 ACE_ERROR_RETURN (( LM_ERROR
,
1347 ACE_TEXT ("ERROR: invalid orb\n")),
1351 if (CORBA::is_nil (nm1ref
))
1353 ACE_ERROR_RETURN (( LM_ERROR
,
1354 ACE_TEXT ("ERROR: invalid nm1\n")),
1358 //ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("nm1ref: %s\n"), nm1ref));
1360 CORBA::Object_var nm1obj
=
1361 orb
->string_to_object (ACE_TEXT_ALWAYS_CHAR (nm1ref
));
1363 if (CORBA::is_nil (nm1obj
.in ()))
1365 ACE_ERROR_RETURN (( LM_ERROR
,
1366 ACE_TEXT ("ERROR: invalid ior <%s>\n"),nm1ref
),
1370 naming_manager_1
= FT_Naming::NamingManager::_narrow (nm1obj
.in ());
1371 if (CORBA::is_nil (naming_manager_1
.in ()))
1373 ACE_ERROR_RETURN (( LM_ERROR
,
1374 ACE_TEXT ("ERROR: invalid ior <%s>\n"),nm1ref
),
1378 NS_group_svc group_svc
;
1380 if( RC_SUCCESS
!= group_svc
.set_orb (theOrb
) )
1382 ACE_ERROR_RETURN (( LM_ERROR
,
1383 ACE_TEXT ("ERROR: invalid orb\n")),
1387 if( RC_SUCCESS
!= group_svc
.set_naming_manager (naming_manager_1
.in ()) )
1389 ACE_ERROR_RETURN (( LM_ERROR
,
1390 ACE_TEXT ("ERROR: invalid ior <%s>\n"),nm1ref
),
1394 /// get BasicGroup member object and verify that it reports the same location
1395 const ACE_TCHAR
* basic_group_name
= ACE_TEXT ("BasicGroup");
1397 if (false == group_svc
.group_exist(basic_group_name
))
1399 ACE_ERROR_RETURN (( LM_ERROR
,
1400 ACE_TEXT ("ERROR: Object Group %s Not Found In Repository\n"),
1404 ACE_DEBUG (( LM_DEBUG
,
1405 ACE_TEXT ("INFO: Object Group %s Found In Repository\n"),
1411 PortableGroup::ObjectGroup_var group_var
=
1412 naming_manager_1
->get_object_group_ref_from_name (
1413 ACE_TEXT_ALWAYS_CHAR (basic_group_name
));
1415 PortableGroup::Locations_var locations
=
1416 naming_manager_1
->locations_of_members (group_var
.in());
1418 for (unsigned int i
= 0; i
< locations
->length(); ++i
)
1420 const PortableGroup::Location
& loc
= locations
[i
];
1421 if (loc
.length() > 0) {
1422 ACE_DEBUG (( LM_DEBUG
,
1423 ACE_TEXT ("INFO: validating group member %C\n"),
1428 PortableGroup::Location
location_name (1);
1429 location_name
.length (1);
1430 location_name
[0].id
= CORBA::string_dup(loc
[0].id
.in());
1432 CORBA::Object_var ior_var
=
1433 naming_manager_1
->get_member_ref (group_var
.in(), location_name
);
1435 // Narrow it to a Basic object
1436 Test::Basic_var basic
= Test::Basic::_narrow (ior_var
.in ());
1437 if (CORBA::is_nil (basic
.in ()))
1439 ACE_ERROR_RETURN ((LM_ERROR
,
1440 ACE_TEXT ("ERROR: Unable to narrow from member ior from %C\n"),
1447 CORBA::String_var the_string
= basic
->get_string ();
1449 ACE_DEBUG (( LM_DEBUG
,
1450 ACE_TEXT ("INFO: object group member at %C reports ")
1455 if ( ACE_OS::strcmp (the_string
.in (), loc
[0].id
.in()) != 0 ) {
1456 ACE_ERROR_RETURN ((LM_ERROR
,
1457 ACE_TEXT ("ERROR: object group member at %C reports %C\n\n"),
1463 catch (const CORBA::Exception
& ex
)
1465 ex
._tao_print_exception ("ERROR: invoking get_string on Basic object.\n");
1469 catch (const PortableGroup::MemberNotFound
&)
1471 ACE_ERROR_RETURN ((LM_ERROR
,
1472 ACE_TEXT ("ERROR: Unable to find member location %C\n"),
1479 std::string
member_data_file ("member.dat");
1481 // Test persisting group modification in first pass and reading
1482 // the persistent data in the second pass.
1483 // This is done by removal of a group member in first pass and
1484 // then adding it back in the second, validation, pass,
1485 // verifying that member count is what it was before the removal.
1486 // This is tracked by saving member data to a file
1487 // in the first pass and then reading it in the second pass.
1493 PortableGroup::Locations_var locations
=
1494 naming_manager_1
->locations_of_members (group_var
.in());
1495 const PortableGroup::Location
& loc
= locations
.inout ()[0];
1496 unsigned int num_locations
= locations
->length();
1498 PortableGroup::Location
location_name (1);
1499 location_name
.length (1);
1500 location_name
[0].id
= CORBA::string_dup(loc
[0].id
.in());
1502 CORBA::Object_var ior_var
=
1503 naming_manager_1
->get_member_ref (group_var
.in(), location_name
);
1505 // Narrow it to a Basic object
1506 Test::Basic_var basic
= Test::Basic::_narrow (ior_var
.in ());
1507 if (CORBA::is_nil (basic
.in ()))
1509 ACE_ERROR_RETURN ((LM_ERROR
,
1510 ACE_TEXT ("ERROR: Unable to narrow from ")
1511 ACE_TEXT ("member ior from %C\n"),
1516 naming_manager_1
->remove_member (group_var
.in(),
1519 // Save data for the removed member
1520 CORBA::String_var member_str
= theOrb
->object_to_string(basic
.in ());
1521 std::ofstream
out(member_data_file
.c_str ());
1522 out
<< num_locations
<< std::endl
;
1523 out
<< loc
[0].id
.in () << std::endl
;
1524 out
<< member_str
.in() << std::endl
;
1526 catch (const PortableGroup::ObjectGroupNotFound
&)
1528 ACE_ERROR_RETURN ((LM_ERROR
,
1529 ACE_TEXT ("ERROR: Unable to find group %C\n"),
1533 catch (const CORBA::Exception
&)
1535 ACE_ERROR_RETURN ((LM_ERROR
,
1536 ACE_TEXT ("ERROR: Unable to remove members ")
1537 ACE_TEXT ("for group %C\n"),
1544 // Read in member data
1545 std::ifstream
in (member_data_file
.c_str ());
1546 unsigned int num_locations
;
1547 in
>> num_locations
;
1548 std::string location_str
;
1550 std::string member_ior
;
1555 ACE_ERROR_RETURN ((LM_ERROR
,
1556 ACE_TEXT ("ERROR: Unable to read member data ")
1557 ACE_TEXT ("from file %C\n"),
1558 member_data_file
.c_str ()),
1562 CORBA::Object_var member
=
1563 theOrb
->string_to_object(member_ior
.c_str ());
1564 PortableGroup::Location
location_name (1);
1565 location_name
.length (1);
1566 location_name
[0].id
= CORBA::string_dup(location_str
.c_str ());
1567 PortableGroup::ObjectGroup_var group_var
=
1568 naming_manager_1
->get_object_group_ref_from_name
1569 (ACE_TEXT_ALWAYS_CHAR (basic_group_name
));
1573 naming_manager_1
->add_member (group_var
.in (),
1576 PortableGroup::Locations_var locations
=
1577 naming_manager_1
->locations_of_members (group_var
.in ());
1579 // Verify number of locations was what it was before removing/adding
1580 if (locations
->length () != num_locations
)
1582 ACE_ERROR ((LM_ERROR
,
1583 ACE_TEXT ("ERROR: Expected %d members but got %d ")
1584 ACE_TEXT ("instead\n"),
1585 num_locations
, locations
->length ()));
1588 // Verify data wasn't corrupt so still can still get
1589 // group information
1590 FT_Naming::GroupNames_var group_names
=
1591 naming_manager_1
->groups (FT_Naming::ROUND_ROBIN
);
1592 if (group_names
->length () == 0)
1594 ACE_ERROR ((LM_ERROR
,
1595 ACE_TEXT ("ERROR: No group names found")));
1598 catch (const CORBA::Exception
& ex
)
1600 ex
._tao_print_exception ("CORBA::Exception caught:");
1601 ACE_ERROR_RETURN ((LM_ERROR
,
1602 ACE_TEXT ("ERROR: Unable to remove member for group %C\n"),
1609 catch (const PortableGroup::ObjectGroupNotFound
&)
1611 ACE_ERROR_RETURN ((LM_ERROR
,
1612 ACE_TEXT ("ERROR: Unable to find group %C\n"),
1616 catch (const CORBA::Exception
&)
1618 ACE_ERROR_RETURN ((LM_ERROR
,
1619 ACE_TEXT ("ERROR: Unable to list members for group %C\n"),
1625 catch (const CORBA::Exception
& ex
)
1627 ex
._tao_print_exception (
1628 ACE_TEXT ("ERROR: Unable To Resolve Name Manager Servers"));
1635 //==============================================================================
1637 //==============================================================================
1638 /// Equivalence Name Test
1640 do_equivalence_name_test (
1641 CORBA::ORB_ptr theOrb
,
1648 const int RC_SUCCESS
= 0;
1649 const int RC_ERROR
= -1;
1651 CosNaming::NamingContext_var root_context_1
;
1652 CosNaming::NamingContext_var root_context_2
;
1656 CORBA::ORB_var orb
= CORBA::ORB::_duplicate(theOrb
);
1658 if (CORBA::is_nil (orb
.in ()))
1660 ACE_ERROR_RETURN (( LM_ERROR
,
1661 ACE_TEXT ("ERROR: invalid orb\n")),
1665 if (CORBA::is_nil (ns1ref
))
1667 ACE_ERROR_RETURN (( LM_ERROR
,
1668 ACE_TEXT ("ERROR: invalid ns1\n")),
1672 if (CORBA::is_nil (ns2ref
))
1674 ACE_ERROR_RETURN (( LM_ERROR
,
1675 ACE_TEXT ("ERROR: invalid ns2\n")),
1679 CORBA::Object_var ns1obj
=
1680 orb
->string_to_object (ACE_TEXT_ALWAYS_CHAR (ns1ref
));
1682 CORBA::Object_var ns2obj
=
1683 orb
->string_to_object (ACE_TEXT_ALWAYS_CHAR (ns2ref
));
1685 if (CORBA::is_nil (ns1obj
.in ()))
1687 ACE_ERROR_RETURN (( LM_ERROR
,
1688 ACE_TEXT ("ERROR: invalid ior <%s>\n"),ns1ref
),
1692 if (CORBA::is_nil (ns2obj
.in ()))
1694 ACE_ERROR_RETURN (( LM_ERROR
,
1695 ACE_TEXT ("ERROR: invalid ior <%s>\n"),ns2ref
),
1699 root_context_1
= CosNaming::NamingContext::_narrow (ns1obj
.in ());
1700 root_context_2
= CosNaming::NamingContext::_narrow (ns2obj
.in ());
1702 if (CORBA::is_nil (root_context_1
.in ()))
1704 ACE_ERROR_RETURN (( LM_ERROR
,
1705 ACE_TEXT ("ERROR: invalid ior <%s>\n"),ns1ref
),
1709 if (CORBA::is_nil (root_context_2
.in ()))
1711 ACE_ERROR_RETURN (( LM_ERROR
,
1712 ACE_TEXT ("ERROR: invalid ior <%s>\n"),ns2ref
),
1716 /// Make sure the two naming manager references point to different objects
1717 if ( true == root_context_1
->_stubobj ()->is_equivalent (
1718 root_context_2
.in ()))
1720 ACE_ERROR_RETURN (( LM_ERROR
,
1721 ACE_TEXT ("ERROR: ns1ref is equivalent to ns2ref\n")),
1725 ACE_DEBUG ((LM_DEBUG
,
1726 ACE_TEXT ("INFO: ns1ref is not equivalent to ns2ref\n")));
1729 root_context_1
->_stubobj ()->base_profiles ().profile_count ();
1732 root_context_2
->_stubobj ()->base_profiles ().profile_count ();
1735 ACE_DEBUG ((LM_DEBUG
,
1736 ACE_TEXT ("INFO: ns1ref profile count: %d\n"),
1739 ACE_DEBUG ((LM_DEBUG
,
1740 ACE_TEXT ("INFO: ns2ref profile count: %d\n"),
1743 catch (const CORBA::Exception
& ex
)
1745 ex
._tao_print_exception (ACE_TEXT ("ERROR: Unable to resolve name servers"));
1749 // Create a bunch of objects in one context
1750 // Note: strings to the naming service must be char, not wchar
1753 // Bind one context level under root.
1754 CosNaming::Name level1
;
1756 level1
[0].id
= CORBA::string_dup ("level1_context");
1757 CosNaming::NamingContext_var level1_context
;
1758 level1_context
= root_context_1
->bind_new_context (level1
);
1759 ACE_OS::thr_yield ();
1761 for (i
=0; i
<o_breadth
; i
++)
1763 // Instantiate a dummy object and bind it under the new context.
1764 My_Test_Object
*impl1
= new My_Test_Object (i
+1);
1765 Test_Object_var obj1
= impl1
->_this ();
1766 impl1
->_remove_ref ();
1770 ACE_OS::sprintf (wide_name
, "obj_%d", i
);
1771 level1
[1].id
= CORBA::string_dup (wide_name
);
1772 root_context_1
->bind (level1
, obj1
.in ());
1773 ACE_OS::thr_yield ();
1775 // See if the newly bound object is available in the
1778 CORBA::Object_var obj1_on_replica
= root_context_2
->resolve (level1
);
1780 catch (const CosNaming::NamingContext::NotFound
& )
1782 ACE_DEBUG ((LM_INFO
,
1783 "INFO: Unable to resolve object from replica. "
1784 "Sleeping for a second.\n"));
1790 CORBA::Object_var obj1_on_replica
= root_context_2
->resolve (level1
);
1791 // We did find the object on the replica, but only after a wait.
1792 // This would be caused by a race condition to access the variable.
1793 ACE_ERROR ((LM_ERROR
,
1794 ACE_TEXT ("INFO: Object appeared after a short ")
1795 ACE_TEXT ("wait.\n")));
1797 catch (const CosNaming::NamingContext::NotFound
& second_ex
)
1799 second_ex
._tao_print_exception (
1800 ACE_TEXT ("ERROR: It really is not there. Failing...\n"));
1806 catch (const CORBA::Exception
& ex
)
1808 ex
._tao_print_exception (
1809 ACE_TEXT ("ERROR: Unable to create a lot of objects"));
1813 // Create a deep context tree
1816 CosNaming::NamingContext_var next_context
= root_context_1
;
1817 for (i
=0; i
<c_depth
; i
++)
1819 // Bind level1 context under root.
1820 CosNaming::Name deep
;
1823 ACE_OS::sprintf (deep_name
, "deep_%d", i
);
1824 deep
[0].id
= CORBA::string_dup (deep_name
);
1825 CosNaming::NamingContext_var deep_context
;
1826 deep_context
= next_context
->bind_new_context (deep
);
1827 ACE_OS::thr_yield ();
1828 next_context
= deep_context
;
1831 catch (const CORBA::Exception
& ex
)
1833 ex
._tao_print_exception (
1834 ACE_TEXT ("ERROR: Unable to create deep context"));
1838 // Create a wide context tree
1841 for (i
=0; i
<c_breadth
; i
++)
1843 // Bind all level of context under root.
1844 CosNaming::Name wide
;
1847 ACE_OS::sprintf (wide_name
, "wide_%d", i
);
1848 wide
[0].id
= CORBA::string_dup (wide_name
);
1849 CosNaming::NamingContext_var wide_context
;
1850 wide_context
= root_context_1
->bind_new_context (wide
);
1851 ACE_OS::thr_yield ();
1854 // Check if the new context is available in the replica
1855 CORBA::Object_var obj1_on_replica
=
1856 root_context_2
->resolve (wide
);
1858 // Make sure it is a context
1859 CosNaming::NamingContext_var nc
=
1860 CosNaming::NamingContext::_narrow (obj1_on_replica
.in ());
1862 catch (const CosNaming::NamingContext::NotFound
&)
1864 ACE_DEBUG ((LM_DEBUG
,
1865 ACE_TEXT ("INFO: Unable to resolve wide context object from ")
1866 ACE_TEXT ("replica. Sleeping for a second.\n")));
1870 // Try again to see if it just was a race condition
1872 CORBA::Object_var obj1_on_replica
=
1873 root_context_2
->resolve (wide
);
1875 // We did find the object on the replica, but only after a wait.
1876 // This would be caused by a race condition to access the variable.
1877 ACE_ERROR ((LM_ERROR
,
1878 ACE_TEXT ("INFO: Object appeared after a ")
1879 ACE_TEXT ("short wait.\n")));
1881 catch (const CosNaming::NamingContext::NotFound
& second_ex
)
1883 second_ex
._tao_print_exception (
1884 ACE_TEXT ("ERROR: It really is not there. Failing...\n"));
1890 catch (const CORBA::Exception
& ex
)
1892 ex
._tao_print_exception (
1893 ACE_TEXT ("ERROR: Unable to create wide context"));
1897 // Delete three selected things, one from each tree
1899 // Remove the second to last object from the Naming Context
1900 CosNaming::Name wide1
;
1903 wide1
[0].id
= CORBA::string_dup ("level1_context");
1906 ACE_OS::sprintf (wide_name
, "obj_%d", o_breadth
-2);
1907 wide1
[1].id
= CORBA::string_dup (wide_name
);
1908 root_context_1
->unbind (wide1
);
1909 ACE_OS::thr_yield ();
1911 bool retried
= false;
1912 // Make sure it is gone from the replica
1914 CORBA::Object_var obj1_on_replica
= root_context_2
->resolve (wide1
);
1916 // An exception should be thrown by the above or
1917 // there is an error. This means the replica did
1918 // not register the loss of the context.
1919 ACE_ERROR (( LM_ERROR
,
1920 ACE_TEXT ("INFO: Unbound deep context not removed from ")
1921 ACE_TEXT ("replica. Trying again...\n")));
1923 retried
= true; // Mark this so it can be reported in catch block.
1924 obj1_on_replica
= root_context_2
->resolve (wide1
);
1926 ACE_ERROR_RETURN (( LM_ERROR
,
1927 ACE_TEXT ("ERROR: Unbound context not removed from ")
1928 ACE_TEXT ("on retry\n")),
1931 catch (const CosNaming::NamingContext::NotFound
&)
1933 // Not on replica --- as it should be.
1934 if (retried
) // Was found on the retry
1935 ACE_ERROR ((LM_ERROR
,
1936 ACE_TEXT ("INFO: Was removed after short wait.\n")));
1939 // Remove the second to last context from the wide root Naming Context
1940 CosNaming::Name wide2
;
1942 ACE_OS::sprintf (wide_name
, "wide_%d", c_breadth
-2);
1943 wide2
[0].id
= CORBA::string_dup (wide_name
);
1945 CORBA::Object_var result_obj_ref
= root_context_1
->resolve (wide2
);
1947 CosNaming::NamingContext_var result_object
=
1948 CosNaming::NamingContext::_narrow (result_obj_ref
.in ());
1950 if (CORBA::is_nil (result_object
.in ()))
1952 ACE_ERROR_RETURN (( LM_ERROR
,
1953 ACE_TEXT ("ERROR: Problems with resolving wide")
1954 ACE_TEXT (" context - nil object ref.\n")),
1958 result_object
->destroy();
1959 root_context_1
->unbind (wide2
);
1960 ACE_OS::thr_yield ();
1962 // Remove the last context from the deep Naming Context
1963 CosNaming::Name deep
;
1964 deep
.length (c_depth
);
1966 for (i
=0; i
<c_depth
; i
++)
1968 ACE_OS::sprintf (deep_name
, "deep_%d", i
);
1969 deep
[i
].id
= CORBA::string_dup (deep_name
);
1971 result_obj_ref
= root_context_1
->resolve (deep
);
1972 result_object
= CosNaming::NamingContext::_narrow (result_obj_ref
.in ());
1973 if (CORBA::is_nil (result_object
.in ()))
1975 ACE_ERROR_RETURN ((LM_ERROR
,
1976 ACE_TEXT ("ERROR: Problems with resolving deep")
1977 ACE_TEXT (" context - nil object ref.\n")),
1980 result_object
->destroy();
1981 root_context_1
->unbind (deep
);
1982 ACE_OS::thr_yield ();
1985 // Make sure it is gone from the replica
1987 CORBA::Object_var obj1_on_replica
= root_context_2
->resolve (deep
);
1989 // An exception should be thrown by the above or
1990 // there is an error. This means the replica did
1991 // not register the loss of the context.
1992 ACE_ERROR (( LM_ERROR
,
1993 ACE_TEXT ("INFO: Unbound deep context not removed from")
1994 ACE_TEXT ("replica. Trying again...\n")));
1996 retried
= true; // Mark this so it can be reported in catch block.
1997 obj1_on_replica
= root_context_2
->resolve (deep
);
1999 ACE_ERROR_RETURN (( LM_ERROR
,
2000 ACE_TEXT ("ERROR: Unbound context not removed from")
2001 ACE_TEXT (" on retry\n")),
2004 catch (const CosNaming::NamingContext::NotFound
&)
2006 // Not on replica --- as it should be.
2007 if (retried
) // Was found on the retry
2008 ACE_ERROR (( LM_ERROR
,
2009 ACE_TEXT ("INFO: Was removed after short wait.\n")));
2012 catch (const CORBA::Exception
& ex
)
2014 ex
._tao_print_exception (
2015 ACE_TEXT ("ERROR: Unable to delete objects"));
2019 // Now use the other name server to access 3 objects next to the
2020 // deleted objects and the 3 deleted objects
2023 // Access the last object from the Naming Context
2024 CosNaming::Name wide
;
2026 wide
[0].id
= CORBA::string_dup ("level1_context");
2028 ACE_OS::sprintf (wide_name
, "obj_%d", o_breadth
-1);
2029 wide
[1].id
= CORBA::string_dup (wide_name
);
2030 CORBA::Object_var result_obj_ref
= root_context_2
->resolve (wide
);
2031 Test_Object_var result_object
= Test_Object::_narrow (result_obj_ref
.in ());
2033 if (CORBA::is_nil (result_object
.in ()))
2035 ACE_ERROR_RETURN ((LM_ERROR
,
2036 ACE_TEXT ("ERROR: Problems with resolving object ")
2037 ACE_TEXT ("from redundant server ")
2038 ACE_TEXT ("- nil object ref.\n")),
2042 catch (const CORBA::Exception
& ex
)
2044 ex
._tao_print_exception (
2045 ACE_TEXT ("ERROR: Unable to resolve object from redundant server"));
2051 // Access the deleted second to last object from the Naming Context
2052 CosNaming::Name wide
;
2054 wide
[0].id
= CORBA::string_dup ("level1_context");
2056 ACE_OS::sprintf (wide_name
, "obj_%d", o_breadth
-2);
2057 wide
[1].id
= CORBA::string_dup (wide_name
);
2059 CORBA::Object_var result_obj_ref
= root_context_2
->resolve (wide
);
2061 ACE_ERROR_RETURN ((LM_ERROR
,
2062 ACE_TEXT ("ERROR: Problems with resolving object from ")
2063 ACE_TEXT ("redundant server - deleted object found.\n")),
2066 catch (const CosNaming::NamingContext::NotFound
& ex
)
2068 // expect exception since the context was deleted.
2069 // Make sure the right exception reason is provided.
2070 if (ex
.why
!= CosNaming::NamingContext::missing_node
)
2071 ACE_ERROR_RETURN (( LM_ERROR
,
2072 ACE_TEXT ("ERROR: Wrong exception returned during ")
2073 ACE_TEXT ("resolve.\n")),
2076 catch (const CORBA::Exception
& ex
)
2078 ex
._tao_print_exception (
2079 ACE_TEXT ("ERROR: Wrong exception type returned from resolve.\n"));
2085 // Access the last context from the wide Naming Context
2086 CosNaming::Name wide
;
2089 ACE_OS::sprintf (wide_name
, "wide_%d", c_breadth
-1);
2090 wide
[0].id
= CORBA::string_dup (wide_name
);
2091 CORBA::Object_var result_obj_ref
= root_context_2
->resolve (wide
);
2093 CosNaming::NamingContext_var result_object
=
2094 CosNaming::NamingContext::_narrow (result_obj_ref
.in ());
2096 if (CORBA::is_nil (result_object
.in ()))
2098 ACE_ERROR_RETURN ((LM_ERROR
,
2099 ACE_TEXT ("ERROR: Problems with resolving wide ")
2100 ACE_TEXT ("context from redundant server ")
2101 ACE_TEXT ("- nil object ref.\n")),
2105 catch (const CosNaming::NamingContext::NotFound
&)
2107 // Expected exception
2109 catch (const CORBA::Exception
& ex
)
2111 ex
._tao_print_exception ( ACE_TEXT ("ERROR: Unexpected Exception ")
2112 ACE_TEXT ("received.\n"));
2118 // Access the deleted second to last object from the Naming Context
2119 CosNaming::Name wide
;
2122 ACE_OS::sprintf (wide_name
, "wide_%d", c_breadth
-2);
2123 wide
[0].id
= CORBA::string_dup (wide_name
);
2124 CORBA::Object_var result_obj_ref
= root_context_2
->resolve (wide
);
2126 ACE_ERROR_RETURN ((LM_ERROR
,
2127 ACE_TEXT ("ERROR: Problems with resolving wide context ")
2128 ACE_TEXT ("from redundant server ")
2129 ACE_TEXT ("- deleted object found.\n")),
2132 catch (const CosNaming::NamingContext::NotFound
&)
2134 // Expected exception
2136 catch (const CORBA::Exception
& ex
)
2138 ex
._tao_print_exception ( ACE_TEXT ("ERROR: Unexpected Exception ")
2139 ACE_TEXT ("received.\n"));
2145 // Access the deleted last context from the deep Naming Context
2146 CosNaming::Name deep
;
2147 deep
.length (c_depth
);
2149 for (i
=0; i
<c_depth
; i
++)
2151 ACE_OS::sprintf (deep_name
, "deep_%d", i
);
2152 deep
[i
].id
= CORBA::string_dup (deep_name
);
2154 CORBA::Object_var result_obj_ref
= root_context_1
->resolve (deep
);
2156 ACE_ERROR_RETURN ((LM_ERROR
,
2157 ACE_TEXT ("ERROR: Problems with resolving deep context ")
2158 ACE_TEXT ("from redundant server ")
2159 ACE_TEXT ("- deleted object found.\n")),
2162 catch (const CosNaming::NamingContext::NotFound
&)
2164 // Expected exception
2166 catch (const CORBA::Exception
& ex
)
2168 ex
._tao_print_exception (
2169 ACE_TEXT ("ERROR: Unexpected Exception received resolving ")
2170 ACE_TEXT ("deep cxt from redundant server.\n"));
2176 // Access the second to last object from the Naming Context
2177 CosNaming::Name deep
;
2178 deep
.length (c_depth
-1);
2180 for (i
=0; i
<c_depth
-1; i
++)
2182 ACE_OS::sprintf (deep_name
, "deep_%d", i
);
2183 deep
[i
].id
= CORBA::string_dup (deep_name
);
2185 CORBA::Object_var result_obj_ref
= root_context_1
->resolve (deep
);
2187 CosNaming::NamingContext_var result_object
=
2188 CosNaming::NamingContext::_narrow (result_obj_ref
.in ());
2190 if (CORBA::is_nil (result_object
.in ()))
2192 ACE_ERROR_RETURN ((LM_ERROR
,
2193 ACE_TEXT ("ERROR: Problems with resolving deep ")
2194 ACE_TEXT ("context from redundant server ")
2195 ACE_TEXT ("- nil object ref.\n")),
2199 catch (const CORBA::Exception
& ex
)
2201 ex
._tao_print_exception (
2202 ACE_TEXT ("ERROR: Unable to resolve deep context from redundant server."));
2210 /// Equivalence ObjectGroup Test
2212 do_equivalence_objectgroup_test (
2213 CORBA::ORB_ptr theOrb
,
2220 ACE_UNUSED_ARG (c_breadth
);
2221 ACE_UNUSED_ARG (c_depth
);
2222 ACE_UNUSED_ARG (o_breadth
);
2224 const int RC_SUCCESS
= 0;
2225 const int RC_ERROR
= -1;
2226 int error_count
= 0;
2229 FT_Naming::NamingManager_var naming_manager_1
;
2230 FT_Naming::NamingManager_var naming_manager_2
;
2233 CORBA::ORB_var orb
= CORBA::ORB::_duplicate(theOrb
);
2234 if (CORBA::is_nil (orb
.in ()))
2236 ACE_ERROR_RETURN (( LM_ERROR
,
2237 ACE_TEXT ("ERROR: invalid orb\n")),
2241 if (CORBA::is_nil (nm1ref
))
2243 ACE_ERROR_RETURN (( LM_ERROR
,
2244 ACE_TEXT ("ERROR: invalid nm1\n")),
2248 ACE_DEBUG (( LM_DEBUG
,
2249 ACE_TEXT ("INFO: nm1ref: %s\n"),
2252 CORBA::Object_var nm1obj
=
2253 orb
->string_to_object (ACE_TEXT_ALWAYS_CHAR (nm1ref
));
2255 if (CORBA::is_nil (nm1obj
.in ()))
2257 ACE_ERROR_RETURN (( LM_ERROR
,
2258 ACE_TEXT ("ERROR: invalid ior <%s>\n"),
2263 naming_manager_1
= FT_Naming::NamingManager::_narrow (nm1obj
.in ());
2264 if (CORBA::is_nil (naming_manager_1
.in ()))
2266 ACE_ERROR_RETURN (( LM_ERROR
,
2267 ACE_TEXT ("ERROR: invalid ior <%s>\n"),
2272 if (CORBA::is_nil (nm2ref
))
2274 ACE_ERROR_RETURN (( LM_ERROR
,
2275 ACE_TEXT ("ERROR: invalid nm2\n")),
2279 ACE_DEBUG (( LM_DEBUG
,
2280 ACE_TEXT ("INFO: nm2ref: %s\n"),
2283 CORBA::Object_var nm2obj
=
2284 orb
->string_to_object (ACE_TEXT_ALWAYS_CHAR (nm2ref
));
2286 if (CORBA::is_nil (nm2obj
.in ()))
2288 ACE_ERROR_RETURN (( LM_ERROR
,
2289 ACE_TEXT ("ERROR: invalid ior <%s>\n"),
2294 naming_manager_2
= FT_Naming::NamingManager::_narrow (nm2obj
.in ());
2296 if (CORBA::is_nil (naming_manager_2
.in ()))
2298 ACE_ERROR_RETURN (( LM_ERROR
,
2299 ACE_TEXT ("ERROR: invalid ior <%s>\n"),
2304 /// Make sure the two naming manager references point to different objects
2305 if ( true == naming_manager_1
->_stubobj ()->is_equivalent (
2306 naming_manager_2
.in ()))
2308 ACE_ERROR_RETURN (( LM_ERROR
,
2309 ACE_TEXT ("ERROR: nm1ref is equivalent to nm2ref\n")),
2313 ACE_DEBUG ((LM_DEBUG
,
2314 ACE_TEXT ("INFO: nm1ref is not equivalent to nm2ref\n")));
2316 naming_manager_1
->_stubobj ()->base_profiles ().profile_count ();
2319 naming_manager_2
->_stubobj ()->base_profiles ().profile_count ();
2322 ACE_DEBUG ((LM_DEBUG
,
2323 ACE_TEXT ("INFO: nm1ref profile count: %d\n"),
2326 ACE_DEBUG ((LM_DEBUG
,
2327 ACE_TEXT ("INFO: nm2ref profile count: %d\n"),
2331 /// Setup 1st NS_group_svc with 1st Naming Manager
2333 if (RC_SUCCESS
!= svc1
.set_orb (theOrb
))
2335 ACE_ERROR_RETURN (( LM_ERROR
,
2336 ACE_TEXT ("ERROR: invalid orb\n")),
2340 if (RC_SUCCESS
!= svc1
.set_naming_manager (naming_manager_1
.in ()))
2342 ACE_ERROR_RETURN (( LM_ERROR
,
2343 ACE_TEXT ("ERROR: invalid ior <%s>\n"),
2348 /// Setup 2nd NS_group_svc with 2nd Naming Manager
2350 if (RC_SUCCESS
!= svc2
.set_orb (theOrb
))
2352 ACE_ERROR_RETURN (( LM_ERROR
,
2353 ACE_TEXT ("ERROR: invalid orb\n")),
2357 if (RC_SUCCESS
!= svc2
.set_naming_manager (naming_manager_2
.in ()))
2359 ACE_ERROR_RETURN (( LM_ERROR
,
2360 ACE_TEXT ("ERROR: invalid ior <%s>\n"),nm2ref
),
2364 /// Now validate seamless operations between the two instances of NS_group
2365 const ACE_TCHAR
* policy
= ACE_TEXT ("round");
2366 const ACE_TCHAR
* test_group_1
= ACE_TEXT ("test_group_1");
2367 const ACE_TCHAR
* test_group_2
= ACE_TEXT ("test_group_2");
2369 if (RC_SUCCESS
!= svc1
.group_create (test_group_1
, policy
))
2371 ACE_ERROR_RETURN (( LM_ERROR
,
2372 ACE_TEXT ("ERROR: Unable to create %s\n"),
2377 if (RC_SUCCESS
!= svc2
.group_create (test_group_2
, policy
))
2379 ACE_ERROR_RETURN (( LM_ERROR
,
2380 ACE_TEXT ("ERROR: Unable to create %s\n"),
2385 if (false == svc1
.group_exist(test_group_1
))
2388 ACE_DEBUG (( LM_DEBUG
,
2389 ACE_TEXT ("ERROR: Primary Not Able To Find Object Group ")
2390 ACE_TEXT ("%s Created By Primary In Repository\n"),
2393 ACE_DEBUG (( LM_DEBUG
,
2394 ACE_TEXT ("INFO: Primary Found Object Group %s Created By ")
2395 ACE_TEXT ("Primary In Repository\n"),
2399 if (false == svc2
.group_exist(test_group_2
))
2402 ACE_DEBUG (( LM_DEBUG
,
2403 ACE_TEXT ("ERROR: Backup Not Able To Find Object Group %s ")
2404 ACE_TEXT ("Created By Backup In Repository\n"),
2407 ACE_DEBUG (( LM_DEBUG
,
2408 ACE_TEXT ("INFO: Backup Found Object Group %s Created By ")
2409 ACE_TEXT ("Backup In Repository\n"),
2413 if (false == svc1
.group_exist(test_group_2
))
2416 ACE_DEBUG (( LM_DEBUG
,
2417 ACE_TEXT ("ERROR: Primary Not Able To Find Object Group %s ")
2418 ACE_TEXT ("Created By Backup In Repository\n"),
2421 ACE_DEBUG (( LM_DEBUG
,
2422 ACE_TEXT ("INFO: Primary Found Object Group %s Created By ")
2423 ACE_TEXT ("Backup In Repository\n"),
2427 if (false == svc2
.group_exist(test_group_1
))
2430 ACE_DEBUG (( LM_DEBUG
,
2431 ACE_TEXT ("ERROR: Backup Not Able To Find Object Group %s ")
2432 ACE_TEXT ("Created By Primary In Repository\n"),
2435 ACE_DEBUG (( LM_DEBUG
,
2436 ACE_TEXT ("INFO: Backup Found Object Group %s Created By ")
2437 ACE_TEXT ("Primary In Repository\n"),
2442 catch (const CORBA::Exception
& ex
)
2445 ex
._tao_print_exception (
2446 ACE_TEXT ("ERROR: Unable to resolve name manager servers"));
2449 return (error_count
> 0) ? RC_ERROR
: RC_SUCCESS
;