diff options
Diffstat (limited to 'TAO/tests/Dynamic_TP')
33 files changed, 2265 insertions, 0 deletions
diff --git a/TAO/tests/Dynamic_TP/Config_Loader/Config_Loader.mpc b/TAO/tests/Dynamic_TP/Config_Loader/Config_Loader.mpc new file mode 100644 index 00000000000..fff50baa1c2 --- /dev/null +++ b/TAO/tests/Dynamic_TP/Config_Loader/Config_Loader.mpc @@ -0,0 +1,5 @@ +// $Id$ + +project(*test) : dynamic_tp { + exename = test +} diff --git a/TAO/tests/Dynamic_TP/Config_Loader/Test.cpp b/TAO/tests/Dynamic_TP/Config_Loader/Test.cpp new file mode 100644 index 00000000000..f6d274e8080 --- /dev/null +++ b/TAO/tests/Dynamic_TP/Config_Loader/Test.cpp @@ -0,0 +1,80 @@ +// $Id$ + +#include "tao/Dynamic_TP/DTP_Config.h" +#include "ace/OS_NS_stdio.h" +#include "ace/Service_Config.h" +#include "ace/Dynamic_Service.h" + +void +show_tp_config (const ACE_CString &name, const TAO_DTP_Definition &entry) +{ + ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Config set for %C:\n"), name.c_str())); + ACE_DEBUG ((LM_DEBUG, ACE_TEXT (" Initial threads: %d:\n"), entry.init_threads_)); + ACE_DEBUG ((LM_DEBUG, ACE_TEXT (" Min threads: %d:\n"), entry.min_threads_)); + ACE_DEBUG ((LM_DEBUG, ACE_TEXT (" Max threads: %d:\n"), entry.max_threads_)); + if (entry.min_threads_ > -1) + ACE_DEBUG ((LM_DEBUG, ACE_TEXT (" Idle Timeout: %d (sec)\n"), entry.timeout_.sec())); + ACE_DEBUG ((LM_DEBUG, ACE_TEXT (" Stack Size: %d:\n"), entry.stack_size_)); + ACE_DEBUG ((LM_DEBUG, ACE_TEXT (" Request queue max depth: %d\n"), entry.queue_depth_)); +} + +int +ACE_TMAIN(int argc, ACE_TCHAR *argv[]) +{ + ACE_Service_Config::open (argc, argv); + + ACE_Service_Gestalt *current = ACE_Service_Config::current(); + TAO_DTP_Config_Registry* registry = + ACE_Dynamic_Service<TAO_DTP_Config_Registry>::instance + (current, "DTP_Config_Registry", true); + + if (registry == 0) + { + ACE_DEBUG ((LM_DEBUG, ACE_TEXT("Unable to load configuration\n"))); + return -1; + } + + TAO_DTP_Definition entry; + + const ACE_TCHAR *name_list [] = + { ACE_TEXT ("ORB"), + ACE_TEXT ("bogus"), + ACE_TEXT ("POA1"), + ACE_TEXT ("defaults"), + ACE_TEXT ("m1"), + ACE_TEXT ("m2"), + ACE_TEXT ("m3"), + ACE_TEXT ("m4"), + ACE_TEXT ("m5"), + ACE_TEXT ("m6"), + ACE_TEXT ("m7"), + 0 + }; + + for (int i = 0; name_list[i] != 0; i++) + { + bool found = registry->find (name_list[i], entry); + if (!found && (i != 1)) + { + ACE_DEBUG ((LM_DEBUG, ACE_TEXT("Cannot find TP Config definition for %C\n"), name_list[i])); + return -1; + } + if (i == 1) + { + if (found) + { + ACE_DEBUG ((LM_DEBUG, ACE_TEXT("Found TP Config definition for %C which should have failed\n"), name_list[i])); + return -1; + } + else + { + ACE_DEBUG ((LM_DEBUG, ACE_TEXT("TP definition for %C not found as expected\n"), name_list[i])); + } + } + else + { + show_tp_config (name_list[i], entry); + } + } + return 0; +} diff --git a/TAO/tests/Dynamic_TP/Config_Loader/svc.conf b/TAO/tests/Dynamic_TP/Config_Loader/svc.conf new file mode 100644 index 00000000000..4b3231a7a8b --- /dev/null +++ b/TAO/tests/Dynamic_TP/Config_Loader/svc.conf @@ -0,0 +1,16 @@ +# $Id$ + +dynamic DTP_Config Service_Object * TAO_Dynamic_TP:_make_TAO_DTP_Config() + "-DTPName ORB -DTPMin 5 -DTPInit 6 -DTPMax 10 -DTPTimeout 240 -DTPStack 10240 -DTPQueue 20" +dynamic DTP_Config Service_Object * TAO_Dynamic_TP:_make_TAO_DTP_Config() "-DTPName POA1 -DTPMin 2 -DTPInit 4 -DTPMax 10 -DTPQueue 10" +dynamic DTP_Config Service_Object * TAO_Dynamic_TP:_make_TAO_DTP_Config() "-DTPName POA1 -DTPOverwrite 1 -DTPMin 7 -DTPMax 14 " +dynamic DTP_Config Service_Object * TAO_Dynamic_TP:_make_TAO_DTP_Config() "-DTPName POA1 -DTPMin 7 -DTPMax 11 -DPQueue 14" +dynamic DTP_Config Service_Object * TAO_Dynamic_TP:_make_TAO_DTP_Config() "-DTPName defaults" +dynamic DTP_Config Service_Object * TAO_Dynamic_TP:_make_TAO_DTP_Config() "-DTPName m1 -DTPMin 3" +dynamic DTP_Config Service_Object * TAO_Dynamic_TP:_make_TAO_DTP_Config() "-DTPName m2 -DTPMax 10" +dynamic DTP_Config Service_Object * TAO_Dynamic_TP:_make_TAO_DTP_Config() "-DTPName m3 -DTPTimeout 120" +dynamic DTP_Config Service_Object * TAO_Dynamic_TP:_make_TAO_DTP_Config() "-DTPName m4 -DTPMin 3 -DTPInit 7 -DTPMax 10 -DTPTimeout 120" +dynamic DTP_Config Service_Object * TAO_Dynamic_TP:_make_TAO_DTP_Config() "-DTPName m5 -DTPMin 3 -DTPInit 10 -DTPTimeout 30" +dynamic DTP_Config Service_Object * TAO_Dynamic_TP:_make_TAO_DTP_Config() "-DTPName m6 -DTPInit 6 -DTPMax -1" +dynamic DTP_Config Service_Object * TAO_Dynamic_TP:_make_TAO_DTP_Config() "-DTPName m7 -DTPInit 7" +dynamic DTP_Config Service_Object * TAO_Dynamic_TP:_make_TAO_DTP_Config() "-DTPName bogus -DTPMin 6 -DTPInit 3" diff --git a/TAO/tests/Dynamic_TP/ORB_ThreadPool/Client.cpp b/TAO/tests/Dynamic_TP/ORB_ThreadPool/Client.cpp new file mode 100644 index 00000000000..f2881d25d63 --- /dev/null +++ b/TAO/tests/Dynamic_TP/ORB_ThreadPool/Client.cpp @@ -0,0 +1,130 @@ +// $Id$ + +#include "TestC.h" +#include "ace/Get_Opt.h" +#include "ace/Task.h" + +class MT_Requestor : public virtual ACE_Task_Base +{ +public: + MT_Requestor (Test::Sleeper_ptr s); + + virtual int svc (void); +private: + Test::Sleeper_var sleeper_; +}; + +MT_Requestor::MT_Requestor (Test::Sleeper_ptr s) + : sleeper_ (Test::Sleeper::_duplicate (s)) +{ +} + +int +MT_Requestor::svc () +{ + int retries = 5; + while (retries-- > 0) + { + ACE_DEBUG ((LM_DEBUG, + ACE_TEXT ("Client thread %t calling delay with %d retries\n"), + retries)); + try + { + this->sleeper_->delay(); + ACE_DEBUG ((LM_DEBUG, + ACE_TEXT ("Client thread %t delay succeeded\n"))); + break; + } + catch (CORBA::Exception &ex) + { + ACE_DEBUG ((LM_DEBUG, + ACE_TEXT ("Client thread %t caught %s\n"), + ex._name())); + } + } + ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Client thread %t done\n"))); + return 0; +} + +const ACE_TCHAR *ior = ACE_TEXT("file://server.ior"); +bool do_shutdown = false; +int num_threads = 1; + +int +parse_args (int argc, ACE_TCHAR *argv[]) +{ + ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("k:n:x")); + int c; + + while ((c = get_opts ()) != -1) + switch (c) + { + case 'k': + ior = get_opts.opt_arg (); + break; + case 'n': + num_threads = ACE_OS::atoi (get_opts.opt_arg ()); + break; + case 'x': + do_shutdown = true; + break; + case '?': + default: + ACE_ERROR_RETURN ((LM_ERROR, + "usage: %s " + "-k <ior> " + "-n <threads> " + "-x " + "\n", + argv [0]), + -1); + } + // Indicates successful parsing of the command line + return 0; +} + +int +ACE_TMAIN(int argc, ACE_TCHAR *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(ior); + + Test::Sleeper_var sleeper = + Test::Sleeper::_narrow(tmp.in ()); + + if (CORBA::is_nil (sleeper.in ())) + { + ACE_ERROR_RETURN ((LM_DEBUG, + "Nil Test::Sleeper reference <%s>\n", + ior), + 1); + } + + MT_Requestor requestor (sleeper.in()); + requestor.activate (THR_NEW_LWP | THR_JOINABLE, num_threads); + requestor.wait (); + + if (do_shutdown) + { + sleeper->shutdown(); + } + + orb->destroy (); + } + catch (const CORBA::Exception& ex) + { + ex._tao_print_exception ("Client main exception caught:"); + return 1; + } + + return 0; +} diff --git a/TAO/tests/Dynamic_TP/ORB_ThreadPool/ORB_ThreadPool.mpc b/TAO/tests/Dynamic_TP/ORB_ThreadPool/ORB_ThreadPool.mpc new file mode 100644 index 00000000000..7fe5b08fac7 --- /dev/null +++ b/TAO/tests/Dynamic_TP/ORB_ThreadPool/ORB_ThreadPool.mpc @@ -0,0 +1,35 @@ +// -*- MPC -*- +// $Id$ + +project(*idl): taoidldefaults { + IDL_Files { + Test.idl + } + custom_only = 1 +} + +project(*Server): taoserver, dynamic_tp { + after += *idl + Source_Files { + Test_i.cpp + Server.cpp + TestC.cpp + TestS.cpp + } + + IDL_Files { + } + +} + +project(*Client): taoclient { + after += *idl + Source_Files { + TestC.cpp + Client.cpp + } + + IDL_Files { + } + +} diff --git a/TAO/tests/Dynamic_TP/ORB_ThreadPool/Server.cpp b/TAO/tests/Dynamic_TP/ORB_ThreadPool/Server.cpp new file mode 100644 index 00000000000..fc23726e81c --- /dev/null +++ b/TAO/tests/Dynamic_TP/ORB_ThreadPool/Server.cpp @@ -0,0 +1,111 @@ +// $Id$ + +#include "Test_i.h" +#include "ace/Get_Opt.h" +#include "ace/OS_NS_stdio.h" +#include "ace/Thread_Manager.h" + +#include "tao/ORB_Core_TSS_Resources.h" +#include "tao/ORB_Core.h" +#include "tao/Dynamic_TP/DTP_Thread_Pool.h" + +const ACE_TCHAR *ior_output_file = ACE_TEXT ("server.ior"); + +int +parse_args (int argc, ACE_TCHAR *argv[]) +{ + ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("o:s:p:")); + int c; + + while ((c = get_opts ()) != -1) + switch (c) + { + case 'o': + ior_output_file = get_opts.opt_arg (); + break; + case '?': + default: + ACE_ERROR_RETURN ((LM_ERROR, + "usage: %s " + "-o <iorfile>" + "\n", + argv [0]), + -1); + } + // Indicates successful parsing of the command line + return 0; +} + +int +ACE_TMAIN (int argc, ACE_TCHAR *argv[]) +{ + try + { + CORBA::ORB_var orb = + CORBA::ORB_init (argc, argv); + + CORBA::Object_var poa_object = + orb->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 (); + + if (parse_args (argc, argv) != 0) + return 1; + + Test_i *test_impl; + ACE_NEW_RETURN (test_impl, Test_i (orb.in ()), 1); + PortableServer::ServantBase_var owner_transfer(test_impl); + PortableServer::ObjectId_var id = root_poa->activate_object (test_impl); + CORBA::Object_var object = root_poa->id_to_reference (id.in ()); + Test::Sleeper_var sleeper = Test::Sleeper::_narrow (object.in ()); + CORBA::String_var ior = orb->object_to_string (sleeper.in ()); + + ACE_DEBUG ((LM_DEBUG,"Server calling poa_manager::activate()\n")); + poa_manager->activate (); + + // Output the IOR to the <ior_output_file> + FILE *output_file= ACE_OS::fopen (ior_output_file, "w"); + if (output_file == 0) + ACE_ERROR_RETURN ((LM_ERROR, + "Cannot open output file %s for writing IOR: %C", + ior_output_file, + ior.in ()), + 1); + ACE_OS::fprintf (output_file, "%s", ior.in ()); + ACE_OS::fclose (output_file); + + TAO_ORB_Core_TSS_Resources &tss = + *orb->orb_core ()->get_tss_resources (); + + // The API calls it a lane but DTP Thread Pools + // are always a single lane. + TAO_DTP_Thread_Pool *pool = + static_cast <TAO_DTP_Thread_Pool *> (tss.lane_); + +#if 0 + ACE_DEBUG ((LM_DEBUG,"Server calling orb::run()\n")); + orb->run (); +#else + pool->wait(); +#endif + + ACE_DEBUG ((LM_DEBUG, "(%P|%t) server - event loop finished\n")); + orb->destroy (); + } + catch (const CORBA::Exception& ex) + { + ex._tao_print_exception ("Exception caught:"); + return 1; + } + + return 0; +} diff --git a/TAO/tests/Dynamic_TP/ORB_ThreadPool/Test.idl b/TAO/tests/Dynamic_TP/ORB_ThreadPool/Test.idl new file mode 100644 index 00000000000..d2760fdd4be --- /dev/null +++ b/TAO/tests/Dynamic_TP/ORB_ThreadPool/Test.idl @@ -0,0 +1,19 @@ +// +// $Id$ +// + +/// Put the interfaces in a module, to avoid global namespace pollution +module Test +{ + /// A very simple interface + interface Sleeper + { + void delay (); + + /// A method to shutdown the ORB + /** + * This method is used to simplify the test shutdown process + */ + oneway void shutdown (); + }; +}; diff --git a/TAO/tests/Dynamic_TP/ORB_ThreadPool/Test_i.cpp b/TAO/tests/Dynamic_TP/ORB_ThreadPool/Test_i.cpp new file mode 100644 index 00000000000..0a5eb7f8185 --- /dev/null +++ b/TAO/tests/Dynamic_TP/ORB_ThreadPool/Test_i.cpp @@ -0,0 +1,24 @@ +// +// $Id$ +// +#include "Test_i.h" +#include "ace/OS_NS_unistd.h" + +Test_i::Test_i (CORBA::ORB_ptr orb) + : orb_ (CORBA::ORB::_duplicate (orb)) +{ +} + +void +Test_i::delay(void) +{ + ACE_DEBUG ((LM_DEBUG, "(%P|%t) Test_i::delay called\n")); + ACE_OS::sleep (1); + ACE_DEBUG ((LM_DEBUG, "(%P|%t) Test_i::delay returning\n")); +} + +void +Test_i::shutdown (void) +{ + this->orb_->shutdown (0); +} diff --git a/TAO/tests/Dynamic_TP/ORB_ThreadPool/Test_i.h b/TAO/tests/Dynamic_TP/ORB_ThreadPool/Test_i.h new file mode 100644 index 00000000000..573d6c55b33 --- /dev/null +++ b/TAO/tests/Dynamic_TP/ORB_ThreadPool/Test_i.h @@ -0,0 +1,29 @@ +// +// $Id$ +// + +#ifndef TEST_I_H +#define TEST_I_H +#include /**/ "ace/pre.h" + +#include "TestS.h" + +/// Implement the Test::Sleeper interface +class Test_i : public virtual POA_Test::Sleeper +{ +public: + /// Constructor + Test_i (CORBA::ORB_ptr orb); + + // = The skeleton methods + virtual void delay (void); + + virtual void shutdown (void); + +private: + CORBA::ORB_var orb_; + +}; + +#include /**/ "ace/post.h" +#endif /* TEST_I_H */ diff --git a/TAO/tests/Dynamic_TP/ORB_ThreadPool/client.conf b/TAO/tests/Dynamic_TP/ORB_ThreadPool/client.conf new file mode 100644 index 00000000000..74326a5cbf4 --- /dev/null +++ b/TAO/tests/Dynamic_TP/ORB_ThreadPool/client.conf @@ -0,0 +1,4 @@ +# $Id$ + +static Client_Strategy_Factory "-ORBTransportMuxStrategy" + diff --git a/TAO/tests/Dynamic_TP/ORB_ThreadPool/run_test.pl b/TAO/tests/Dynamic_TP/ORB_ThreadPool/run_test.pl new file mode 100755 index 00000000000..7bce5b75574 --- /dev/null +++ b/TAO/tests/Dynamic_TP/ORB_ThreadPool/run_test.pl @@ -0,0 +1,77 @@ +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::TestTarget; + +$status = 0; +$threads = 10; +$sdebug = ""; +$cdebug = ""; +foreach $i (@ARGV) { + if ($i eq '-sdebug' || $i eq '-debug') { + $sdebug = "-ORBDebuglevel 10 -ORBVerboseLogging 1"; + } + if ($i eq '-cdebug' || $i eq '-debug') { + $sdebug = "-ORBDebuglevel 10 -ORBVerboseLogging 1"; + } +} + +my $server = PerlACE::TestTarget::create_target (1) || die "Create target 1 failed\n"; +my $client = PerlACE::TestTarget::create_target (2) || die "Create target 2 failed\n"; + +my $iorbase = "server.ior"; +my $server_iorfile = $server->LocalFile ($iorbase); +my $client_iorfile = $client->LocalFile ($iorbase); +$server->DeleteFile($iorbase); +$client->DeleteFile($iorbase); + +$SV = $server->CreateProcess ("server", "$sdebug -ORBSvcConf server.conf -ORBDynamicThreadPoolName ORBPool -o $server_iorfile"); +$CL = $client->CreateProcess ("client", "$cdebug -ORBSvcConf client.conf -k file://$client_iorfile -n $threads -x"); +$server_status = $SV->Spawn (); + +if ($server_status != 0) { + print STDERR "ERROR: server returned $server_status\n"; + exit 1; +} + +if ($server->WaitForFileTimed ($iorbase, + $server->ProcessStartWaitInterval()) == -1) { + print STDERR "ERROR: cannot find file <$server_iorfile>\n"; + $SV->Kill (); $SV->TimedWait (1); + exit 1; +} + +if ($server->GetFile ($iorbase) == -1) { + print STDERR "ERROR: cannot retrieve file <$server_iorfile>\n"; + $SV->Kill (); $SV->TimedWait (1); + exit 1; +} +if ($client->PutFile ($iorbase) == -1) { + print STDERR "ERROR: cannot set file <$client_iorfile>\n"; + $SV->Kill (); $SV->TimedWait (1); + exit 1; +} + +$client_status = $CL->SpawnWaitKill ($client->ProcessStartWaitInterval() + 10); + +if ($client_status != 0) { + print STDERR "ERROR: client returned $client_status\n"; + $status = 1; +} + +$server_status = $SV->WaitKill ($server->ProcessStopWaitInterval()); + +if ($server_status != 0) { + print STDERR "ERROR: server returned $server_status\n"; + $status = 1; +} + +$server->DeleteFile($iorbase); +$client->DeleteFile($iorbase); + +exit $status; diff --git a/TAO/tests/Dynamic_TP/ORB_ThreadPool/server.conf b/TAO/tests/Dynamic_TP/ORB_ThreadPool/server.conf new file mode 100644 index 00000000000..ec0ca59c0ed --- /dev/null +++ b/TAO/tests/Dynamic_TP/ORB_ThreadPool/server.conf @@ -0,0 +1,4 @@ +# $Id$ + +dynamic DTP_Config Service_Object * TAO_Dynamic_TP:_make_TAO_DTP_Config() "-DTPName ORBPool -DTPMin 3 -DTPInit 4 -DTPMax 7 -DTPTimeout 30" +dynamic DTP_ORB_Loader Service_Object * TAO_Dynamic_TP:_make_TAO_DTP_ORB_Loader() "" diff --git a/TAO/tests/Dynamic_TP/POA_Loader/Dynamic_TP_POA_Test_Dynamic/Dynamic_TP_POA_Test_Dynamic.mpc b/TAO/tests/Dynamic_TP/POA_Loader/Dynamic_TP_POA_Test_Dynamic/Dynamic_TP_POA_Test_Dynamic.mpc new file mode 100644 index 00000000000..d7225b8511a --- /dev/null +++ b/TAO/tests/Dynamic_TP/POA_Loader/Dynamic_TP_POA_Test_Dynamic/Dynamic_TP_POA_Test_Dynamic.mpc @@ -0,0 +1,35 @@ +// -*- MPC -*- +// $Id$ + +project(*idl): taoidldefaults { + IDL_Files { + Test.idl + } + custom_only = 1 +} + +project(Dynamic_TP_POA_Test_Dynamic_Server): taoserver, csd_framework, dynamic_tp { + after += *idl + Source_Files { + Hello.cpp + server.cpp + TestC.cpp + TestS.cpp + } + + IDL_Files { + } + +} + +project(Dynamic_TP_POA_Test_Dynamic_Client): taoclient { + after += Dynamic_TP_POA_Test_Dynamic_Server + Source_Files { + TestC.cpp + client.cpp + } + + IDL_Files { + } + +} diff --git a/TAO/tests/Dynamic_TP/POA_Loader/Dynamic_TP_POA_Test_Dynamic/Hello.cpp b/TAO/tests/Dynamic_TP/POA_Loader/Dynamic_TP_POA_Test_Dynamic/Hello.cpp new file mode 100644 index 00000000000..313393fc02c --- /dev/null +++ b/TAO/tests/Dynamic_TP/POA_Loader/Dynamic_TP_POA_Test_Dynamic/Hello.cpp @@ -0,0 +1,43 @@ +// +// $Id$ +// +#include "Hello.h" +#include "ace/OS_NS_unistd.h" + +Hello::Hello (CORBA::ORB_ptr orb) + : orb_ (CORBA::ORB::_duplicate (orb)), sleep_sec_(1) +{ +} + +CORBA::Short +Hello::sleep_sec() +{ + return this->sleep_sec_; +} + +void + Hello::sleep_sec(CORBA::Short sl_sec) +{ + this->sleep_sec_ = sl_sec; + ACE_DEBUG ((LM_DEBUG, "(%P|%t) Hello::sleep_sec returning\n")); +} + +char * +Hello::get_string (CORBA::Long client_num) +{ + ACE_DEBUG ((LM_INFO, + ACE_TEXT ("TAO (%P|%t) - Server: Sleeping for client->%d....\n "), + client_num)); + + ACE_OS::sleep(this->sleep_sec_); + ACE_DEBUG ((LM_INFO, + ACE_TEXT ("TAO (%P|%t) - Server: Returning for client->%d....\n "), + client_num)); + return CORBA::string_dup ("Hello there!"); +} + +void +Hello::shutdown (void) +{ + this->orb_->shutdown (0); +} diff --git a/TAO/tests/Dynamic_TP/POA_Loader/Dynamic_TP_POA_Test_Dynamic/Hello.h b/TAO/tests/Dynamic_TP/POA_Loader/Dynamic_TP_POA_Test_Dynamic/Hello.h new file mode 100644 index 00000000000..93afd1f3913 --- /dev/null +++ b/TAO/tests/Dynamic_TP/POA_Loader/Dynamic_TP_POA_Test_Dynamic/Hello.h @@ -0,0 +1,34 @@ +// +// $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 CORBA::Short sleep_sec (); + virtual void sleep_sec (CORBA::Short sleep_sec); + virtual char * get_string (CORBA::Long); + + virtual void shutdown (void); + +private: + /// Use an ORB reference to convert strings to objects and shutdown + /// the application. + CORBA::ORB_var orb_; + CORBA::Short sleep_sec_; +}; + +#include /**/ "ace/post.h" +#endif /* HELLO_H */ diff --git a/TAO/tests/Dynamic_TP/POA_Loader/Dynamic_TP_POA_Test_Dynamic/Test.idl b/TAO/tests/Dynamic_TP/POA_Loader/Dynamic_TP_POA_Test_Dynamic/Test.idl new file mode 100644 index 00000000000..0e2180b8481 --- /dev/null +++ b/TAO/tests/Dynamic_TP/POA_Loader/Dynamic_TP_POA_Test_Dynamic/Test.idl @@ -0,0 +1,24 @@ +// +// $Id$ +// + +/// Put the interfaces in a module, to avoid global namespace pollution +module Test +{ + /// A very simple interface + interface Hello + { + /// Attribute to hold a sleep time in seconds + /// for the Hello servant + attribute short sleep_sec; + + /// Return a simple string + string get_string (in long cl); + + /// A method to shutdown the ORB + /** + * This method is used to simplify the test shutdown process + */ + oneway void shutdown (); + }; +}; diff --git a/TAO/tests/Dynamic_TP/POA_Loader/Dynamic_TP_POA_Test_Dynamic/client.cpp b/TAO/tests/Dynamic_TP/POA_Loader/Dynamic_TP_POA_Test_Dynamic/client.cpp new file mode 100644 index 00000000000..6525413101d --- /dev/null +++ b/TAO/tests/Dynamic_TP/POA_Loader/Dynamic_TP_POA_Test_Dynamic/client.cpp @@ -0,0 +1,98 @@ +// $Id$ + +#include "TestC.h" +#include "ace/Get_Opt.h" + +const ACE_TCHAR *ior = ACE_TEXT("file://server.ior"); +int client_num = 1; +int report_exception = 1; +bool is_shutdown = false; + +int +parse_args (int argc, ACE_TCHAR *argv[]) +{ + ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("c:e:k:s")); + int c; + + while ((c = get_opts ()) != -1) + switch (c) + { + case 'c': + client_num = ACE_OS::atoi(get_opts.opt_arg ()); + break; + case 'e': + report_exception = ACE_OS::atoi(get_opts.opt_arg ()); + break; + case 'k': + ior = get_opts.opt_arg (); + break; + case 's': + is_shutdown = true; + break; + case '?': + default: + ACE_ERROR_RETURN ((LM_ERROR, + "usage: %s " + "-c <client #> " + "-e <0|1> " + "-k <ior> " + "-s (shutdown) " + "\n", + argv [0]), + -1); + } + // Indicates successful parsing of the command line + return 0; +} + +int +ACE_TMAIN(int argc, ACE_TCHAR *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(ior); + + Test::Hello_var hello = + Test::Hello::_narrow(tmp.in ()); + + if (CORBA::is_nil (hello.in ())) + { + ACE_ERROR_RETURN ((LM_DEBUG, + "Nil Test::Hello reference <%s>\n", + ior), + 1); + } + + if (is_shutdown) + { + hello->shutdown(); + } + else + { + CORBA::String_var the_string = + hello->get_string (client_num); + ACE_DEBUG((LM_DEBUG, + "Client %d received return text of: [%C %d].\n", + client_num, + the_string.in(), + client_num)); + } + orb->destroy (); + } + catch (const CORBA::Exception& ex) + { + if (report_exception) + ex._tao_print_exception ("Exception caught:"); + return 1; + } + + return 0; +} diff --git a/TAO/tests/Dynamic_TP/POA_Loader/Dynamic_TP_POA_Test_Dynamic/run_test.pl b/TAO/tests/Dynamic_TP/POA_Loader/Dynamic_TP_POA_Test_Dynamic/run_test.pl new file mode 100755 index 00000000000..ff8141814bb --- /dev/null +++ b/TAO/tests/Dynamic_TP/POA_Loader/Dynamic_TP_POA_Test_Dynamic/run_test.pl @@ -0,0 +1,404 @@ +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::TestTarget; + + +sub count_strings +{ + my $log_file = shift; + my $find_str = shift; + open my $fh, '<', $log_file or die $!; + my $cnt=0; + while (<$fh>) + { + $f = quotemeta($find_str); + $cnt += $_ =~ /$f/; + } + print STDERR "INFO: Count - [$cnt]\n"; + close $fh; + return($cnt); +} + +sub test_1 +{ +# Test 1: +# This is a test for the creation of initial_pool_threads. +# The test will start up a server with default pool values +# and will result in 5 initial threads being started. + + my $server = shift; + my $client = shift; + my $iorbase = shift; + my $deletelogs = shift; + my $status = 0; + + print "\nRunning Test 1....\n"; + $test_num=1; + + my $lfname = "server_test" . $test_num . ".log"; + my $scname = "svc" . $test_num . ".conf"; + my $server_iorfile = $server->LocalFile ($iorbase); + my $client_iorfile = $client->LocalFile ($iorbase); + my $server_logfile = $server->LocalFile ($lfname); + my $svc_conf = $server->LocalFile($scname); + + $server->DeleteFile($lfname); + + $SV = $server->CreateProcess ("server", " -ORBDebugLevel 5 -ORBSvcConf $svc_conf -ORBLogFile $server_logfile -s 3 -o $server_iorfile"); + $SC = $client->CreateProcess ("client", "-k file://$client_iorfile -s"); + + $server_status = $SV->Spawn (); + + if ($server_status != 0) { + print STDERR "ERROR: server returned $server_status\n"; + exit 1; + } + + if ($server->WaitForFileTimed ($iorbase, + $server->ProcessStartWaitInterval()) == -1) { + print STDERR "ERROR: cannot find file <$server_iorfile>\n"; + $SV->Kill (); $SV->TimedWait (1); + exit 1; + } + + $client_status = $SC->SpawnWaitKill ($client->ProcessStopWaitInterval()); + if ($client_status != 0) { + print STDERR "ERROR: client $i returned $client_status\n"; + } + + # Now find the spawned threads in the log file. + + $find_this="DTP_Task::svc() New thread created."; + $found_cnt=0; + + my($found_cnt) = count_strings($server_logfile,$find_this); + + if ($found_cnt != 5) { + print STDERR "ERROR: initial_pool_thread test failed w/$found_cnt instead of 5\n"; + $status = 1; + } + elsif ($deletelogs) { + $server->DeleteFile($lfname); + } + + $server_status = $SV->WaitKill ($server->ProcessStopWaitInterval()); + + if ($server_status != 0) { + print STDERR "ERROR: server returned $server_status\n"; + $status = 1; + } + + $server->DeleteFile($iorbase); + $client->DeleteFile($iorbase); + + return($status); +} + +sub test_2 +{ + # Test 2: + # This is a test for showing a process maintaining a min_pool_threads after + # the creation of initial_pool_threads is higher. This test will also + # exercise the thread_idle_time (timeout). + # The test will start up a server with 10 init_pool_threads and 5 min_pool_threads. + # After 10 seconds, 5 threads should expire leaving the minimum 5 threads. + + + my $server = shift; + my $client = shift; + my $iorbase = shift; + my $deletelogs = shift; + my $status = 0; + + + print "\nRunning Test 2....\n"; + $test_num=2; + my $lfname = "server_test" . $test_num . ".log"; + my $scname = "svc" . $test_num . ".conf"; + my $server_iorfile = $server->LocalFile ($iorbase); + my $client_iorfile = $client->LocalFile ($iorbase); + my $server_logfile = $server->LocalFile ($lfname); + my $svc_conf = $server->LocalFile($scname); + + $server->DeleteFile($lfname); + + $SV = $server->CreateProcess ("server", " -ORBDebugLevel 5 -ORBSvcConf $svc_conf -ORBLogFile $server_logfile -s 3 -o $server_iorfile"); + $SC = $client->CreateProcess ("client", "-k file://$client_iorfile -s"); + + $server_status = $SV->Spawn (); + + if ($server_status != 0) { + print STDERR "ERROR: server returned $server_status\n"; + exit 1; + } + + if ($server->WaitForFileTimed ($iorbase, + $server->ProcessStartWaitInterval()) == -1) { + print STDERR "ERROR: cannot find file <$server_iorfile>\n"; + $SV->Kill (); $SV->TimedWait (1); + exit 1; + } + + # Sleep here for more than the timeout to let the threads die off and log. + print STDERR "INFO: sleeping 15 seconds\n"; + sleep(15); + + $client_status = $SC->SpawnWaitKill ($client->ProcessStopWaitInterval()); + if ($client_status != 0) { + print STDERR "ERROR: client $i returned $client_status\n"; + } + # Now find the spawned threads in the log file. + + $find_this="DTP_Task::svc() Existing thread expiring."; + $found_cnt=0; + + my($found_cnt) = count_strings($server_logfile,$find_this); + + if ($found_cnt != 5) { + print STDERR "ERROR: min_pool_thread test failed w/$found_cnt instead of 5\n"; + $status = 1; + } + elsif ($deletelogs) { + $server->DeleteFile($lfname); + } + + $server_status = $SV->WaitKill ($server->ProcessStopWaitInterval()); + + if ($server_status != 0) { + print STDERR "ERROR: server returned $server_status\n"; + $status = 1; + } + + $server->DeleteFile($iorbase); + $client->DeleteFile($iorbase); + + return($status); +} + +sub test_3 +{ + # Test 3: + # This is a test for showing a process maintaining a max_request_queue_depth after + # more clients request service than the queue allows for. + # The test will start up a server with a max_request_queue_depth of 10 and + # will issue calls from 15 clients. There should be 5 CORBA exceptions found + # in the log after the run. + # + my $server = shift; + my $client = shift; + my $iorbase = shift; + my $deletelogs = shift; + my $status = 0; + + print "\nRunning Test 3....\n"; + $test_num=3; + $num_clients=15; + my $lfname = "server_test" . $test_num . ".log"; + my $scname = "svc" . $test_num . ".conf"; + my $server_iorfile = $server->LocalFile ($iorbase); + my $client_iorfile = $client->LocalFile ($iorbase); + my $server_logfile = $server->LocalFile ($lfname); + my $svc_conf = $server->LocalFile($scname); + + $server->DeleteFile($lfname); + + $SV = $server->CreateProcess ("server", " -ORBDebugLevel 5 -ORBSvcConf $svc_conf -ORBLogFile $server_logfile -s 3 -o $server_iorfile"); + + $server_status = $SV->Spawn (); + + if ($server_status != 0) { + print STDERR "ERROR: server returned $server_status\n"; + exit 1; + } + + if ($server->WaitForFileTimed ($iorbase, + $server->ProcessStartWaitInterval()) == -1) { + print STDERR "ERROR: cannot find file <$server_iorfile>\n"; + $SV->Kill (); $SV->TimedWait (1); + exit 1; + } + + for ($i = 0; $i < $num_clients; $i++) { + $CLS[$i] = $client->CreateProcess ("client", "-c $i -k file://$client_iorfile -e 0"); + $CLS[$i]->Spawn (); + } + + my $valid_num_exceptions=5; + my $num_exceptions=0; + + for ($i = 0; $i < $num_clients; $i++) { + + $client_status = $CLS[$i]->WaitKill ($client->ProcessStopWaitInterval()); + + if ($client_status != 0) { + $num_exceptions++; + print STDERR "STATUS: client $i returned $client_status\n"; + } + } + + $SC = $client->CreateProcess ("client", "-k file://$client_iorfile -s"); + $client_status = $SC->SpawnWaitKill ($client->ProcessStopWaitInterval()); + if ($client_status != 0) { + print STDERR "ERROR: client $i returned $client_status\n"; + } + + if ($num_exceptions != $valid_num_exceptions) + { + print STDERR "ERROR: max_request_queue_depth test failed w/$num_exceptions instead of $valid_num_exceptions\n"; + $status = 1; + } + elsif ($deletelogs) { + $server->DeleteFile($lfname); + } + + + $server_status = $SV->WaitKill ($server->ProcessStopWaitInterval()); + + if ($server_status != 0) { + print STDERR "ERROR: server returned $server_status\n"; + $status = 1; + } + + $server->DeleteFile($iorbase); + $client->DeleteFile($iorbase); + + return($status); +} + +sub test_4 +{ + + # Test 4: + # This is a test for showing a process maintaining a max_pool_threads after + # more clients request service than the queue allows for. + # The test will start up a server with a max_request_queue_depth of 10 and + # will issue calls from 10 clients. There should be 5 CORBA exceptions found + # in the log after the run. + # + + my $server = shift; + my $client = shift; + my $iorbase = shift; + my $deletelogs = shift; + my $status = 0; + + print "\nRunning Test 4....\n"; + $test_num=4; + $num_clients=10; + my $lfname = "server_test" . $test_num . ".log"; + my $scname = "svc" . $test_num . ".conf"; + my $server_iorfile = $server->LocalFile ($iorbase); + my $client_iorfile = $client->LocalFile ($iorbase); + my $server_logfile = $server->LocalFile ($lfname); + my $svc_conf = $server->LocalFile($scname); + + $server->DeleteFile($lfname); + + $SV = $server->CreateProcess ("server", " -ORBDebugLevel 5 -ORBSvcConf $svc_conf -ORBLogFile $server_logfile -s 5 -o $server_iorfile"); + $SC = $client->CreateProcess ("client", "-k file://$client_iorfile -s"); + + $server_status = $SV->Spawn (); + + if ($server_status != 0) { + print STDERR "ERROR: server returned $server_status\n"; + exit 1; + } + + if ($server->WaitForFileTimed ($iorbase, + $server->ProcessStartWaitInterval()) == -1) { + print STDERR "ERROR: cannot find file <$server_iorfile>\n"; + $SV->Kill (); $SV->TimedWait (1); + exit 1; + } + + for ($i = 0; $i < $num_clients; $i++) { + $CLS[$i] = $client->CreateProcess ("client", "-c $i -k file://$client_iorfile"); + $CLS[$i]->Spawn (); + } + + + for ($i = 0; $i < $num_clients; $i++) { + + $client_status = $CLS[$i]->WaitKill ($client->ProcessStopWaitInterval()); + + if ($client_status != 0) { + print STDERR "ERROR: client $i returned $client_status\n"; + } + } + + $client_status = $SC->SpawnWaitKill ($client->ProcessStopWaitInterval()); + + # Now find the spawned threads in the log file. + + $find_this="Growing threadcount."; + $found_cnt=0; + $valid_cnt=4; + + my($found_cnt) = count_strings($server_logfile,$find_this); + + if ($found_cnt != $valid_cnt) { + print STDERR "ERROR: max_pool_thread test failed w/$found_cnt instead of $valid_cnt\n"; + $status = 1; + } + elsif ($deletelogs) { + $server->DeleteFile($lfname); + } + + $server_status = $SV->WaitKill ($server->ProcessStopWaitInterval()); + + if ($server_status != 0) { + print STDERR "ERROR: server returned $server_status\n"; + $status = 1; + } + + $server->DeleteFile($iorbase); + $client->DeleteFile($iorbase); + return($status); +} + +my $server = PerlACE::TestTarget::create_target (1) || die "Create target 1 failed\n"; +my $client = PerlACE::TestTarget::create_target (2) || die "Create target 2 failed\n"; +my $iorbase = "server.ior"; +my $server_iorfile = $server->LocalFile ($iorbase); +my $client_iorfile = $client->LocalFile ($iorbase); +my $deletelogs = 1; + +$server->DeleteFile($iorbase); +$client->DeleteFile($iorbase); + +my $status = 0; + +# Each test below will start up a server and optionally some clients. +# When a server gets a call it will sleep some number of seconds before responding. +# The -s parameter controls how many seconds it will sleep. +# The order is mandatory and must not contain spaces. It is defined as follows: +# min_pool_threads +# initial_pool_threads +# max_pool_threads +# thread_stack_size +# thread_timeout (in seconds) +# max_queue_request_depth + + while () + { + $status = test_1($server, $client, $iorbase, $deletelogs); + last if ($status); + $status = test_2($server, $client, $iorbase, $deletelogs); + last if ($status); + $status = test_3($server, $client, $iorbase, $deletelogs); + last if ($status); + $status = test_4($server, $client, $iorbase, $deletelogs); + last; + } + +$server->DeleteFile($iorbase); +$client->DeleteFile($iorbase); + +exit $status; + diff --git a/TAO/tests/Dynamic_TP/POA_Loader/Dynamic_TP_POA_Test_Dynamic/server.cpp b/TAO/tests/Dynamic_TP/POA_Loader/Dynamic_TP_POA_Test_Dynamic/server.cpp new file mode 100644 index 00000000000..fcdfee2efe0 --- /dev/null +++ b/TAO/tests/Dynamic_TP/POA_Loader/Dynamic_TP_POA_Test_Dynamic/server.cpp @@ -0,0 +1,122 @@ +// $Id$ + +#include "Hello.h" +#include "tao/Dynamic_TP/DTP_POA_Strategy.h" +#include "ace/Get_Opt.h" +#include "ace/OS_NS_stdio.h" +#include "ace/Thread_Manager.h" + +const ACE_TCHAR *ior_output_file = ACE_TEXT ("server.ior"); +int sleep_sec = 1; + +int +parse_args (int argc, ACE_TCHAR *argv[]) +{ + ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("o:s:")); + int c; + + while ((c = get_opts ()) != -1) + switch (c) + { + case 'o': + ior_output_file = get_opts.opt_arg (); + break; + case 's': + sleep_sec = ACE_OS::strtol(get_opts.opt_arg (),NULL,0); + break; + case '?': + default: + ACE_ERROR_RETURN ((LM_ERROR, + "usage: %s " + "-o <iorfile>" + "-s (# sec to sleep)" + "\n", + argv [0]), + -1); + } + // Indicates successful parsing of the command line + return 0; +} + +int +ACE_TMAIN (int argc, ACE_TCHAR *argv[]) +{ + try + { + CORBA::ORB_var orb = + CORBA::ORB_init (argc, argv); + + CORBA::Object_var poa_object = + orb->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 (); + + if (parse_args (argc, argv) != 0) + return 1; + + Hello *hello_impl; + ACE_NEW_RETURN (hello_impl, + Hello (orb.in ()), + 1); + PortableServer::ServantBase_var owner_transfer(hello_impl); + + PortableServer::ObjectId_var id = + root_poa->activate_object (hello_impl); + + CORBA::Object_var object = root_poa->id_to_reference (id.in ()); + + Test::Hello_var hello = + Test::Hello::_narrow (object.in ()); + + CORBA::String_var ior = + orb->object_to_string (hello.in ()); + + // Output the IOR to the <ior_output_file> + FILE *output_file= ACE_OS::fopen (ior_output_file, "w"); + if (output_file == 0) + ACE_ERROR_RETURN ((LM_ERROR, + "Cannot open output file %s for writing IOR: %C", + ior_output_file, + ior.in ()), + 1); + ACE_OS::fprintf (output_file, "%s", ior.in ()); + ACE_OS::fclose (output_file); + + ACE_DEBUG ((LM_DEBUG,"Server calling poa_manager::activate()\n")); + poa_manager->activate (); + + + ACE_DEBUG ((LM_DEBUG,"Server calling hello->sleep_sec()\n")); + // Set the sleep time for the Hello object + hello->sleep_sec(sleep_sec); + + ACE_DEBUG ((LM_DEBUG,"Server calling orb::run()\n")); + orb->run (); + + ACE_DEBUG ((LM_DEBUG, "(%P|%t) server - event loop finished\n")); + // Wait for all CSD task threads exit. + ACE_Thread_Manager::instance ()->wait (); + + root_poa->destroy (1, 1); + + orb->destroy (); + + + } + catch (const CORBA::Exception& ex) + { + ex._tao_print_exception ("Exception caught:"); + return 1; + } + + return 0; +} diff --git a/TAO/tests/Dynamic_TP/POA_Loader/Dynamic_TP_POA_Test_Dynamic/svc1.conf b/TAO/tests/Dynamic_TP/POA_Loader/Dynamic_TP_POA_Test_Dynamic/svc1.conf new file mode 100644 index 00000000000..98c7ce1492f --- /dev/null +++ b/TAO/tests/Dynamic_TP/POA_Loader/Dynamic_TP_POA_Test_Dynamic/svc1.conf @@ -0,0 +1,4 @@ +# $Id$ + +dynamic DTP_Config Service_Object * TAO_Dynamic_TP:_make_TAO_DTP_Config() "-DTPName POA1 -DTPMin -1 -DTPInit 5 -DTPMax -1 -DTPTimeout 60 -DTPStack 0 -DTPQueue 0" +dynamic DTP_POA_Loader Service_Object * TAO_Dynamic_TP:_make_TAO_DTP_POA_Loader() "-DTPPOAConfigMap RootPOA,MyPOA2,MyPOA3:POA1" diff --git a/TAO/tests/Dynamic_TP/POA_Loader/Dynamic_TP_POA_Test_Dynamic/svc2.conf b/TAO/tests/Dynamic_TP/POA_Loader/Dynamic_TP_POA_Test_Dynamic/svc2.conf new file mode 100644 index 00000000000..a0c90c7be1d --- /dev/null +++ b/TAO/tests/Dynamic_TP/POA_Loader/Dynamic_TP_POA_Test_Dynamic/svc2.conf @@ -0,0 +1,4 @@ +# $Id$ + +dynamic DTP_Config Service_Object * TAO_Dynamic_TP:_make_TAO_DTP_Config() "-DTPName POA1 -DTPMin 5 -DTPInit 10 -DTPMax -1 -DTPTimeout 10 -DTPStack 0 -DTPQueue 0" +dynamic DTP_POA_Loader Service_Object * TAO_Dynamic_TP:_make_TAO_DTP_POA_Loader() "-DTPPOAConfigMap RootPOA,MyPOA2,MyPOA3:POA1" diff --git a/TAO/tests/Dynamic_TP/POA_Loader/Dynamic_TP_POA_Test_Dynamic/svc3.conf b/TAO/tests/Dynamic_TP/POA_Loader/Dynamic_TP_POA_Test_Dynamic/svc3.conf new file mode 100644 index 00000000000..1e56b9c2599 --- /dev/null +++ b/TAO/tests/Dynamic_TP/POA_Loader/Dynamic_TP_POA_Test_Dynamic/svc3.conf @@ -0,0 +1,4 @@ +# $Id$ + +dynamic DTP_Config Service_Object * TAO_Dynamic_TP:_make_TAO_DTP_Config() "-DTPName POA1 -DTPMin -1 -DTPInit 15 -DTPMax -1 -DTPTimeout 10 -DTPStack 0 -DTPQueue 10" +dynamic DTP_POA_Loader Service_Object * TAO_Dynamic_TP:_make_TAO_DTP_POA_Loader() "-DTPPOAConfigMap RootPOA,MyPOA2,MyPOA3:POA1" diff --git a/TAO/tests/Dynamic_TP/POA_Loader/Dynamic_TP_POA_Test_Dynamic/svc4.conf b/TAO/tests/Dynamic_TP/POA_Loader/Dynamic_TP_POA_Test_Dynamic/svc4.conf new file mode 100644 index 00000000000..7b8f2807899 --- /dev/null +++ b/TAO/tests/Dynamic_TP/POA_Loader/Dynamic_TP_POA_Test_Dynamic/svc4.conf @@ -0,0 +1,4 @@ +# $Id$ + +dynamic DTP_Config Service_Object * TAO_Dynamic_TP:_make_TAO_DTP_Config() "-DTPName POA1 -DTPMin -1 -DTPInit 1 -DTPMax 5 -DTPTimeout 60 -DTPStack 0 -DTPQueue 10" +dynamic DTP_POA_Loader Service_Object * TAO_Dynamic_TP:_make_TAO_DTP_POA_Loader() "-DTPPOAConfigMap RootPOA,MyPOA2,MyPOA3:POA1" diff --git a/TAO/tests/Dynamic_TP/POA_Loader/Dynamic_TP_POA_Test_Static/Dynamic_TP_POA_Test_Static.mpc b/TAO/tests/Dynamic_TP/POA_Loader/Dynamic_TP_POA_Test_Static/Dynamic_TP_POA_Test_Static.mpc new file mode 100644 index 00000000000..7662ee6d861 --- /dev/null +++ b/TAO/tests/Dynamic_TP/POA_Loader/Dynamic_TP_POA_Test_Static/Dynamic_TP_POA_Test_Static.mpc @@ -0,0 +1,35 @@ +// -*- MPC -*- +// $Id$ + +project(Dynamic_TP_POA_Test_Static_idl): taoidldefaults { + IDL_Files { + Test.idl + } + custom_only = 1 +} + +project(Dynamic_TP_POA_Test_Static_Server): taoserver, csd_framework, dynamic_tp { + after += Dynamic_TP_POA_Test_Static_idl + Source_Files { + Hello.cpp + server.cpp + TestC.cpp + TestS.cpp + } + + IDL_Files { + } + +} + +project(Dynamic_TP_POA_Test_Static_Client): taoclient { + after += Dynamic_TP_POA_Test_Static_Server + Source_Files { + TestC.cpp + client.cpp + } + + IDL_Files { + } + +} diff --git a/TAO/tests/Dynamic_TP/POA_Loader/Dynamic_TP_POA_Test_Static/Hello.cpp b/TAO/tests/Dynamic_TP/POA_Loader/Dynamic_TP_POA_Test_Static/Hello.cpp new file mode 100644 index 00000000000..313393fc02c --- /dev/null +++ b/TAO/tests/Dynamic_TP/POA_Loader/Dynamic_TP_POA_Test_Static/Hello.cpp @@ -0,0 +1,43 @@ +// +// $Id$ +// +#include "Hello.h" +#include "ace/OS_NS_unistd.h" + +Hello::Hello (CORBA::ORB_ptr orb) + : orb_ (CORBA::ORB::_duplicate (orb)), sleep_sec_(1) +{ +} + +CORBA::Short +Hello::sleep_sec() +{ + return this->sleep_sec_; +} + +void + Hello::sleep_sec(CORBA::Short sl_sec) +{ + this->sleep_sec_ = sl_sec; + ACE_DEBUG ((LM_DEBUG, "(%P|%t) Hello::sleep_sec returning\n")); +} + +char * +Hello::get_string (CORBA::Long client_num) +{ + ACE_DEBUG ((LM_INFO, + ACE_TEXT ("TAO (%P|%t) - Server: Sleeping for client->%d....\n "), + client_num)); + + ACE_OS::sleep(this->sleep_sec_); + ACE_DEBUG ((LM_INFO, + ACE_TEXT ("TAO (%P|%t) - Server: Returning for client->%d....\n "), + client_num)); + return CORBA::string_dup ("Hello there!"); +} + +void +Hello::shutdown (void) +{ + this->orb_->shutdown (0); +} diff --git a/TAO/tests/Dynamic_TP/POA_Loader/Dynamic_TP_POA_Test_Static/Hello.h b/TAO/tests/Dynamic_TP/POA_Loader/Dynamic_TP_POA_Test_Static/Hello.h new file mode 100644 index 00000000000..93afd1f3913 --- /dev/null +++ b/TAO/tests/Dynamic_TP/POA_Loader/Dynamic_TP_POA_Test_Static/Hello.h @@ -0,0 +1,34 @@ +// +// $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 CORBA::Short sleep_sec (); + virtual void sleep_sec (CORBA::Short sleep_sec); + virtual char * get_string (CORBA::Long); + + virtual void shutdown (void); + +private: + /// Use an ORB reference to convert strings to objects and shutdown + /// the application. + CORBA::ORB_var orb_; + CORBA::Short sleep_sec_; +}; + +#include /**/ "ace/post.h" +#endif /* HELLO_H */ diff --git a/TAO/tests/Dynamic_TP/POA_Loader/Dynamic_TP_POA_Test_Static/Test.idl b/TAO/tests/Dynamic_TP/POA_Loader/Dynamic_TP_POA_Test_Static/Test.idl new file mode 100644 index 00000000000..0e2180b8481 --- /dev/null +++ b/TAO/tests/Dynamic_TP/POA_Loader/Dynamic_TP_POA_Test_Static/Test.idl @@ -0,0 +1,24 @@ +// +// $Id$ +// + +/// Put the interfaces in a module, to avoid global namespace pollution +module Test +{ + /// A very simple interface + interface Hello + { + /// Attribute to hold a sleep time in seconds + /// for the Hello servant + attribute short sleep_sec; + + /// Return a simple string + string get_string (in long cl); + + /// A method to shutdown the ORB + /** + * This method is used to simplify the test shutdown process + */ + oneway void shutdown (); + }; +}; diff --git a/TAO/tests/Dynamic_TP/POA_Loader/Dynamic_TP_POA_Test_Static/client.cpp b/TAO/tests/Dynamic_TP/POA_Loader/Dynamic_TP_POA_Test_Static/client.cpp new file mode 100644 index 00000000000..6525413101d --- /dev/null +++ b/TAO/tests/Dynamic_TP/POA_Loader/Dynamic_TP_POA_Test_Static/client.cpp @@ -0,0 +1,98 @@ +// $Id$ + +#include "TestC.h" +#include "ace/Get_Opt.h" + +const ACE_TCHAR *ior = ACE_TEXT("file://server.ior"); +int client_num = 1; +int report_exception = 1; +bool is_shutdown = false; + +int +parse_args (int argc, ACE_TCHAR *argv[]) +{ + ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("c:e:k:s")); + int c; + + while ((c = get_opts ()) != -1) + switch (c) + { + case 'c': + client_num = ACE_OS::atoi(get_opts.opt_arg ()); + break; + case 'e': + report_exception = ACE_OS::atoi(get_opts.opt_arg ()); + break; + case 'k': + ior = get_opts.opt_arg (); + break; + case 's': + is_shutdown = true; + break; + case '?': + default: + ACE_ERROR_RETURN ((LM_ERROR, + "usage: %s " + "-c <client #> " + "-e <0|1> " + "-k <ior> " + "-s (shutdown) " + "\n", + argv [0]), + -1); + } + // Indicates successful parsing of the command line + return 0; +} + +int +ACE_TMAIN(int argc, ACE_TCHAR *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(ior); + + Test::Hello_var hello = + Test::Hello::_narrow(tmp.in ()); + + if (CORBA::is_nil (hello.in ())) + { + ACE_ERROR_RETURN ((LM_DEBUG, + "Nil Test::Hello reference <%s>\n", + ior), + 1); + } + + if (is_shutdown) + { + hello->shutdown(); + } + else + { + CORBA::String_var the_string = + hello->get_string (client_num); + ACE_DEBUG((LM_DEBUG, + "Client %d received return text of: [%C %d].\n", + client_num, + the_string.in(), + client_num)); + } + orb->destroy (); + } + catch (const CORBA::Exception& ex) + { + if (report_exception) + ex._tao_print_exception ("Exception caught:"); + return 1; + } + + return 0; +} diff --git a/TAO/tests/Dynamic_TP/POA_Loader/Dynamic_TP_POA_Test_Static/run_test.pl b/TAO/tests/Dynamic_TP/POA_Loader/Dynamic_TP_POA_Test_Static/run_test.pl new file mode 100755 index 00000000000..bc66e52623f --- /dev/null +++ b/TAO/tests/Dynamic_TP/POA_Loader/Dynamic_TP_POA_Test_Static/run_test.pl @@ -0,0 +1,403 @@ +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::TestTarget; + + +sub count_strings +{ + my $log_file = shift; + my $find_str = shift; + open my $fh, '<', $log_file or die $!; + my $cnt=0; + while (<$fh>) + { + $f = quotemeta($find_str); + $cnt += $_ =~ /$f/; + } + print STDERR "INFO: Count - [$cnt]\n"; + close $fh; + return($cnt); +} + +sub test_1 +{ +# Test 1: +# This is a test for the creation of initial_pool_threads. +# The test will start up a server with default pool values +# and will result in 5 initial threads being started. + + my $server = shift; + my $client = shift; + my $iorbase = shift; + my $deletelogs = shift; + my $status = 0; + + print "\nRunning Test 1....\n"; + $test_num=1; + + my $lfname = "server_test" . $test_num . ".log"; + my $scname = "svc" . $test_num . ".conf"; + my $server_iorfile = $server->LocalFile ($iorbase); + my $client_iorfile = $client->LocalFile ($iorbase); + my $server_logfile = $server->LocalFile ($lfname); + my $svc_conf = $server->LocalFile($scname); + + $server->DeleteFile($lfname); + + $SV = $server->CreateProcess ("server", " -ORBDebugLevel 5 -ORBLogFile $server_logfile -s 3 -p {-1,5,-1,0,60,0} -o $server_iorfile"); + $SC = $client->CreateProcess ("client", "-k file://$client_iorfile -s"); + + $server_status = $SV->Spawn (); + + if ($server_status != 0) { + print STDERR "ERROR: server returned $server_status\n"; + exit 1; + } + + if ($server->WaitForFileTimed ($iorbase, + $server->ProcessStartWaitInterval()) == -1) { + print STDERR "ERROR: cannot find file <$server_iorfile>\n"; + $SV->Kill (); $SV->TimedWait (1); + exit 1; + } + + $client_status = $SC->SpawnWaitKill ($client->ProcessStopWaitInterval()); + if ($client_status != 0) { + print STDERR "ERROR: client $i returned $client_status\n"; + } + + # Now find the spawned threads in the log file. + + $find_this="DTP_Task::svc() New thread created."; + $found_cnt=0; + + my($found_cnt) = count_strings($server_logfile,$find_this); + + if ($found_cnt != 5) { + print STDERR "ERROR: initial_pool_thread test failed w/$found_cnt instead of 5\n"; + $status = 1; + } + elsif ($deletelogs) { + $server->DeleteFile($lfname); + } + + $server_status = $SV->WaitKill ($server->ProcessStopWaitInterval()); + + if ($server_status != 0) { + print STDERR "ERROR: server returned $server_status\n"; + $status = 1; + } + + $server->DeleteFile($iorbase); + $client->DeleteFile($iorbase); + + return($status); +} + +sub test_2 +{ + # Test 2: + # This is a test for showing a process maintaining a min_pool_threads after + # the creation of initial_pool_threads is higher. This test will also + # exercise the thread_idle_time (timeout). + # The test will start up a server with 10 init_pool_threads and 5 min_pool_threads. + # After 10 seconds, 5 threads should expire leaving the minimum 5 threads. + + + my $server = shift; + my $client = shift; + my $iorbase = shift; + my $deletelogs = shift; + my $status = 0; + + + print "\nRunning Test 2....\n"; + $test_num=2; + my $lfname = "server_test" . $test_num . ".log"; + my $scname = "svc" . $test_num . ".conf"; + my $server_iorfile = $server->LocalFile ($iorbase); + my $client_iorfile = $client->LocalFile ($iorbase); + my $server_logfile = $server->LocalFile ($lfname); + my $svc_conf = $server->LocalFile($scname); + + $server->DeleteFile($lfname); + + $SV = $server->CreateProcess ("server", " -ORBDebugLevel 5 -ORBLogFile $server_logfile -s 3 -p {5,10,-1,0,10,0} -o $server_iorfile"); + $SC = $client->CreateProcess ("client", "-k file://$client_iorfile -s"); + + $server_status = $SV->Spawn (); + + if ($server_status != 0) { + print STDERR "ERROR: server returned $server_status\n"; + exit 1; + } + + if ($server->WaitForFileTimed ($iorbase, + $server->ProcessStartWaitInterval()) == -1) { + print STDERR "ERROR: cannot find file <$server_iorfile>\n"; + $SV->Kill (); $SV->TimedWait (1); + exit 1; + } + + # Sleep here for more than the timeout to let the threads die off and log. + print STDERR "INFO: sleeping 15 seconds\n"; + sleep(15); + + $client_status = $SC->SpawnWaitKill ($client->ProcessStopWaitInterval()); + if ($client_status != 0) { + print STDERR "ERROR: client $i returned $client_status\n"; + } + # Now find the spawned threads in the log file. + + $find_this="DTP_Task::svc() Existing thread expiring."; + $found_cnt=0; + + my($found_cnt) = count_strings($server_logfile,$find_this); + + if ($found_cnt != 5) { + print STDERR "ERROR: min_pool_thread test failed w/$found_cnt instead of 5\n"; + $status = 1; + } + elsif ($deletelogs) { + $server->DeleteFile($lfname); + } + + $server_status = $SV->WaitKill ($server->ProcessStopWaitInterval()); + + if ($server_status != 0) { + print STDERR "ERROR: server returned $server_status\n"; + $status = 1; + } + + $server->DeleteFile($iorbase); + $client->DeleteFile($iorbase); + + return($status); +} + +sub test_3 +{ + # Test 3: + # This is a test for showing a process maintaining a max_request_queue_depth after + # more clients request service than the queue allows for. + # The test will start up a server with a max_request_queue_depth of 10 and + # will issue calls from 15 clients. There should be 5 CORBA exceptions found + # in the log after the run. + # + my $server = shift; + my $client = shift; + my $iorbase = shift; + my $deletelogs = shift; + my $status = 0; + + print "\nRunning Test 3....\n"; + $test_num=3; + $num_clients=15; + my $lfname = "server_test" . $test_num . ".log"; + my $scname = "svc" . $test_num . ".conf"; + my $server_iorfile = $server->LocalFile ($iorbase); + my $client_iorfile = $client->LocalFile ($iorbase); + my $server_logfile = $server->LocalFile ($lfname); + my $svc_conf = $server->LocalFile($scname); + + $server->DeleteFile($lfname); + + $SV = $server->CreateProcess ("server", " -ORBDebugLevel 5 -ORBLogFile $server_logfile -s 3 -p {-1,15,-1,0,10,10} -o $server_iorfile"); + + $server_status = $SV->Spawn (); + + if ($server_status != 0) { + print STDERR "ERROR: server returned $server_status\n"; + exit 1; + } + + if ($server->WaitForFileTimed ($iorbase, + $server->ProcessStartWaitInterval()) == -1) { + print STDERR "ERROR: cannot find file <$server_iorfile>\n"; + $SV->Kill (); $SV->TimedWait (1); + exit 1; + } + + for ($i = 0; $i < $num_clients; $i++) { + $CLS[$i] = $client->CreateProcess ("client", "-c $i -k file://$client_iorfile -e 0"); + $CLS[$i]->Spawn (); + } + + my $valid_num_exceptions=5; + my $num_exceptions=0; + + for ($i = 0; $i < $num_clients; $i++) { + + $client_status = $CLS[$i]->WaitKill ($client->ProcessStopWaitInterval()); + + if ($client_status != 0) { + $num_exceptions++; + print STDERR "STATUS: client $i returned $client_status\n"; + } + } + + $SC = $client->CreateProcess ("client", "-k file://$client_iorfile -s"); + $client_status = $SC->SpawnWaitKill ($client->ProcessStopWaitInterval()); + if ($client_status != 0) { + print STDERR "ERROR: client $i returned $client_status\n"; + } + + if ($num_exceptions != $valid_num_exceptions) + { + print STDERR "ERROR: max_request_queue_depth test failed w/$num_exceptions instead of $valid_num_exceptions\n"; + $status = 1; + } + elsif ($deletelogs) { + $server->DeleteFile($lfname); + } + + + $server_status = $SV->WaitKill ($server->ProcessStopWaitInterval()); + + if ($server_status != 0) { + print STDERR "ERROR: server returned $server_status\n"; + $status = 1; + } + + $server->DeleteFile($iorbase); + $client->DeleteFile($iorbase); + + return($status); +} + +sub test_4 +{ + + # Test 4: + # This is a test for showing a process maintaining a max_pool_threads after + # more clients request service than the queue allows for. + # The test will start up a server with a max_request_queue_depth of 10 and + # will issue calls from 10 clients. There should be 5 CORBA exceptions found + # in the log after the run. + # + + my $server = shift; + my $client = shift; + my $iorbase = shift; + my $deletelogs = shift; + my $status = 0; + + print "\nRunning Test 4....\n"; + $test_num=4; + $num_clients=10; + my $lfname = "server_test" . $test_num . ".log"; + my $scname = "svc" . $test_num . ".conf"; + my $server_iorfile = $server->LocalFile ($iorbase); + my $client_iorfile = $client->LocalFile ($iorbase); + my $server_logfile = $server->LocalFile ($lfname); + my $svc_conf = $server->LocalFile($scname); + + $server->DeleteFile($lfname); + + $SV = $server->CreateProcess ("server", " -ORBDebugLevel 5 -ORBLogFile $server_logfile -s 5 -p {-1,1,5,0,60,10} -o $server_iorfile"); + $SC = $client->CreateProcess ("client", "-k file://$client_iorfile -s"); + + $server_status = $SV->Spawn (); + + if ($server_status != 0) { + print STDERR "ERROR: server returned $server_status\n"; + exit 1; + } + + if ($server->WaitForFileTimed ($iorbase, + $server->ProcessStartWaitInterval()) == -1) { + print STDERR "ERROR: cannot find file <$server_iorfile>\n"; + $SV->Kill (); $SV->TimedWait (1); + exit 1; + } + + for ($i = 0; $i < $num_clients; $i++) { + $CLS[$i] = $client->CreateProcess ("client", "-c $i -k file://$client_iorfile"); + $CLS[$i]->Spawn (); + } + + + for ($i = 0; $i < $num_clients; $i++) { + + $client_status = $CLS[$i]->WaitKill ($client->ProcessStopWaitInterval()); + + if ($client_status != 0) { + print STDERR "ERROR: client $i returned $client_status\n"; + } + } + + $client_status = $SC->SpawnWaitKill ($client->ProcessStopWaitInterval()); + + # Now find the spawned threads in the log file. + + $find_this="Growing threadcount."; + $found_cnt=0; + $valid_cnt=4; + + my($found_cnt) = count_strings($server_logfile,$find_this); + + if ($found_cnt != $valid_cnt) { + print STDERR "ERROR: max_pool_thread test failed w/$found_cnt instead of $valid_cnt\n"; + $status = 1; + } + elsif ($deletelogs) { + $server->DeleteFile($lfname); + } + + $server_status = $SV->WaitKill ($server->ProcessStopWaitInterval()); + + if ($server_status != 0) { + print STDERR "ERROR: server returned $server_status\n"; + $status = 1; + } + + $server->DeleteFile($iorbase); + $client->DeleteFile($iorbase); + return($status); +} + +my $server = PerlACE::TestTarget::create_target (1) || die "Create target 1 failed\n"; +my $client = PerlACE::TestTarget::create_target (2) || die "Create target 2 failed\n"; +my $iorbase = "server.ior"; +my $server_iorfile = $server->LocalFile ($iorbase); +my $client_iorfile = $client->LocalFile ($iorbase); +my $deletelogs = 1; + +$server->DeleteFile($iorbase); +$client->DeleteFile($iorbase); + +my $status = 0; + +# Each test below will start up a server and optionally some clients. +# When a server gets a call it will sleep some number of seconds before responding. +# The -s parameter controls how many seconds it will sleep. +# The order is mandatory and must not contain spaces. It is defined as follows: +# min_pool_threads +# initial_pool_threads +# max_pool_threads +# thread_stack_size +# thread_timeout (in seconds) +# max_queue_request_depth + + while () + { + $status = test_1($server, $client, $iorbase, $deletelogs); + last if ($status); + $status = test_2($server, $client, $iorbase, $deletelogs); + last if ($status); + $status = test_3($server, $client, $iorbase, $deletelogs); + last if ($status); + $status = test_4($server, $client, $iorbase, $deletelogs); + last; + } + +$server->DeleteFile($iorbase); +$client->DeleteFile($iorbase); + +exit $status; diff --git a/TAO/tests/Dynamic_TP/POA_Loader/Dynamic_TP_POA_Test_Static/server.cpp b/TAO/tests/Dynamic_TP/POA_Loader/Dynamic_TP_POA_Test_Static/server.cpp new file mode 100644 index 00000000000..0e6b309f82b --- /dev/null +++ b/TAO/tests/Dynamic_TP/POA_Loader/Dynamic_TP_POA_Test_Static/server.cpp @@ -0,0 +1,196 @@ +// $Id$ + +#include "Hello.h" +#include "tao/Dynamic_TP/DTP_POA_Strategy.h" +#include "ace/Get_Opt.h" +#include "ace/OS_NS_stdio.h" +#include "ace/Thread_Manager.h" + +const ACE_TCHAR *ior_output_file = ACE_TEXT ("server.ior"); +int sleep_sec = 1; + +// The parms below must be in a particular order for this test. +// min_threads_ = -1; +// init_threads_ = 1; +// max_threads_ = -1; +// stack_size_ = 0; +// timeout_ = 60; +// queue_depth_ = 0; + +const ACE_TCHAR *parms = "{-1,1,-1,0,60,0}"; + +int +parse_args (int argc, ACE_TCHAR *argv[]) +{ + ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("o:s:p:")); + int c; + + while ((c = get_opts ()) != -1) + switch (c) + { + case 'o': + ior_output_file = get_opts.opt_arg (); + break; + case 'p': + parms = get_opts.opt_arg (); + break; + case 's': + sleep_sec = ACE_OS::strtol(get_opts.opt_arg (),NULL,0); + break; + case '?': + default: + ACE_ERROR_RETURN ((LM_ERROR, + "usage: %s " + "-o <iorfile>" + "-p (parm array)" + "-s (# sec to sleep)" + "\n", + argv [0]), + -1); + } + // Indicates successful parsing of the command line + return 0; +} + +void +set_parms ( TAO_DTP_Definition * this_config) +{ + ACE_TCHAR *sep; + long val; + + // Get past the brace + val = ACE_OS::strtol(parms,&sep,10); + // min_threads_ = -1; + this_config->min_threads_ = ACE_OS::strtol(sep+1,&sep,10); + + // init_threads_ = 1; + this_config->init_threads_ = ACE_OS::strtol(sep+1,&sep,10); + + // max_threads_ = 1; + this_config->max_threads_ = ACE_OS::strtol(sep+1,&sep,10); + + // stack_size_ = 0; + this_config->stack_size_ = ACE_OS::strtol(sep+1,&sep,10); + + // timeout_ = 60; + this_config->timeout_.set(ACE_OS::strtol(sep+1,&sep,10),0); + + // queue_depth_ = 0; + this_config->queue_depth_ = ACE_OS::strtol(sep+1,&sep,10); +} + +int +ACE_TMAIN (int argc, ACE_TCHAR *argv[]) +{ + try + { + CORBA::ORB_var orb = + CORBA::ORB_init (argc, argv); + + CORBA::Object_var poa_object = + orb->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 (); + + if (parse_args (argc, argv) != 0) + return 1; + + + TAO_DTP_Definition dtp_config; + + set_parms(&dtp_config); + + //dtp_config.min_threads_ = -1; + //dtp_config.init_threads_ = 5; + //dtp_config.max_threads_ = -1; + //dtp_config.stack_size_ = (40 * 1024); + //dtp_config.timeout_.set(10,0); + //dtp_config.queue_depth_ = 10; + + ACE_DEBUG((LM_INFO,ACE_TEXT("TAO (%P|%t) - Server : min_threads_ = %d\n"),dtp_config.min_threads_)); + ACE_DEBUG((LM_INFO,ACE_TEXT("TAO (%P|%t) - Server : init_threads_ = %d\n"),dtp_config.init_threads_)); + ACE_DEBUG((LM_INFO,ACE_TEXT("TAO (%P|%t) - Server : max_threads_ = %d\n"),dtp_config.max_threads_)); + ACE_DEBUG((LM_INFO,ACE_TEXT("TAO (%P|%t) - Server : stack_size_ = %d\n"),dtp_config.stack_size_)); + ACE_DEBUG((LM_INFO,ACE_TEXT("TAO (%P|%t) - Server : timeout_ = %d\n"),dtp_config.timeout_.sec())); + ACE_DEBUG((LM_INFO,ACE_TEXT("TAO (%P|%t) - Server : queue_depth_ = %d\n"),dtp_config.queue_depth_)); + ACE_DEBUG((LM_INFO,ACE_TEXT("TAO (%P|%t) - Server : sleep_sec = %d\n"),sleep_sec)); + + // Create the thread pool servant dispatching strategy object, and + // hold it in a (local) smart pointer variable. + TAO_Intrusive_Ref_Count_Handle<TAO_DTP_POA_Strategy> csd_strategy = + new TAO_DTP_POA_Strategy(&dtp_config, false); + + // Tell the strategy to apply itself to the child poa. + if (csd_strategy->apply_to(root_poa.in()) == false) + { + ACE_ERROR((LM_ERROR, + "Failed to apply CSD strategy to root poa.\n")); + return -1; + } + + Hello *hello_impl; + ACE_NEW_RETURN (hello_impl, + Hello (orb.in ()), + 1); + PortableServer::ServantBase_var owner_transfer(hello_impl); + + PortableServer::ObjectId_var id = + root_poa->activate_object (hello_impl); + + CORBA::Object_var object = root_poa->id_to_reference (id.in ()); + + Test::Hello_var hello = + Test::Hello::_narrow (object.in ()); + + CORBA::String_var ior = + orb->object_to_string (hello.in ()); + + ACE_DEBUG ((LM_DEBUG,"Server calling poa_manager::activate()\n")); + poa_manager->activate (); + + // Output the IOR to the <ior_output_file> + FILE *output_file= ACE_OS::fopen (ior_output_file, "w"); + if (output_file == 0) + ACE_ERROR_RETURN ((LM_ERROR, + "Cannot open output file %s for writing IOR: %C", + ior_output_file, + ior.in ()), + 1); + ACE_OS::fprintf (output_file, "%s", ior.in ()); + ACE_OS::fclose (output_file); + + + ACE_DEBUG ((LM_DEBUG,"Server calling hello->sleep_sec()\n")); + // Set the sleep time for the Hello object + hello->sleep_sec(sleep_sec); + + ACE_DEBUG ((LM_DEBUG,"Server calling orb::run()\n")); + orb->run (); + + ACE_DEBUG ((LM_DEBUG, "(%P|%t) server - event loop finished\n")); + // Wait for all CSD task threads exit. + ACE_Thread_Manager::instance ()->wait (); + + root_poa->destroy (1, 1); + + orb->destroy (); + + + } + catch (const CORBA::Exception& ex) + { + ex._tao_print_exception ("Exception caught:"); + return 1; + } + + return 0; +} diff --git a/TAO/tests/Dynamic_TP/POA_Loader/POA_Loader.mpc b/TAO/tests/Dynamic_TP/POA_Loader/POA_Loader.mpc new file mode 100644 index 00000000000..5ab8a83701c --- /dev/null +++ b/TAO/tests/Dynamic_TP/POA_Loader/POA_Loader.mpc @@ -0,0 +1,5 @@ +// $Id$ + +project(*test) : dynamic_tp,csd_framework { + exename = test +} diff --git a/TAO/tests/Dynamic_TP/POA_Loader/Test.cpp b/TAO/tests/Dynamic_TP/POA_Loader/Test.cpp new file mode 100644 index 00000000000..538f19b126e --- /dev/null +++ b/TAO/tests/Dynamic_TP/POA_Loader/Test.cpp @@ -0,0 +1,102 @@ +// $Id$ + +#include "tao/Dynamic_TP/DTP_POA_Strategy.h" +#include "tao/CSD_Framework/CSD_Strategy_Repository.h" + +#include "ace/OS_NS_stdio.h" +#include "ace/Service_Config.h" +#include "ace/Dynamic_Service.h" +#include <iostream> +#include "tao/debug.h" + +void +show_tp_config (const ACE_CString &name, const TAO_DTP_Definition &entry) +{ + ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Config set for %C:\n"), name.c_str())); + ACE_DEBUG ((LM_DEBUG, ACE_TEXT (" Initial threads: %d:\n"), entry.init_threads_)); + ACE_DEBUG ((LM_DEBUG, ACE_TEXT (" Min threads: %d:\n"), entry.min_threads_)); + ACE_DEBUG ((LM_DEBUG, ACE_TEXT (" Max threads: %d:\n"), entry.max_threads_)); + if (entry.min_threads_ > -1) + ACE_DEBUG ((LM_DEBUG, ACE_TEXT (" Idle Timeout: %d (sec)\n"), entry.timeout_.sec())); + ACE_DEBUG ((LM_DEBUG, ACE_TEXT (" Stack Size: %d:\n"), entry.stack_size_)); + ACE_DEBUG ((LM_DEBUG, ACE_TEXT (" Request queue max depth: %d\n"), entry.queue_depth_)); +} + +//void +//show_poa_config (const ACE_CString &name, TAO_DTP_POA_Strategy * strat) +//{ + //ACE_DEBUG ((LM_INFO, ACE_TEXT ("POA [%C] has the configuration key [%C]\n"), name.c_str(),strat->get_tp_config().c_str())); + //ACE_DEBUG ((LM_DEBUG, ACE_TEXT (" Initial threads: %d:\n"), entry.init_threads_)); + //ACE_DEBUG ((LM_DEBUG, ACE_TEXT (" Min threads: %d:\n"), entry.min_threads_)); + //ACE_DEBUG ((LM_DEBUG, ACE_TEXT (" Max threads: %d:\n"), entry.max_threads_)); + //if (entry.min_threads_ > -1) + // ACE_DEBUG ((LM_DEBUG, ACE_TEXT (" Idle Timeout: %d (sec)\n"), entry.timeout_)); + //ACE_DEBUG ((LM_DEBUG, ACE_TEXT (" Stack Size: %d:\n"), entry.stack_size_)); + //ACE_DEBUG ((LM_DEBUG, ACE_TEXT (" Request queue max depth: %d\n"), entry.queue_depth_)); +//} + +int +ACE_TMAIN(int argc, ACE_TCHAR *argv[]) +{ + TAO_debug_level = 1; + + ACE_Service_Config::open (argc, argv); + + // Dump the POA to Strategy map + TAO_CSD_Strategy_Repository* dtp_poa_strat_repo = + ACE_Dynamic_Service<TAO_CSD_Strategy_Repository>::instance + ("TAO_CSD_Strategy_Repository"); + + if (dtp_poa_strat_repo == 0) + { + ACE_DEBUG ((LM_DEBUG, ACE_TEXT("Unable to load configuration\n"))); + return -1; + } + else + { + ACE_DEBUG ((LM_DEBUG, ACE_TEXT("TAO_CSD_Strategy_Repository found\n"))); + } + + + // Now iterate through the repository and attempt to find sample POA configurations + + const ACE_TCHAR *poa_list [] = + { ACE_TEXT ("MyPOA"), // should find this one + ACE_TEXT ("POA2"), // shouldn't find this one + ACE_TEXT ("MyPOA3"), // should find this one + ACE_TEXT ("MyPOA1"), // should find this one + 0 + }; + + TAO_DTP_POA_Strategy * mapped_strategy; + + for (int i = 0; poa_list[i] != 0; i++) + { + mapped_strategy = 0; + ACE_DEBUG ((LM_INFO, ACE_TEXT("Config definition for %C\n"), poa_list[i])); + mapped_strategy = dynamic_cast <TAO_DTP_POA_Strategy*> (dtp_poa_strat_repo->find (poa_list[i])); + if ((mapped_strategy == 0) && (i != 1) && (i != 3)) + { + ACE_DEBUG ((LM_DEBUG, ACE_TEXT("Cannot find TP Config definition for %C\n"), poa_list[i])); + continue; + } + if (i == 1 || i == 3) + { + if (mapped_strategy) + { + ACE_DEBUG ((LM_DEBUG, ACE_TEXT("Found TP Config definition for %C which should have failed\n"), poa_list[i])); + } + else + { + ACE_DEBUG ((LM_DEBUG, ACE_TEXT("Config definition for %C not found as expected\n"), poa_list[i])); + } + } + else + { + //show_poa_config (poa_list[i], mapped_strategy); + } + } + + + return 0; +} diff --git a/TAO/tests/Dynamic_TP/POA_Loader/svc.conf b/TAO/tests/Dynamic_TP/POA_Loader/svc.conf new file mode 100644 index 00000000000..664f8220087 --- /dev/null +++ b/TAO/tests/Dynamic_TP/POA_Loader/svc.conf @@ -0,0 +1,15 @@ +# $Id$ +dynamic DTP_Config Service_Object * TAO_Dynamic_TP:_make_TAO_DTP_Config() "-DTPName ORB -DTPMin 5 -DTPInit 6 -DTPMax 10 -DTPTimeout 240 -DTPStack 10240 -DTPQueue 20" +dynamic DTP_Config Service_Object * TAO_Dynamic_TP:_make_TAO_DTP_Config() "-DTPName POA1 -DTPMin 2 -DTPInit 4 -DTPMax 10 -DTPQueue 10" +dynamic DTP_Config Service_Object * TAO_Dynamic_TP:_make_TAO_DTP_Config() "-DTPName POA1 -DTPOverwrite 1 -DTPMin 7 -DTPMax 14 " +dynamic DTP_Config Service_Object * TAO_Dynamic_TP:_make_TAO_DTP_Config() "-DTPName POA1 -DTPMin 7 -DTPMax 11 -DPQueue 14" +dynamic DTP_Config Service_Object * TAO_Dynamic_TP:_make_TAO_DTP_Config() "-DTPName defaults" +dynamic DTP_Config Service_Object * TAO_Dynamic_TP:_make_TAO_DTP_Config() "-DTPName m1 -DTPMin 3" +dynamic DTP_Config Service_Object * TAO_Dynamic_TP:_make_TAO_DTP_Config() "-DTPName m2 -DTPMax 10" +dynamic DTP_Config Service_Object * TAO_Dynamic_TP:_make_TAO_DTP_Config() "-DTPName m3 -DTPTimeout 120" +dynamic DTP_Config Service_Object * TAO_Dynamic_TP:_make_TAO_DTP_Config() "-DTPName m4 -DTPMin 3 -DTPInit 7 -DTPMax 10 -DTPTimeout 120" +dynamic DTP_Config Service_Object * TAO_Dynamic_TP:_make_TAO_DTP_Config() "-DTPName m5 -DTPMin 3 -DTPInit 10 -DTPTimeout 30" +dynamic DTP_Config Service_Object * TAO_Dynamic_TP:_make_TAO_DTP_Config() "-DTPName m6 -DTPInit 6 -DTPMax -1" +dynamic DTP_Config Service_Object * TAO_Dynamic_TP:_make_TAO_DTP_Config() "-DTPName m7 -DTPInit 7" +dynamic DTP_Config Service_Object * TAO_Dynamic_TP:_make_TAO_DTP_Config() "-DTPName bogus -DTPMin 6 -DTPInit 3" +dynamic DTP_POA_Loader Service_Object * TAO_Dynamic_TP:_make_TAO_DTP_POA_Loader() "-DTPPOAConfigMap MyPOA,MyPOA2,MyPOA3:POA1" |