Revert "Use a variable on the stack to not have a temporary in the call"
[ACE_TAO.git] / TAO / orbsvcs / tests / FT_Naming / FaultTolerant / client.cpp
blob9fd2d63703685673549bb6692bbdafef9d6bbcf9
1 //=============================================================================
2 /**
3 * @file client.cpp
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>
9 */
10 //=============================================================================
12 #include "TestC.h"
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"
18 #include "tao/Stub.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"
24 #include <iostream>
26 #if defined (_MSC_VER)
27 # pragma warning (disable : 4250)
28 #endif /* _MSC_VER */
30 //==============================================================================
32 //==============================================================================
33 class My_Test_Object :
34 public virtual POA_Test_Object
36 public:
37 My_Test_Object (CORBA::Short id = 0);
38 // Constructor.
40 ~My_Test_Object ();
41 // Destructor.
43 // = Interface implementation accessor methods.
45 void id (CORBA::Short id);
46 // Sets id.
48 CORBA::Short id ();
49 // Gets id.
51 private:
52 short id_;
55 My_Test_Object::My_Test_Object (CORBA::Short id)
56 : id_ (id)
60 My_Test_Object::~My_Test_Object ()
64 CORBA::Short
65 My_Test_Object::id ()
67 return id_;
70 void
71 My_Test_Object::id (CORBA::Short id)
73 id_ = id;
76 //==============================================================================
78 //==============================================================================
79 /// Failover Name Test
80 int
81 do_failover_name_test (
82 CORBA::ORB_ptr theOrb,
83 ACE_TCHAR *ns1ref,
84 int c_breadth,
85 int c_depth,
86 int o_breadth);
88 /// Failover ObjectGroup Test
89 int
90 do_failover_objectgroup_test (
91 CORBA::ORB_ptr theOrb,
92 ACE_TCHAR *nm1ref,
93 int c_breadth,
94 int c_depth,
95 int o_breadth);
97 //==============================================================================
99 //==============================================================================
100 /// Persistence Name Test
102 do_persistence_name_test (
103 CORBA::ORB_ptr theOrb,
104 ACE_TCHAR *ns1ref,
105 int c_breadth,
106 int c_depth,
107 int o_breadth,
108 bool validate_only);
110 /// Persistence ObjectGroup Test
112 do_persistence_objectgroup_test (
113 CORBA::ORB_ptr theOrb,
114 ACE_TCHAR *nm1ref,
115 int c_breadth,
116 int c_depth,
117 int o_breadth,
118 bool validate_only);
120 //==============================================================================
122 //==============================================================================
123 /// Equivalence Name Test
125 do_equivalence_name_test (
126 CORBA::ORB_ptr theOrb,
127 ACE_TCHAR *ns1ref,
128 ACE_TCHAR *ns2ref,
129 int c_breadth,
130 int c_depth,
131 int o_breadth);
133 /// Equivalence ObjectGroup Test
135 do_equivalence_objectgroup_test (
136 CORBA::ORB_ptr theOrb,
137 ACE_TCHAR *nm1ref,
138 ACE_TCHAR *nm2ref,
139 int c_breadth,
140 int c_depth,
141 int o_breadth);
144 //==============================================================================
146 //==============================================================================
148 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
150 const int RC_SUCCESS = 0;
151 const int RC_ERROR = 1;
153 int rc = RC_SUCCESS;
155 int c_breadth = 4;
156 int c_depth = 4;
157 int o_breadth = 4;
159 ACE_TCHAR *ns1ref = 0;
160 ACE_TCHAR *ns2ref = 0;
162 ACE_TCHAR *nm1ref = 0;
163 ACE_TCHAR *nm2ref = 0;
165 typedef enum {
166 TT_FAILOVER,
167 TT_PERSISTENCE,
168 TT_EQUIVALENCE
169 } fault_tolerant_test;
170 fault_tolerant_test test_type = TT_FAILOVER;
172 typedef enum {
173 TT_INIT,
174 TT_CREATE,
175 TT_VALIDATE
176 } fault_tolerant_test_phase;
177 fault_tolerant_test_phase test_phase = TT_INIT;
179 //////////////////////////////////////////////////////////////////////////////
180 // optional
181 //////////////////////////////////////////////////////////////////////////////
182 // -b <breadth of context tree>
183 // -d <depth of context tree>
184 // -o <breadth of object tree>
185 //////////////////////////////////////////////////////////////////////////////
186 // required
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
203 // Initialize orb
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:"));
207 int c;
208 int i;
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)
216 switch (c)
218 case 'b':
219 i = ACE_OS::atoi(get_opts.opt_arg ());
220 if (i<2)
222 ACE_ERROR((LM_ERROR,
223 ACE_TEXT ("Invalid breadth, must be 2 or more\n")));
224 ACE_OS::exit(RC_ERROR);
226 c_breadth = i;
227 break;
228 case 'd':
229 i = ACE_OS::atoi(get_opts.opt_arg ());
230 if (i<2)
232 ACE_ERROR((LM_ERROR,
233 ACE_TEXT ("Invalid depth, must be 2 or more\n")));
234 ACE_OS::exit(RC_ERROR);
236 c_depth = i;
237 break;
238 case 'o':
239 i = ACE_OS::atoi(get_opts.opt_arg ());
240 if (i<2)
242 ACE_ERROR((LM_ERROR,
243 ACE_TEXT ("Invalid breadth, must be 2 or more\n")));
244 ACE_OS::exit(RC_ERROR);
246 o_breadth = i;
247 break;
248 case 'p':
249 ns1ref = get_opts.opt_arg ();
250 break;
251 case 'q':
252 ns2ref = get_opts.opt_arg ();
253 break;
254 case 'r':
255 nm1ref = get_opts.opt_arg ();
256 break;
257 case 's':
258 nm2ref = get_opts.opt_arg ();
259 break;
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;
289 break;
291 default:
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>")
301 ACE_TEXT ("\n")),
302 RC_ERROR);
305 switch(test_type) {
306 case TT_FAILOVER:
308 if( RC_SUCCESS != do_failover_name_test (
309 orb.in (),
310 ns1ref,
311 c_breadth,
312 c_depth,
313 o_breadth ))
315 ACE_DEBUG ((LM_DEBUG,
316 ACE_TEXT ("ERROR: Failover Name Test Failed\n")));
317 rc = RC_ERROR;
318 } else {
319 ACE_DEBUG ((LM_DEBUG,
320 ACE_TEXT ("INFO: Failover Name Test OK\n")));
323 if( RC_SUCCESS != do_failover_objectgroup_test (
324 orb.in (),
325 nm1ref,
326 c_breadth,
327 c_depth,
328 o_breadth ))
330 ACE_DEBUG ((LM_DEBUG,
331 ACE_TEXT ("ERROR: Failover ObjectGroup ")
332 ACE_TEXT ("Test Failed\n")));
333 rc = RC_ERROR;
334 } else {
335 ACE_DEBUG ((LM_DEBUG,
336 ACE_TEXT ("INFO: Failover ObjectGroup Test OK\n")));
339 break;
341 case TT_PERSISTENCE:
343 switch(test_phase){
344 case TT_CREATE:
345 if (RC_SUCCESS != do_persistence_name_test (
346 orb.in (),
347 ns1ref,
348 c_breadth,
349 c_depth,
350 o_breadth,
351 false ))
353 ACE_DEBUG ((LM_DEBUG,
354 ACE_TEXT ("ERROR: Persistence Creation Name ")
355 ACE_TEXT ("Test Failed\n")));
356 rc = RC_ERROR;
357 } else {
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(
363 orb.in (),
364 nm1ref,
365 c_breadth,
366 c_depth,
367 o_breadth,
368 false ))
370 ACE_DEBUG ((LM_DEBUG,
371 ACE_TEXT ("ERROR: Persistence Creation ObjectGroup ")
372 ACE_TEXT ("Test Failed\n")));
373 rc = RC_ERROR;
374 } else {
375 ACE_DEBUG ((LM_DEBUG,
376 ACE_TEXT ("INFO: Persistence Creation ObjectGroup ")
377 ACE_TEXT ("Test OK\n")));
379 break;
381 case TT_VALIDATE:
382 if (RC_SUCCESS != do_persistence_name_test (
383 orb.in (),
384 ns1ref,
385 c_breadth,
386 c_depth,
387 o_breadth,
388 true ))
390 ACE_DEBUG ((LM_DEBUG,
391 ACE_TEXT ("ERROR: Persistence Validation ")
392 ACE_TEXT ("Name Test Failed\n")));
393 rc = RC_ERROR;
394 } else {
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 (
401 orb.in (),
402 nm1ref,
403 c_breadth,
404 c_depth,
405 o_breadth,
406 true ))
408 ACE_DEBUG ((LM_DEBUG,
409 ACE_TEXT ("ERROR: Persistence Validation ")
410 ACE_TEXT ("ObjectGroup Test Failed\n")));
411 rc = RC_ERROR;
412 } else {
413 ACE_DEBUG ((LM_DEBUG,
414 ACE_TEXT ("INFO: Persistence Validation ")
415 ACE_TEXT ("ObjectGroup Test OK\n")));
417 break;
419 case TT_INIT:
420 default:
421 ACE_DEBUG ((LM_DEBUG,
422 ACE_TEXT ("ERROR: Missing Required Persistence ")
423 ACE_TEXT ("Argument [--create|--validate] \n")));
424 rc = RC_ERROR;
425 break;
427 break;
429 case TT_EQUIVALENCE:
431 if (RC_SUCCESS != do_equivalence_name_test (
432 orb.in (),
433 ns1ref,
434 ns2ref,
435 c_breadth,
436 c_depth,
437 o_breadth ))
439 ACE_DEBUG ((LM_DEBUG,
440 ACE_TEXT ("ERROR: Equivalence Name Test\n")));
441 rc = RC_ERROR;
442 } else {
443 ACE_DEBUG ((LM_DEBUG,
444 ACE_TEXT ("INFO: Equivalence Name Test OK\n")));
447 if (RC_SUCCESS != do_equivalence_objectgroup_test(
448 orb.in (),
449 nm1ref,
450 nm2ref,
451 c_breadth,
452 c_depth,
453 o_breadth ))
455 ACE_DEBUG ((LM_DEBUG,
456 ACE_TEXT ("ERROR: Equivalence ObjectGroup Test\n")));
457 rc = RC_ERROR;
458 } else {
459 ACE_DEBUG ((LM_DEBUG,
460 ACE_TEXT ("INFO: Equivalence ObjectGroup Test OK\n")));
462 break;
465 catch (const CORBA::Exception& ex)
467 ex._tao_print_exception (
468 ACE_TEXT ("ERROR: Unable to resolve name servers"));
469 return RC_ERROR;
473 return rc;
476 //==============================================================================
478 //==============================================================================
479 /// Failover Name Test
481 do_failover_name_test (
482 CORBA::ORB_ptr theOrb,
483 ACE_TCHAR *ns1ref,
484 int c_breadth,
485 int c_depth,
486 int o_breadth )
488 const int RC_SUCCESS = 0;
489 const int RC_ERROR = -1;
490 CosNaming::NamingContext_var root_context_1;
491 int i;
493 try {
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")),
500 RC_ERROR);
503 if (CORBA::is_nil (ns1ref))
505 ACE_ERROR_RETURN (( LM_ERROR,
506 ACE_TEXT ("ERROR: invalid ns1\n")),
507 RC_ERROR);
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),
517 RC_ERROR);
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),
526 RC_ERROR);
530 catch (const CORBA::Exception& ex)
532 ex._tao_print_exception (
533 ACE_TEXT ("ERROR: Unable to resolve name servers"));
534 return RC_ERROR;
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;
543 level1.length (1);
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 ();
557 level1.length (2);
559 char wide_name[16];
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
567 // replica
568 try {
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
577 ACE_OS::sleep (1);
579 // Try again...
580 try {
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"));
594 return RC_ERROR;
599 catch (const CORBA::Exception& ex)
601 ex._tao_print_exception (
602 ACE_TEXT ("ERROR: Unable to create a lot of objects"));
603 return RC_ERROR;
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;
614 deep.length (1);
615 char deep_name[16];
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"));
628 return RC_ERROR;
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;
638 wide.length (1);
639 char wide_name[16];
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 ();
646 try {
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")));
659 ACE_OS::sleep (1);
661 // Try again to see if it just was a race condition
662 try {
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"));
674 return RC_ERROR;
679 catch (const CORBA::Exception& ex)
681 ex._tao_print_exception (
682 ACE_TEXT ("ERROR: Unable to create wide context"));
683 return RC_ERROR;
686 // Delete three selected things, one from each tree
687 try {
688 // Remove the second to last object from the Naming Context
689 CosNaming::Name wide1;
690 wide1.length (2);
691 wide1[0].id = CORBA::string_dup ("level1_context");
692 char wide_name[16];
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
700 try {
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")),
716 RC_ERROR);
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;
728 wide2.length (1);
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")),
742 RC_ERROR);
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);
753 char deep_name[16];
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")),
768 RC_ERROR);
771 result_object->destroy();
772 root_context_1->unbind (deep);
773 ACE_OS::thr_yield ();
775 retried = false;
776 // Make sure it is gone from the replica
777 try {
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")),
793 RC_ERROR);
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"));
807 return RC_ERROR;
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;
816 wide.length (2);
817 wide[0].id = CORBA::string_dup ("level1_context");
818 char wide_name[16];
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")),
828 RC_ERROR);
831 catch (const CORBA::Exception& ex)
833 ex._tao_print_exception (
834 ACE_TEXT ("ERROR: Unable to resolve object from redundant server"));
835 return RC_ERROR;
840 // Access the deleted second to last object from the Naming Context
841 CosNaming::Name wide;
842 wide.length (2);
843 wide[0].id = CORBA::string_dup ("level1_context");
844 char wide_name[16];
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")),
853 RC_ERROR);
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")),
863 RC_ERROR);
866 catch (const CORBA::Exception& ex)
868 ex._tao_print_exception (
869 ACE_TEXT ("ERROR: Wrong exception type returned from resolve.\n"));
870 return RC_ERROR;
875 // Access the last context from the wide Naming Context
876 CosNaming::Name wide;
877 wide.length (1);
878 char wide_name[16];
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")),
892 RC_ERROR);
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"));
902 return RC_ERROR;
907 // Access the deleted second to last object from the Naming Context
908 CosNaming::Name wide;
909 wide.length (2);
910 char wide_name[16];
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")),
919 RC_ERROR);
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"));
928 return RC_ERROR;
933 // Access the deleted last context from the deep Naming Context
934 CosNaming::Name deep;
935 deep.length (c_depth);
936 char deep_name[16];
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")),
948 RC_ERROR);
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"));
959 return RC_ERROR;
964 // Access the second to last object from the Naming Context
965 CosNaming::Name deep;
966 deep.length (c_depth-1);
967 char deep_name[16];
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")),
985 RC_ERROR);
988 catch (const CORBA::Exception& ex)
990 ex._tao_print_exception (
991 ACE_TEXT ("ERROR: Unable to resolve deep context from redundant server"));
992 return RC_ERROR;
995 return RC_SUCCESS;
998 /// Failover ObjectGroup Test
1000 do_failover_objectgroup_test (
1001 CORBA::ORB_ptr theOrb,
1002 ACE_TCHAR *nm1ref,
1003 int c_breadth,
1004 int c_depth,
1005 int o_breadth )
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;
1016 try {
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")),
1022 RC_ERROR);
1025 if (CORBA::is_nil (nm1ref))
1027 ACE_ERROR_RETURN (( LM_ERROR,
1028 ACE_TEXT ("ERROR: invalid nm1\n")),
1029 RC_ERROR);
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),
1041 RC_ERROR);
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),
1049 RC_ERROR);
1052 NS_group_svc svc;
1054 if (RC_SUCCESS != svc.set_orb (theOrb))
1056 ACE_ERROR_RETURN (( LM_ERROR,
1057 ACE_TEXT ("ERROR: invalid orb\n")),
1058 RC_ERROR);
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),
1065 RC_ERROR);
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),
1076 RC_ERROR);
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")),
1083 RC_ERROR);
1084 } else {
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"));
1095 return RC_ERROR;
1098 return RC_SUCCESS;
1102 //==============================================================================
1104 //==============================================================================
1105 /// Persistence Name Test
1107 do_persistence_name_test (
1108 CORBA::ORB_ptr theOrb,
1109 ACE_TCHAR *ns1ref,
1110 int c_breadth,
1111 int c_depth,
1112 int o_breadth,
1113 bool validate_only)
1115 const int RC_ERROR = -1;
1116 const int RC_SUCCESS = 0;
1117 CosNaming::NamingContext_var root_context_1;
1118 int i;
1120 try {
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")),
1127 RC_ERROR);
1130 if (CORBA::is_nil (ns1ref))
1132 ACE_ERROR_RETURN (( LM_ERROR,
1133 ACE_TEXT ("ERROR: invalid ns1\n")),
1134 RC_ERROR);
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),
1144 RC_ERROR);
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),
1153 RC_ERROR);
1156 catch (const CORBA::Exception& ex)
1158 ex._tao_print_exception (ACE_TEXT ("ERROR: Unable to resolve name servers"));
1159 return RC_ERROR;
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;
1168 level1.length (1);
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 ();
1184 level1.length (2);
1185 char wide_name[16];
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
1196 try {
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"));
1204 ACE_OS::sleep (1);
1206 // Try again...
1207 try {
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"));
1218 return RC_ERROR;
1223 catch (const CORBA::Exception& ex)
1225 ex._tao_print_exception (
1226 ACE_TEXT ("ERROR: Unable to create or validate a lot of objects"));
1228 return RC_ERROR;
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;
1240 deep.length (1);
1241 char deep_name[16];
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"));
1254 return RC_ERROR;
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;
1265 wide.length (1);
1266 char wide_name[16];
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 ();
1276 try {
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")));
1291 ACE_OS::sleep (1);
1293 // Try again to see if it just was a race condition
1294 try {
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"));
1306 return RC_ERROR;
1311 catch (const CORBA::Exception& ex)
1313 ex._tao_print_exception (
1314 ACE_TEXT ("ERROR: Unable to create or validate wide context"));
1315 return RC_ERROR;
1318 return RC_SUCCESS;
1322 /// Persistence ObjectGroup Test
1324 do_persistence_objectgroup_test (
1325 CORBA::ORB_ptr theOrb,
1326 ACE_TCHAR *nm1ref,
1327 int c_breadth,
1328 int c_depth,
1329 int o_breadth,
1330 bool validate_only)
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;
1341 try {
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")),
1348 RC_ERROR);
1351 if (CORBA::is_nil (nm1ref))
1353 ACE_ERROR_RETURN (( LM_ERROR,
1354 ACE_TEXT ("ERROR: invalid nm1\n")),
1355 RC_ERROR);
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),
1367 RC_ERROR);
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),
1375 RC_ERROR);
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")),
1384 RC_ERROR);
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),
1391 RC_ERROR);
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"),
1401 basic_group_name),
1402 RC_ERROR);
1403 } else {
1404 ACE_DEBUG (( LM_DEBUG,
1405 ACE_TEXT ("INFO: Object Group %s Found In Repository\n"),
1406 basic_group_name));
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"),
1424 loc[0].id.in()));
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"),
1441 loc[0].id.in()),
1442 RC_ERROR);
1447 CORBA::String_var the_string = basic->get_string ();
1449 ACE_DEBUG (( LM_DEBUG,
1450 ACE_TEXT ("INFO: object group member at %C reports ")
1451 ACE_TEXT ("%C\n"),
1452 loc[0].id.in(),
1453 the_string.in ()));
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"),
1458 loc[0].id.in(),
1459 the_string.in ()),
1460 RC_ERROR);
1463 catch (const CORBA::Exception& ex)
1465 ex._tao_print_exception ("ERROR: invoking get_string on Basic object.\n");
1466 return RC_ERROR;
1469 catch (const PortableGroup::MemberNotFound&)
1471 ACE_ERROR_RETURN ((LM_ERROR,
1472 ACE_TEXT ("ERROR: Unable to find member location %C\n"),
1473 loc[0].id.in()),
1474 RC_ERROR);
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.
1489 if (!validate_only)
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"),
1512 loc[0].id.in()),
1513 RC_ERROR);
1515 group_var =
1516 naming_manager_1->remove_member (group_var.in(),
1517 location_name);
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"),
1530 basic_group_name),
1531 RC_ERROR);
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"),
1538 basic_group_name),
1539 RC_ERROR);
1541 } else {
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;
1549 in >> location_str;
1550 std::string member_ior;
1551 in >> member_ior;
1553 if (!in.good ())
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 ()),
1559 RC_ERROR);
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));
1571 // Add back member
1572 group_var =
1573 naming_manager_1->add_member (group_var.in (),
1574 location_name,
1575 member.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"),
1603 basic_group_name),
1604 RC_ERROR);
1609 catch (const PortableGroup::ObjectGroupNotFound&)
1611 ACE_ERROR_RETURN ((LM_ERROR,
1612 ACE_TEXT ("ERROR: Unable to find group %C\n"),
1613 basic_group_name),
1614 RC_ERROR);
1616 catch (const CORBA::Exception&)
1618 ACE_ERROR_RETURN ((LM_ERROR,
1619 ACE_TEXT ("ERROR: Unable to list members for group %C\n"),
1620 basic_group_name),
1621 RC_ERROR);
1625 catch (const CORBA::Exception& ex)
1627 ex._tao_print_exception (
1628 ACE_TEXT ("ERROR: Unable To Resolve Name Manager Servers"));
1629 return RC_ERROR;
1632 return RC_SUCCESS;
1635 //==============================================================================
1637 //==============================================================================
1638 /// Equivalence Name Test
1640 do_equivalence_name_test (
1641 CORBA::ORB_ptr theOrb,
1642 ACE_TCHAR *ns1ref,
1643 ACE_TCHAR *ns2ref,
1644 int c_breadth,
1645 int c_depth,
1646 int o_breadth)
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;
1653 int i;
1655 try {
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")),
1662 RC_ERROR);
1665 if (CORBA::is_nil (ns1ref))
1667 ACE_ERROR_RETURN (( LM_ERROR,
1668 ACE_TEXT ("ERROR: invalid ns1\n")),
1669 RC_ERROR);
1672 if (CORBA::is_nil (ns2ref))
1674 ACE_ERROR_RETURN (( LM_ERROR,
1675 ACE_TEXT ("ERROR: invalid ns2\n")),
1676 RC_ERROR);
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),
1689 RC_ERROR);
1692 if (CORBA::is_nil (ns2obj.in ()))
1694 ACE_ERROR_RETURN (( LM_ERROR,
1695 ACE_TEXT ("ERROR: invalid ior <%s>\n"),ns2ref),
1696 RC_ERROR);
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),
1706 RC_ERROR);
1709 if (CORBA::is_nil (root_context_2.in ()))
1711 ACE_ERROR_RETURN (( LM_ERROR,
1712 ACE_TEXT ("ERROR: invalid ior <%s>\n"),ns2ref),
1713 RC_ERROR);
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")),
1722 RC_ERROR);
1725 ACE_DEBUG ((LM_DEBUG,
1726 ACE_TEXT ("INFO: ns1ref is not equivalent to ns2ref\n")));
1728 int ns1_count =
1729 root_context_1->_stubobj ()->base_profiles ().profile_count ();
1731 int ns2_count =
1732 root_context_2->_stubobj ()->base_profiles ().profile_count ();
1735 ACE_DEBUG ((LM_DEBUG,
1736 ACE_TEXT ("INFO: ns1ref profile count: %d\n"),
1737 ns1_count));
1739 ACE_DEBUG ((LM_DEBUG,
1740 ACE_TEXT ("INFO: ns2ref profile count: %d\n"),
1741 ns2_count));
1743 catch (const CORBA::Exception& ex)
1745 ex._tao_print_exception (ACE_TEXT ("ERROR: Unable to resolve name servers"));
1746 return RC_ERROR;
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;
1755 level1.length (1);
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 ();
1768 level1.length (2);
1769 char wide_name[16];
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
1776 // replica
1777 try {
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"));
1786 ACE_OS::sleep (1);
1788 // Try again...
1789 try {
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"));
1801 return RC_ERROR;
1806 catch (const CORBA::Exception& ex)
1808 ex._tao_print_exception (
1809 ACE_TEXT ("ERROR: Unable to create a lot of objects"));
1810 return RC_ERROR;
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;
1821 deep.length (1);
1822 char deep_name[16];
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"));
1835 return RC_ERROR;
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;
1845 wide.length (1);
1846 char wide_name[16];
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 ();
1853 try {
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")));
1868 ACE_OS::sleep (1);
1870 // Try again to see if it just was a race condition
1871 try {
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"));
1885 return RC_ERROR;
1890 catch (const CORBA::Exception& ex)
1892 ex._tao_print_exception (
1893 ACE_TEXT ("ERROR: Unable to create wide context"));
1894 return RC_ERROR;
1897 // Delete three selected things, one from each tree
1898 try {
1899 // Remove the second to last object from the Naming Context
1900 CosNaming::Name wide1;
1901 wide1.length (2);
1903 wide1[0].id = CORBA::string_dup ("level1_context");
1905 char wide_name[16];
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
1913 try {
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")),
1929 RC_ERROR);
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;
1941 wide2.length (1);
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")),
1955 RC_ERROR);
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);
1965 char deep_name[16];
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")),
1978 RC_ERROR);
1980 result_object->destroy();
1981 root_context_1->unbind (deep);
1982 ACE_OS::thr_yield ();
1984 retried = false;
1985 // Make sure it is gone from the replica
1986 try {
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")),
2002 RC_ERROR);
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"));
2016 return RC_ERROR;
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;
2025 wide.length (2);
2026 wide[0].id = CORBA::string_dup ("level1_context");
2027 char wide_name[16];
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")),
2039 RC_ERROR);
2042 catch (const CORBA::Exception& ex)
2044 ex._tao_print_exception (
2045 ACE_TEXT ("ERROR: Unable to resolve object from redundant server"));
2046 return RC_ERROR;
2051 // Access the deleted second to last object from the Naming Context
2052 CosNaming::Name wide;
2053 wide.length (2);
2054 wide[0].id = CORBA::string_dup ("level1_context");
2055 char wide_name[16];
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")),
2064 RC_ERROR);
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")),
2074 RC_ERROR);
2076 catch (const CORBA::Exception& ex)
2078 ex._tao_print_exception (
2079 ACE_TEXT ("ERROR: Wrong exception type returned from resolve.\n"));
2080 return RC_ERROR;
2085 // Access the last context from the wide Naming Context
2086 CosNaming::Name wide;
2087 wide.length (1);
2088 char wide_name[16];
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")),
2102 RC_ERROR);
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"));
2113 return RC_ERROR;
2118 // Access the deleted second to last object from the Naming Context
2119 CosNaming::Name wide;
2120 wide.length (2);
2121 char wide_name[16];
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")),
2130 RC_ERROR);
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"));
2140 return RC_ERROR;
2145 // Access the deleted last context from the deep Naming Context
2146 CosNaming::Name deep;
2147 deep.length (c_depth);
2148 char deep_name[16];
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")),
2160 RC_ERROR);
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"));
2171 return RC_ERROR;
2176 // Access the second to last object from the Naming Context
2177 CosNaming::Name deep;
2178 deep.length (c_depth-1);
2179 char deep_name[16];
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")),
2196 RC_ERROR);
2199 catch (const CORBA::Exception& ex)
2201 ex._tao_print_exception (
2202 ACE_TEXT ("ERROR: Unable to resolve deep context from redundant server."));
2203 return RC_ERROR;
2206 return RC_SUCCESS;
2210 /// Equivalence ObjectGroup Test
2212 do_equivalence_objectgroup_test (
2213 CORBA::ORB_ptr theOrb,
2214 ACE_TCHAR *nm1ref,
2215 ACE_TCHAR *nm2ref,
2216 int c_breadth,
2217 int c_depth,
2218 int o_breadth )
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;
2232 try {
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")),
2238 RC_ERROR);
2241 if (CORBA::is_nil (nm1ref))
2243 ACE_ERROR_RETURN (( LM_ERROR,
2244 ACE_TEXT ("ERROR: invalid nm1\n")),
2245 RC_ERROR);
2248 ACE_DEBUG (( LM_DEBUG,
2249 ACE_TEXT ("INFO: nm1ref: %s\n"),
2250 nm1ref));
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"),
2259 nm1ref),
2260 RC_ERROR);
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"),
2268 nm1ref),
2269 RC_ERROR);
2272 if (CORBA::is_nil (nm2ref))
2274 ACE_ERROR_RETURN (( LM_ERROR,
2275 ACE_TEXT ("ERROR: invalid nm2\n")),
2276 RC_ERROR);
2279 ACE_DEBUG (( LM_DEBUG,
2280 ACE_TEXT ("INFO: nm2ref: %s\n"),
2281 nm2ref));
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"),
2290 nm2ref),
2291 RC_ERROR);
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"),
2300 nm2ref),
2301 RC_ERROR);
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")),
2310 RC_ERROR);
2313 ACE_DEBUG ((LM_DEBUG,
2314 ACE_TEXT ("INFO: nm1ref is not equivalent to nm2ref\n")));
2315 int nm1_count =
2316 naming_manager_1->_stubobj ()->base_profiles ().profile_count ();
2318 int nm2_count =
2319 naming_manager_2->_stubobj ()->base_profiles ().profile_count ();
2322 ACE_DEBUG ((LM_DEBUG,
2323 ACE_TEXT ("INFO: nm1ref profile count: %d\n"),
2324 nm1_count));
2326 ACE_DEBUG ((LM_DEBUG,
2327 ACE_TEXT ("INFO: nm2ref profile count: %d\n"),
2328 nm2_count));
2331 /// Setup 1st NS_group_svc with 1st Naming Manager
2332 NS_group_svc svc1;
2333 if (RC_SUCCESS != svc1.set_orb (theOrb))
2335 ACE_ERROR_RETURN (( LM_ERROR,
2336 ACE_TEXT ("ERROR: invalid orb\n")),
2337 RC_ERROR);
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"),
2344 nm1ref),
2345 RC_ERROR);
2348 /// Setup 2nd NS_group_svc with 2nd Naming Manager
2349 NS_group_svc svc2;
2350 if (RC_SUCCESS != svc2.set_orb (theOrb))
2352 ACE_ERROR_RETURN (( LM_ERROR,
2353 ACE_TEXT ("ERROR: invalid orb\n")),
2354 RC_ERROR);
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),
2361 RC_ERROR);
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"),
2373 test_group_1),
2374 RC_ERROR);
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"),
2381 test_group_2),
2382 RC_ERROR);
2385 if (false == svc1.group_exist(test_group_1))
2387 ++error_count;
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"),
2391 test_group_1));
2392 } else {
2393 ACE_DEBUG (( LM_DEBUG,
2394 ACE_TEXT ("INFO: Primary Found Object Group %s Created By ")
2395 ACE_TEXT ("Primary In Repository\n"),
2396 test_group_1));
2399 if (false == svc2.group_exist(test_group_2))
2401 ++error_count;
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"),
2405 test_group_2));
2406 } else {
2407 ACE_DEBUG (( LM_DEBUG,
2408 ACE_TEXT ("INFO: Backup Found Object Group %s Created By ")
2409 ACE_TEXT ("Backup In Repository\n"),
2410 test_group_2));
2413 if (false == svc1.group_exist(test_group_2))
2415 ++error_count;
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"),
2419 test_group_2));
2420 } else {
2421 ACE_DEBUG (( LM_DEBUG,
2422 ACE_TEXT ("INFO: Primary Found Object Group %s Created By ")
2423 ACE_TEXT ("Backup In Repository\n"),
2424 test_group_2));
2427 if (false == svc2.group_exist(test_group_1))
2429 ++error_count;
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"),
2433 test_group_1));
2434 } else {
2435 ACE_DEBUG (( LM_DEBUG,
2436 ACE_TEXT ("INFO: Backup Found Object Group %s Created By ")
2437 ACE_TEXT ("Primary In Repository\n"),
2438 test_group_1));
2442 catch (const CORBA::Exception& ex)
2444 ++error_count;
2445 ex._tao_print_exception (
2446 ACE_TEXT ("ERROR: Unable to resolve name manager servers"));
2449 return (error_count > 0) ? RC_ERROR : RC_SUCCESS;