diff options
Diffstat (limited to 'TAO/orbsvcs/tests')
21 files changed, 1232 insertions, 0 deletions
diff --git a/TAO/orbsvcs/tests/Bug_2800_Regression/Bug_2800_Regression.mpc b/TAO/orbsvcs/tests/Bug_2800_Regression/Bug_2800_Regression.mpc new file mode 100644 index 00000000000..04fcfb3257f --- /dev/null +++ b/TAO/orbsvcs/tests/Bug_2800_Regression/Bug_2800_Regression.mpc @@ -0,0 +1,33 @@ +// -*- MPC -*- +// $Id$ + +project(*idl): taoidldefaults { + IDL_Files { + Test.idl + } + custom_only = 1 +} + +project(*Server): namingexe, naming_serv { + after += *idl + Source_Files { + Hello.cpp + NamingTask.cpp + nsmain.cpp + } + Source_Files { + TestC.cpp + TestS.cpp + } +} + +project(*Client): namingexe { + after += *idl + Source_Files { + client.cpp + } + Source_Files { + TestC.cpp + } +} + diff --git a/TAO/orbsvcs/tests/Bug_2800_Regression/Hello.cpp b/TAO/orbsvcs/tests/Bug_2800_Regression/Hello.cpp new file mode 100644 index 00000000000..3bb0a772b76 --- /dev/null +++ b/TAO/orbsvcs/tests/Bug_2800_Regression/Hello.cpp @@ -0,0 +1,25 @@ +// +// $Id$ +// +#include "Hello.h" + +ACE_RCSID(Hello, Hello, "$Id$") + +Hello::Hello (CORBA::ORB_ptr orb) + : orb_ (CORBA::ORB::_duplicate (orb)) +{ +} + +char * +Hello::get_string (void) + ACE_THROW_SPEC ((CORBA::SystemException)) +{ + return CORBA::string_dup ("Hello there!"); +} + +void +Hello::shutdown (void) + ACE_THROW_SPEC ((CORBA::SystemException)) +{ + this->orb_->shutdown (0); +} diff --git a/TAO/orbsvcs/tests/Bug_2800_Regression/Hello.h b/TAO/orbsvcs/tests/Bug_2800_Regression/Hello.h new file mode 100644 index 00000000000..6131e1a3c88 --- /dev/null +++ b/TAO/orbsvcs/tests/Bug_2800_Regression/Hello.h @@ -0,0 +1,33 @@ +// +// $Id$ +// + +#ifndef HELLO_H +#define HELLO_H +#include /**/ "ace/pre.h" + +#include "TestS.h" + +/// Implement the Test::Hello interface +class Hello + : public virtual POA_Test::Hello +{ +public: + /// Constructor + Hello (CORBA::ORB_ptr orb); + + // = The skeleton methods + virtual char * get_string (void) + ACE_THROW_SPEC ((CORBA::SystemException)); + + virtual void shutdown (void) + ACE_THROW_SPEC ((CORBA::SystemException)); + +private: + /// Use an ORB reference to conver strings to objects and shutdown + /// the application. + CORBA::ORB_var orb_; +}; + +#include /**/ "ace/post.h" +#endif /* HELLO_H */ diff --git a/TAO/orbsvcs/tests/Bug_2800_Regression/NamingTask.cpp b/TAO/orbsvcs/tests/Bug_2800_Regression/NamingTask.cpp new file mode 100644 index 00000000000..a76b3e659db --- /dev/null +++ b/TAO/orbsvcs/tests/Bug_2800_Regression/NamingTask.cpp @@ -0,0 +1,86 @@ +// $Id$ + +#include "NamingTask.h" +#include "orbsvcs/Naming/Naming_Server.h" +#include "ace/OS_NS_unistd.h" +#include "ace/Argv_Type_Converter.h" + +NamingTask::NamingTask (const char* orbname, int argc, char** argv, unsigned short port) + : initialized_(false) +{ + char** my_argv = new char*[argc + 2]; + char buf[128]; + int my_argc = 0; + for(; my_argc<argc ;++my_argc) + my_argv[my_argc] = argv[my_argc]; + ACE_OS::sprintf (buf, "iiop://localhost:%d", port); + my_argv[my_argc++] = "-ORBEndpoint"; + my_argv[my_argc++] = buf; + + ACE_Argv_Type_Converter satc (my_argc, my_argv); + orb_ = CORBA::ORB_init(satc.get_argc (), satc.get_TCHAR_argv (), orbname); +} + +void NamingTask::waitInit () +{ + // Wait for Naming Service initialized. + while (! initialized_) { + ACE_OS::sleep(ACE_Time_Value(0, 100 * 1000)); + } +} + +void NamingTask::end() +{ + orb_->shutdown(0); + wait(); +} + +const char* NamingTask::ior() +{ + return ior_.in (); +} + +int NamingTask::svc() +{ + try { + // Get reference to Root POA + CORBA::Object_var obj = orb_->resolve_initial_references("RootPOA"); + PortableServer::POA_var poa = PortableServer::POA::_narrow(obj.in()); + + // Activate POA Manager + PortableServer::POAManager_var poaManager = poa->the_POAManager(); + poaManager->activate(); + + // Initialize the naming service + // We are not going to look for other naming servers + TAO_Naming_Server naming; + if (naming.init(orb_.in(), + poa.in(), + ACE_DEFAULT_MAP_SIZE, + 0, + 0, + 0, + TAO_NAMING_BASE_ADDR, + 0) == 0) + { + ACE_DEBUG ((LM_DEBUG, "The Naming Service Task is ready.\n")); + ior_ = CORBA::string_dup (naming.naming_service_ior ()); + initialized_ = true; + // Accept requests + orb_->run(); + orb_->destroy(); + return 0; + } + else + { + ACE_ERROR ((LM_ERROR, "Unable to initialize the Naming Service.\n")); + } + } + catch (CORBA::Exception& ex) + { + ex._tao_print_exception ("NamingTask::svc() CORBA::Exception: "); + } + + return -1; +} + diff --git a/TAO/orbsvcs/tests/Bug_2800_Regression/NamingTask.h b/TAO/orbsvcs/tests/Bug_2800_Regression/NamingTask.h new file mode 100644 index 00000000000..f9108a4ba45 --- /dev/null +++ b/TAO/orbsvcs/tests/Bug_2800_Regression/NamingTask.h @@ -0,0 +1,26 @@ +// $Id$ + +#ifndef NAMINGTASK_H +#define NAMINGTASK_H + +#include "tao/CORBA_String.h" +#include "tao/ORB.h" +#include "ace/Task.h" + +class NamingTask : public ACE_Task<ACE_MT_SYNCH> +{ +public: + NamingTask (const char* orbname, int argc, char** argv, unsigned short port); + virtual int svc(); + void waitInit (); + void end(); + + const char* ior (); + +private: + CORBA::ORB_var orb_; + bool initialized_; + CORBA::String_var ior_; +}; + +#endif diff --git a/TAO/orbsvcs/tests/Bug_2800_Regression/Test.idl b/TAO/orbsvcs/tests/Bug_2800_Regression/Test.idl new file mode 100644 index 00000000000..3c0976e106d --- /dev/null +++ b/TAO/orbsvcs/tests/Bug_2800_Regression/Test.idl @@ -0,0 +1,20 @@ +// +// $Id$ +// + +/// Put the interfaces in a module, to avoid global namespace pollution +module Test +{ + /// A very simple interface + interface Hello + { + /// Return a simple string + string get_string (); + + /// A method to shutdown the ORB + /** + * This method is used to simplify the test shutdown process + */ + oneway void shutdown (); + }; +}; diff --git a/TAO/orbsvcs/tests/Bug_2800_Regression/client.cpp b/TAO/orbsvcs/tests/Bug_2800_Regression/client.cpp new file mode 100644 index 00000000000..397f101215c --- /dev/null +++ b/TAO/orbsvcs/tests/Bug_2800_Regression/client.cpp @@ -0,0 +1,96 @@ +// $Id$ + +#include "TestC.h" +#include "orbsvcs/CosNamingC.h" +#include "ace/Get_Opt.h" + +ACE_RCSID(Hello, client, "$Id$") + +int +parse_args (int argc, char *argv[]) +{ + ACE_Get_Opt get_opts (argc, argv, "k:"); + int c; + + while ((c = get_opts ()) != -1) + switch (c) + { + case '?': + default: + ACE_ERROR_RETURN ((LM_ERROR, + "usage: %s " + "\n", + argv [0]), + -1); + } + // Indicates sucessful parsing of the command line + return 0; +} + +int +main (int argc, char *argv[]) +{ + try + { + CORBA::ORB_var orb = + CORBA::ORB_init (argc, argv); + + if (parse_args (argc, argv) != 0) + return 1; + + CORBA::Object_var tmp = + orb->string_to_object("corbaloc:iiop:1.2@localhost:9931/NameService"); + + CosNaming::NamingContext_var root = + CosNaming::NamingContext::_narrow(tmp.in()); + + if (CORBA::is_nil (root.in ())) + { + ACE_ERROR_RETURN ((LM_DEBUG, + "Nil NamingService reference\n"), + 1); + } + + ACE_DEBUG ((LM_INFO, "**** Narrowed root NamingContext\n")); + + CosNaming::Name name; + name.length(2); + name[0].id = CORBA::string_dup("example"); + name[1].id = CORBA::string_dup("Hello"); + + tmp = root->resolve (name); + + ACE_DEBUG ((LM_INFO, "**** Resolved #example/Hello\n")); + + Test::Hello_var hello = + Test::Hello::_narrow(tmp.in ()); + + if (CORBA::is_nil (hello.in ())) + { + ACE_ERROR_RETURN ((LM_DEBUG, + "Nil Test::Hello reference\n"), + 1); + } + + CORBA::String_var the_string = + hello->get_string (); + + ACE_DEBUG ((LM_DEBUG, "(%P|%t) - string returned <%s>\n", + the_string.in ())); + + hello->shutdown (); + + orb->destroy (); + } + catch (const CosNaming::NamingContext::CannotProceed&) + { + ACE_DEBUG ((LM_DEBUG, "Catched correct exception\n")); + } + catch (const CORBA::Exception& ex) + { + ex._tao_print_exception ("Exception caught:"); + return 1; + } + + return 0; +} diff --git a/TAO/orbsvcs/tests/Bug_2800_Regression/nsmain.cpp b/TAO/orbsvcs/tests/Bug_2800_Regression/nsmain.cpp new file mode 100644 index 00000000000..e0e5f55acf3 --- /dev/null +++ b/TAO/orbsvcs/tests/Bug_2800_Regression/nsmain.cpp @@ -0,0 +1,164 @@ + +#include "NamingTask.h" +#include "Hello.h" +#include "orbsvcs/CosNamingC.h" +#include "ace/OS.h" +#include "ace/Get_Opt.h" + +class TestTask : public ACE_Task_Base +{ +public: + TestTask(int argc, char **argv); + virtual int svc(); + + int parse_args (int argc, char **argv); + + void end(); +private: + NamingTask namingServiceA_; + NamingTask namingServiceB_; + CORBA::ORB_var orb_; + CORBA::Boolean shutdown_ns_; +}; + +TestTask::TestTask(int argc, char **argv) + : namingServiceA_("NamingORBA", argc, argv, 9931), + namingServiceB_("NamingORBB", argc, argv, 9932) +{ + orb_ = CORBA::ORB_init(argc, argv, "ServerORB"); + shutdown_ns_ = false; + parse_args(argc, argv); +} + +void TestTask::end() +{ + orb_->shutdown(0); + wait(); +} + +int +TestTask::parse_args (int argc, char **argv) +{ + ACE_Get_Opt get_opts (argc, argv, "s"); + int c; + + while ((c = get_opts ()) != -1) + switch (c) + { + case 's': + shutdown_ns_ = true; + break; + } + // Indicates sucessful parsing of the command line + return 0; +} + +int TestTask::svc() +{ + + try { + // Start the Naming Service tasks + namingServiceA_.activate(); + // Wait for the Naming Service initialized. + namingServiceA_.waitInit(); + + namingServiceB_.activate(); + // Wait for the Naming Service initialized. + namingServiceB_.waitInit(); + + FILE *output_file= ACE_OS::fopen ("ns.ior", "w"); + if (output_file == 0) + ACE_ERROR_RETURN ((LM_ERROR, + "Cannot open output file for writing IOR: ns.ior\n"), + 1); + ACE_OS::fprintf (output_file, "%s", namingServiceA_.ior ()); + ACE_OS::fclose (output_file); + + // Get reference to Root POA + CORBA::Object_var obj = orb_->resolve_initial_references("RootPOA"); + PortableServer::POA_var poa = PortableServer::POA::_narrow(obj.in()); + + // Activate POA Manager + PortableServer::POAManager_var mgr = poa->the_POAManager(); + mgr->activate(); + + // Find the Naming Service + obj = orb_->string_to_object (namingServiceB_.ior ()); + CosNaming::NamingContext_var root = + CosNaming::NamingContext::_narrow(obj.in()); + + if (CORBA::is_nil(root.in())) { + ACE_ERROR ((LM_ERROR, "Error, Nil Naming Context reference\n")); + return 1; + } + // Bind the example Naming Context, if necessary + CosNaming::NamingContext_var example_nc; + CosNaming::Name name; + name.length(1); + name[0].id = CORBA::string_dup("example"); + try { + obj = root->resolve(name); + example_nc = + CosNaming::NamingContext::_narrow(obj.in()); + } + catch (CosNaming::NamingContext::NotFound&) { + example_nc = root->bind_new_context(name); + } + + // Bind the Test object + name.length(2); + name[1].id = CORBA::string_dup("Hello"); + + // Create an object + Hello servant(orb_.in ()); + PortableServer::ObjectId_var oid = poa->activate_object(&servant); + obj = poa->id_to_reference(oid.in()); + root->rebind(name, obj.in()); + + ACE_DEBUG ((LM_INFO, "Hello object bound in Naming Service B\n")); + + name.length(1); + obj = orb_->string_to_object (namingServiceA_.ior ()); + root = CosNaming::NamingContext::_narrow(obj.in()); + root->bind_context (name, example_nc.in ()); + + ACE_DEBUG ((LM_INFO, "'example' context of NS B bound in Naming Service A\n")); + + if (shutdown_ns_) + { + namingServiceB_.end(); + + ACE_DEBUG ((LM_INFO, "Naming Service B shut down\n")); + } + + // Normally we run the orb and the orb is shutdown by + // calling TestTask::end(). + // Accept requests + orb_->run(); + orb_->destroy(); + + // Shutdown the Naming Services. + namingServiceA_.end(); + namingServiceB_.end(); + + return 0; + } + catch (CORBA::Exception& ex) + { + ex._tao_print_exception ("CORBA exception: "); + } + + return -1; +} + +int main(int argc, char* argv[]) +{ + // Start the Test task + TestTask test_(argc, argv); + test_.activate(); + + // Wait the Test task finish. + test_.wait(); + + return 0; +} diff --git a/TAO/orbsvcs/tests/Bug_2800_Regression/run_test.pl b/TAO/orbsvcs/tests/Bug_2800_Regression/run_test.pl new file mode 100755 index 00000000000..7148d2f8a49 --- /dev/null +++ b/TAO/orbsvcs/tests/Bug_2800_Regression/run_test.pl @@ -0,0 +1,56 @@ +eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}' + & eval 'exec perl -S $0 $argv:q' + if 0; + +# $Id$ +# -*- perl -*- + +use lib "$ENV{ACE_ROOT}/bin"; +use PerlACE::Run_Test; + +$status = 0; +$debug_level = '0'; + +foreach $i (@ARGV) { + if ($i eq '-debug') { + $debug_level = '10'; + } +} + +$iorfile = PerlACE::LocalFile ("ns.ior"); +unlink $iorfile; + +$SV = new PerlACE::Process ("nsmain", "-s -ORBDebuglevel $debug_level"); +$CL = new PerlACE::Process ("client", ""); + +$server = $SV->Spawn (); + +if ($server != 0) { + print STDERR "ERROR: server returned $server\n"; + exit 1; +} + +if (PerlACE::waitforfile_timed ($iorfile, + $PerlACE::wait_interval_for_process_creation) == -1) { + print STDERR "ERROR: cannot find file <$iorfile>\n"; + $SV->Kill (); $SV->TimedWait (1); + exit 1; +} + +$client = $CL->SpawnWaitKill (300); + +if ($client != 0) { + print STDERR "ERROR: client returned $client\n"; + $status = 1; +} + +$server = $SV->WaitKill (10); + +if ($server != 0) { + print STDERR "ERROR: server returned $server\n"; + $status = 1; +} + +unlink $iorfile; + +exit $status; diff --git a/TAO/orbsvcs/tests/COIOP_Naming_Test/COIOP_Naming_Test.mpc b/TAO/orbsvcs/tests/COIOP_Naming_Test/COIOP_Naming_Test.mpc new file mode 100644 index 00000000000..c89940b5559 --- /dev/null +++ b/TAO/orbsvcs/tests/COIOP_Naming_Test/COIOP_Naming_Test.mpc @@ -0,0 +1,26 @@ +// -*- MPC -*- +// $Id$ + +project(*idl): taoidldefaults { + IDL_Files { + Test.idl + } + custom_only = 1 +} + +project(COIOP_Naming_Test): taoserver, strategies, naming, naming_serv { + exename = COIOP_Naming_Test + after += *idl + Source_Files { + TestC.cpp + TestS.cpp + COIOP_Test.cpp + Client_Task.cpp + Server_Task.cpp + NamingTask.cpp + Hello.cpp + } + IDL_Files { + } +} + diff --git a/TAO/orbsvcs/tests/COIOP_Naming_Test/COIOP_Test.cpp b/TAO/orbsvcs/tests/COIOP_Naming_Test/COIOP_Test.cpp new file mode 100644 index 00000000000..b895c972726 --- /dev/null +++ b/TAO/orbsvcs/tests/COIOP_Naming_Test/COIOP_Test.cpp @@ -0,0 +1,110 @@ +//$Id$ +#include "Server_Task.h" +#include "Client_Task.h" +#include "ace/Get_Opt.h" +#include "ace/Argv_Type_Converter.h" +#include "ace/SString.h" +#include "ace/Manual_Event.h" +#include "tao/Strategies/advanced_resource.h" +#include "NamingTask.h" + +ACE_CString server_orb; +ACE_CString client_orb; +CORBA::Boolean result = false; + +int +parse_args (int argc, char *argv[]) +{ + ACE_Get_Opt get_opts (argc, argv, "sk:o:n"); + int c; + + while ((c = get_opts ()) != -1) + switch (c) + { + case 's' : + result = true; + break; + case 'n': + server_orb.set ("server_orb"); + client_orb.set ("client_orb"); + break; + case '?': + default: + // This is a hack but that is okay! + return 0; + } + // Indicates sucessful parsing of the command line + return 0; +} + +int +main (int argc, char *argv[]) +{ + if (parse_args (argc, + argv) == -1) + return -1; + + try + { + // Start the Naming Service tasks + NamingTask name_service ("NamingORBA", argc, argv); + name_service.activate(); + // Wait for the Naming Service initialized. + name_service.waitInit(); + + ACE_Argv_Type_Converter satc (argc, argv); + CORBA::ORB_var sorb = + CORBA::ORB_init (satc.get_argc (), + satc.get_TCHAR_argv (), + server_orb.c_str ()); + + ACE_Manual_Event me; + Server_Task server_task (name_service.root (), + sorb.in (), + me, + ACE_Thread_Manager::instance ()); + + if (server_task.activate (THR_NEW_LWP | THR_JOINABLE, + 1, + 1) == -1) + { + ACE_ERROR ((LM_ERROR, "Error activating server task\n")); + } + + // Wait for the server thread to do some processing + me.wait (); + + ACE_Argv_Type_Converter catc (argc, argv); + CORBA::ORB_var corb = + CORBA::ORB_init (catc.get_argc (), + catc.get_TCHAR_argv (), + client_orb.c_str ()); + + Client_Task client_task (name_service.root (), + corb.in (), + ACE_Thread_Manager::instance (), + result); + + if (client_task.activate (THR_NEW_LWP | THR_JOINABLE, + 1, + 1) == -1) + { + ACE_ERROR ((LM_ERROR, "Error activating client task\n")); + } + + // Wait for the client and server to finish + ACE_Thread_Manager::instance ()->wait (); + + // Now that all threads have completed we can destroy the ORB + sorb->destroy (); + if (server_orb != client_orb) + { + corb->destroy (); + } + } + catch (const CORBA::Exception&) + { + // Ignore exceptions.. + } + return 0; +} diff --git a/TAO/orbsvcs/tests/COIOP_Naming_Test/Client_Task.cpp b/TAO/orbsvcs/tests/COIOP_Naming_Test/Client_Task.cpp new file mode 100644 index 00000000000..df927dc4b1d --- /dev/null +++ b/TAO/orbsvcs/tests/COIOP_Naming_Test/Client_Task.cpp @@ -0,0 +1,78 @@ +// +// $Id$ +// + +#include "Client_Task.h" +#include "tao/ORB_Core.h" +#include "TestC.h" + +ACE_RCSID(Muxing, Client_Task, "$Id$") + +Client_Task::Client_Task (CosNaming::NamingContext_ptr root_context, + CORBA::ORB_ptr corb, + ACE_Thread_Manager *thr_mgr, + CORBA::Boolean result) + : ACE_Task_Base (thr_mgr) + , root_context_ (CosNaming::NamingContext::_duplicate (root_context)) + , corb_ (CORBA::ORB::_duplicate (corb)) + , result_ (result) +{ +} + +int +Client_Task::svc (void) +{ + try + { + CosNaming::Name name; + name.length(1); + name[0].id = CORBA::string_dup("Hello"); + + CORBA::Object_var tmp = root_context_->resolve (name); + + Test::Hello_var hello = + Test::Hello::_narrow(tmp.in ()); + + if (CORBA::is_nil (hello.in ())) + { + ACE_ERROR_RETURN ((LM_DEBUG, + "Nil Test::Hello reference\n"), + 1); + } + + CORBA::String_var the_string = + hello->get_string (); + + ACE_DEBUG ((LM_DEBUG, "(%P|%t) - string returned <%s>\n", + the_string.in ())); + + if (!this->result_) + { + // We would expect the call to fail, so we have an error now + ACE_ERROR ((LM_ERROR, "(%P|%t) - ERROR: get_string should have failed\n")); + } + + hello->shutdown (); + } + catch (const CORBA::TRANSIENT& ex) + { + if (!this->result_) + { + ACE_DEBUG ((LM_DEBUG, "(%P|%t) - caught expected exception\n")); + // When collocation has been disabled we expect a transient + // with minor code 2 + return 0; + } + + ex._tao_print_exception ("Caught exception:"); + return 1; + } + catch (const CORBA::Exception& ex) + { + ex._tao_print_exception ("Exception caught:"); + return 1; + } + + return 0; + +} diff --git a/TAO/orbsvcs/tests/COIOP_Naming_Test/Client_Task.h b/TAO/orbsvcs/tests/COIOP_Naming_Test/Client_Task.h new file mode 100644 index 00000000000..38be7e2df24 --- /dev/null +++ b/TAO/orbsvcs/tests/COIOP_Naming_Test/Client_Task.h @@ -0,0 +1,41 @@ +// +// $Id$ +// + +#ifndef COLLOCATED_TEST_CLIENT_TASK_H +#define COLLOCATED_TEST_CLIENT_TASK_H +#include /**/ "ace/pre.h" +#include "ace/Task.h" + +#if !defined (ACE_LACKS_PRAGMA_ONCE) +# pragma once +#endif /* ACE_LACKS_PRAGMA_ONCE */ + +#include "tao/ORB.h" +#include "orbsvcs/CosNamingC.h" + +/// Implement a Task to run the client as a thread +class Client_Task : public ACE_Task_Base +{ +public: + + /// Constructor + Client_Task (CosNaming::NamingContext_ptr root_context, + CORBA::ORB_ptr corb, + ACE_Thread_Manager *thr_mgr, + CORBA::Boolean result); + + /// Thread entry point + int svc (void); + +private: + CosNaming::NamingContext_var root_context_; + + CORBA::ORB_var corb_; + + // Boolean to indicate whether the invocation should work or not. + CORBA::Boolean result_; +}; + +#include /**/ "ace/post.h" +#endif /* COLLOCATED_TEST_CLIENT_TASK_H */ diff --git a/TAO/orbsvcs/tests/COIOP_Naming_Test/Hello.cpp b/TAO/orbsvcs/tests/COIOP_Naming_Test/Hello.cpp new file mode 100644 index 00000000000..d7339a7eb0b --- /dev/null +++ b/TAO/orbsvcs/tests/COIOP_Naming_Test/Hello.cpp @@ -0,0 +1,70 @@ +// +// $Id$ +// +#include "Hello.h" +#include "tao/ORB_Core.h" +#include "tao/ORB_Table.h" +#include "tao/Strategies/advanced_resource.h" + +ACE_RCSID(Hello, Hello, "$Id$") + + Hello::Hello (CORBA::ORB_ptr orb, + ACE_thread_t thrid) + : orb_ (CORBA::ORB::_duplicate (orb)) + , thr_id_ (thrid) +{ +} + +char * +Hello::get_string (void) + ACE_THROW_SPEC ((CORBA::SystemException)) +{ + ACE_DEBUG ((LM_DEBUG, + "(%P|%t) Upcall in process ..\n")); + + // Use portable thread IDs + ACE_Thread_ID self_ID; + ACE_Thread_ID this_ID; + this_ID.id(this->thr_id_); + + if (self_ID == this_ID) + { + if (this->orb_->orb_core ()->optimize_collocation_objects () && + this->orb_->orb_core ()->use_global_collocation ()) + { + ACE_ERROR ((LM_ERROR, + "(%P|%t) ERROR: A remote call has been made " + " exiting ..\n")); + ACE_OS::abort (); + } + else if (this->orb_->orb_core ()->optimize_collocation_objects () && + this->orb_->orb_core ()->use_global_collocation () == 0) + { + TAO::ORB_Table * const orb_table = + TAO::ORB_Table::instance (); + + if (orb_table->find ("server_orb") == 0) + { + // We are running on a single ORB and this is an error. + ACE_ERROR ((LM_ERROR, + "(%P|%t) ERROR: A remote call has been made " + " with a single ORB " + " exiting ..\n")); + ACE_OS::abort (); + } + } + } + + return CORBA::string_dup ("Hello there!"); +} + +void +Hello::shutdown (void) + ACE_THROW_SPEC ((CORBA::SystemException)) +{ + // Give the client thread time to return from the collocated + // call to this method before shutting down the ORB. We sleep + // to avoid BAD_INV_ORDER exceptions on fast dual processor machines. + ACE_OS::sleep (1); + this->orb_->shutdown (0); +} diff --git a/TAO/orbsvcs/tests/COIOP_Naming_Test/Hello.h b/TAO/orbsvcs/tests/COIOP_Naming_Test/Hello.h new file mode 100644 index 00000000000..63b4ec180be --- /dev/null +++ b/TAO/orbsvcs/tests/COIOP_Naming_Test/Hello.h @@ -0,0 +1,38 @@ +// +// $Id$ +// + +#ifndef HELLO_H +#define HELLO_H +#include /**/ "ace/pre.h" + +#include "TestS.h" + +#include "ace/OS.h" + +/// Implement the Test::Hello interface +class Hello + : public virtual POA_Test::Hello +{ +public: + /// Constructor + Hello (CORBA::ORB_ptr orb, + ACE_thread_t thr_id); + + // = The skeleton methods + virtual char * get_string (void) + ACE_THROW_SPEC ((CORBA::SystemException)); + + virtual void shutdown (void) + ACE_THROW_SPEC ((CORBA::SystemException)); + +private: + /// Use an ORB reference to conver strings to objects and shutdown + /// the application. + CORBA::ORB_var orb_; + + ACE_thread_t thr_id_; +}; + +#include /**/ "ace/post.h" +#endif /* HELLO_H */ diff --git a/TAO/orbsvcs/tests/COIOP_Naming_Test/NamingTask.cpp b/TAO/orbsvcs/tests/COIOP_Naming_Test/NamingTask.cpp new file mode 100644 index 00000000000..521f7a478e6 --- /dev/null +++ b/TAO/orbsvcs/tests/COIOP_Naming_Test/NamingTask.cpp @@ -0,0 +1,77 @@ + +#include "NamingTask.h" +#include <tao/Version.h> +#include <orbsvcs/Naming/Naming_Server.h> +#include <ace/OS_NS_unistd.h> +#include "ace/Argv_Type_Converter.h" +#include <iostream> + +NamingTask::NamingTask (const char* orbname, int argc, char** argv) + : initialized_(false) +{ + ACE_Argv_Type_Converter satc (argc, argv); + orb_ = CORBA::ORB_init(satc.get_argc (), satc.get_TCHAR_argv (), orbname); +} + +void NamingTask::waitInit () +{ + // Wait for Naming Service initialized. + while (! initialized_) { + ACE_OS::sleep(ACE_Time_Value(0, 100 * 1000)); + } +} + +void NamingTask::end() +{ + orb_->shutdown(0); + wait(); +} + +CosNaming::NamingContext_ptr +NamingTask::root (void) const +{ + return CosNaming::NamingContext::_duplicate (root_); +} + +int NamingTask::svc() +{ + try { + // Get reference to Root POA + CORBA::Object_var obj = orb_->resolve_initial_references("RootPOA"); + PortableServer::POA_var poa = PortableServer::POA::_narrow(obj.in()); + + // Activate POA Manager + PortableServer::POAManager_var poaManager = poa->the_POAManager(); + poaManager->activate(); + + // Initialize the naming service + // We are not going to look for other naming servers + TAO_Naming_Server naming; + if (naming.init(orb_.in(), + poa.in(), + ACE_DEFAULT_MAP_SIZE, + 0, + 0, + 0, + TAO_NAMING_BASE_ADDR, + 0) == 0) + { + ACE_DEBUG ((LM_DEBUG, "The Naming Service Task is ready.\n")); + root_ = CosNaming::NamingContext::_duplicate (naming.operator->()); + initialized_ = true; + // Accept requests + orb_->run(); + orb_->destroy(); + return 0; + } + else { + std::cerr << "Unable to initialize the Naming Service." << std::endl; + } + } + catch (CORBA::Exception& ex) { + std::cerr << "NamingTask::svc() CORBA::Exception: " << ex << std::endl; + } + + return -1; +} + diff --git a/TAO/orbsvcs/tests/COIOP_Naming_Test/NamingTask.h b/TAO/orbsvcs/tests/COIOP_Naming_Test/NamingTask.h new file mode 100644 index 00000000000..e2a618d9422 --- /dev/null +++ b/TAO/orbsvcs/tests/COIOP_Naming_Test/NamingTask.h @@ -0,0 +1,24 @@ +#ifndef NAMINGTASK_H +#define NAMINGTASK_H + +#include <tao/corba.h> +#include <ace/Task.h> +#include "orbsvcs/CosNamingC.h" + +class NamingTask : public ACE_Task<ACE_MT_SYNCH> +{ +public: + NamingTask (const char* orbname, int argc, char** argv); + virtual int svc(); + void waitInit (); + void end(); + + CosNaming::NamingContext_ptr root (void) const; + +private: + CORBA::ORB_var orb_; + bool initialized_; + CosNaming::NamingContext_var root_; +}; + +#endif diff --git a/TAO/orbsvcs/tests/COIOP_Naming_Test/Server_Task.cpp b/TAO/orbsvcs/tests/COIOP_Naming_Test/Server_Task.cpp new file mode 100644 index 00000000000..768850a5536 --- /dev/null +++ b/TAO/orbsvcs/tests/COIOP_Naming_Test/Server_Task.cpp @@ -0,0 +1,79 @@ +// +// $Id$ +// +#include "Server_Task.h" +#include "TestS.h" +#include "Hello.h" + +#include "ace/Manual_Event.h" + +ACE_RCSID(Collocated_Test, + Server_Task, + "$Id$") + + +Server_Task::Server_Task (CosNaming::NamingContext_ptr root_context, + CORBA::ORB_ptr sorb, + ACE_Manual_Event &me, + ACE_Thread_Manager *thr_mgr) + : ACE_Task_Base (thr_mgr) + , root_context_ (CosNaming::NamingContext::_duplicate (root_context)) + , me_ (me) + , sorb_ (CORBA::ORB::_duplicate (sorb)) +{ +} + +int +Server_Task::svc (void) +{ + try + { + CORBA::Object_var poa_object = + this->sorb_->resolve_initial_references("RootPOA"); + + PortableServer::POA_var root_poa = + PortableServer::POA::_narrow (poa_object.in ()); + + if (CORBA::is_nil (root_poa.in ())) + ACE_ERROR_RETURN ((LM_ERROR, + " (%P|%t) Panic: nil RootPOA\n"), + 1); + + PortableServer::POAManager_var poa_manager = + root_poa->the_POAManager (); + + Hello *hello_impl = 0; + ACE_NEW_RETURN (hello_impl, + Hello (this->sorb_.in (), + ACE_Thread::self ()), + 1); + + PortableServer::ServantBase_var owner_transfer(hello_impl); + + Test::Hello_var hello = + hello_impl->_this (); + + CosNaming::NamingContext_var example_nc; + CosNaming::Name name; + name.length(1); + name[0].id = CORBA::string_dup("Hello"); + root_context_->rebind(name, hello.in()); + + poa_manager->activate (); + + // Signal the main thread before we call orb->run (); + this->me_.signal (); + + ACE_Time_Value runtime (10); + this->sorb_->run (runtime); + + ACE_DEBUG ((LM_DEBUG, "(%P|%t) server - event loop finished\n")); + } + catch (const CORBA::Exception& ex) + { + ex._tao_print_exception ("Exception caught:"); + return 1; + } + + return 0; +} diff --git a/TAO/orbsvcs/tests/COIOP_Naming_Test/Server_Task.h b/TAO/orbsvcs/tests/COIOP_Naming_Test/Server_Task.h new file mode 100644 index 00000000000..4d7be111da0 --- /dev/null +++ b/TAO/orbsvcs/tests/COIOP_Naming_Test/Server_Task.h @@ -0,0 +1,48 @@ +// -*- C++ -*- +// +// $Id$ + +#ifndef COLLOCATED_SERVER_TASK_H +#define COLLOCATED_SERVER_TASK_H + +#include /**/ "ace/pre.h" + +#include "ace/Task.h" + +#if !defined (ACE_LACKS_PRAGMA_ONCE) +# pragma once +#endif /* ACE_LACKS_PRAGMA_ONCE */ + +#include "tao/ORB.h" +#include "orbsvcs/CosNamingC.h" + +ACE_BEGIN_VERSIONED_NAMESPACE_DECL +class ACE_Manual_Event; +ACE_END_VERSIONED_NAMESPACE_DECL + +/// Implement a Task to run the server in a single thread +class Server_Task : public ACE_Task_Base +{ +public: + /// Constructor + Server_Task (CosNaming::NamingContext_ptr root_context, + CORBA::ORB_ptr sorb, + ACE_Manual_Event &me, + ACE_Thread_Manager *thr_mgr); + + /// Thread entry point + int svc (void); + +private: + CosNaming::NamingContext_var root_context_; + + /// Manual event to wake up the main thread to create a client + /// thread. + ACE_Manual_Event &me_; + + CORBA::ORB_var sorb_; +}; + +#include /**/ "ace/post.h" + +#endif /* COLLOCATED_SERVER_TASK_H */ diff --git a/TAO/orbsvcs/tests/COIOP_Naming_Test/Test.idl b/TAO/orbsvcs/tests/COIOP_Naming_Test/Test.idl new file mode 100644 index 00000000000..3c0976e106d --- /dev/null +++ b/TAO/orbsvcs/tests/COIOP_Naming_Test/Test.idl @@ -0,0 +1,20 @@ +// +// $Id$ +// + +/// Put the interfaces in a module, to avoid global namespace pollution +module Test +{ + /// A very simple interface + interface Hello + { + /// Return a simple string + string get_string (); + + /// A method to shutdown the ORB + /** + * This method is used to simplify the test shutdown process + */ + oneway void shutdown (); + }; +}; diff --git a/TAO/orbsvcs/tests/COIOP_Naming_Test/run_test.pl b/TAO/orbsvcs/tests/COIOP_Naming_Test/run_test.pl new file mode 100755 index 00000000000..7c45f9d5df0 --- /dev/null +++ b/TAO/orbsvcs/tests/COIOP_Naming_Test/run_test.pl @@ -0,0 +1,82 @@ +eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}' + & eval 'exec perl -S $0 $argv:q' + if 0; + +# $Id$ +# -*- perl -*- + +use lib "$ENV{ACE_ROOT}/bin"; +use PerlACE::Run_Test; + +$iorfile = PerlACE::LocalFile ("test.ior"); +unlink $iorfile; +$status = 0; + +if (PerlACE::is_vxworks_test()) { + $SV = new PerlACE::ProcessVX ("COIOP_Naming_Test"); +} +else { + $SV = new PerlACE::Process ("COIOP_Naming_Test"); +} + +print STDERR "======== Running in Default Mode \n"; +$SV->Arguments ("-s -o $iorfile -k file://$iorfile -ORBDebugLevel 10"); +$sv = $SV->SpawnWaitKill (60); + +if ($sv != 0) { + print STDERR "ERROR in Collocated_Test\n"; + $status = 1; +} +unlink $iorfile; + +print STDERR "======== Running with per-orb \n"; +$SV->Arguments ("-s -o $iorfile -k file://$iorfile -ORBCollocation per-orb"); +$sv = $SV->SpawnWaitKill (60); + +if ($sv != 0) { + print STDERR "ERROR in Collocated_Test\n"; + $status = 1; +} +unlink $iorfile; + +print STDERR "======== Running with no collocation \n"; +$SV->Arguments ("-o $iorfile -k file://$iorfile -ORBCollocation no"); +$sv = $SV->SpawnWaitKill (60); + +if ($sv != 0) { + print STDERR "ERROR in Collocated_Test\n"; + $status = 1; +} +unlink $iorfile; + +print STDERR "======== Running in default mode and two ORBS \n"; +$SV->Arguments ("-s -o $iorfile -k file://$iorfile -n"); +$sv = $SV->SpawnWaitKill (60); + +if ($sv != 0) { + print STDERR "ERROR in Collocated_Test\n"; + $status = 1; +} +unlink $iorfile; + +print STDERR "======== Running in per-orb mode and two ORBS \n"; +$SV->Arguments ("-o $iorfile -k file://$iorfile -n -ORBCollocation per-orb"); +$sv = $SV->SpawnWaitKill (60); + +if ($sv != 0) { + print STDERR "ERROR in Collocated_Test\n"; + $status = 1; +} +unlink $iorfile; + +print STDERR "======== Running in no collocation mode and two ORBS \n"; +$SV->Arguments ("-o $iorfile -k file://$iorfile -n -ORBCollocation no"); +$sv = $SV->SpawnWaitKill (60); + +if ($sv != 0) { + print STDERR "ERROR in Collocated_Test\n"; + $status = 1; +} +unlink $iorfile; + +exit $status; |