diff options
Diffstat (limited to 'TAO/tests/Dynamic_TP/POA_Loader')
21 files changed, 1731 insertions, 0 deletions
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" |