diff options
author | William R. Otte <wotte@dre.vanderbilt.edu> | 2006-07-24 15:50:21 +0000 |
---|---|---|
committer | William R. Otte <wotte@dre.vanderbilt.edu> | 2006-07-24 15:50:21 +0000 |
commit | 3aff90f4a822fcf5d902bbfbcc9fa931d6191a8c (patch) | |
tree | 197c810e5f5bce17b1233a7cb8d7b50c0bcd25e2 /TAO/tests/Server_Connection_Purging | |
parent | 6b846cf03c0bcbd8c276cb0af61a181e5f98eaae (diff) | |
download | ATCD-3aff90f4a822fcf5d902bbfbcc9fa931d6191a8c.tar.gz |
Repo restructuring
Diffstat (limited to 'TAO/tests/Server_Connection_Purging')
-rw-r--r-- | TAO/tests/Server_Connection_Purging/.cvsignore | 2 | ||||
-rw-r--r-- | TAO/tests/Server_Connection_Purging/Server_Connection_Purging.mpc | 18 | ||||
-rw-r--r-- | TAO/tests/Server_Connection_Purging/Test.idl | 10 | ||||
-rw-r--r-- | TAO/tests/Server_Connection_Purging/Test_i.cpp | 12 | ||||
-rw-r--r-- | TAO/tests/Server_Connection_Purging/Test_i.h | 24 | ||||
-rw-r--r-- | TAO/tests/Server_Connection_Purging/client.cpp | 137 | ||||
-rwxr-xr-x | TAO/tests/Server_Connection_Purging/run_test.pl | 45 | ||||
-rw-r--r-- | TAO/tests/Server_Connection_Purging/server.cpp | 110 | ||||
-rw-r--r-- | TAO/tests/Server_Connection_Purging/svc.conf | 3 |
9 files changed, 361 insertions, 0 deletions
diff --git a/TAO/tests/Server_Connection_Purging/.cvsignore b/TAO/tests/Server_Connection_Purging/.cvsignore new file mode 100644 index 00000000000..f2ad85300eb --- /dev/null +++ b/TAO/tests/Server_Connection_Purging/.cvsignore @@ -0,0 +1,2 @@ +client +server diff --git a/TAO/tests/Server_Connection_Purging/Server_Connection_Purging.mpc b/TAO/tests/Server_Connection_Purging/Server_Connection_Purging.mpc new file mode 100644 index 00000000000..a50eda03b14 --- /dev/null +++ b/TAO/tests/Server_Connection_Purging/Server_Connection_Purging.mpc @@ -0,0 +1,18 @@ +// -*- MPC -*- +// $Id$ + +project(*Server): taoserver { + Source_Files { + Test_i.cpp + server.cpp + } +} + +project(*Client): taoclient, anytypecode { + after += *Server + Source_Files { + TestC.cpp + client.cpp + } +} + diff --git a/TAO/tests/Server_Connection_Purging/Test.idl b/TAO/tests/Server_Connection_Purging/Test.idl new file mode 100644 index 00000000000..ca9b3e126c0 --- /dev/null +++ b/TAO/tests/Server_Connection_Purging/Test.idl @@ -0,0 +1,10 @@ +// $Id$ + +interface test +{ + /* + * A simple remote operation.. + */ + void send_stuff(in string foo); + +}; diff --git a/TAO/tests/Server_Connection_Purging/Test_i.cpp b/TAO/tests/Server_Connection_Purging/Test_i.cpp new file mode 100644 index 00000000000..da045e2503f --- /dev/null +++ b/TAO/tests/Server_Connection_Purging/Test_i.cpp @@ -0,0 +1,12 @@ +// +// $Id$ +// +#include "Test_i.h" + +void +test_i::send_stuff (const char* string + ACE_ENV_ARG_DECL_NOT_USED) + ACE_THROW_SPEC ((CORBA::SystemException)) +{ + ACE_DEBUG ((LM_DEBUG, "TAO (%P|%t) - %s\n", string)); +} diff --git a/TAO/tests/Server_Connection_Purging/Test_i.h b/TAO/tests/Server_Connection_Purging/Test_i.h new file mode 100644 index 00000000000..0f6e923322d --- /dev/null +++ b/TAO/tests/Server_Connection_Purging/Test_i.h @@ -0,0 +1,24 @@ +// +// $Id$ +// + +#ifndef TEST_I_H +#define TEST_I_H +#include /**/ "ace/pre.h" + +#include "TestS.h" + +class test_i + : public virtual POA_test +{ +public: + // = The skeleton methods + virtual void send_stuff (const char* string + ACE_ENV_ARG_DECL) + ACE_THROW_SPEC ((CORBA::SystemException)); + +private: +}; + +#include /**/ "ace/post.h" +#endif /* TEST_I_H */ diff --git a/TAO/tests/Server_Connection_Purging/client.cpp b/TAO/tests/Server_Connection_Purging/client.cpp new file mode 100644 index 00000000000..80d03ad751b --- /dev/null +++ b/TAO/tests/Server_Connection_Purging/client.cpp @@ -0,0 +1,137 @@ +// $Id$ +#include "ace/Get_Opt.h" +#include "ace/Log_Msg.h" +#include "ace/SOCK_Connector.h" +#include "ace/TP_Reactor.h" +#include "ace/Reactor.h" + +const char *host = "localhost"; +static int port = 10008; +const int iter = 80; +int purged_handles = 0; + +int +parse_args (int argc, char *argv[]) +{ + ACE_Get_Opt get_opts (argc, argv, "h:p:"); + int c; + + while ((c = get_opts ()) != -1) + switch (c) + { + case 'h': + host = get_opts.opt_arg (); + break; + case 'p': + port = ACE_OS::atoi (get_opts.opt_arg ()); + break; + case '?': + default: + ACE_ERROR_RETURN ((LM_ERROR, + "usage: %s " + "-h <host> " + "-p <port>" + "-i <iterations>" + "\n", + argv [0]), + -1); + } + + // Indicates sucessful parsing of the command line + return 0; +} + +class Purging_Handler : public ACE_Event_Handler +{ +public: + virtual int handle_input (ACE_HANDLE h); + virtual int handle_close (ACE_HANDLE h, + ACE_Reactor_Mask m); +}; + +int +Purging_Handler::handle_input (ACE_HANDLE ) +{ + return -1; +} + +int +Purging_Handler::handle_close (ACE_HANDLE h, + ACE_Reactor_Mask ) +{ + if (purged_handles % 10 == 0) + ACE_DEBUG ((LM_DEBUG, + "(%P|%t) purging handle [%d] \n", + h)); + + ++purged_handles; + + return 0; +} + +int +main (int argc, char *argv[]) +{ + if (parse_args (argc, argv) == -1) + return -1; + + ACE_Select_Reactor sr; + + ACE_Reactor reac (&sr); + + ACE_Reactor::instance (&reac); + + ACE_SOCK_Stream stream[iter]; + + ACE_SOCK_Connector connector[iter]; + + Purging_Handler ph[iter]; + + ACE_INET_Addr addr (port, + host); + + + ACE_Reactor *singleton = + ACE_Reactor::instance (); + + for (int i = 0; i != iter; ++i) + { + if (connector[i].connect (stream[i], + addr) == -1) + ACE_ERROR_RETURN ((LM_ERROR, + "Error while connecting: %p\n", + "client"), + -1); + + if (stream[i].get_handle () == ACE_INVALID_HANDLE) + ACE_ERROR_RETURN ((LM_ERROR, + "Got invalid handles after connecting the [%d] time\n",i), + -1); + if (singleton->register_handler (stream[i].get_handle (), + &ph[i], + ACE_Event_Handler::READ_MASK) == -1) + ACE_ERROR_RETURN ((LM_ERROR, + "Registration failed \n"), + -1); + + ACE_Time_Value tv (1); + + while (singleton->handle_events (&tv) >= 1); + } + + // Remove the handlers to avoid the possibility of the reactor + // using any of them after they leave the scope (those that haven't + // been closed and removed already, that is). + for (int j = 0; j != iter; ++j) + { + singleton->remove_handler (stream[j].get_handle (), + ACE_Event_Handler::READ_MASK); + } + + if ((iter - purged_handles) > 20) + ACE_ERROR_RETURN ((LM_ERROR, + "(%P|%t) Purging hasnt worked at all \n"), + -1); + + return 0; +} diff --git a/TAO/tests/Server_Connection_Purging/run_test.pl b/TAO/tests/Server_Connection_Purging/run_test.pl new file mode 100755 index 00000000000..4220bc5fc4f --- /dev/null +++ b/TAO/tests/Server_Connection_Purging/run_test.pl @@ -0,0 +1,45 @@ +eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}' + & eval 'exec perl -S $0 $argv:q' + if 0; + +# $Id$ +# -*- perl -*- + +use lib '../../../bin'; +use PerlACE::Run_Test; + +$iorfile = PerlACE::LocalFile ("server.ior"); +$orbport = 10000 + PerlACE::uniqueid (); +unlink $iorfile; +$status = 0; + +$SV = new PerlACE::Process ("server", "-ORBEndpoint iiop://localhost:$orbport"); +$CL = new PerlACE::Process ("client", "-h localhost -p $orbport"); + +print STDERR $CL->CommandLine(), "\n" ; +$SV->Spawn (); + +if (PerlACE::waitforfile_timed ($iorfile, + $PerlACE::wait_interval_for_process_creation) == -1) { + print STDERR "ERROR: cannot find file <$iorfile>\n"; + $SV->Kill (); $SV->TimedWait (1); + exit 1; +} + +$client = $CL->SpawnWaitKill (300); + +if ($client != 0) { + print STDERR "ERROR: client returned $client\n"; + $status = 1; +} + +$server = $SV->WaitKill (120); + +if ($server != 0) { + print STDERR "ERROR: server returned $server\n"; + $status = 1; +} + +unlink $iorfile; + +exit $status; diff --git a/TAO/tests/Server_Connection_Purging/server.cpp b/TAO/tests/Server_Connection_Purging/server.cpp new file mode 100644 index 00000000000..52c7b5e6395 --- /dev/null +++ b/TAO/tests/Server_Connection_Purging/server.cpp @@ -0,0 +1,110 @@ +// $Id$ + +#include "Test_i.h" +#include "ace/Get_Opt.h" +#include "ace/OS_NS_stdio.h" + +const char *ior_output_file = "server.ior"; + +int +parse_args (int argc, char *argv[]) +{ + ACE_Get_Opt get_opts (argc, argv, ""); + int c; + + while ((c = get_opts ()) != -1) + switch (c) + { + case '?': + default: + ACE_ERROR_RETURN ((LM_ERROR, + "usage: %s " + "\n", + argv [0]), + -1); + } + // Indicates sucessful parsing of the command line + return 0; +} + +int +main (int argc, char *argv[]) +{ + ACE_DECLARE_NEW_CORBA_ENV; + + ACE_TRY + { + CORBA::ORB_var orb = + CORBA::ORB_init (argc, argv, "" ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + CORBA::Object_var poa_object = + orb->resolve_initial_references("RootPOA" ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + PortableServer::POA_var root_poa = + PortableServer::POA::_narrow (poa_object.in () ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + if (CORBA::is_nil (root_poa.in ())) + ACE_ERROR_RETURN ((LM_ERROR, + " (%P|%t) Panic: nil RootPOA\n"), + 1); + + PortableServer::POAManager_var poa_manager = + root_poa->the_POAManager (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_TRY_CHECK; + + if (parse_args (argc, argv) != 0) + return 1; + + test_i *test_impl; + ACE_NEW_RETURN (test_impl, + test_i (), + 1); + PortableServer::ServantBase_var owner_transfer(test_impl); + + test_var test = + test_impl->_this (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_TRY_CHECK; + + CORBA::String_var ior = + orb->object_to_string (test.in () ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + // If the ior_output_file exists, output the ior to it + FILE *output_file= ACE_OS::fopen (ior_output_file, "w"); + if (output_file == 0) + ACE_ERROR_RETURN ((LM_ERROR, + "Cannot open output file for writing IOR: %s", + ior_output_file), + 1); + ACE_OS::fprintf (output_file, "%s", ior.in ()); + ACE_OS::fclose (output_file); + + poa_manager->activate (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_TRY_CHECK; + + ACE_Time_Value tv (120, 0); + + orb->run (&tv ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + ACE_DEBUG ((LM_DEBUG, "(%P|%t) server - event loop finished\n")); + + root_poa->destroy (1, 1 ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + orb->destroy (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_TRY_CHECK; + } + ACE_CATCHANY + { + ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, + "Exception caught:"); + return 1; + } + ACE_ENDTRY; + + return 0; +} diff --git a/TAO/tests/Server_Connection_Purging/svc.conf b/TAO/tests/Server_Connection_Purging/svc.conf new file mode 100644 index 00000000000..e20a98842a7 --- /dev/null +++ b/TAO/tests/Server_Connection_Purging/svc.conf @@ -0,0 +1,3 @@ +# $Id$ +# +static Resource_Factory "-ORBConnectionPurgingStrategy lru -ORBConnectionCacheMax 20 -ORBConnectionCachePurgePercentage 30" |