diff options
Diffstat (limited to 'TAO/orbsvcs/tests/LoadBalancing/LoadMonitor')
6 files changed, 332 insertions, 0 deletions
diff --git a/TAO/orbsvcs/tests/LoadBalancing/LoadMonitor/CPU/LoadMonitorCPU.mpc b/TAO/orbsvcs/tests/LoadBalancing/LoadMonitor/CPU/LoadMonitorCPU.mpc new file mode 100644 index 00000000000..55c91a8d3df --- /dev/null +++ b/TAO/orbsvcs/tests/LoadBalancing/LoadMonitor/CPU/LoadMonitorCPU.mpc @@ -0,0 +1,4 @@ +// $Id$ + +project(*Client): loadbalancing { +} diff --git a/TAO/orbsvcs/tests/LoadBalancing/LoadMonitor/CPU/Makefile.am b/TAO/orbsvcs/tests/LoadBalancing/LoadMonitor/CPU/Makefile.am new file mode 100644 index 00000000000..f9c6fe2837e --- /dev/null +++ b/TAO/orbsvcs/tests/LoadBalancing/LoadMonitor/CPU/Makefile.am @@ -0,0 +1,63 @@ +## Process this file with automake to create Makefile.in +## +## $Id$ +## +## This file was generated by MPC. Any changes made directly to +## this file will be lost the next time it is generated. +## +## MPC Command: +## ../bin/mwc.pl -type automake -noreldefs TAO.mwc + +ACE_BUILDDIR = $(top_builddir)/.. +ACE_ROOT = $(top_srcdir)/.. +TAO_BUILDDIR = $(top_builddir) +TAO_ROOT = $(top_srcdir) + + +## Makefile.LoadMonitorCPU_Client.am + +if BUILD_AMI +if BUILD_CORBA_MESSAGING +if !BUILD_MINIMUM_CORBA + +noinst_PROGRAMS = client + +client_CPPFLAGS = \ + -I$(ACE_ROOT) \ + -I$(ACE_BUILDDIR) \ + -I$(TAO_ROOT) \ + -I$(TAO_BUILDDIR) \ + -I$(TAO_ROOT)/orbsvcs \ + -I$(TAO_BUILDDIR)/orbsvcs + +client_SOURCES = \ + client.cpp + +client_LDADD = \ + $(TAO_BUILDDIR)/orbsvcs/orbsvcs/libTAO_CosLoadBalancing.la \ + $(TAO_BUILDDIR)/tao/libTAO_IORInterceptor.la \ + $(TAO_BUILDDIR)/tao/libTAO_ObjRefTemplate.la \ + $(TAO_BUILDDIR)/tao/libTAO_PI_Server.la \ + $(TAO_BUILDDIR)/orbsvcs/orbsvcs/libTAO_PortableGroup.la \ + $(TAO_BUILDDIR)/tao/libTAO_IORManip.la \ + $(TAO_BUILDDIR)/orbsvcs/orbsvcs/libTAO_CosNaming.la \ + $(TAO_BUILDDIR)/tao/libTAO_Messaging.la \ + $(TAO_BUILDDIR)/tao/libTAO_PI.la \ + $(TAO_BUILDDIR)/tao/libTAO_CodecFactory.la \ + $(TAO_BUILDDIR)/tao/libTAO_PortableServer.la \ + $(TAO_BUILDDIR)/tao/libTAO_Valuetype.la \ + $(TAO_BUILDDIR)/tao/libTAO_AnyTypeCode.la \ + $(TAO_BUILDDIR)/tao/libTAO.la \ + $(ACE_BUILDDIR)/ace/libACE.la + +endif !BUILD_MINIMUM_CORBA +endif BUILD_CORBA_MESSAGING +endif BUILD_AMI + +## Clean up template repositories, etc. +clean-local: + -rm -f *~ *.bak *.rpo *.sym lib*.*_pure_* core core.* + -rm -f gcctemp.c gcctemp so_locations *.ics + -rm -rf cxx_repository ptrepository ti_files + -rm -rf templateregistry ir.out + -rm -rf ptrepository SunWS_cache Templates.DB diff --git a/TAO/orbsvcs/tests/LoadBalancing/LoadMonitor/CPU/README b/TAO/orbsvcs/tests/LoadBalancing/LoadMonitor/CPU/README new file mode 100644 index 00000000000..ee845ff6081 --- /dev/null +++ b/TAO/orbsvcs/tests/LoadBalancing/LoadMonitor/CPU/README @@ -0,0 +1,11 @@ +# $Id$ + +This test verifies that Cygnus' CPU load monitor is working correctly. +Run the test using the `run_test.pl' Perl script. The expected test +output is the following: + +==== Running CPU Load Monitor test + +Retrieving loads from LoadManager ...... DONE +Retrieving loads directly from LoadMonitor ... DONE +CPU Load Monitor test passed. diff --git a/TAO/orbsvcs/tests/LoadBalancing/LoadMonitor/CPU/client.cpp b/TAO/orbsvcs/tests/LoadBalancing/LoadMonitor/CPU/client.cpp new file mode 100644 index 00000000000..ccae399abb8 --- /dev/null +++ b/TAO/orbsvcs/tests/LoadBalancing/LoadMonitor/CPU/client.cpp @@ -0,0 +1,180 @@ +// $Id$ + +#include "orbsvcs/CosLoadBalancingC.h" +#include "orbsvcs/PortableGroup/PG_Operators.h" +#include "ace/Get_Opt.h" +#include "ace/OS_NS_unistd.h" + +ACE_RCSID (CPU, + client, + "$Id$") + + +const char * location = "MyLocation"; + +const int MAX_RETRIES = 10; +const CosLoadBalancing::LoadId LOAD_ID = CosLoadBalancing::LoadAverage; + +int +parse_args (int argc, char *argv[]) +{ + ACE_Get_Opt get_opts (argc, argv, "l:"); + + int c; + + while ((c = get_opts ()) != -1) + switch (c) + { + case 'l': + location = get_opts.opt_arg (); + break; + + default: + ACE_ERROR_RETURN ((LM_ERROR, + "Usage: %s -l <ior>\n", + argv[0]), + -1); + } + + return 0; +} + +void +check_loads (const CosLoadBalancing::LoadList & loads + ACE_ENV_ARG_DECL) +{ + if (loads.length () != 1) + { + ACE_ERROR ((LM_ERROR, + "ERROR: Load list length is not equal to one.\n")); + + ACE_THROW (CORBA::INTERNAL ()); + } + + if (loads[0].id != LOAD_ID + || loads[0].value < 0) + { + ACE_ERROR ((LM_ERROR, + "ERROR: Returned load is not a CPU load.\n")); + + ACE_THROW (CORBA::INTERNAL ()); + } +} + +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; + + // Obtain a reference to the LoadManager. + CORBA::Object_var obj = + orb->resolve_initial_references ("LoadManager" + ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + CosLoadBalancing::LoadManager_var lm = + CosLoadBalancing::LoadManager::_narrow (obj.in () + ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + CosLoadBalancing::Location the_location (1); + the_location.length (1); + + the_location[0].id = CORBA::string_dup (location); + + // Attempt to get loads from the LoadManager. + ACE_DEBUG ((LM_INFO, + "\n" + "Retrieving loads from LoadManager ...")); + + CosLoadBalancing::LoadList_var loads; + + CORBA::Boolean retrieved_load = 0; + + // Try a few times until a load is capable of being retrieved. + for (int i = 0; i < MAX_RETRIES && retrieved_load == 0; ++i) + { + ACE_TRY_EX (foo) + { + loads = lm->get_loads (the_location + ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK_EX (foo); + + retrieved_load = 1; + } + ACE_CATCHANY + { + ACE_DEBUG ((LM_DEBUG, ".")); // Show some progress. + + // Give some time for loads to be reported to the + // LoadManager. + ACE_OS::sleep (2); + } + ACE_ENDTRY; + ACE_TRY_CHECK; + } + + if (retrieved_load == 0) + ACE_ERROR_RETURN ((LM_ERROR, + "\nERROR: Unable to retrieve loads " + "from LoadManager.\n"), + -1); + else + ACE_DEBUG ((LM_INFO, + " DONE\n")); + + ::check_loads (loads.in () + ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + // Attempt to get loads directly from the LoadMonitor. + CosLoadBalancing::LoadMonitor_var monitor = + lm->get_load_monitor (the_location + ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + CosLoadBalancing::Location_var cpu_mon_location = + monitor->the_location (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_TRY_CHECK; + + if (cpu_mon_location.in () != the_location) + { + ACE_ERROR ((LM_ERROR, + "ERROR: Mismatched CPU load monitor location\n")); + + ACE_TRY_THROW (CORBA::INTERNAL ()); + } + + ACE_DEBUG ((LM_INFO, + "Retrieving loads directly from LoadMonitor ...")); + + loads = monitor->loads (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_TRY_CHECK; + + ACE_DEBUG ((LM_INFO, + " DONE\n")); + + ::check_loads (loads.in () + ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + } + ACE_CATCHANY + { + ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, + "CPU Load Monitor test:"); + return -1; + } + ACE_ENDTRY; + + ACE_DEBUG ((LM_INFO, "CPU Load Monitor test passed.\n\n")); + + return 0; +} diff --git a/TAO/orbsvcs/tests/LoadBalancing/LoadMonitor/CPU/run_test.pl b/TAO/orbsvcs/tests/LoadBalancing/LoadMonitor/CPU/run_test.pl new file mode 100755 index 00000000000..7b7ed466ffc --- /dev/null +++ b/TAO/orbsvcs/tests/LoadBalancing/LoadMonitor/CPU/run_test.pl @@ -0,0 +1,61 @@ +eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}' + & eval 'exec perl -S $0 $argv:q' + if 0; + +# -*- perl -*- +# $Id$ + +use lib "../../../../../../bin"; +use PerlACE::Run_Test; + +print STDERR "\n\n==== Running CPU Load Monitor test\n"; + + +$lm_ior = "lm.ior"; +unlink $lm_ior; + +$status = 0; + +$init_ref = "-ORBInitRef LoadManager=file://" . $lm_ior; + +$location = "MyLocation"; + +$LM = new PerlACE::Process ("../../../../LoadBalancer/LoadManager", + "-o " . $lm_ior); + +$MON = new PerlACE::Process ("../../../../LoadBalancer/LoadMonitor", + "-l " . $location + . " -t CPU -s PULL " + . $init_ref); + +$CL = new PerlACE::Process ("client", + $init_ref + . " -l " . $location); + +$LM->Spawn (); + +if (PerlACE::waitforfile_timed ($lm_ior, 8) == -1) { + print STDERR "ERROR: cannot find file LoadManager IOR: " . $lm_ior ."\n"; + exit 1; +} + +$MON->Spawn (); + +$client = $CL->SpawnWaitKill (100); + +if ($client != 0) { + print STDERR "ERROR: client returned $client\n"; + $status = 1; +} + +$load_monitor = $MON->TerminateWaitKill (10); +$load_manager = $LM->TerminateWaitKill (10); + +if ($load_manager != 0 || $load_monitor != 0) { + print STDERR "Error terminating LoadManager or LoadMonitor.\n"; + $status = 1; +} + +unlink $lm_ior; + +exit $status; diff --git a/TAO/orbsvcs/tests/LoadBalancing/LoadMonitor/Makefile.am b/TAO/orbsvcs/tests/LoadBalancing/LoadMonitor/Makefile.am new file mode 100644 index 00000000000..cc16d67d6f5 --- /dev/null +++ b/TAO/orbsvcs/tests/LoadBalancing/LoadMonitor/Makefile.am @@ -0,0 +1,13 @@ +## Process this file with automake to create Makefile.in +## +## $Id$ +## +## This file was generated by MPC. Any changes made directly to +## this file will be lost the next time it is generated. +## +## MPC Command: +## ../bin/mwc.pl -type automake -noreldefs TAO.mwc + +SUBDIRS = \ + CPU + |