diff options
author | dai_y <dai_y@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 2005-10-19 00:27:51 +0000 |
---|---|---|
committer | dai_y <dai_y@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 2005-10-19 00:27:51 +0000 |
commit | b29e5800752ecefbe4e9317ac908e40d9c6eded0 (patch) | |
tree | 3bdec835860a692ca76bdcd5baa5f069645bf248 /TAO/performance-tests/CSD_Strategy/TestInf | |
parent | 189f1baf20ea719b1724adef186b8699706eb065 (diff) | |
download | ATCD-b29e5800752ecefbe4e9317ac908e40d9c6eded0.tar.gz |
Tue Oct 18 17:24:26 MST 2005 Yan Dai <dai_y@ociweb.com>
Diffstat (limited to 'TAO/performance-tests/CSD_Strategy/TestInf')
26 files changed, 1317 insertions, 0 deletions
diff --git a/TAO/performance-tests/CSD_Strategy/TestInf/AppHelper.cpp b/TAO/performance-tests/CSD_Strategy/TestInf/AppHelper.cpp new file mode 100644 index 00000000000..0f60191a9bd --- /dev/null +++ b/TAO/performance-tests/CSD_Strategy/TestInf/AppHelper.cpp @@ -0,0 +1,102 @@ +// $Id$ +#include "AppHelper.h" + +void +AppHelper::ref_to_file(CORBA::ORB_ptr orb, + CORBA::Object_ptr obj, + const char* filename + ACE_ENV_ARG_DECL) +{ + CORBA::String_var ior = orb->object_to_string(obj); + + FILE* ior_file = ACE_OS::fopen(filename, "w"); + + if (ior_file == 0) + { + ACE_ERROR((LM_ERROR, + "(%P|%t) Cannot open output file [%s] to write IOR.", + filename)); + ACE_THROW (TestAppException()); + } + + ACE_OS::fprintf(ior_file, "%s", ior.in()); + ACE_OS::fclose(ior_file); +} + + +PortableServer::POA_ptr +AppHelper::create_poa(const char* name, + PortableServer::POA_ptr root_poa, + PortableServer::POAManager_ptr mgr, + CORBA::PolicyList& policies + ACE_ENV_ARG_DECL) +{ + PortableServer::POA_var child_poa = root_poa->create_POA(name, + mgr, + policies + ACE_ENV_ARG_PARAMETER); + ACE_CHECK_RETURN (PortableServer::POA::_nil ()); + + if (CORBA::is_nil(child_poa.in())) + { + ACE_ERROR((LM_ERROR, + "(%P|%t) Failed to create child POA: %s.\n", name)); + ACE_THROW_RETURN (TestAppException(), PortableServer::POA::_nil ()); + } + + return child_poa._retn(); +} + + +CORBA::Object_ptr +AppHelper::activate_servant(PortableServer::POA_ptr poa, + PortableServer::Servant servant + ACE_ENV_ARG_DECL) +{ + // Activate the servant using the Child POA. + PortableServer::ObjectId_var oid + = poa->activate_object(servant ACE_ENV_ARG_PARAMETER); + ACE_CHECK_RETURN (CORBA::Object::_nil ()); + + CORBA::Object_var obj + = poa->servant_to_reference(servant ACE_ENV_ARG_PARAMETER); + ACE_CHECK_RETURN (CORBA::Object::_nil ()); + + if (CORBA::is_nil(obj.in())) + { + ACE_ERROR((LM_ERROR, + "(%P|%t) Failed to convert servant_to_ref.\n")); + ACE_THROW_RETURN (TestAppException(), CORBA::Object::_nil ()); + } + + return obj._retn(); +} + + +bool +AppHelper::validate_connection (CORBA::Object_ptr obj) +{ + for (CORBA::ULong j = 0; j != 100; ++j) + { + ACE_TRY_NEW_ENV + { +#if (TAO_HAS_CORBA_MESSAGING == 1) + CORBA::PolicyList_var unused; + obj->_validate_connection (unused + ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; +#else + obj->_is_a ("Not_An_IDL_Type" + ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; +#endif /* TAO_HAS_MESSAGING == 1 */ + return true; + } + ACE_CATCHANY + { + } + ACE_ENDTRY; + } + + return false; +} diff --git a/TAO/performance-tests/CSD_Strategy/TestInf/AppHelper.h b/TAO/performance-tests/CSD_Strategy/TestInf/AppHelper.h new file mode 100644 index 00000000000..bdc6c2ab5b3 --- /dev/null +++ b/TAO/performance-tests/CSD_Strategy/TestInf/AppHelper.h @@ -0,0 +1,114 @@ +// $Id$ +#ifndef APPHELPER_H +#define APPHELPER_H + +#include "CSD_PT_TestInf_Export.h" +#include "TestAppExceptionC.h" +#include "tao/PortableServer/PortableServer.h" +#include "tao/ORB.h" +#include "ace/OS.h" +#include "ace/Log_Msg.h" + + +template <typename T> +struct RefHelper +{ + typedef typename T::_ptr_type T_ptr; + typedef typename T::_var_type T_var; + + static T_ptr string_to_ref(CORBA::ORB_ptr orb, + const char* ior + ACE_ENV_ARG_DECL) + { + CORBA::Object_var obj = orb->string_to_object(ior ACE_ENV_ARG_PARAMETER); + ACE_CHECK_RETURN(T::_nil ()); + + if (CORBA::is_nil(obj.in())) + { + ACE_ERROR((LM_ERROR, + "(%P|%t) Failed to convert IOR string to obj ref.\n")); + ACE_THROW_RETURN (TestAppException(), T::_nil ()); + } + + T_var t_obj = T::_narrow(obj.in() ACE_ENV_ARG_PARAMETER); + ACE_CHECK_RETURN(T::_nil ()); + + if (CORBA::is_nil(t_obj.in())) + { + ACE_ERROR((LM_ERROR, + "(%P|%t) Failed to narrow obj ref to T interface.\n")); + ACE_THROW_RETURN (TestAppException(), T::_nil ()); + } + + return t_obj._retn(); + } + + static T_ptr resolve_initial_ref(CORBA::ORB_ptr orb, + const char* name + ACE_ENV_ARG_DECL) + { + CORBA::Object_var obj + = orb->resolve_initial_references(name ACE_ENV_ARG_PARAMETER); + ACE_CHECK_RETURN (T::_nil ()); + + if (CORBA::is_nil(obj.in())) + { + ACE_ERROR((LM_ERROR, + "(%P|%t) Failed to resolve initial ref for '%s'.\n", + name)); + ACE_THROW_RETURN (TestAppException(), T::_nil ()); + } + + T_var t_obj = T::_narrow(obj.in() ACE_ENV_ARG_PARAMETER); + ACE_CHECK_RETURN (T::_nil ()); + + + if (CORBA::is_nil(t_obj.in())) + { + ACE_ERROR((LM_ERROR, + "(%P|%t) Failed to narrow resolved initial ref '%s'.\n", + name)); + ACE_THROW_RETURN (TestAppException(), T::_nil ()); + } + + return t_obj._retn(); + } + +}; + +struct CSD_PT_TestInf_Export AppHelper +{ + + static void ref_to_file(CORBA::ORB_ptr orb, + CORBA::Object_ptr obj, + const char* filename + ACE_ENV_ARG_DECL); + + static PortableServer::POA_ptr create_poa + (const char* name, + PortableServer::POA_ptr root_poa, + PortableServer::POAManager_ptr mgr, + CORBA::PolicyList& policies + ACE_ENV_ARG_DECL); + + static CORBA::Object_ptr activate_servant(PortableServer::POA_ptr poa, + PortableServer::Servant servant + ACE_ENV_ARG_DECL); + + // This helper method is used because there is a chance that the + // initial CORBA request made to the target ORB will fail during + // connection establishment with a TRANSIENT CORBA SystemException. + // This occurs for some platforms (ie, windows) when several clients + // make their initial CORBA request to the same ORB at the same time, + // causing the ORB to attempt to handle several connection establishments + // at one time. Apparently, under certain conditions, it will throw the + // TRANSIENT exception to tell the client application to "try again later". + // The analogy is making a phone call. Sometimes you get a busy tone. + // This means "try again later". + // This helper function will retry until the connection establishment + // works - or until it decides that enough is enough. + static bool validate_connection (CORBA::Object_ptr obj); +}; + +#endif + diff --git a/TAO/performance-tests/CSD_Strategy/TestInf/AppShutdown.cpp b/TAO/performance-tests/CSD_Strategy/TestInf/AppShutdown.cpp new file mode 100644 index 00000000000..79d7f28c0d9 --- /dev/null +++ b/TAO/performance-tests/CSD_Strategy/TestInf/AppShutdown.cpp @@ -0,0 +1,84 @@ +// $Id$ +#include "AppShutdown.h" +#include "TestAppExceptionC.h" +#include "ace/Log_Msg.h" +#include "ace/OS_NS_unistd.h" + +AppShutdown::AppShutdown() + : num_clients_(0), + num_clients_shutdown_(0) +{ +} + + +AppShutdown::~AppShutdown() +{ +} + + +void +AppShutdown::init(CORBA::ORB_ptr orb, + unsigned num_clients + ACE_ENV_ARG_DECL) +{ + if ((!CORBA::is_nil(this->orb_.in())) || + (CORBA::is_nil(orb)) || + (num_clients == 0)) + { + // Already init()'ed, or bad argument values. + ACE_THROW(TestAppException()); + } + else + { + this->orb_ = CORBA::ORB::_duplicate(orb); + this->num_clients_ = num_clients; + this->num_clients_shutdown_ = 0; + } +} + + +void +AppShutdown::wait () +{ + this->orb_shutdown_task_.wait(); +} + + +void +AppShutdown::client_done() +{ + if ((this->num_clients_ == 0) || (CORBA::is_nil(this->orb_.in()))) + { + ACE_ERROR((LM_ERROR, "(%P|%t) AppShutdown was never initialized.\n")); + return; + } + + unsigned cur_shutdown; + + { + GuardType guard(this->lock_); + cur_shutdown = ++this->num_clients_shutdown_; + } + + if (cur_shutdown == this->num_clients_) + { + // Sleep for one second before shutting down the ORB. This + // is a poor-man version of "wait until the CSD request queue drains". + ACE_OS::sleep(1); + this->orb_shutdown_task_.orb(this->orb_.in()); + if (this->orb_shutdown_task_.open(0) != 0) + { + ACE_ERROR((LM_ERROR, "(%P|%t) AppShutdown failed to create orb "\ + "shutdown thread.\n")); + return; + } + } +} + + +AppShutdown* +AppShutdown::instance () +{ + static AppShutdown app_shutdown; + return &app_shutdown; +} diff --git a/TAO/performance-tests/CSD_Strategy/TestInf/AppShutdown.h b/TAO/performance-tests/CSD_Strategy/TestInf/AppShutdown.h new file mode 100644 index 00000000000..481659d734e --- /dev/null +++ b/TAO/performance-tests/CSD_Strategy/TestInf/AppShutdown.h @@ -0,0 +1,42 @@ +// $Id$ +#ifndef APP_SHUTDOWN_H +#define APP_SHUTDOWN_H + +#include "CSD_PT_TestInf_Export.h" +#include "OrbShutdownTask.h" +#include "tao/ORB.h" + +class CSD_PT_TestInf_Export AppShutdown +{ + public: + + AppShutdown(); + virtual ~AppShutdown(); + + void init(CORBA::ORB_ptr orb, + unsigned num_clients + ACE_ENV_ARG_DECL); + + void wait (); + + void client_done(); + + static AppShutdown* instance (); + + private: + + typedef ACE_SYNCH_MUTEX LockType; + typedef ACE_Guard<LockType> GuardType; + + LockType lock_; + CORBA::ORB_var orb_; + unsigned num_clients_; + unsigned num_clients_shutdown_; + + OrbShutdownTask orb_shutdown_task_; +}; + + +#define TheAppShutdown AppShutdown::instance() + +#endif diff --git a/TAO/performance-tests/CSD_Strategy/TestInf/CSD_PT_TestInf_Export.h b/TAO/performance-tests/CSD_Strategy/TestInf/CSD_PT_TestInf_Export.h new file mode 100644 index 00000000000..91f36276272 --- /dev/null +++ b/TAO/performance-tests/CSD_Strategy/TestInf/CSD_PT_TestInf_Export.h @@ -0,0 +1,58 @@ + +// -*- C++ -*- +// $Id$ +// Definition for Win32 Export directives. +// This file is generated automatically by generate_export_file.pl -s CSD_PT_TestInf +// ------------------------------ +#ifndef CSD_PT_TESTINF_EXPORT_H +#define CSD_PT_TESTINF_EXPORT_H + +#include "ace/config-all.h" + +#if defined (ACE_AS_STATIC_LIBS) && !defined (CSD_PT_TESTINF_HAS_DLL) +# define CSD_PT_TESTINF_HAS_DLL 0 +#endif /* ACE_AS_STATIC_LIBS && CSD_PT_TESTINF_HAS_DLL */ + +#if !defined (CSD_PT_TESTINF_HAS_DLL) +# define CSD_PT_TESTINF_HAS_DLL 1 +#endif /* ! CSD_PT_TESTINF_HAS_DLL */ + +#if defined (CSD_PT_TESTINF_HAS_DLL) && (CSD_PT_TESTINF_HAS_DLL == 1) +# if defined (CSD_PT_TESTINF_BUILD_DLL) +# define CSD_PT_TestInf_Export ACE_Proper_Export_Flag +# define CSD_PT_TESTINF_SINGLETON_DECLARATION(T) ACE_EXPORT_SINGLETON_DECLARATION (T) +# define CSD_PT_TESTINF_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) ACE_EXPORT_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) +# else /* CSD_PT_TESTINF_BUILD_DLL */ +# define CSD_PT_TestInf_Export ACE_Proper_Import_Flag +# define CSD_PT_TESTINF_SINGLETON_DECLARATION(T) ACE_IMPORT_SINGLETON_DECLARATION (T) +# define CSD_PT_TESTINF_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) ACE_IMPORT_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) +# endif /* CSD_PT_TESTINF_BUILD_DLL */ +#else /* CSD_PT_TESTINF_HAS_DLL == 1 */ +# define CSD_PT_TestInf_Export +# define CSD_PT_TESTINF_SINGLETON_DECLARATION(T) +# define CSD_PT_TESTINF_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) +#endif /* CSD_PT_TESTINF_HAS_DLL == 1 */ + +// Set CSD_PT_TESTINF_NTRACE = 0 to turn on library specific tracing even if +// tracing is turned off for ACE. +#if !defined (CSD_PT_TESTINF_NTRACE) +# if (ACE_NTRACE == 1) +# define CSD_PT_TESTINF_NTRACE 1 +# else /* (ACE_NTRACE == 1) */ +# define CSD_PT_TESTINF_NTRACE 0 +# endif /* (ACE_NTRACE == 1) */ +#endif /* !CSD_PT_TESTINF_NTRACE */ + +#if (CSD_PT_TESTINF_NTRACE == 1) +# define CSD_PT_TESTINF_TRACE(X) +#else /* (CSD_PT_TESTINF_NTRACE == 1) */ +# if !defined (ACE_HAS_TRACE) +# define ACE_HAS_TRACE +# endif /* ACE_HAS_TRACE */ +# define CSD_PT_TESTINF_TRACE(X) ACE_TRACE_IMPL(X) +# include "ace/Trace.h" +#endif /* (CSD_PT_TESTINF_NTRACE == 1) */ + +#endif /* CSD_PT_TESTINF_EXPORT_H */ + +// End of auto generated file. diff --git a/TAO/performance-tests/CSD_Strategy/TestInf/CancelledException.idl b/TAO/performance-tests/CSD_Strategy/TestInf/CancelledException.idl new file mode 100644 index 00000000000..8f9afcf68de --- /dev/null +++ b/TAO/performance-tests/CSD_Strategy/TestInf/CancelledException.idl @@ -0,0 +1,7 @@ +// $Id$ +#ifndef CANCELAPPXCEPTION_IDL +#define CANCELAPPXCEPTION_IDL + +exception CancelledException {}; + +#endif diff --git a/TAO/performance-tests/CSD_Strategy/TestInf/ClientEngine.cpp b/TAO/performance-tests/CSD_Strategy/TestInf/ClientEngine.cpp new file mode 100644 index 00000000000..361bb3cd465 --- /dev/null +++ b/TAO/performance-tests/CSD_Strategy/TestInf/ClientEngine.cpp @@ -0,0 +1,12 @@ +// $Id$ +#include "ClientEngine.h" + + +ClientEngine::ClientEngine() +{ +} + + +ClientEngine::~ClientEngine() +{ +} diff --git a/TAO/performance-tests/CSD_Strategy/TestInf/ClientEngine.h b/TAO/performance-tests/CSD_Strategy/TestInf/ClientEngine.h new file mode 100644 index 00000000000..93acb571cdc --- /dev/null +++ b/TAO/performance-tests/CSD_Strategy/TestInf/ClientEngine.h @@ -0,0 +1,39 @@ +// This may look like C, but it's really -*- C++ -*- + +//============================================================================= +/** + * @file ClientEngine.h + * + * $Id$ + * + * @author Tim Bradley <bradley_t@ociweb.com> + */ +//============================================================================= + +#ifndef CLIENT_ENGINE_H +#define CLIENT_ENGINE_H + +#include "CSD_PT_TestInf_Export.h" +#include "tao/Intrusive_Ref_Count_Base_T.h" +#include "tao/Intrusive_Ref_Count_Handle_T.h" +#include "tao/Environment.h" +#include "ace/Synch.h" +#include "ace/CORBA_macros.h" + + +class ClientEngine; +typedef TAO_Intrusive_Ref_Count_Handle<ClientEngine> ClientEngine_Handle; + + +class CSD_PT_TestInf_Export ClientEngine : public TAO_Intrusive_Ref_Count_Base<ACE_SYNCH_MUTEX> +{ + public: + + ClientEngine(); + virtual ~ClientEngine(); + + virtual bool execute(unsigned num_loops + ACE_ENV_ARG_DECL) = 0; +}; + +#endif diff --git a/TAO/performance-tests/CSD_Strategy/TestInf/ClientTask.cpp b/TAO/performance-tests/CSD_Strategy/TestInf/ClientTask.cpp new file mode 100644 index 00000000000..9b5ad8bc3cd --- /dev/null +++ b/TAO/performance-tests/CSD_Strategy/TestInf/ClientTask.cpp @@ -0,0 +1,117 @@ +// $Id$ +// This may look like C, but it's really -*- C++ -*- +#include "ClientTask.h" +#include "tao/Exception.h" +#include "ace/SString.h" + + +ClientTask::ClientTask() + : failure_count_(0), + num_loops_(1) +{ +} + + +ClientTask::~ClientTask() +{ +} + + +void +ClientTask::add_engine(ClientEngine* engine) +{ + // Pass in false so that _add_ref() is called. + ClientEngine_Handle engine_handle(engine,false); + this->engines_.push_back(engine_handle); +} + + +void +ClientTask::num_loops(unsigned num_loops) +{ + this->num_loops_ = num_loops; +} + + +int +ClientTask::open(void*) +{ + unsigned num_threads = this->engines_.size(); + + if (num_threads == 0) + { + ACE_ERROR_RETURN((LM_ERROR, + "(%P|%t) ClientTask cannot activate 0 threads.\n"), + -1); + } + + if (this->activate(THR_NEW_LWP | THR_JOINABLE, num_threads) != 0) + { + // Assumes that when activate returns non-zero return code that + // no threads were activated. + ACE_ERROR_RETURN((LM_ERROR, + "(%P|%t) ClientTask failed to activate " + "the %d client threads.\n", num_threads), + -1); + } + + return 0; +} + + +int +ClientTask::svc() +{ + ClientEngine_Handle engine; + unsigned num_loops; + + { + GuardType guard(this->lock_); + this->engines_.get(engine, this->engines_.size() - 1); + this->engines_.pop_back(); + num_loops = this->num_loops_; + } + + ACE_TRY_NEW_ENV + { + if (engine->execute(num_loops ACE_ENV_ARG_PARAMETER) == false) + { + GuardType guard(this->lock_); + this->failure_count_++; + } + ACE_TRY_CHECK; + } + ACE_CATCHANY + { + ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, + "ClientTask::svc Caught exception from execute():"); + + GuardType guard(this->lock_); + this->failure_count_ ++; + } + ACE_CATCHALL + { + ACE_ERROR((LM_ERROR, + "(%P|%t) ClientTask::svc caught unknown (...) exception "\ + "in execute() " )); + GuardType guard(this->lock_); + this->failure_count_++; + } + ACE_ENDTRY; + + return 0; +} + + +int +ClientTask::close(u_long) +{ + return 0; +} + + +unsigned +ClientTask::failure_count() const +{ + return this->failure_count_; +} diff --git a/TAO/performance-tests/CSD_Strategy/TestInf/ClientTask.h b/TAO/performance-tests/CSD_Strategy/TestInf/ClientTask.h new file mode 100644 index 00000000000..a99ccc6ad43 --- /dev/null +++ b/TAO/performance-tests/CSD_Strategy/TestInf/ClientTask.h @@ -0,0 +1,53 @@ +// This may look like C, but it's really -*- C++ -*- + +//============================================================================= +/** + * @file ClientTask.h + * + * $Id$ + * + * @author Tim Bradley <bradley_t@ociweb.com> + */ +//============================================================================= + +#ifndef CLIENT_TASK_H +#define CLIENT_TASK_H + +#include "CSD_PT_TestInf_Export.h" +#include "ClientEngine.h" +#include "ace/Task.h" +#include "ace/Vector_T.h" +#include "ace/Synch.h" + + +class CSD_PT_TestInf_Export ClientTask : public ACE_Task_Base +{ + public: + + ClientTask(); + virtual ~ClientTask(); + + void add_engine(ClientEngine* engine); + void num_loops(unsigned num_loops); + + virtual int open(void* arg = 0); + virtual int svc(); + virtual int close(u_long); + + unsigned failure_count() const; + + + private: + + typedef ACE_SYNCH_MUTEX LockType; + typedef ACE_Guard<LockType> GuardType; + + typedef ACE_Vector<ClientEngine_Handle> EngineVector; + + LockType lock_; + EngineVector engines_; + unsigned failure_count_; + unsigned num_loops_; +}; + +#endif diff --git a/TAO/performance-tests/CSD_Strategy/TestInf/CustomException.idl b/TAO/performance-tests/CSD_Strategy/TestInf/CustomException.idl new file mode 100644 index 00000000000..794900c41ce --- /dev/null +++ b/TAO/performance-tests/CSD_Strategy/TestInf/CustomException.idl @@ -0,0 +1,7 @@ +// $Id$ +#ifndef CUSTOMEXCEPTION_IDL +#define CUSTOMEXCEPTION_IDL + +exception CustomException {}; + +#endif diff --git a/TAO/performance-tests/CSD_Strategy/TestInf/FooException.idl b/TAO/performance-tests/CSD_Strategy/TestInf/FooException.idl new file mode 100644 index 00000000000..4f76953e24c --- /dev/null +++ b/TAO/performance-tests/CSD_Strategy/TestInf/FooException.idl @@ -0,0 +1,7 @@ +// $Id$ +#ifndef FOOEXCEPTION_IDL +#define FOOEXCEPTION_IDL + +exception FooException {}; + +#endif diff --git a/TAO/performance-tests/CSD_Strategy/TestInf/OrbRunner.cpp b/TAO/performance-tests/CSD_Strategy/TestInf/OrbRunner.cpp new file mode 100644 index 00000000000..fc2ddbdec04 --- /dev/null +++ b/TAO/performance-tests/CSD_Strategy/TestInf/OrbRunner.cpp @@ -0,0 +1,57 @@ +// $Id$ +#include "OrbRunner.h" +#include "OrbTask.h" +#include "TestAppExceptionC.h" + + +OrbRunner::OrbRunner(CORBA::ORB_ptr orb, unsigned num_orb_threads) + : orb_(CORBA::ORB::_duplicate(orb)), + num_orb_threads_(num_orb_threads) +{ +} + + +OrbRunner::~OrbRunner() +{ +} + + +void +OrbRunner::run(ACE_ENV_SINGLE_ARG_DECL) +{ + ACE_ASSERT(this->num_orb_threads_ > 0); + + // If the num_orb_threads_ is exactly one, then just use the current + // (mainline) thread to run the ORB event loop. + if (this->num_orb_threads_ == 1) + { + // Since the num_orb_threads_ is exactly one, we just use the current + // (mainline) thread to run the ORB event loop. + this->orb_->run(ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_CHECK; + } + else + { + // The num_orb_threads_ is greater than 1, so we will use an OrbTask + // (active object) to run the ORB event loop in (num_orb_threads_ - 1) + // threads. We use the current (mainline) thread as the other thread + // running the ORB event loop. + OrbTask orb_task(this->orb_.in(), this->num_orb_threads_ - 1); + + // Activate the OrbTask worker threads + if (orb_task.open(0) != 0) + { + ACE_ERROR((LM_ERROR, + "(%P|%t) Failed to open the OrbTask.\n")); + ACE_THROW(TestAppException()); + } + + // This will use the current (mainline) thread to run the ORB event loop. + this->orb_->run(ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_CHECK; + + // Now that the current thread has unblocked from running the orb, + // make sure to wait for all of the worker threads to complete. + orb_task.wait(); + } +} diff --git a/TAO/performance-tests/CSD_Strategy/TestInf/OrbRunner.h b/TAO/performance-tests/CSD_Strategy/TestInf/OrbRunner.h new file mode 100644 index 00000000000..cdbbcfea222 --- /dev/null +++ b/TAO/performance-tests/CSD_Strategy/TestInf/OrbRunner.h @@ -0,0 +1,24 @@ +// $Id$ +#ifndef ORB_RUNNER_H +#define ORB_RUNNER_H + +#include "CSD_PT_TestInf_Export.h" +#include "tao/ORB.h" + +class CSD_PT_TestInf_Export OrbRunner +{ + public: + + OrbRunner(CORBA::ORB_ptr orb, unsigned num_orb_threads = 1); + virtual ~OrbRunner(); + + void run(ACE_ENV_SINGLE_ARG_DECL); + + + private: + + CORBA::ORB_var orb_; + unsigned num_orb_threads_; +}; + +#endif diff --git a/TAO/performance-tests/CSD_Strategy/TestInf/OrbShutdownTask.cpp b/TAO/performance-tests/CSD_Strategy/TestInf/OrbShutdownTask.cpp new file mode 100644 index 00000000000..79ba1ba3f5e --- /dev/null +++ b/TAO/performance-tests/CSD_Strategy/TestInf/OrbShutdownTask.cpp @@ -0,0 +1,75 @@ +// This may look like C, but it's really -*- C++ -*- + +//============================================================================= +/** + * @file OrbShutdownTask.cpp + * + * $Id$ + * + * @author Tim Bradley <bradley_t@ociweb.com> + */ +//============================================================================= + +#include "OrbShutdownTask.h" +#include "ace/CORBA_macros.h" +#include "ace/OS_NS_unistd.h" + + +OrbShutdownTask::OrbShutdownTask() +{ +} + + +OrbShutdownTask::~OrbShutdownTask() +{ +} + + +void +OrbShutdownTask::orb(CORBA::ORB_ptr orb) +{ + this->orb_ = CORBA::ORB::_duplicate(orb); +} + + +int +OrbShutdownTask::open(void*) +{ + if (this->activate(THR_NEW_LWP | THR_JOINABLE, 1) != 0) + { + // Assumes that when activate returns non-zero return code that + // no threads were activated. + ACE_ERROR_RETURN((LM_ERROR, + "(%P|%t) OrbShutdownTask failed to open().\n"), + -1); + } + + return 0; +} + + +int +OrbShutdownTask::svc() +{ + ACE_TRY_NEW_ENV + { + this->orb_->shutdown(0 ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + } + ACE_CATCHALL + { + ACE_ERROR((LM_ERROR, + "(%P|%t) Exception raised by ORB::shutdown() call " + "in OrbShutdownTask::svc().\n")); + } + ACE_ENDTRY; + + return 0; +} + + +int +OrbShutdownTask::close(u_long) +{ + return 0; +} diff --git a/TAO/performance-tests/CSD_Strategy/TestInf/OrbShutdownTask.h b/TAO/performance-tests/CSD_Strategy/TestInf/OrbShutdownTask.h new file mode 100644 index 00000000000..11f2bbd341a --- /dev/null +++ b/TAO/performance-tests/CSD_Strategy/TestInf/OrbShutdownTask.h @@ -0,0 +1,40 @@ +// This may look like C, but it's really -*- C++ -*- + +//============================================================================= +/** + * @file OrbShutdownTask.h + * + * $Id$ + * + * @author Tim Bradley <bradley_t@ociweb.com> + */ +//============================================================================= + +#ifndef ORB_SHUTDOWN_TASK_H +#define ORB_SHUTDOWN_TASK_H + +#include "CSD_PT_TestInf_Export.h" +#include "ace/Task.h" +#include "tao/ORB.h" + + +class CSD_PT_TestInf_Export OrbShutdownTask : public ACE_Task_Base +{ + public: + + OrbShutdownTask(); + virtual ~OrbShutdownTask(); + + void orb(CORBA::ORB_ptr orb); + + virtual int open(void*); + virtual int svc(); + virtual int close(u_long); + + + private: + + CORBA::ORB_var orb_; +}; + +#endif diff --git a/TAO/performance-tests/CSD_Strategy/TestInf/OrbTask.cpp b/TAO/performance-tests/CSD_Strategy/TestInf/OrbTask.cpp new file mode 100644 index 00000000000..bca9d522e94 --- /dev/null +++ b/TAO/performance-tests/CSD_Strategy/TestInf/OrbTask.cpp @@ -0,0 +1,98 @@ +// This may look like C, but it's really -*- C++ -*- + +//============================================================================= +/** + * @file OrbTask.cpp + * + * $Id$ + * + * @author Tim Bradley <bradley_t@ociweb.com> + */ +//============================================================================= + +#include "OrbTask.h" + +namespace { enum { MAX_ORB_TASK_WORKER_THREADS = 20 }; } + + +OrbTask::OrbTask(CORBA::ORB_ptr orb, unsigned num_threads) + : orb_(CORBA::ORB::_duplicate(orb)), + num_threads_(num_threads) +{ +} + + +OrbTask::~OrbTask() +{ +} + + +int +OrbTask::open(void*) +{ + if (this->num_threads_ < 1) + { + ACE_ERROR_RETURN((LM_ERROR, + "(%P|%t) OrbTask failed to open. " + "num_threads_ (%d) is less-than 1.\n", + this->num_threads_), + -1); + } + + if (this->num_threads_ > MAX_ORB_TASK_WORKER_THREADS) + { + ACE_ERROR_RETURN((LM_ERROR, + "(%P|%t) OrbTask failed to open. " + "num_threads_ (%d) is too large. Max is %d.\n", + this->num_threads_, MAX_ORB_TASK_WORKER_THREADS), + -1); + } + + if (CORBA::is_nil(this->orb_.in())) + { + ACE_ERROR_RETURN((LM_ERROR, + "(%P|%t) OrbTask failed to open. " + "ORB object reference is nil.\n"), + -1); + } + + if (this->activate(THR_NEW_LWP | THR_JOINABLE, this->num_threads_) != 0) + { + // Assumes that when activate returns non-zero return code that + // no threads were activated. + ACE_ERROR_RETURN((LM_ERROR, + "(%P|%t) OrbTask failed to activate " + "(%d) worker threads.\n", + this->num_threads_), + -1); + } + + return 0; +} + + +int +OrbTask::svc() +{ + ACE_TRY_NEW_ENV + { + this->orb_->run(ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_TRY_CHECK; + } + ACE_CATCHALL + { + ACE_ERROR((LM_ERROR, + "(%P|%t) Exception raised by ORB::run() method. " + "OrbTask is stopping.\n")); + } + ACE_ENDTRY; + + return 0; +} + + +int +OrbTask::close(u_long) +{ + return 0; +} diff --git a/TAO/performance-tests/CSD_Strategy/TestInf/OrbTask.h b/TAO/performance-tests/CSD_Strategy/TestInf/OrbTask.h new file mode 100644 index 00000000000..3631273c548 --- /dev/null +++ b/TAO/performance-tests/CSD_Strategy/TestInf/OrbTask.h @@ -0,0 +1,39 @@ +// This may look like C, but it's really -*- C++ -*- + +//============================================================================= +/** + * @file OrbTask.h + * + * $Id$ + * + * @author Tim Bradley <bradley_t@ociweb.com> + */ +//============================================================================= + +#ifndef ORB_TASK_H +#define ORB_TASK_H + +#include "CSD_PT_TestInf_Export.h" +#include "ace/Task.h" +#include "tao/ORB.h" + + +class CSD_PT_TestInf_Export OrbTask : public ACE_Task_Base +{ + public: + + OrbTask(CORBA::ORB_ptr orb, unsigned num_threads = 1); + virtual ~OrbTask(); + + virtual int open(void*); + virtual int svc(); + virtual int close(u_long); + + + private: + + CORBA::ORB_var orb_; + unsigned num_threads_; +}; + +#endif diff --git a/TAO/performance-tests/CSD_Strategy/TestInf/README b/TAO/performance-tests/CSD_Strategy/TestInf/README new file mode 100644 index 00000000000..1d7f59a5c47 --- /dev/null +++ b/TAO/performance-tests/CSD_Strategy/TestInf/README @@ -0,0 +1,13 @@ +/** + +@page CSD_Strategy TestInf README File + + This is the test infrastructure library. It contains the common shared +code such as test exception idl files, the helper functions that wrap multiple +TAO operations and the classes provide the basic test functionalities. Adding +this library is to simplify the development of the new tests. + +*/ + + + diff --git a/TAO/performance-tests/CSD_Strategy/TestInf/ServantList_T.cpp b/TAO/performance-tests/CSD_Strategy/TestInf/ServantList_T.cpp new file mode 100644 index 00000000000..22133fa9868 --- /dev/null +++ b/TAO/performance-tests/CSD_Strategy/TestInf/ServantList_T.cpp @@ -0,0 +1,102 @@ +// $Id$ +#include "ServantList_T.h" +#include "AppHelper.h" +#include "TestAppExceptionC.h" + + +template <typename T> +ServantList<T>::ServantList() +{ +} + + +template <typename T> +ServantList<T>::~ServantList() +{ +} + + +template <typename T> +void +ServantList<T>::create_and_activate(unsigned num_servants, + CORBA::ORB_ptr orb, + PortableServer::POA_ptr poa, + const char* ior_fname_prefix + ACE_ENV_ARG_DECL) +{ + for (unsigned i = 0; i < num_servants; i++) + { + char buf[32]; + ACE_OS::sprintf(buf, "%02d", i + 1); + ACE_CString filename = ACE_CString(ior_fname_prefix) + "_" + buf + ".ior"; + ServantRecord record; + record.servant_ = new T(); + record.safe_servant_ = record.servant_; + + CORBA::Object_var obj + = AppHelper::activate_servant(poa, + record.safe_servant_.in() + ACE_ENV_ARG_PARAMETER); + ACE_CHECK; + + AppHelper::ref_to_file(orb, obj.in(), filename.c_str() ACE_ENV_ARG_PARAMETER); + ACE_CHECK; + + record.obj_ = T_stub::_narrow(obj.in() ACE_ENV_ARG_PARAMETER); + ACE_CHECK; + + if (CORBA::is_nil(record.obj_.in())) + { + ACE_THROW (TestAppException()); + } + + this->servant_records_.push_back(record); + } +} + + +template <typename T> +void +ServantList<T>::create_and_activate(unsigned num_servants, + PortableServer::POA_ptr poa + ACE_ENV_ARG_DECL) +{ + for (unsigned i = 0; i < num_servants; i++) + { + ServantRecord record; + record.servant_ = new T(); + record.safe_servant_ = record.servant_; + + CORBA::Object_var obj + = AppHelper::activate_servant(poa, + record.safe_servant_.in() + ACE_ENV_ARG_PARAMETER); + ACE_CHECK; + + record.obj_ = T_stub::_narrow(obj.in() ACE_ENV_ARG_PARAMETER); + ACE_CHECK; + + if (CORBA::is_nil(record.obj_.in())) + { + ACE_THROW (TestAppException()); + } + + this->servant_records_.push_back(record); + } +} + + +template <typename T> +typename ServantList<T>::T_stub_ptr +ServantList<T>::objref(unsigned index) +{ + return T_stub::_duplicate(this->servant_records_[index].obj_.in()); +} + + +template <typename T> +T* +ServantList<T>::servant(unsigned index) +{ + return this->servant_records_[index].servant_; +} diff --git a/TAO/performance-tests/CSD_Strategy/TestInf/ServantList_T.h b/TAO/performance-tests/CSD_Strategy/TestInf/ServantList_T.h new file mode 100644 index 00000000000..57143d889c1 --- /dev/null +++ b/TAO/performance-tests/CSD_Strategy/TestInf/ServantList_T.h @@ -0,0 +1,67 @@ +// $Id$ +#ifndef SERVANTLIST_T_H +#define SERVANTLIST_T_H + +#include "tao/PortableServer/PortableServer.h" +#include "tao/PortableServer/Servant_Base.h" +#include "ace/Vector_T.h" + + +// The T type is a concrete servant type. +template <class T> +class ServantList +{ + public: + + typedef typename T::_stub_type T_stub; + typedef typename T::_stub_ptr_type T_stub_ptr; + typedef typename T::_stub_var_type T_stub_var; + + ServantList(); + ~ServantList(); + + /// Activate servant and output ior to a file. + void create_and_activate(unsigned num_servants, + CORBA::ORB_ptr orb, + PortableServer::POA_ptr poa, + const char* ior_fname_prefix + ACE_ENV_ARG_DECL); + + /// Activate servant and not output ior to a file. + void create_and_activate(unsigned num_servants, + PortableServer::POA_ptr poa + ACE_ENV_ARG_DECL); + + + /// Get a (copy) of one of the object references (for a specific servant). + T_stub_ptr objref(unsigned index); + + /// This doesn't return a copy. + T* servant(unsigned index); + + + private: + + struct ServantRecord + { + T* servant_; + PortableServer::ServantBase_var safe_servant_; + T_stub_var obj_; + }; + + typedef ACE_Vector<ServantRecord> ServantRecordVector; + + ServantRecordVector servant_records_; +}; + + +#if defined (ACE_TEMPLATES_REQUIRE_SOURCE) +#include "ServantList_T.cpp" +#endif /* ACE_TEMPLATES_REQUIRE_SOURCE */ + +#if defined (ACE_TEMPLATES_REQUIRE_PRAGMA) +#pragma implementation ("ServantList_T.cpp") +#endif /* ACE_TEMPLATES_REQUIRE_PRAGMA */ + +#endif /* SERVANTLIST_T_H */ + diff --git a/TAO/performance-tests/CSD_Strategy/TestInf/TestAppBase.cpp b/TAO/performance-tests/CSD_Strategy/TestInf/TestAppBase.cpp new file mode 100644 index 00000000000..f2a2e97b7a2 --- /dev/null +++ b/TAO/performance-tests/CSD_Strategy/TestInf/TestAppBase.cpp @@ -0,0 +1,30 @@ +// $Id$ +#include "TestAppBase.h" + +TestAppBase::TestAppBase(const char* name) + : name_(name) +{ +} + + +TestAppBase::~TestAppBase() +{ +} + + +const char* +TestAppBase::name() const +{ + return this->name_.c_str(); +} + + +int +TestAppBase::run(int argc, char* argv[] ACE_ENV_ARG_DECL) +{ + int rc = this->run_i(argc, argv ACE_ENV_ARG_PARAMETER); + ACE_CHECK_RETURN (-1); + + // Convert 1 to 0. Leave 0 and -1 as they are. + return (rc == 1) ? 0 : rc; +} diff --git a/TAO/performance-tests/CSD_Strategy/TestInf/TestAppBase.h b/TAO/performance-tests/CSD_Strategy/TestInf/TestAppBase.h new file mode 100644 index 00000000000..b14436b623c --- /dev/null +++ b/TAO/performance-tests/CSD_Strategy/TestInf/TestAppBase.h @@ -0,0 +1,36 @@ +// $Id$ +#ifndef TESTAPPBASE_H +#define TESTAPPBASE_H + +#include "CSD_PT_TestInf_Export.h" +#include "ace/SString.h" +#include "tao/Environment.h" +#include "ace/CORBA_macros.h" + + +class CSD_PT_TestInf_Export TestAppBase +{ + public: + + virtual ~TestAppBase(); + + // Returns 0 for success, and -1 for failure. + int run(int argc, char* argv[] ACE_ENV_ARG_DECL); + + const char* name() const; + + + protected: + + TestAppBase(const char* name); + + // Returns -1 for failure, 0 for success + virtual int run_i(int argc, char* argv[] ACE_ENV_ARG_DECL) = 0; + + + private: + + ACE_CString name_; +}; + +#endif diff --git a/TAO/performance-tests/CSD_Strategy/TestInf/TestAppException.idl b/TAO/performance-tests/CSD_Strategy/TestInf/TestAppException.idl new file mode 100644 index 00000000000..2ac53939b77 --- /dev/null +++ b/TAO/performance-tests/CSD_Strategy/TestInf/TestAppException.idl @@ -0,0 +1,7 @@ +// $Id$ +#ifndef TESTAPPXCEPTION_IDL +#define TESTAPPXCEPTION_IDL + +exception TestAppException {}; + +#endif diff --git a/TAO/performance-tests/CSD_Strategy/TestInf/TestAppMain.h b/TAO/performance-tests/CSD_Strategy/TestInf/TestAppMain.h new file mode 100644 index 00000000000..062b6fc0c8e --- /dev/null +++ b/TAO/performance-tests/CSD_Strategy/TestInf/TestAppMain.h @@ -0,0 +1,49 @@ +// $Id$ +#ifndef TESTAPPMAIN_H +#define TESTAPPMAIN_H + +#include "ace/Log_Msg.h" +#include "ace/SString.h" +#include "tao/Exception.h" +#include "tao/Environment.h" + +#define TEST_APP_MAIN(APP_TYPE) \ +int \ +main(int argc, char* argv[]) \ +{ \ + ACE_LOG_MSG->priority_mask(LM_TRACE | \ + LM_DEBUG | \ + LM_INFO | \ + LM_NOTICE | \ + LM_WARNING | \ + LM_ERROR | \ + LM_CRITICAL | \ + LM_ALERT | \ + LM_EMERGENCY, \ + ACE_Log_Msg::PROCESS); \ +\ + APP_TYPE app; \ +\ + ACE_TRY_NEW_ENV \ + { \ + int ret = app.run(argc,argv ACE_ENV_ARG_PARAMETER); \ + ACE_TRY_CHECK; \ + return ret; \ + } \ + ACE_CATCHANY \ + { \ + ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, \ + "Caught exception:"); \ + } \ + ACE_CATCHALL \ + { \ + ACE_ERROR((LM_ERROR, \ + "(%P|%t) Unknown (...) exception caught in main() " \ + "for App [%d].\n", app.name())); \ + } \ + ACE_ENDTRY; \ + \ + return 1; \ +} + +#endif diff --git a/TAO/performance-tests/CSD_Strategy/TestInf/csd_pt_testinf.mpc b/TAO/performance-tests/CSD_Strategy/TestInf/csd_pt_testinf.mpc new file mode 100644 index 00000000000..39bea8a0c18 --- /dev/null +++ b/TAO/performance-tests/CSD_Strategy/TestInf/csd_pt_testinf.mpc @@ -0,0 +1,38 @@ +//$Id$ +project : taolib_with_idl, csd_threadpool { + sharedname = CSD_PT_TestInf + dynamicflags = CSD_PT_TESTINF_BUILD_DLL + idlflags += -Wb,export_macro=CSD_PT_TestInf_Export -Wb,export_include=CSD_PT_TestInf_Export.h + includes += $(TAO_ROOT)/tao + + IDL_Files { + FooException.idl + TestAppException.idl + CancelledException.idl + CustomException.idl + } + + Source_Files { + AppHelper.cpp + AppShutdown.cpp + ClientEngine.cpp + ClientTask.cpp + OrbRunner.cpp + OrbShutdownTask.cpp + OrbTask.cpp + TestAppBase.cpp + FooExceptionC.cpp + FooExceptionS.cpp + TestAppExceptionC.cpp + TestAppExceptionS.cpp + CancelledExceptionC.cpp + CancelledExceptionS.cpp + CustomExceptionC.cpp + CustomExceptionS.cpp + } + + Template_Files { + ServantList_T.cpp + } + +} |