diff options
author | Johnny Willemsen <jwillemsen@remedy.nl> | 2005-08-08 08:54:30 +0000 |
---|---|---|
committer | Johnny Willemsen <jwillemsen@remedy.nl> | 2005-08-08 08:54:30 +0000 |
commit | 497c3c6f4c3cde70f2b1e13d59d7015cf7f90417 (patch) | |
tree | f9b270aeef8881569b917292a4776bb83dc8d8c1 /TAO/tests/Collocation_Oneway_Tests | |
parent | 8f46a76c1ba1336c38c785b68f19bcc74a3bcc49 (diff) | |
download | ATCD-497c3c6f4c3cde70f2b1e13d59d7015cf7f90417.tar.gz |
ChangeLogTag: Mon Aug 8 08:48:12 UTC 2005 Johnny Willemsen <jwillemsen@remedy.nl>
Diffstat (limited to 'TAO/tests/Collocation_Oneway_Tests')
-rw-r--r-- | TAO/tests/Collocation_Oneway_Tests/Client_Task.cpp | 114 | ||||
-rw-r--r-- | TAO/tests/Collocation_Oneway_Tests/Client_Task.h | 46 | ||||
-rw-r--r-- | TAO/tests/Collocation_Oneway_Tests/Collocated_Test.cpp | 132 | ||||
-rw-r--r-- | TAO/tests/Collocation_Oneway_Tests/Collocation__Oneway_Tests.mpc | 6 | ||||
-rw-r--r-- | TAO/tests/Collocation_Oneway_Tests/Hello.cpp | 75 | ||||
-rw-r--r-- | TAO/tests/Collocation_Oneway_Tests/Hello.h | 50 | ||||
-rw-r--r-- | TAO/tests/Collocation_Oneway_Tests/Server_Task.cpp | 105 | ||||
-rw-r--r-- | TAO/tests/Collocation_Oneway_Tests/Server_Task.h | 46 | ||||
-rw-r--r-- | TAO/tests/Collocation_Oneway_Tests/Test.idl | 23 | ||||
-rwxr-xr-x | TAO/tests/Collocation_Oneway_Tests/run_test.pl | 62 |
10 files changed, 659 insertions, 0 deletions
diff --git a/TAO/tests/Collocation_Oneway_Tests/Client_Task.cpp b/TAO/tests/Collocation_Oneway_Tests/Client_Task.cpp new file mode 100644 index 00000000000..5d3f4b65659 --- /dev/null +++ b/TAO/tests/Collocation_Oneway_Tests/Client_Task.cpp @@ -0,0 +1,114 @@ +// +// $Id$ +// + +#include "tao/Messaging/Messaging.h" +#include "Client_Task.h" +#include "TestC.h" + +ACE_RCSID(Collocation_Oneway_Tests, Client_Task, "$Id$") + +Client_Task::Client_Task (const char *ior, + CORBA::ORB_ptr corb, + Client_Task::ClientSyncModeEnum syncMode, + ACE_Thread_Manager *thr_mgr) + : ACE_Task_Base (thr_mgr) + , input_ (ior) + , corb_ (CORBA::ORB::_duplicate (corb)) + , syncMode_ (syncMode) + +{ +} + +int +Client_Task::svc (void) +{ + ACE_TRY_NEW_ENV + { + CORBA::Object_var tmp = + this->corb_->string_to_object (input_ + ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + Test::Hello_var hello = + Test::Hello::_narrow(tmp.in () ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + if (CORBA::is_nil (hello.in ())) + { + ACE_ERROR_RETURN ((LM_DEBUG, + "Nil Test::Hello reference <%s>\n", + input_), + 1); + } + + Test::Hello_var tmpVar = hello; + CORBA::Any anyPolicy; + + Messaging::SyncScope selectedScope = Messaging::SYNC_NONE; // default + + if(syncMode_ == Client_Task::TRANSPORT) { + selectedScope = Messaging::SYNC_WITH_TRANSPORT; + ACE_DEBUG ((LM_DEBUG, "(%P|%t) - SYNC_WITH_TRANSPORT collocated oneway test\n")); + } + else if(syncMode_ == Client_Task::SERVER) { + selectedScope = Messaging::SYNC_WITH_SERVER; + ACE_DEBUG ((LM_DEBUG, "(%P|%t) - SYNC_WITH_SERVER collocated oneway test\n")); + } + else if(syncMode_ == Client_Task::TARGET) { + selectedScope = Messaging::SYNC_WITH_TARGET; + ACE_DEBUG ((LM_DEBUG, "(%P|%t) - SYNC_WITH_TARGET collocated oneway test\n")); + } + else if(syncMode_ == Client_Task::NONE) { + selectedScope = Messaging::SYNC_NONE; + ACE_DEBUG ((LM_DEBUG, "(%P|%t) - SYNC_NONE collocated oneway test\n")); + } + + anyPolicy <<= selectedScope; + CORBA::PolicyList polList; + polList.length(1); + polList[0] = this->corb_->create_policy( + Messaging::SYNC_SCOPE_POLICY_TYPE, anyPolicy ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + CORBA::Object_var tmpGenericVar = + tmpVar->_set_policy_overrides(polList,CORBA::ADD_OVERRIDE ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + // do unchecked narrow because ORB's not activated. Otherwise get TRANSIENT exception + hello = Test::Hello::_narrow(tmpGenericVar.in()); + + if (CORBA::is_nil (hello.in ())) + { + ACE_ERROR_RETURN ((LM_DEBUG, + "Nil Test::Hello reference <%s>\n", + input_), + 1); + } + + CORBA::String_var the_string = + hello->get_string (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_TRY_CHECK; + + ACE_DEBUG ((LM_DEBUG, "(%P|%t) - string returned <%s>\n", + the_string.in ())); + + hello->onewayTest(ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_TRY_CHECK; + + ACE_DEBUG ((LM_DEBUG, "(%P|%t) - returned from onewayTest() call \n")); + + hello->shutdown (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_TRY_CHECK; + } + ACE_CATCHANY + { + ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, + "Exception caught:"); + return 1; + } + ACE_ENDTRY; + + return 0; + +} diff --git a/TAO/tests/Collocation_Oneway_Tests/Client_Task.h b/TAO/tests/Collocation_Oneway_Tests/Client_Task.h new file mode 100644 index 00000000000..ffd155b2e2c --- /dev/null +++ b/TAO/tests/Collocation_Oneway_Tests/Client_Task.h @@ -0,0 +1,46 @@ +// +// $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" + + +/// Implement a Task to run the client as a thread +class Client_Task : public ACE_Task_Base +{ +public: + +enum ClientSyncModeEnum { + NONE, + TRANSPORT, + SERVER, + TARGET +}; + + /// Constructor + Client_Task (const char *input, + CORBA::ORB_ptr corb, + ClientSyncModeEnum syncMode, + ACE_Thread_Manager *thr_mgr); + + /// Thread entry point + int svc (void); + +private: + const char *input_; + + CORBA::ORB_var corb_; + + ClientSyncModeEnum syncMode_; +}; + +#include /**/ "ace/post.h" +#endif /* COLLOCATED_TEST_CLIENT_TASK_H */ diff --git a/TAO/tests/Collocation_Oneway_Tests/Collocated_Test.cpp b/TAO/tests/Collocation_Oneway_Tests/Collocated_Test.cpp new file mode 100644 index 00000000000..d2801d12946 --- /dev/null +++ b/TAO/tests/Collocation_Oneway_Tests/Collocated_Test.cpp @@ -0,0 +1,132 @@ +// $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" + +const char *output = "test.ior"; +const char *input = "file://test.ior"; +const char *mode = "SYNC_NONE"; + +Client_Task::ClientSyncModeEnum syncMode = Client_Task::NONE; + +// static int named_orbs = 0; +ACE_CString server_orb; +ACE_CString client_orb; +int +parse_args (int argc, char *argv[]) +{ + ACE_Get_Opt get_opts (argc, argv, "k:o:n:m:"); + int c; + + while ((c = get_opts ()) != -1) + switch (c) + { + case 'o': + output = get_opts.opt_arg (); + break; + case 'k': + input = get_opts.opt_arg (); + break; + case 'n': + // named_orbs = 1; + server_orb.set ("server_orb"); + client_orb.set ("client_orb"); + break; + case 'm': + mode = get_opts.opt_arg (); + // cout << "mode = " << mode << endl; + ACE_DEBUG ((LM_DEBUG, "(%P|%t) - mode set to <%C> for collocated oneway test\n", mode)); + if(mode) { + if(!strcmp("none", mode)) { + syncMode = Client_Task::NONE; + } + else if (!strcmp("transport", mode)) { + syncMode = Client_Task::TRANSPORT; + } + else if (!strcmp("server", mode)) { + syncMode = Client_Task::SERVER; + } + else if (!strcmp("target", mode)) { + syncMode = Client_Task::TARGET; + } + } + else { + // same hack used in original test! + return 0; + } + 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; + + ACE_DECLARE_NEW_CORBA_ENV; + ACE_TRY + { + 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_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + ACE_Manual_Event me; + Server_Task server_task (output, + 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 () + ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + Client_Task client_task (input, + corb.in (), + syncMode, + ACE_Thread_Manager::instance ()); + + if (client_task.activate (THR_NEW_LWP | THR_JOINABLE, + 1, + 1) == -1) + { + ACE_ERROR ((LM_ERROR, "Error activating client task\n")); + } + + ACE_Thread_Manager::instance ()->wait (); + } + ACE_CATCHANY + { + // Ignore exceptions.. + } + ACE_ENDTRY; + return 0; +} diff --git a/TAO/tests/Collocation_Oneway_Tests/Collocation__Oneway_Tests.mpc b/TAO/tests/Collocation_Oneway_Tests/Collocation__Oneway_Tests.mpc new file mode 100644 index 00000000000..43a83482d9e --- /dev/null +++ b/TAO/tests/Collocation_Oneway_Tests/Collocation__Oneway_Tests.mpc @@ -0,0 +1,6 @@ +// -*- MPC -*- +// $Id$ + +project(Collocation_Tests): taoserver, messaging, valuetype { + exename = Collocated_Test +} diff --git a/TAO/tests/Collocation_Oneway_Tests/Hello.cpp b/TAO/tests/Collocation_Oneway_Tests/Hello.cpp new file mode 100644 index 00000000000..e4f3c6d80d7 --- /dev/null +++ b/TAO/tests/Collocation_Oneway_Tests/Hello.cpp @@ -0,0 +1,75 @@ +// +// $Id$ +// +#include "Hello.h" +#include "tao/ORB_Core.h" +#include "tao/ORB_Table.h" + +ACE_RCSID(Collocation_Oneway_Tests, Hello, "$Id$") + + Hello::Hello (CORBA::ORB_ptr orb, + ACE_thread_t thrid) + : orb_ (CORBA::ORB::_duplicate (orb)) + , thr_id_ (thrid) +{ +} + +void +Hello::onewayTest (ACE_ENV_SINGLE_ARG_DECL_NOT_USED) + ACE_THROW_SPEC ((CORBA::SystemException)) +{ + ACE_DEBUG ((LM_DEBUG, + "(%P|%t) onewayTest() Upcall in process ..\n")); + return; +} + + +char * +Hello::get_string (ACE_ENV_SINGLE_ARG_DECL_NOT_USED) + 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 (ACE_ENV_SINGLE_ARG_DECL) + ACE_THROW_SPEC ((CORBA::SystemException)) +{ + this->orb_->shutdown (0 ACE_ENV_ARG_PARAMETER); +} diff --git a/TAO/tests/Collocation_Oneway_Tests/Hello.h b/TAO/tests/Collocation_Oneway_Tests/Hello.h new file mode 100644 index 00000000000..c145e77f7c1 --- /dev/null +++ b/TAO/tests/Collocation_Oneway_Tests/Hello.h @@ -0,0 +1,50 @@ +// +// $Id$ +// + +#ifndef HELLO_H +#define HELLO_H +#include /**/ "ace/pre.h" + +#include "TestS.h" + +#if defined (_MSC_VER) +# pragma warning(push) +# pragma warning (disable:4250) +#endif /* _MSC_VER */ + +#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 (ACE_ENV_SINGLE_ARG_DECL) + ACE_THROW_SPEC ((CORBA::SystemException)); + + virtual void onewayTest (ACE_ENV_SINGLE_ARG_DECL) + ACE_THROW_SPEC ((CORBA::SystemException)); + + virtual void shutdown (ACE_ENV_SINGLE_ARG_DECL) + 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_; +}; + +#if defined(_MSC_VER) +# pragma warning(pop) +#endif /* _MSC_VER */ + +#include /**/ "ace/post.h" +#endif /* HELLO_H */ diff --git a/TAO/tests/Collocation_Oneway_Tests/Server_Task.cpp b/TAO/tests/Collocation_Oneway_Tests/Server_Task.cpp new file mode 100644 index 00000000000..746c3ff7758 --- /dev/null +++ b/TAO/tests/Collocation_Oneway_Tests/Server_Task.cpp @@ -0,0 +1,105 @@ +// +// $Id$ +// +#include "Server_Task.h" +#include "TestS.h" +#include "Hello.h" + +#include "ace/Manual_Event.h" + +ACE_RCSID(Collocation_Oneway_Tests, + Server_Task, + "$Id$") + + +Server_Task::Server_Task (const char *output, + CORBA::ORB_ptr sorb, + ACE_Manual_Event &me, + ACE_Thread_Manager *thr_mgr) + : ACE_Task_Base (thr_mgr) + , output_ (output) + , me_ (me) + , sorb_ (CORBA::ORB::_duplicate (sorb)) +{ +} + +int +Server_Task::svc (void) +{ + ACE_TRY_NEW_ENV + { + CORBA::Object_var poa_object = + this->sorb_->resolve_initial_references("RootPOA" + ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + PortableServer::POA_var root_poa = + PortableServer::POA::_narrow (poa_object.in () + ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + 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 (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_TRY_CHECK; + + Hello *hello_impl; + 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 (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_TRY_CHECK; + + CORBA::String_var ior = + this->sorb_->object_to_string (hello.in () + ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + // Output the IOR to the <this->output_> + FILE *output_file= ACE_OS::fopen (this->output_, + "w"); + if (output_file == 0) + ACE_ERROR_RETURN ((LM_ERROR, + "Cannot open output file for writing IOR: %s", + this->output_), + 1); + + ACE_OS::fprintf (output_file, "%s", ior.in ()); + ACE_OS::fclose (output_file); + + poa_manager->activate (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_TRY_CHECK; + + // Signal the main thread before we call orb->run (); + this->me_.signal (); + + this->sorb_->run (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_TRY_CHECK; + + ACE_DEBUG ((LM_DEBUG, "(%P|%t) server - event loop finished\n")); + + root_poa->destroy (1, 1 ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + this->sorb_->destroy (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_TRY_CHECK; + } + ACE_CATCHANY + { + ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, + "Exception caught:"); + return 1; + } + ACE_ENDTRY; + + return 0; +} diff --git a/TAO/tests/Collocation_Oneway_Tests/Server_Task.h b/TAO/tests/Collocation_Oneway_Tests/Server_Task.h new file mode 100644 index 00000000000..4f2307adc30 --- /dev/null +++ b/TAO/tests/Collocation_Oneway_Tests/Server_Task.h @@ -0,0 +1,46 @@ +// -*- 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" + +class ACE_Manual_Event; + +/// Implement a Task to run the server in a single thread +class Server_Task : public ACE_Task_Base +{ +public: + /// Constructor + Server_Task (const char *output, + CORBA::ORB_ptr sorb, + ACE_Manual_Event &me, + ACE_Thread_Manager *thr_mgr); + + /// Thread entry point + int svc (void); + +private: + /// Output file for IOR + const char *output_; + + /// 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/tests/Collocation_Oneway_Tests/Test.idl b/TAO/tests/Collocation_Oneway_Tests/Test.idl new file mode 100644 index 00000000000..dc244b3ff58 --- /dev/null +++ b/TAO/tests/Collocation_Oneway_Tests/Test.idl @@ -0,0 +1,23 @@ +// +// $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 (); + + /// test oneway call + oneway void onewayTest(); + + /// A method to shutdown the ORB + /** + * This method is used to simplify the test shutdown process + */ + oneway void shutdown (); + }; +}; diff --git a/TAO/tests/Collocation_Oneway_Tests/run_test.pl b/TAO/tests/Collocation_Oneway_Tests/run_test.pl new file mode 100755 index 00000000000..833ea238102 --- /dev/null +++ b/TAO/tests/Collocation_Oneway_Tests/run_test.pl @@ -0,0 +1,62 @@ +eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}' + & eval 'exec perl -S $0 $argv:q' + if 0; + +# $Id$ +# -*- perl -*- + +use lib '../../../bin'; +use PerlACE::Run_Test; + +$iorfile = PerlACE::LocalFile ("test.ior"); +unlink $iorfile; +$status = 0; + +if (PerlACE::is_vxworks_test()) { + $SV = new PerlACE::ProcessVX ("Collocated_Test"); +} +else { + $SV = new PerlACE::Process ("Collocated_Test"); +} + +print STDERR "======== Running in Default Mode \n"; +$SV->Arguments ("-o $iorfile -k file://$iorfile -m none "); +$sv = $SV->SpawnWaitKill (60); + +if ($sv != 0) { + print STDERR "ERROR in Collocation_Oneway_Test\n"; + $status = 1; +} +unlink $iorfile; + +print STDERR "======== Running in Default Mode \n"; +$SV->Arguments ("-o $iorfile -k file://$iorfile -m transport"); +$sv = $SV->SpawnWaitKill (60); + +if ($sv != 0) { + print STDERR "ERROR in Collocation_Oneway_Test\n"; + $status = 1; +} +unlink $iorfile; + +print STDERR "======== Running in Default Mode \n"; +$SV->Arguments ("-o $iorfile -k file://$iorfile -m server"); +$sv = $SV->SpawnWaitKill (60); + +if ($sv != 0) { + print STDERR "ERROR in Collocation_Oneway_Test\n"; + $status = 1; +} +unlink $iorfile; + +print STDERR "======== Running in Default Mode \n"; +$SV->Arguments ("-o $iorfile -k file://$iorfile -m target"); +$sv = $SV->SpawnWaitKill (60); + +if ($sv != 0) { + print STDERR "ERROR in Collocation_Oneway_Test\n"; + $status = 1; +} +unlink $iorfile; + +exit $status; |