diff options
Diffstat (limited to 'TAO/orbsvcs/tests/ImplRepo')
37 files changed, 4116 insertions, 0 deletions
diff --git a/TAO/orbsvcs/tests/ImplRepo/Airplane.idl b/TAO/orbsvcs/tests/ImplRepo/Airplane.idl new file mode 100644 index 00000000000..ecc38afa7c5 --- /dev/null +++ b/TAO/orbsvcs/tests/ImplRepo/Airplane.idl @@ -0,0 +1,7 @@ +// $Id$ + +interface Paper_Airplane_Server +{ + string get_plane (); + // Returns the plane of the moment. +}; diff --git a/TAO/orbsvcs/tests/ImplRepo/ImplRepo.mpc b/TAO/orbsvcs/tests/ImplRepo/ImplRepo.mpc new file mode 100644 index 00000000000..848b239d9ee --- /dev/null +++ b/TAO/orbsvcs/tests/ImplRepo/ImplRepo.mpc @@ -0,0 +1,90 @@ +// -*- MPC -*- +// $Id$ + +project(airplane_idl) : taoidldefaults { + IDL_Files { + Airplane.idl + } + custom_only = 1 +} + + +project(airplane server) : portableserver, orbsvcsexe, minimum_corba, iortable, imr_client { + after += airplane_idl + + IDL_Files { + } + + Source_Files { + AirplaneC.cpp + AirplaneS.cpp + airplane_i.cpp + airplane_server_i.cpp + airplane_server.cpp + } +} + +project(airplane client) : portableserver, orbsvcsexe, minimum_corba, iortable { + after += airplane_idl + + IDL_Files { + } + + Source_Files { + AirplaneC.cpp + AirplaneS.cpp + airplane_client_i.cpp + airplane_client.cpp + } +} + +project(nestea_idl): taoidldefaults { + IDL_Files { + Nestea.idl + } + + custom_only = 1 +} + +project(nestea server) : portableserver, orbsvcsexe, minimum_corba, iortable, imr_client { + avoids += ace_for_tao + after += nestea_idl + + IDL_Files { + } + + Source_Files { + NesteaC.cpp + NesteaS.cpp + nestea_i.cpp + nestea_server_i.cpp + nestea_server.cpp + } + // To avoid link errors with SunCC 5.[34], put this project's + // object files (and resulting SunWS_cache directory) in a different + // location than the default. + verbatim(gnuace, macros) { + VDIR := .obj/nestea_server/ + } +} + +project(nestea client) : portableserver, orbsvcsexe, minimum_corba, iortable { + after += nestea_idl + + IDL_Files { + } + + Source_Files { + NesteaC.cpp + NesteaS.cpp + nestea_client_i.cpp + nestea_client.cpp + } + // To avoid link errors with SunCC 5.[34], put this project's + // object files (and resulting SunWS_cache directory) in a different + // location than the default. + verbatim(gnuace, macros) { + VDIR := .obj/nestea_client/ + } +} + diff --git a/TAO/orbsvcs/tests/ImplRepo/Makefile.am b/TAO/orbsvcs/tests/ImplRepo/Makefile.am new file mode 100644 index 00000000000..15e3b659ff7 --- /dev/null +++ b/TAO/orbsvcs/tests/ImplRepo/Makefile.am @@ -0,0 +1,210 @@ +## 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_IDL = ACE_ROOT=$(ACE_ROOT) TAO_ROOT=$(TAO_ROOT) $(TAO_BUILDDIR)/TAO_IDL/tao_idl +TAO_IDL_DEP = $(TAO_BUILDDIR)/TAO_IDL/tao_idl +TAO_IDLFLAGS = -Ge 1 -Wb,pre_include=ace/pre.h -Wb,post_include=ace/post.h -I$(TAO_ROOT) -I$(srcdir) -g $(ACE_BUILDDIR)/apps/gperf/src/gperf +TAO_ROOT = $(top_srcdir) + +SUBDIRS = \ + . \ + NameService \ + scale + +noinst_PROGRAMS = + +## Makefile.airplane_idl.am + +BUILT_SOURCES = \ + AirplaneC.cpp \ + AirplaneC.h \ + AirplaneC.inl \ + AirplaneS.cpp \ + AirplaneS.h \ + AirplaneS.inl + +CLEANFILES = \ + Airplane-stamp \ + AirplaneC.cpp \ + AirplaneC.h \ + AirplaneC.inl \ + AirplaneS.cpp \ + AirplaneS.h \ + AirplaneS.inl + +AirplaneC.cpp AirplaneC.h AirplaneC.inl AirplaneS.cpp AirplaneS.h AirplaneS.inl: Airplane-stamp + +Airplane-stamp: $(srcdir)/Airplane.idl $(TAO_IDL_DEP) + $(TAO_IDL) $(TAO_IDLFLAGS) -Sa -St $(srcdir)/Airplane.idl + @touch $@ + + +noinst_HEADERS = \ + Airplane.idl + +## Makefile.airplane_client.am + +if !BUILD_MINIMUM_CORBA + +noinst_PROGRAMS += airplane_client + +airplane_client_CPPFLAGS = \ + -I$(ACE_ROOT) \ + -I$(ACE_BUILDDIR) \ + -I$(TAO_ROOT) \ + -I$(TAO_BUILDDIR) + +airplane_client_SOURCES = \ + AirplaneC.cpp \ + AirplaneS.cpp \ + airplane_client.cpp \ + airplane_client_i.cpp \ + airplane_client_i.h + +airplane_client_LDADD = \ + $(TAO_BUILDDIR)/tao/libTAO_IORTable.la \ + $(TAO_BUILDDIR)/tao/libTAO_PortableServer.la \ + $(TAO_BUILDDIR)/tao/libTAO_AnyTypeCode.la \ + $(TAO_BUILDDIR)/tao/libTAO.la \ + $(ACE_BUILDDIR)/ace/libACE.la + +endif !BUILD_MINIMUM_CORBA + +## Makefile.airplane_server.am + +if !BUILD_MINIMUM_CORBA + +noinst_PROGRAMS += airplane_server + +airplane_server_CPPFLAGS = \ + -I$(ACE_ROOT) \ + -I$(ACE_BUILDDIR) \ + -I$(TAO_ROOT) \ + -I$(TAO_BUILDDIR) + +airplane_server_SOURCES = \ + AirplaneC.cpp \ + AirplaneS.cpp \ + airplane_i.cpp \ + airplane_server.cpp \ + airplane_server_i.cpp \ + airplane_i.h \ + airplane_server_i.h + +airplane_server_LDADD = \ + $(TAO_BUILDDIR)/tao/libTAO_ImR_Client.la \ + $(TAO_BUILDDIR)/tao/libTAO_IORTable.la \ + $(TAO_BUILDDIR)/tao/libTAO_PortableServer.la \ + $(TAO_BUILDDIR)/tao/libTAO_AnyTypeCode.la \ + $(TAO_BUILDDIR)/tao/libTAO.la \ + $(ACE_BUILDDIR)/ace/libACE.la + +endif !BUILD_MINIMUM_CORBA + +## Makefile.nestea_idl.am + +BUILT_SOURCES += \ + NesteaC.cpp \ + NesteaC.h \ + NesteaC.inl \ + NesteaS.cpp \ + NesteaS.h \ + NesteaS.inl + +CLEANFILES += \ + Nestea-stamp \ + NesteaC.cpp \ + NesteaC.h \ + NesteaC.inl \ + NesteaS.cpp \ + NesteaS.h \ + NesteaS.inl + +NesteaC.cpp NesteaC.h NesteaC.inl NesteaS.cpp NesteaS.h NesteaS.inl: Nestea-stamp + +Nestea-stamp: $(srcdir)/Nestea.idl $(TAO_IDL_DEP) + $(TAO_IDL) $(TAO_IDLFLAGS) -Sa -St $(srcdir)/Nestea.idl + @touch $@ + + +noinst_HEADERS += \ + Nestea.idl + +## Makefile.nestea_client.am + +if !BUILD_MINIMUM_CORBA + +noinst_PROGRAMS += nestea_client + +nestea_client_CPPFLAGS = \ + -I$(ACE_ROOT) \ + -I$(ACE_BUILDDIR) \ + -I$(TAO_ROOT) \ + -I$(TAO_BUILDDIR) + +nestea_client_SOURCES = \ + NesteaC.cpp \ + NesteaS.cpp \ + nestea_client.cpp \ + nestea_client_i.cpp \ + nestea_client_i.h + +nestea_client_LDADD = \ + $(TAO_BUILDDIR)/tao/libTAO_IORTable.la \ + $(TAO_BUILDDIR)/tao/libTAO_PortableServer.la \ + $(TAO_BUILDDIR)/tao/libTAO_AnyTypeCode.la \ + $(TAO_BUILDDIR)/tao/libTAO.la \ + $(ACE_BUILDDIR)/ace/libACE.la + +endif !BUILD_MINIMUM_CORBA + +## Makefile.nestea_server.am + +if !BUILD_ACE_FOR_TAO +if !BUILD_MINIMUM_CORBA + +noinst_PROGRAMS += nestea_server + +nestea_server_CPPFLAGS = \ + -I$(ACE_ROOT) \ + -I$(ACE_BUILDDIR) \ + -I$(TAO_ROOT) \ + -I$(TAO_BUILDDIR) + +nestea_server_SOURCES = \ + NesteaC.cpp \ + NesteaS.cpp \ + nestea_i.cpp \ + nestea_server.cpp \ + nestea_server_i.cpp \ + nestea_i.h \ + nestea_server_i.h + +nestea_server_LDADD = \ + $(TAO_BUILDDIR)/tao/libTAO_ImR_Client.la \ + $(TAO_BUILDDIR)/tao/libTAO_IORTable.la \ + $(TAO_BUILDDIR)/tao/libTAO_PortableServer.la \ + $(TAO_BUILDDIR)/tao/libTAO_AnyTypeCode.la \ + $(TAO_BUILDDIR)/tao/libTAO.la \ + $(ACE_BUILDDIR)/ace/libACE.la + +endif !BUILD_MINIMUM_CORBA +endif !BUILD_ACE_FOR_TAO + +## 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/ImplRepo/NameService/ImplRepo_NameService.mpc b/TAO/orbsvcs/tests/ImplRepo/NameService/ImplRepo_NameService.mpc new file mode 100644 index 00000000000..fe939b060c5 --- /dev/null +++ b/TAO/orbsvcs/tests/ImplRepo/NameService/ImplRepo_NameService.mpc @@ -0,0 +1,6 @@ +// -*- MPC -*- +// $Id$ + +project: namingexe, minimum_corba { +} + diff --git a/TAO/orbsvcs/tests/ImplRepo/NameService/Makefile.am b/TAO/orbsvcs/tests/ImplRepo/NameService/Makefile.am new file mode 100644 index 00000000000..038d3a8f254 --- /dev/null +++ b/TAO/orbsvcs/tests/ImplRepo/NameService/Makefile.am @@ -0,0 +1,48 @@ +## 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.ImplRepo_NameService.am + +if !BUILD_MINIMUM_CORBA + +noinst_PROGRAMS = test + +test_CPPFLAGS = \ + -I$(ACE_ROOT) \ + -I$(ACE_BUILDDIR) \ + -I$(TAO_ROOT) \ + -I$(TAO_BUILDDIR) \ + -I$(TAO_ROOT)/orbsvcs \ + -I$(TAO_BUILDDIR)/orbsvcs + +test_SOURCES = \ + test.cpp + +test_LDADD = \ + $(TAO_BUILDDIR)/orbsvcs/orbsvcs/libTAO_CosNaming.la \ + $(TAO_BUILDDIR)/tao/libTAO_AnyTypeCode.la \ + $(TAO_BUILDDIR)/tao/libTAO.la \ + $(ACE_BUILDDIR)/ace/libACE.la + +endif !BUILD_MINIMUM_CORBA + +## 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/ImplRepo/NameService/README b/TAO/orbsvcs/tests/ImplRepo/NameService/README new file mode 100644 index 00000000000..b89a2d8e93d --- /dev/null +++ b/TAO/orbsvcs/tests/ImplRepo/NameService/README @@ -0,0 +1,3 @@ +================================================================================ +Soon there will be a test to show off how the Implementation Repository can +automatically activate the NameService and other common services. diff --git a/TAO/orbsvcs/tests/ImplRepo/NameService/run_test.pl b/TAO/orbsvcs/tests/ImplRepo/NameService/run_test.pl new file mode 100755 index 00000000000..e8e91200bb0 --- /dev/null +++ b/TAO/orbsvcs/tests/ImplRepo/NameService/run_test.pl @@ -0,0 +1,139 @@ +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; + +################################################################################ +# Program locations + +$imr_ior = PerlACE::LocalFile ("imr.ior"); +$name_ior = PerlACE::LocalFile ("name.ior"); +$activator_ior = PerlACE::LocalFile("activator.ior"); + +$IMR = new PerlACE::Process ("../../../ImplRepo_Service/ImplRepo_Service"); +$ACTIVATOR = new PerlACE::Process("../../../ImplRepo_Service/ImR_Activator"); +$NS = new PerlACE::Process ("../../../Naming_Service/Naming_Service"); +$TAO_IMR = new PerlACE::Process ("../../../../../bin/tao_imr"); + +# We want the tao_imr executable to be found exactly in the path +# given, without being modified by the value of -ExeSubDir. +# So, we tell its Process object to ignore the setting of -ExeSubDir. + +$TAO_IMR->IgnoreExeSubDir (1); + +$TEST = new PerlACE::Process ("test"); + +$imr_init_ref = "-ORBInitRef ImplRepoService=file://$imr_ior"; + +################################################################################ + +$errors = 0; + +unlink $imr_ior; +unlink $name_ior; +unlink $activator_ior; + +################################################################################ +## Start the implementation Repository + +$IMR->Arguments ("-o $imr_ior -d 2"); +$IMR->Spawn (); + +if (PerlACE::waitforfile_timed ($imr_ior, 10) == -1) { + print STDERR "ERROR: waiting for $imr_ior\n"; + $IMR->Kill (); + exit 1; +} + +$ACTIVATOR->Arguments("-d 1 -o $activator_ior $imr_init_ref"); +$ACTIVATOR->Spawn(); + +if (PerlACE::waitforfile_timed ($activator_ior, 10) == -1) { + print STDERR "ERROR: waiting for $activator_ior\n"; + $IMR->Kill (); + $ACTIVATOR->Kill(); + exit 1; +} + +################################################################################ +## Register the NameService + +$TAO_IMR->Arguments("$imr_init_ref" + . " add NameService " + ." -c \"" . $NS->Executable () + ." $imr_init_ref" + ." -ORBUseIMR 1 .\""); + +$taoimr = $TAO_IMR->SpawnWaitKill (60); + +if ($taoimr != 0) { + print STDERR "ERROR: tao_imr (add) returned $taoimr\n"; + ++$errors; +} + +################################################################################ +## Create IOR for NameService + +$TAO_IMR->Arguments ("$imr_init_ref ior NameService -f $name_ior"); + + +$taoimr = $TAO_IMR->SpawnWaitKill (60); + +if ($taoimr != 0) { + print STDERR "ERROR: tao_imr (ior) returned $taoimr\n"; + ++$errors; +} + +################################################################################ +## Run the test + +$TEST->Arguments ("-ORBInitRef NameService=file://$name_ior"); + +$test = $TEST->SpawnWaitKill (60); + +if ($test != 0) { + print STDERR "ERROR: test returned $test\n"; + ++$errors; +} + + +################################################################################ +## Shutdown the NameService + +$TAO_IMR->Arguments ("-ORBInitRef ImplRepoService=file://$imr_ior shutdown " + . "NameService "); + +$taoimr = $TAO_IMR->SpawnWaitKill (60); + +if ($taoimr != 0) { + print STDERR "ERROR: tao_imr (shutdown) returned $taoimr\n"; + ++$errors; +} + +################################################################################ +## Kill the IMR + +$iserver = $ACTIVATOR->TerminateWaitKill (5); + +if ($iserver != 0) { + print STDERR "ERROR: ImR_Activator returned $iserver\n"; + ++$errors; +} + +$iserver = $IMR->TerminateWaitKill (5); + +if ($iserver != 0) { + print STDERR "ERROR: IMR returned $iserver\n"; + ++$errors; +} + +unlink $imr_ior; +unlink $name_ior; +unlink $activator_ior; + +exit $errors; diff --git a/TAO/orbsvcs/tests/ImplRepo/NameService/test.cpp b/TAO/orbsvcs/tests/ImplRepo/NameService/test.cpp new file mode 100644 index 00000000000..b885f1b28ed --- /dev/null +++ b/TAO/orbsvcs/tests/ImplRepo/NameService/test.cpp @@ -0,0 +1,52 @@ +// +// $Id$ +// + +#include "orbsvcs/CosNamingC.h" + +#include "ace/Log_Msg.h" + +int main (int argc, char *argv[]) +{ + ACE_TRY_NEW_ENV + { + CORBA::ORB_var orb = CORBA::ORB_init (argc, argv, "" ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + CORBA::Object_var ns_obj = + orb->resolve_initial_references ("NameService" ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + if (CORBA::is_nil (ns_obj.in ())) + ACE_ERROR_RETURN ((LM_ERROR, + "Could not resolve Naming Service"), + 1); + + CosNaming::NamingContext_var inc = + CosNaming::NamingContext::_narrow (ns_obj.in () + ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + if (CORBA::is_nil (inc.in ())) + ACE_ERROR_RETURN ((LM_ERROR, + "Could not resolve Naming Service"), + 1); + + CosNaming::Name name; + name.length (1); + name[0].id = CORBA::string_dup ("yourself"); + + inc->bind (name, ns_obj.in () ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + ACE_DEBUG ((LM_DEBUG, "Test Successful\n")); + } + ACE_CATCHANY + { + ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, "Test"); + return 1; + } + ACE_ENDTRY; + + return 0; +} diff --git a/TAO/orbsvcs/tests/ImplRepo/Nestea.idl b/TAO/orbsvcs/tests/ImplRepo/Nestea.idl new file mode 100644 index 00000000000..b101254bfe4 --- /dev/null +++ b/TAO/orbsvcs/tests/ImplRepo/Nestea.idl @@ -0,0 +1,19 @@ +// $Id$ + +// Just implements a nice little Nestea server +interface Nestea_Bookshelf +{ + void drink (in long cans); + // Add a number of cans to the bookshelf. + + void crush (in long cans); + // Crush some of those cans. + + long bookshelf_size (); + // How many cans are in the collection? + + string get_praise (); + // What does the server think of your collection? + + oneway void shutdown(); +}; diff --git a/TAO/orbsvcs/tests/ImplRepo/README b/TAO/orbsvcs/tests/ImplRepo/README new file mode 100644 index 00000000000..82647bcdb19 --- /dev/null +++ b/TAO/orbsvcs/tests/ImplRepo/README @@ -0,0 +1,75 @@ +$Id$ + +Here are a few tests for the ImplRepo. The best way to test is to +use the run_test.pl passing it one of the following arguments: + +airplane runs airplane client and server without ImplRepo. +airplane_ir same as above but uses ImplRepo. +nt_service_ir same as above but runs ImplRepo as an NT service. +nestea runs nestea client and server without ImplRepo. +nestea_ir same as above but uses ImplRepo. +both_ir combines airplane_ir and nestea_ir. +persistent_ir same as airplane_ir, but using persistent ImplRepo. + +The nt_service_ir test will work only on Win32 platforms. For the test to +run successfully, these conditions must be met: + +-- The user must be logged in as administrator, or have administrative + priveleges (in order to register an NT service). + +-- ACE_ROOT must be set to the ACE_wrappers directory in the system + environment. + +-- ACE_ROOT/bin must be in the system path. + +How to use NT ImR Services +================================== + +The first step is to install one or both ImplRepo applications as NT +services. To do this run: + +ImplRepo_Service -c install +ImR_Activator -c install + +If you want to reinstall or change the installed settings then you +must first use: + +ImplRepo_Service -c remove +ImR_Activator -c remove + +Any extra command line options, will be saved in the Windows registry, +and used when the service is actually started. + +In the following example I start the activator service, and then the +ImplRepo itself on port 8888 using iiop. I also tell the activator to use +xml as its persistence format, and to timeout unresponsive servers in 60 seconds. +I disable debug output for both, as there seems to be no way to access it anyway. + +* copy the exe's to the same location as their dll's +cd %ace_root%\lib +copy %tao_root%\orbsvcs\ImplRepo_Service\*.exe .\ + +* Register the services. (You may have to remove them first) +ImR_Activator -c install -x activator.xml -t 60 -d 0 -orbinitref ImplRepoService=corbaloc::localhost:8888/ImplRepoService +ImplRepo_Service -c install -d 0 -orbendpoint iiop://:8888 + +* Start both services. +net start taoimrlocator +net start taoimractivator + +* Register a server +cd %tao_root%\orbsvcs\tests\ImplRepo +%tao_root%\orbsvcs\ImplRepo_service\tao_imr add airplane_server -orbuseimr 1 -orbinitref ImplRepoService=corbaloc::localhost:8888/ImplRepoService + +* Run the server +airplane_server -o airplane.ior -orbuseimr 1 -orbinitref ImplRepoService=corbaloc::localhost:8888/ImplRepoService + +* Run the client +airplane_client -k file://airplane.ior +--or-- +airplane_client -k corbaloc::localhost:8888/airplane_server + + +More information about the Implementation Repository can be found in +TAO/docs. + diff --git a/TAO/orbsvcs/tests/ImplRepo/airplane_client.cpp b/TAO/orbsvcs/tests/ImplRepo/airplane_client.cpp new file mode 100644 index 00000000000..1bee519f70d --- /dev/null +++ b/TAO/orbsvcs/tests/ImplRepo/airplane_client.cpp @@ -0,0 +1,24 @@ +// $Id$ + +#include "airplane_client_i.h" + +#include "ace/Log_Msg.h" + +ACE_RCSID (ImplRepo, + airplane_client, + "$Id$") + +// This function runs the test. + +int +main (int argc, char **argv) +{ + Airplane_Client_i client; + + ACE_DEBUG ((LM_DEBUG, "\n\tPaper Airplane Client\n\n")); + + if (client.init (argc, argv) == -1) + return 1; + else + return client.run (); +} diff --git a/TAO/orbsvcs/tests/ImplRepo/airplane_client_i.cpp b/TAO/orbsvcs/tests/ImplRepo/airplane_client_i.cpp new file mode 100644 index 00000000000..079c8e9b4e1 --- /dev/null +++ b/TAO/orbsvcs/tests/ImplRepo/airplane_client_i.cpp @@ -0,0 +1,146 @@ +// $Id$ + +#include "airplane_client_i.h" +#include "tao/debug.h" +#include "ace/Get_Opt.h" +#include "ace/Read_Buffer.h" +#include "ace/ACE.h" + +ACE_RCSID(ImplRepo, airplane_client_i, "$Id$") + +// Constructor. +Airplane_Client_i::Airplane_Client_i (void) + : server_key_ (ACE::strnew ("key0")), + loop_count_ (10), + server_ (Paper_Airplane_Server::_nil ()) +{ +} + + +// Parses the command line arguments and returns an error status. + +int +Airplane_Client_i::parse_args (void) +{ + ACE_Get_Opt get_opts (argc_, argv_, "dn:k:"); + int c; + + while ((c = get_opts ()) != -1) + switch (c) + { + case 'd': // debug flag + TAO_debug_level++; + break; + case 'n': // loop count + this->loop_count_ = (u_int) ACE_OS::atoi (get_opts.opt_arg ()); + break; + case 'k': // ior provide on command line + this->server_key_ = ACE::strnew (get_opts.opt_arg ()); + break; + case '?': + default: + ACE_ERROR_RETURN ((LM_ERROR, + "usage: %s" + " [-d]" + " [-n loopcount]" + " [-k server-obj-key]" + "\n", + this->argv_ [0]), + -1); + } + + // Indicates successful parsing of command line. + return 0; +} + +// Retreives <count> paper airplanes from the server. + +void +Airplane_Client_i::get_planes (size_t count) +{ + for (size_t i = 0; i < count; i++) + { + ACE_DECLARE_NEW_CORBA_ENV; + ACE_TRY + { + CORBA::String_var response = + this->server_->get_plane (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_TRY_CHECK; + + ACE_DEBUG ((LM_DEBUG, "Plane %d is %s\n", i, response.in ())); + } + ACE_CATCHANY + { + ACE_ERROR ((LM_ERROR, "Plane %d exception:\n", i)); + ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, "get_planes"); + } + ACE_ENDTRY; + } +} + + +// Execute client example code. + +int +Airplane_Client_i::run () +{ + this->get_planes (this->loop_count_); + + return 0; +} + +Airplane_Client_i::~Airplane_Client_i (void) +{ + // Free resources + CORBA::release (this->server_); + + delete [] this->server_key_; +} + + +int +Airplane_Client_i::init (int argc, char **argv) +{ + this->argc_ = argc; + this->argv_ = argv; + + ACE_DECLARE_NEW_CORBA_ENV; + ACE_TRY + { + // Retrieve the ORB. + this->orb_ = CORBA::ORB_init (this->argc_, + this->argv_, + "internet" + ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + // Parse command line and verify parameters. + if (this->parse_args () == -1) + return -1; + + if (this->server_key_ == 0) + ACE_ERROR_RETURN ((LM_ERROR, + "%s: no server key specified\n", + this->argv_[0]), + -1); + + CORBA::Object_var server_object = + this->orb_->string_to_object (this->server_key_ ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + this->server_ = Paper_Airplane_Server::_narrow (server_object.in() ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + if (CORBA::is_nil (server_object.in ())) + ACE_ERROR_RETURN ((LM_ERROR, + "Error: invalid server key <%s>\n", this->server_key_), -1); + } + ACE_CATCHANY + { + ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, "Airplane_Client_i::init"); + return -1; + } + ACE_ENDTRY; + + return 0; +} diff --git a/TAO/orbsvcs/tests/ImplRepo/airplane_client_i.h b/TAO/orbsvcs/tests/ImplRepo/airplane_client_i.h new file mode 100644 index 00000000000..864c750fd67 --- /dev/null +++ b/TAO/orbsvcs/tests/ImplRepo/airplane_client_i.h @@ -0,0 +1,70 @@ +// -*- C++ -*- + +//============================================================================= +/** + * @file airplane_client_i.h + * + * $Id$ + * + * This class implements a simple CORBA client which returns a random + * paper airplane from the paper airplane server. + * + * + * @author Darrell Brunsch <brunsch@cs.wustl.edu> + */ +//============================================================================= + + +#if !defined (AIRPLANE_CLIENT_I_H) +#define AIRPLANE_CLIENT_I_H + +#include "AirplaneC.h" + +/** + * @class Airplane_Client_i + * + * @brief Paper Airplane Client Implementation + * + * Class wrapper for a client which gets the server IOR and then makes + * a couple of calls to the server. + */ +class Airplane_Client_i +{ +public: + // = Constructor and destructor. + Airplane_Client_i (void); + ~Airplane_Client_i (void); + + /// Execute client example code. + int run (); + + /// Initialize the client communication endpoint with server. + int init (int argc, char **argv); + +private: + /// Parses the arguments passed on the command line. + int parse_args (void); + + /// Ask the Paper Airplane Server for <count> planes. + void get_planes (size_t count); + + /// # of arguments on the command line. + int argc_; + + /// arguments from command line. + char **argv_; + + /// Key of the obj ref of the server. + char *server_key_; + + /// Number of airplanes to query for. + size_t loop_count_; + + /// Server object ptr. + Paper_Airplane_Server_ptr server_; + + /// Remember our orb. + CORBA::ORB_var orb_; +}; + +#endif /* AIRPLANE_CLIENT_I_H */ diff --git a/TAO/orbsvcs/tests/ImplRepo/airplane_i.cpp b/TAO/orbsvcs/tests/ImplRepo/airplane_i.cpp new file mode 100644 index 00000000000..90f93c31e54 --- /dev/null +++ b/TAO/orbsvcs/tests/ImplRepo/airplane_i.cpp @@ -0,0 +1,91 @@ +// $Id$ + +#include "airplane_i.h" + +#include "tao/debug.h" +#include "ace/OS_NS_time.h" + +ACE_RCSID (ImplRepo, + airplane_i, + "$Id$") + +// Constructor + + Airplane_i::Airplane_i () +{ + // Seed the random number generator + ACE_OS::srand (ACE_OS::time (0L)); +} + + +// Destructor + +Airplane_i::~Airplane_i (void) +{ + // Nothing +} + + +// Returns a random plane and page number + +char * +Airplane_i::get_plane (ACE_ENV_SINGLE_ARG_DECL_NOT_USED) + ACE_THROW_SPEC ((CORBA::SystemException)) +{ + if (TAO_debug_level) + ACE_DEBUG ((LM_DEBUG, "Airplane_i::get_plane\n")); + + switch (ACE_OS::rand () % 24) + { + case 0: + return CORBA::string_dup ("Seagull, page 2"); + case 1: + return CORBA::string_dup ("Albatross, page 7"); + case 2: + return CORBA::string_dup ("Owl, page 13"); + case 3: + return CORBA::string_dup ("Falcon, page 19"); + case 4: + return CORBA::string_dup ("Sparrow, page 24"); + case 5: + return CORBA::string_dup ("Condor, page 31"); + case 6: + return CORBA::string_dup ("Basic wing-flapper, page 36"); + case 7: + return CORBA::string_dup ("Butterfly, page 42"); + case 8: + return CORBA::string_dup ("Moth, page 49"); + case 9: + return CORBA::string_dup ("Bat, page 54"); + case 10: + return CORBA::string_dup ("Wind rider, page 62"); + case 11: + return CORBA::string_dup ("Bobber, page 67"); + case 12: + return CORBA::string_dup ("Thunderbird, page 72"); + case 13: + return CORBA::string_dup ("Oddbird, page 77"); + case 14: + return CORBA::string_dup ("Another oddbird, page 81"); + case 15: + return CORBA::string_dup ("Asymmetric plane, page 86"); + case 16: + return CORBA::string_dup ("Flying spectacles, page 90"); + case 17: + return CORBA::string_dup ("UFO, page 100"); + case 18: + return CORBA::string_dup ("Space fighter #1, page 105"); + case 19: + return CORBA::string_dup ("Space fighter #2, page 110"); + case 20: + return CORBA::string_dup ("Pinwheel, page 120"); + case 21: + return CORBA::string_dup ("Flying saucer, page 128"); + case 22: + return CORBA::string_dup ("Flying teacup, page 134"); + case 23: + return CORBA::string_dup ("Tumbler, page 138"); + } + + return 0; +} diff --git a/TAO/orbsvcs/tests/ImplRepo/airplane_i.h b/TAO/orbsvcs/tests/ImplRepo/airplane_i.h new file mode 100644 index 00000000000..10982838106 --- /dev/null +++ b/TAO/orbsvcs/tests/ImplRepo/airplane_i.h @@ -0,0 +1,55 @@ +// -*- C++ -*- + +//============================================================================= +/** + * @file airplane_i.h + * + * $Id$ + * + * This class implements a simple CORBA server which returns a random + * paper airplane from the book "Oddballs, Wing-Flappers, & Spinners: + * Great Paper Airplanes" by John Bringhurst. ISBN: 0-07-067910-X (pbk.) + * An excellent book to have! I personally recommend getting it just + * for the wing-flappers. + * + * + * @author Darrell Brunsch <brunsch@cs.wustl.edu> + */ +//============================================================================= + + +#if !defined (AIRPLANE_I_H) +#define AIRPLANE_I_H + +#include "AirplaneS.h" + +// Forward declarations. +class Airplane_i; + +// Typedefs. +typedef Airplane_i *Airplane_i_ptr; +typedef Airplane_i_ptr Airplane_i_ref; + +/** + * @class Airplane_i: + * + * @brief Paper Airplane Server Implementation + * + * This server has one method that returns the featured paper airplane + * at this moment (in other words, a random airplane). + */ +class Airplane_i: public POA_Paper_Airplane_Server +{ +public: + /// Constructor + Airplane_i (); + + /// Destructor + ~Airplane_i (void); + + /// Returns a random plane. + virtual char *get_plane (ACE_ENV_SINGLE_ARG_DECL) + ACE_THROW_SPEC ((CORBA::SystemException)); +}; + +#endif /* AIRPLANE_I_H */ diff --git a/TAO/orbsvcs/tests/ImplRepo/airplane_server.cpp b/TAO/orbsvcs/tests/ImplRepo/airplane_server.cpp new file mode 100644 index 00000000000..45f4bd9bca3 --- /dev/null +++ b/TAO/orbsvcs/tests/ImplRepo/airplane_server.cpp @@ -0,0 +1,44 @@ +// $Id$ + +#include "airplane_server_i.h" + +ACE_RCSID (ImplRepo, + airplane_server, + "$Id$") + +int +main (int argc, char *argv[]) +{ + Airplane_Server_i server; + + ACE_DEBUG ((LM_DEBUG, "\n\tPaper Airplane Server\n\n")); + + ACE_DECLARE_NEW_CORBA_ENV; + ACE_TRY + { + int retval = server.init (argc, argv ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + if (retval == -1) + return -1; + + + retval = server.run (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_TRY_CHECK; + + ACE_DEBUG ((LM_DEBUG, "Paper Airplane Server says goodnight\n")); + + return retval; + } + ACE_CATCH (CORBA::SystemException, sysex) + { + ACE_PRINT_EXCEPTION (sysex, "System Exception"); + } + ACE_CATCH (CORBA::UserException, userex) + { + ACE_PRINT_EXCEPTION (userex, "User Exception"); + } + ACE_ENDTRY; + + return 1; +} diff --git a/TAO/orbsvcs/tests/ImplRepo/airplane_server_i.cpp b/TAO/orbsvcs/tests/ImplRepo/airplane_server_i.cpp new file mode 100644 index 00000000000..92ffd886c0f --- /dev/null +++ b/TAO/orbsvcs/tests/ImplRepo/airplane_server_i.cpp @@ -0,0 +1,227 @@ +// $Id$ + +#include "airplane_server_i.h" + +#include "tao/IORTable/IORTable.h" +#include "tao/ImR_Client/ImR_Client.h" +#include "tao/debug.h" +#include "tao/PortableServer/Root_POA.h" + +#include "ace/Get_Opt.h" +#include "ace/Read_Buffer.h" +#include "ace/OS_NS_stdio.h" +#include "ace/OS_NS_sys_time.h" + +ACE_RCSID (ImplRepo, + airplane_server_i, + "$Id$") + +// The server name of the Aiprlane Server +const char SERVER_NAME[] = "airplane_server"; + +Airplane_Server_i::Airplane_Server_i (void) + : server_impl_ (0), + ior_output_file_ (0) +{ + // Nothing +} + +int +Airplane_Server_i::parse_args (void) +{ + ACE_Get_Opt get_opts (this->argc_, this->argv_, "do:"); + int c; + + while ((c = get_opts ()) != -1) + switch (c) + { + case 'd': // debug flag. + TAO_debug_level++; + break; + case 'o': // output the IOR to a file. + this->ior_output_file_ = ACE_OS::fopen (get_opts.opt_arg (), "w"); + if (this->ior_output_file_ == 0) + ACE_ERROR_RETURN ((LM_ERROR, + "Unable to open %s for writing: %p\n", + get_opts.opt_arg ()), -1); + break; + case '?': // display help for use of the server. + default: + ACE_ERROR_RETURN ((LM_ERROR, + "usage: %s" + " [-d]" + " [-o] <ior_output_file>" + "\n", + argv_ [0]), + 1); + } + + // Indicates successful parsing of command line. + return 0; +} + +int +Airplane_Server_i::init (int argc, char** argv ACE_ENV_ARG_DECL) +{ + // Since the Implementation Repository keys off of the POA name, we need + // to use the SERVER_NAME as the POA's name. + const char *poa_name = SERVER_NAME; + + ACE_TRY + { + // Initialize the ORB + this->orb_ = CORBA::ORB_init (argc, argv, 0 ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + // Save pointers to the command line arguments + this->argc_ = argc; + this->argv_ = argv; + + // Now check the arguments for our options + int retval = this->parse_args (); + + if (retval != 0) + return retval; + + // Get the POA from the ORB. + CORBA::Object_var obj = + this->orb_->resolve_initial_references ("RootPOA" + ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + ACE_ASSERT(! CORBA::is_nil (obj.in ())); + + // Narrow the object to a POA. + root_poa_ = PortableServer::POA::_narrow (obj.in () ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + // Get the POA_Manager. + this->poa_manager_ = this->root_poa_->the_POAManager (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_TRY_CHECK; + + // We now need to create a POA with the persistent and user_id policies, + // since they are need for use with the Implementation Repository. + + CORBA::PolicyList policies (2); + policies.length (2); + + policies[0] = + this->root_poa_->create_id_assignment_policy (PortableServer::USER_ID + ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK + + policies[1] = + this->root_poa_->create_lifespan_policy (PortableServer::PERSISTENT + ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + this->airplane_poa_ = + this->root_poa_->create_POA (poa_name, + this->poa_manager_.in (), + policies + ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + // Creation of the new POA is over, so destroy the Policy_ptr's. + for (CORBA::ULong i = 0; i < policies.length (); ++i) + { + CORBA::Policy_ptr policy = policies[i]; + policy->destroy (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_TRY_CHECK; + } + + ACE_NEW_RETURN (this->server_impl_, Airplane_i, -1); + + PortableServer::ObjectId_var server_id = + PortableServer::string_to_ObjectId ("server"); + + this->airplane_poa_->activate_object_with_id (server_id.in (), + this->server_impl_ + ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + obj = this->airplane_poa_->id_to_reference (server_id.in () ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + CORBA::String_var ior = + this->orb_->object_to_string (obj.in () ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + if (TAO_debug_level > 0) + ACE_DEBUG ((LM_DEBUG, "The ImRified IOR is: <%s>\n", ior.in ())); + + TAO_Root_POA* tmp_poa = dynamic_cast<TAO_Root_POA*>(airplane_poa_.in()); + obj = tmp_poa->id_to_reference_i (server_id.in (), false ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + CORBA::String_var plain_ior = + this->orb_->object_to_string (obj.in () ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + if (TAO_debug_level > 0) + ACE_DEBUG ((LM_DEBUG, "The plain IOR is: <%s>\n", plain_ior.in ())); + + // Note : The IORTable will only be used for those clients who try to + // invoke indirectly using a simple object_key reference + // like "corbaloc::localhost:8888/airplane_server". + obj = this->orb_->resolve_initial_references ("IORTable" ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + IORTable::Table_var adapter = + IORTable::Table::_narrow (obj.in () ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + ACE_ASSERT(! CORBA::is_nil (adapter.in ())); + adapter->bind (poa_name, plain_ior.in () ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + this->poa_manager_->activate (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_TRY_CHECK; + + if (this->ior_output_file_) + { + ACE_OS::fprintf (this->ior_output_file_, "%s", ior.in ()); + ACE_OS::fclose (this->ior_output_file_); + } + } + ACE_CATCHANY + { + ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, "Airplane_Server_i::init"); + ACE_RE_THROW; + } + ACE_ENDTRY; + + ACE_CHECK_RETURN (-1); + + return 0; +} + +int +Airplane_Server_i::run (ACE_ENV_SINGLE_ARG_DECL) +{ + ACE_TRY + { + ACE_Time_Value tv(60); + ACE_Time_Value tvStart = ACE_OS::gettimeofday(); + + this->orb_->run (tv ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + ACE_Time_Value tvEnd = ACE_OS::gettimeofday(); + + this->root_poa_->destroy(1, 1); + this->orb_->destroy(); + + if (tvEnd - tvStart > tv - ACE_Time_Value(5)) + return 1; + } + ACE_CATCHANY + { + ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, "Airplane_Server_i::run"); + ACE_RE_THROW; + } + ACE_ENDTRY; + + ACE_CHECK_RETURN (-1); + + return 0; +} + +Airplane_Server_i::~Airplane_Server_i (void) +{ + delete this->server_impl_; +} diff --git a/TAO/orbsvcs/tests/ImplRepo/airplane_server_i.h b/TAO/orbsvcs/tests/ImplRepo/airplane_server_i.h new file mode 100644 index 00000000000..3b9a1b1131e --- /dev/null +++ b/TAO/orbsvcs/tests/ImplRepo/airplane_server_i.h @@ -0,0 +1,75 @@ +// -*- C++ -*- + +//============================================================================= +/** + * @file airplane_server_i.h + * + * $Id$ + * + * Server that sets up the ORB and handles the registration and execution + * of the Paper Airplane Server. + * + * + * @author Darrell Brunsch <brunsch@cs.wustl.edu> + */ +//============================================================================= + + +#if !defined (AIRPLANE_SERVER_I_H) +#define AIRPLANE_SERVER_I_H + +#include "airplane_i.h" + +/** + * @class Airplane_Server_i + * + * @brief Paper Airplane Server Implementation Class + * + * Sets up everything necessary to get the Paper Airplane Server + * running. + */ +class Airplane_Server_i +{ +public: + // = Initialization and termination methods. + /// Default constructor + Airplane_Server_i (void); + + /// Destructor + ~Airplane_Server_i (void); + + /// Initialize the Server state - parsing arguments and waiting + int init (int argc, char **argv ACE_ENV_ARG_DECL); + + /// Run the orb + int run (ACE_ENV_SINGLE_ARG_DECL); + +private: + /// Parses the commandline arguments. + int parse_args (void); + + /// Number of command line arguments. + int argc_; + + /// The command line arguments. + char **argv_; + + /// The ORB. + CORBA::ORB_var orb_; + + PortableServer::POA_var root_poa_; + + /// The POA for the Airplane Server. + PortableServer::POA_var airplane_poa_; + + /// The POA manager. + PortableServer::POAManager_var poa_manager_; + + /// The Paper Airplane Server Implementation. + Airplane_i *server_impl_; + + /// File where the IOR of the server object is stored. + FILE *ior_output_file_; +}; + +#endif /* AIRPLANE_SERVER_I_H */ diff --git a/TAO/orbsvcs/tests/ImplRepo/locked/run_test.pl b/TAO/orbsvcs/tests/ImplRepo/locked/run_test.pl new file mode 100755 index 00000000000..9f570603f1f --- /dev/null +++ b/TAO/orbsvcs/tests/ImplRepo/locked/run_test.pl @@ -0,0 +1,188 @@ +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; + +################################################################################ +# Program locations + +$imr_locator_ior = PerlACE::LocalFile ("imr_locator.ior"); +$pfile = PerlACE::LocalFile ("persistence.dat"); + +$IMR_LOCATOR = new PerlACE::Process ("../../../ImplRepo_Service/ImplRepo_Service"); +$TAO_IMR = new PerlACE::Process ("../../../../../bin/tao_imr"); + +# We want the tao_imr executable to be found exactly in the path +# given, without being modified by the value of -ExeSubDir. +# So, we tell its Process object to ignore the setting of -ExeSubDir. + +$TAO_IMR->IgnoreExeSubDir (1); + +################################################################################ + +$errors = 0; + +unlink $imr_locator_ior; +unlink $pfile; + +################################################################################ +## Start the implementation Repository Locator + +$IMR_LOCATOR->Arguments ("-p $pfile -o $imr_locator_ior -d 2"); +$IMR_LOCATOR->Spawn (); + +if (PerlACE::waitforfile_timed ($imr_locator_ior, 20) == -1) { + print STDERR "ERROR: waiting for $imr_locator_ior\n"; + $IMR_LOCATOR->Kill (); + exit 1; +} + +################################################################################ +## Test out commands on the IMR + +print "===== Adding a server\n"; + +$TAO_IMR->Arguments("-ORBInitRef ImplRepoService=file://$imr_locator_ior" + . " add Foo -c foobarbaz"); + +$taoimr = $TAO_IMR->SpawnWaitKill (10); + +if ($taoimr != 0) { + print STDERR "ERROR: tao_imr (add) returned $taoimr\n"; + ++$errors; +} + +print "===== Updating a server\n"; + +$TAO_IMR->Arguments("-ORBInitRef ImplRepoService=file://$imr_locator_ior" + . " update Foo -w foodir" ); + +$taoimr = $TAO_IMR->SpawnWaitKill (10); + +if ($taoimr != 0) { + print STDERR "ERROR: tao_imr (update) returned $taoimr\n"; + ++$errors; +} + +print "===== Removing a server\n"; + +$TAO_IMR->Arguments("-ORBInitRef ImplRepoService=file://$imr_locator_ior" + . " remove Foo"); + +$taoimr = $TAO_IMR->SpawnWaitKill (10); + +if ($taoimr != 0) { + print STDERR "ERROR: tao_imr (remove) returned $taoimr\n"; + ++$errors; +} + +print "===== Re-adding a server\n"; + +$TAO_IMR->Arguments("-ORBInitRef ImplRepoService=file://$imr_locator_ior" + . " add Foo -c foobarbaz"); + +$taoimr = $TAO_IMR->SpawnWaitKill (10); + +if ($taoimr != 0) { + print STDERR "ERROR: tao_imr (add) returned $taoimr\n"; + ++$errors; +} + +################################################################################ +## Kill the IMR +print "===== Killing the ImR and restarting in locked mode.\n"; + +$iserver = $IMR_LOCATOR->TerminateWaitKill (5); + +if ($iserver != 0) { + print STDERR "ERROR: IMR returned $iserver\n"; + ++$errors; +} + +unlink $imr_locator_ior; + +################################################################################ +## Restart the Implementation Repository in locked mode. + +$IMR_LOCATOR->Arguments ("-l -p $pfile -o $imr_locator_ior -d 2"); +$IMR_LOCATOR->Spawn (); + +if (PerlACE::waitforfile_timed ($imr_locator_ior, 10) == -1) { + print STDERR "ERROR: waiting for $imr_locator_ior\n"; + $IMR_LOCATOR->Kill (); + exit 1; +} + +################################################################################ +## Test out commands on the IMR + +print "===== Listing registered servers.\n"; + +$TAO_IMR->Arguments("-ORBInitRef ImplRepoService=file://$imr_locator_ior" + . " list"); + +$taoimr = $TAO_IMR->SpawnWaitKill (10); + +if ($taoimr != 0) { + print STDERR "ERROR: tao_imr (list) returned $taoimr\n"; + ++$errors; +} + +print "===== Adding a server (should fail)\n"; + +$TAO_IMR->Arguments("-ORBInitRef ImplRepoService=file://$imr_locator_ior" + . " add Foo2 -c foobarbaz"); + +$taoimr = $TAO_IMR->SpawnWaitKill (10); + +## Note : If you receive a 5 (NOT_FOUND) then it's likely that +## persistence isn't working correctly. +if ($taoimr != 2) { # NO_PERMISSION + print STDERR "ERROR: tao_imr (add) returned $taoimr\n"; + ++$errors; +} + +print "===== Updating a server (should fail)\n"; + +$TAO_IMR->Arguments("-ORBInitRef ImplRepoService=file://$imr_locator_ior" + . " update Foo -w foodir"); + +$taoimr = $TAO_IMR->SpawnWaitKill (10); + +if ($taoimr != 2) { # NO_PERMISSION + print STDERR "ERROR: tao_imr (update) returned $taoimr\n"; + ++$errors; +} + +print "===== Removing a server (should fail)\n"; + +$TAO_IMR->Arguments("-ORBInitRef ImplRepoService=file://$imr_locator_ior" + . " remove Foo"); + +$taoimr = $TAO_IMR->SpawnWaitKill (10); + +if ($taoimr != 2) { # NO_PERMISSION + print STDERR "ERROR: tao_imr (remove) returned $taoimr\n"; + ++$errors; +} + +################################################################################ +## Kill the IMR + +$iserver = $IMR_LOCATOR->TerminateWaitKill (5); + +if ($iserver != 0) { + print STDERR "ERROR: IMR returned $iserver\n"; + ++$errors; +} + +unlink $imr_locator_ior; + +unlink $pfile; + +exit $errors; diff --git a/TAO/orbsvcs/tests/ImplRepo/nestea_client.cpp b/TAO/orbsvcs/tests/ImplRepo/nestea_client.cpp new file mode 100644 index 00000000000..60d05c63a82 --- /dev/null +++ b/TAO/orbsvcs/tests/ImplRepo/nestea_client.cpp @@ -0,0 +1,25 @@ +// $Id$ + +#include "nestea_client_i.h" + +#include "ace/Log_Msg.h" + +ACE_RCSID (ImplRepo, + nestea_client, + "$Id$") + +// This function runs the test. + +int +main (int argc, char **argv) +{ + Nestea_Client_i client; + + ACE_DEBUG ((LM_DEBUG, "\n\tNestea Bookshelf Client\n\n")); + + if (client.init (argc, argv) == -1) + return 1; + else + return client.run (); +} + diff --git a/TAO/orbsvcs/tests/ImplRepo/nestea_client_i.cpp b/TAO/orbsvcs/tests/ImplRepo/nestea_client_i.cpp new file mode 100644 index 00000000000..a92bf39e6c8 --- /dev/null +++ b/TAO/orbsvcs/tests/ImplRepo/nestea_client_i.cpp @@ -0,0 +1,138 @@ +// $Id$ + +#include "nestea_client_i.h" +#include "tao/debug.h" +#include "ace/Get_Opt.h" +#include "ace/Read_Buffer.h" +#include "ace/ACE.h" + +ACE_RCSID(ImplRepo, nestea_client_i, "$Id$") + +// Constructor. +Nestea_Client_i::Nestea_Client_i (void) + : server_key_ (ACE::strnew ("key0")) + , server_ (Nestea_Bookshelf::_nil ()) + , shutdown_server_(false) +{ +} + + +// Parses the command line arguments and returns an error status. + +int +Nestea_Client_i::parse_args (void) +{ + ACE_Get_Opt get_opts (argc_, argv_, "dsn:k:"); + int c; + + while ((c = get_opts ()) != -1) + switch (c) + { + case 'd': // debug flag + TAO_debug_level++; + break; + case 'k': // ior provide on command line + this->server_key_ = ACE::strnew (get_opts.opt_arg ()); + break; + case 's': // shutdown server before exiting + this->shutdown_server_ = true; + break; + case '?': + default: + ACE_ERROR_RETURN ((LM_ERROR, + "usage: %s" + " [-d]" + " [-n loopcount]" + " [-s]" + " [-k server-object-key]" + "\n", + this->argv_ [0]), + -1); + } + + // Indicates successful parsing of command line. + return 0; +} + +// Execute client example code. + +int +Nestea_Client_i::run () +{ + this->server_->drink (40); + this->server_->drink (100); + + ACE_DEBUG ((LM_DEBUG, "Cans: %d\n" + "Praise: %s\n", + this->server_->bookshelf_size (), + this->server_->get_praise ())); + + this->server_->drink (500); + this->server_->crush (200); + + ACE_DEBUG ((LM_DEBUG, "Cans: %d\n" + "Praise: %s\n", + this->server_->bookshelf_size (), + this->server_->get_praise ())); + + if (shutdown_server_) + server_->shutdown(); + + return 0; +} + +Nestea_Client_i::~Nestea_Client_i (void) +{ + // Free resources + CORBA::release (this->server_); + + delete [] this->server_key_; +} + + +int +Nestea_Client_i::init (int argc, char **argv) +{ + this->argc_ = argc; + this->argv_ = argv; + + ACE_DECLARE_NEW_CORBA_ENV; + ACE_TRY + { + // Retrieve the ORB. + this->orb_ = CORBA::ORB_init (this->argc_, + this->argv_, + "internet" + ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + // Parse command line and verify parameters. + if (this->parse_args () == -1) + return -1; + + if (this->server_key_ == 0) + ACE_ERROR_RETURN ((LM_ERROR, + "%s: no server key specified\n", + this->argv_[0]), + -1); + + CORBA::Object_var server_object = + this->orb_->string_to_object (this->server_key_ ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + this->server_ = Nestea_Bookshelf::_narrow (server_object.in() ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + if (CORBA::is_nil (server_object.in ())) + ACE_ERROR_RETURN ((LM_ERROR, + "Error: invalid server key <%s>\n", this->server_key_), -1); + } + ACE_CATCHANY + { + ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, "Nestea_Client_i::init"); + return -1; + } + ACE_ENDTRY; + + return 0; +} diff --git a/TAO/orbsvcs/tests/ImplRepo/nestea_client_i.h b/TAO/orbsvcs/tests/ImplRepo/nestea_client_i.h new file mode 100644 index 00000000000..866641d1656 --- /dev/null +++ b/TAO/orbsvcs/tests/ImplRepo/nestea_client_i.h @@ -0,0 +1,66 @@ +// -*- C++ -*- + +//============================================================================= +/** + * @file nestea_client_i.h + * + * $Id$ + * + * This class implements a simple CORBA client which controls a Nestea + * can database + * + * + * @author Darrell Brunsch <brunsch@cs.wustl.edu> + */ +//============================================================================= + + +#if !defined (NESTEA_CLIENT_I_H) +#define NESTEA_CLIENT_I_H + +#include "NesteaC.h" + +/** + * @class Nestea_Client_i + * + * @brief Nestea Bookshelf Client Implementation + * + * Class wrapper for a client which gets the server IOR and then makes + * a couple of calls to the server. + */ +class Nestea_Client_i +{ +public: + // = Constructor and destructor. + Nestea_Client_i (void); + ~Nestea_Client_i (void); + + /// Execute client example code. + int run (); + + /// Initialize the client communication endpoint with server. + int init (int argc, char **argv); + +private: + /// Parses the arguments passed on the command line. + int parse_args (void); + + /// # of arguments on the command line. + int argc_; + + /// arguments from command line. + char **argv_; + + /// Key of the obj ref of the server. + char *server_key_; + + /// Server object ptr. + Nestea_Bookshelf_ptr server_; + + /// Remember our orb. + CORBA::ORB_var orb_; + + bool shutdown_server_; +}; + +#endif /* NESTEA_CLIENT_I_H */ diff --git a/TAO/orbsvcs/tests/ImplRepo/nestea_i.cpp b/TAO/orbsvcs/tests/ImplRepo/nestea_i.cpp new file mode 100644 index 00000000000..4706cf0304d --- /dev/null +++ b/TAO/orbsvcs/tests/ImplRepo/nestea_i.cpp @@ -0,0 +1,166 @@ +// $Id$ + +#include "nestea_i.h" +#include "tao/debug.h" +#include "ace/ACE.h" +#include "ace/FILE_Addr.h" +#include "ace/FILE_Connector.h" +#include "ace/FILE_IO.h" +#include "ace/OS_NS_stdio.h" +#include "ace/OS_NS_string.h" + +const size_t MAX_UINT32_STR_LEN = 11; // Largest UINT32 is 8589934591 + NUL is 11 characters + +ACE_RCSID(ImplRepo, nestea_i, "$Id$") + +Nestea_i::Nestea_i (CORBA::ORB_ptr orb, const char *filename) +: cans_ (0) +{ + orb_ = CORBA::ORB::_duplicate(orb); + + this->data_filename_ = ACE::strnew (filename); + + // @@ This should probably be called from somewhere else + this->load_data (); +} + + +Nestea_i::~Nestea_i (void) +{ + delete [] this->data_filename_; +} + + +// Add <cans> number of cans to the bookshelf. + +void +Nestea_i::drink (CORBA::Long cans + ACE_ENV_ARG_DECL_NOT_USED) + ACE_THROW_SPEC ((CORBA::SystemException)) +{ + if (TAO_debug_level) + ACE_DEBUG ((LM_DEBUG, "Nestea_i::drink %d cans\n", cans)); + + this->cans_ += cans; + + this->save_data (); +} + + +// Removes <cans> number of cans from the bookshelf. + +void +Nestea_i::crush (CORBA::Long cans + ACE_ENV_ARG_DECL_NOT_USED) + ACE_THROW_SPEC ((CORBA::SystemException)) +{ + if (TAO_debug_level) + ACE_DEBUG ((LM_DEBUG, "Nestea_i::crush %d cans\n", cans)); + + if (static_cast<ACE_UINT32> (cans) > this->cans_) + this->cans_ = 0; + else + this->cans_ -= cans; + + this->save_data (); +} + + +// Returns the number of cans in the bookshelf. + +CORBA::Long +Nestea_i::bookshelf_size (ACE_ENV_SINGLE_ARG_DECL_NOT_USED) + ACE_THROW_SPEC ((CORBA::SystemException)) +{ + if (TAO_debug_level) + ACE_DEBUG ((LM_DEBUG, "Nestea_i::bookshelf_size\n")); + + return this->cans_; +} + +// Returns comments about your collection. + +char * +Nestea_i::get_praise (ACE_ENV_SINGLE_ARG_DECL_NOT_USED) + ACE_THROW_SPEC ((CORBA::SystemException)) +{ + if (TAO_debug_level) + ACE_DEBUG ((LM_DEBUG, "Nestea_i::get_praise\n")); + + if (this->cans_ > 500) + return CORBA::string_dup ("Man, that is one excellent Nestea Collection!"); + else if (this->cans_ > 250) + return CORBA::string_dup ("We are getting into the big leagues now!"); + else if (this->cans_ > 100) + return CORBA::string_dup ("Things are looking up!"); + else if (this->cans_ > 0) + return CORBA::string_dup ("Well, it is a start. Drink more Nestea!"); + else + return CORBA::string_dup ("No cans, no praise."); +} + +void +Nestea_i::shutdown (ACE_ENV_SINGLE_ARG_DECL_NOT_USED) + ACE_THROW_SPEC ((CORBA::SystemException)) +{ + if (TAO_debug_level) + ACE_DEBUG ((LM_DEBUG, "Nestea_i::shutdown\n")); + + orb_->shutdown(0); +} + +// Saves bookshelf data to a file. + +int +Nestea_i::save_data (void) +{ + ACE_FILE_IO file; + ACE_FILE_Connector connector; + + if (connector.connect (file, + ACE_FILE_Addr (this->data_filename_), + 0, + ACE_Addr::sap_any) == -1) + ACE_ERROR_RETURN ((LM_ERROR, + "%p\n to %s", + "connect", + this->data_filename_), + -1); + + char str[MAX_UINT32_STR_LEN]; + + ACE_OS::sprintf (str, "%d", this->cans_); + + return file.send_n (str, ACE_OS::strlen (str) + 1); +} + + +// Loads bookshelf data from a file. + +int +Nestea_i::load_data (void) +{ + ACE_FILE_IO file; + ACE_FILE_Connector connector; + + if (connector.connect (file, + ACE_FILE_Addr (this->data_filename_), + 0, + ACE_Addr::sap_any) == -1) + ACE_ERROR_RETURN ((LM_ERROR, + "%p\n to %s", + "connect", + this->data_filename_), + -1); + + char str[MAX_UINT32_STR_LEN]; + + int len = file.recv (str, MAX_UINT32_STR_LEN); + str[len] = 0; + + if (len > 0) + this->cans_ = ACE_OS::atoi (str); + else + this->cans_ = 0; + return 0; +} diff --git a/TAO/orbsvcs/tests/ImplRepo/nestea_i.h b/TAO/orbsvcs/tests/ImplRepo/nestea_i.h new file mode 100644 index 00000000000..3e9aa019ff6 --- /dev/null +++ b/TAO/orbsvcs/tests/ImplRepo/nestea_i.h @@ -0,0 +1,83 @@ +// -*- C++ -*- + +//============================================================================= +/** + * @file nestea_i.h + * + * $Id$ + * + * This class is an implementation of the Nestea Bookshelf interface. + * + * + * @author Darrell Brunsch <brunsch@cs.wustl.edu> + */ +//============================================================================= + + +#if !defined (NESTEA_I_H) +#define NESTEA_I_H + +#include "NesteaS.h" + +// Forward declarations. +class Nestea_i; + +// Typedefs. +typedef Nestea_i *Nestea_i_ptr; +typedef Nestea_i_ptr Nestea_i_ref; + +/** + * @class Nestea_i: + * + * @brief Nestea Bookshelf Implementation + * + * Implements the Nestea Bookshelf server, which keeps track of the + * number of nestea cans in a bookshelf. You can drink Nestea to add + * it to the bookshelf or crush the cans to remove them. + */ +class Nestea_i: public POA_Nestea_Bookshelf +{ +public: + /// Constructor + Nestea_i (CORBA::ORB_ptr orb, const char *filename = "nestea.dat"); + + /// Destructor + virtual ~Nestea_i (void); + + /// Add <cans> number of cans to the bookshelf. + virtual void drink (CORBA::Long cans + ACE_ENV_ARG_DECL_WITH_DEFAULTS) + ACE_THROW_SPEC ((CORBA::SystemException)); + + /// Removes <cans> number of cans from the bookshelf. + virtual void crush (CORBA::Long cans + ACE_ENV_ARG_DECL_WITH_DEFAULTS) + ACE_THROW_SPEC ((CORBA::SystemException)); + + /// Returns the number of cans in the bookshelf. + virtual CORBA::Long bookshelf_size (ACE_ENV_SINGLE_ARG_DECL_WITH_DEFAULTS) + ACE_THROW_SPEC ((CORBA::SystemException)); + + /// Returns comments about your collection. + virtual char *get_praise (ACE_ENV_SINGLE_ARG_DECL_WITH_DEFAULTS) + ACE_THROW_SPEC ((CORBA::SystemException)); + + virtual void shutdown(ACE_ENV_SINGLE_ARG_DECL_WITH_DEFAULTS) + ACE_THROW_SPEC ((CORBA::SystemException)); +private: + /// Saves bookshelf data to a file. + int save_data (void); + + /// Loads bookshelf data from a file. + int load_data (void); + + /// The name of the file to store the data in. + char *data_filename_; + + /// Number of cans in the bookshelf. + ACE_UINT32 cans_; + + CORBA::ORB_var orb_; +}; + +#endif /* NESTEA_I_H */ diff --git a/TAO/orbsvcs/tests/ImplRepo/nestea_server.cpp b/TAO/orbsvcs/tests/ImplRepo/nestea_server.cpp new file mode 100644 index 00000000000..51a8ec71ebe --- /dev/null +++ b/TAO/orbsvcs/tests/ImplRepo/nestea_server.cpp @@ -0,0 +1,43 @@ +// $Id$ + +#include "nestea_server_i.h" + +ACE_RCSID(ImplRepo, nestea_server, "$Id$") + +int +main (int argc, char *argv[]) +{ + Nestea_Server_i server; + + ACE_DEBUG ((LM_DEBUG, "\n\tNestea Bookshelf Server\n\n")); + + ACE_DECLARE_NEW_CORBA_ENV; + ACE_TRY + { + int retval = server.init (argc, argv ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + if (retval == -1) + return -1; + else + { + server.run (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_TRY_CHECK; + } + } + ACE_CATCH (CORBA::SystemException, sysex) + { + ACE_PRINT_EXCEPTION (sysex, "System Exception"); + return -1; + } + ACE_CATCH (CORBA::UserException, userex) + { + ACE_PRINT_EXCEPTION (userex, "User Exception"); + return -1; + } + ACE_ENDTRY; + + ACE_DEBUG ((LM_DEBUG, "Nestea Bookshelf Server says goodnight\n")); + + return 0; +} diff --git a/TAO/orbsvcs/tests/ImplRepo/nestea_server_i.cpp b/TAO/orbsvcs/tests/ImplRepo/nestea_server_i.cpp new file mode 100644 index 00000000000..f3278167081 --- /dev/null +++ b/TAO/orbsvcs/tests/ImplRepo/nestea_server_i.cpp @@ -0,0 +1,239 @@ +// $Id$ + +#include "nestea_server_i.h" + +#include "tao/IORTable/IORTable.h" +#include "tao/ImR_Client/ImR_Client.h" +#include "tao/debug.h" +#include "tao/PortableServer/Root_POA.h" + +#include "ace/Get_Opt.h" +#include "ace/Read_Buffer.h" +#include "ace/OS_NS_stdio.h" + +ACE_RCSID(ImplRepo, nestea_server_i, "$Id$") + +// The file to save the persistent state to. +const char NESTEA_DATA_FILENAME[] = "nestea.dat"; + +// The server name of the Nestea Server +const char SERVER_NAME[] = "nestea_server"; + +const int SELF_DESTRUCT_SECS = 8; // Must coordinate with run_test.pl + +Nestea_Server_i::Nestea_Server_i (const char * /*filename*/) + : server_impl_ (0), + ior_output_file_ (0) +{ + // Nothing +} + +Nestea_Server_i::~Nestea_Server_i (void) +{ + delete this->server_impl_; +} + +int +Nestea_Server_i::parse_args (void) +{ + ACE_Get_Opt get_opts (this->argc_, this->argv_, "do:"); + int c; + + while ((c = get_opts ()) != -1) + switch (c) + { + case 'd': // debug flag. + TAO_debug_level++; + break; + case 'o': // output the IOR to a file. + this->ior_output_file_ = ACE_OS::fopen (get_opts.opt_arg (), "w"); + if (this->ior_output_file_ == 0) + ACE_ERROR_RETURN ((LM_ERROR, + "Unable to open %s for writing: %p\n", + get_opts.opt_arg ()), -1); + break; + case '?': // display help for use of the server. + default: + ACE_ERROR_RETURN ((LM_ERROR, + "usage: %s" + " [-d]" + " [-r]" + " [-o] <ior_output_file>" + "\n", + argv_ [0]), + 1); + } + + // Indicates successful parsing of command line. + return 0; +} + + +// The init() method does quite a few things. +// +// - Initialize the ORB +// - Create a persistent POA for the server +// - Activate the POA Manager +// - Activate the servant under the POA +// - Uses the IR helper class to alter the object +// - Creates an IOR from the servant and outputs it to a file + +static void printEnvVars() { + char* useimr = ACE_OS::getenv("TAO_USE_IMR"); + char* ior = ACE_OS::getenv("ImplRepoServiceIOR"); + ACE_OS::printf("nestea_server: TAO_USE_IMR=%s\n", useimr != 0 ? useimr : "<null>"); + ACE_OS::printf("nestea_server: ImplRepoServiceIOR=%s\n", ior != 0 ? ior : "<null>"); +} + +int +Nestea_Server_i::init (int argc, char** argv ACE_ENV_ARG_DECL) +{ + printEnvVars(); + // Since the Implementation Repository keys off of the POA name, we need + // to use the SERVER_NAME as the POA's name. + const char *poa_name = SERVER_NAME; + + ACE_TRY + { + // Initialize the ORB + this->orb_ = CORBA::ORB_init (argc, argv, 0 ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + // Save pointers to the command line arguments + this->argc_ = argc; + this->argv_ = argv; + + // Now check the arguments for our options + int retval = this->parse_args (); + + if (retval != 0) + return retval; + + // Get the POA from the ORB. + CORBA::Object_var obj = + this->orb_->resolve_initial_references ("RootPOA" + ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + ACE_ASSERT(! CORBA::is_nil (obj.in ())); + + this->root_poa_ = PortableServer::POA::_narrow (obj.in () ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + this->poa_manager_ = this->root_poa_->the_POAManager (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_TRY_CHECK; + + // We now need to create a POA with the persistent and user_id policies, + // since they are need for use with the Implementation Repository. + + CORBA::PolicyList policies (2); + policies.length (2); + + policies[0] = + this->root_poa_->create_id_assignment_policy (PortableServer::USER_ID + ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK + + policies[1] = + this->root_poa_->create_lifespan_policy (PortableServer::PERSISTENT + ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + this->nestea_poa_ = + this->root_poa_->create_POA (poa_name, + this->poa_manager_.in (), + policies + ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + // Creation of the new POA is over, so destroy the Policy_ptr's. + for (CORBA::ULong i = 0; i < policies.length (); ++i) + { + CORBA::Policy_ptr policy = policies[i]; + policy->destroy (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_TRY_CHECK; + } + + ACE_NEW_RETURN (this->server_impl_, + Nestea_i (orb_.in(), NESTEA_DATA_FILENAME), + -1); + + PortableServer::ObjectId_var server_id = + PortableServer::string_to_ObjectId ("server"); + + this->nestea_poa_->activate_object_with_id (server_id.in (), + this->server_impl_ + ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + obj = this->nestea_poa_->id_to_reference (server_id.in () ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + CORBA::String_var ior = + this->orb_->object_to_string (obj.in () ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + if (TAO_debug_level > 0) + ACE_DEBUG ((LM_DEBUG, "The IOR is: <%s>\n", ior.in ())); + + TAO_Root_POA* tmp_poa = dynamic_cast<TAO_Root_POA*>(nestea_poa_.in()); + obj = tmp_poa->id_to_reference_i (server_id.in (), false ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + CORBA::String_var rawior = + this->orb_->object_to_string (obj.in () ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + obj = this->orb_->resolve_initial_references ("IORTable" ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + IORTable::Table_var adapter = + IORTable::Table::_narrow (obj.in () ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + ACE_ASSERT(! CORBA::is_nil (adapter.in ())); + + adapter->bind (poa_name, rawior.in() ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + this->poa_manager_->activate (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_TRY_CHECK; + + if (this->ior_output_file_) + { + ACE_OS::fprintf (this->ior_output_file_, "%s", ior.in ()); + ACE_OS::fclose (this->ior_output_file_); + } + } + ACE_CATCHANY + { + ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, "Nestea_i::init"); + ACE_RE_THROW; + } + ACE_ENDTRY; + + ACE_CHECK_RETURN (-1); + + return 0; +} + +int +Nestea_Server_i::run (ACE_ENV_SINGLE_ARG_DECL) +{ + int status = 0; + + ACE_TRY + { + ACE_Time_Value tv(SELF_DESTRUCT_SECS); + + this->orb_->run (tv ACE_ENV_ARG_PARAMETER); + + this->root_poa_->destroy(1, 1); + this->orb_->destroy(); + } + ACE_CATCHANY + { + status = -1; + ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, "Nestea_i::run"); + ACE_RE_THROW; + } + ACE_ENDTRY; + ACE_CHECK_RETURN (-1); + + return status; +} diff --git a/TAO/orbsvcs/tests/ImplRepo/nestea_server_i.h b/TAO/orbsvcs/tests/ImplRepo/nestea_server_i.h new file mode 100644 index 00000000000..ff3aee780de --- /dev/null +++ b/TAO/orbsvcs/tests/ImplRepo/nestea_server_i.h @@ -0,0 +1,74 @@ +// -*- C++ -*- + +//============================================================================= +/** + * @file nestea_server_i.h + * + * $Id$ + * + * Server that sets up the ORB and handles the registration and execution + * of the Nestea Bookshelf Server. + * + * + * @author Darrell Brunsch <brunsch@cs.wustl.edu> + */ +//============================================================================= + + +#if !defined (NESTEA_SERVER_I_H) +#define NESTEA_SERVER_I_H + +#include "nestea_i.h" + +/** + * @class Nestea_Server_i + * + * @brief Nestea Bookshelf Server Implementation Class + * + * Sets up everything necessary to get the Nestea Bookshelf Server + * running. + */ +class Nestea_Server_i +{ +public: + // = Initialization and termination methods. + /// Default constructor + Nestea_Server_i (const char *filename = "nestea.dat"); + + /// Destructor + ~Nestea_Server_i (void); + + /// Initialize the Server state - parsing arguments and waiting + int init (int argc, char **argv ACE_ENV_ARG_DECL); + + /// Run the orb + int run (ACE_ENV_SINGLE_ARG_DECL); + +private: + /// Parses the commandline arguments. + int parse_args (void); + + /// Number of command line arguments. + int argc_; + + /// The command line arguments. + char **argv_; + + CORBA::ORB_var orb_; + + PortableServer::POA_var root_poa_; + + /// The POA for the Nestea Server. + PortableServer::POA_var nestea_poa_; + + /// The POA manager. + PortableServer::POAManager_var poa_manager_; + + /// The Nestea Bookshelf Server Implementation. + Nestea_i *server_impl_; + + /// File where the IOR of the server object is stored. + FILE *ior_output_file_; +}; + +#endif /* NESTEA_SERVER_I_H */ diff --git a/TAO/orbsvcs/tests/ImplRepo/run_test.pl b/TAO/orbsvcs/tests/ImplRepo/run_test.pl new file mode 100755 index 00000000000..db82e5938fa --- /dev/null +++ b/TAO/orbsvcs/tests/ImplRepo/run_test.pl @@ -0,0 +1,1001 @@ +eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}' + & eval 'exec perl -S $0 $argv:q' + if 0; + +# $Id$ +# -*- perl -*- + +############################################################################### + +use strict; + +use lib "../../../../bin"; +use PerlACE::Run_Test; +use Cwd; +use Sys::Hostname; +use File::Copy; + +my $cwd = getcwd(); + +my $ACE_ROOT = $ENV{ACE_ROOT}; + +if (!defined $ACE_ROOT) { + chdir ('../../../../'); + $ACE_ROOT = getcwd (); + chdir ($cwd); + print "ACE_ROOT not defined, defaulting to ACE_ROOT=$ACE_ROOT\n"; +} + +my $airplane_ior = PerlACE::LocalFile ("airplane.ior"); +my $nestea_ior = PerlACE::LocalFile ("nestea.ior"); +my $imr_activator_ior = PerlACE::LocalFile ("imr_activator.ior"); +my $imr_locator_ior = PerlACE::LocalFile ("imr_locator.ior"); + +my $refstyle = " -ORBObjRefStyle URL"; + +my $backing_store = "imr_backing_store.xml"; +my $P_SVR = new PerlACE::Process (PerlACE::LocalFile("persist server")); +my $nestea_dat = "nestea.dat"; + +my $protocol = "iiop"; +my $host = hostname(); +my $port = 12345; +my $endpoint = "-ORBEndpoint " . "$protocol" . "://:" . $port; + + +my $IMR_LOCATOR = new PerlACE::Process ("../../ImplRepo_Service/ImplRepo_Service"); +my $IMR_ACTIVATOR = new PerlACE::Process ("../../ImplRepo_Service/ImR_Activator"); +my $TAO_IMR = new PerlACE::Process("../../../../bin/tao_imr"); + +# We want the tao_imr executable to be found exactly in the path +# given, without being modified by the value of -ExeSubDir. +# So, we tell its Process object to ignore the setting of -ExeSubDir. + +$TAO_IMR->IgnoreExeSubDir (1); + +sub create_acli { + return new PerlACE::Process (PerlACE::LocalFile ("airplane_client"), " -k file://$airplane_ior"); +} + +sub create_ncli { + return new PerlACE::Process (PerlACE::LocalFile ("nestea_client"), " -k file://$nestea_ior"); +} + +my $A_SVR = new PerlACE::Process (PerlACE::LocalFile ("airplane_server")); +my $A_CLI = create_acli(); +my $N_SVR = new PerlACE::Process (PerlACE::LocalFile ("nestea_server")); +my $N_CLI = create_ncli(); + +# Make sure the files are gone, so we can wait on them. +unlink $airplane_ior; +unlink $nestea_ior; +unlink $imr_locator_ior; +unlink $imr_activator_ior; +unlink $backing_store; +unlink $nestea_dat; +unlink $P_SVR->Executable(); + + + +# The Tests + +############################################################################### + +sub airplane_test +{ + my $status = 0; + + $A_SVR->Arguments ("-o $airplane_ior $refstyle"); + $A_SVR->Spawn (); + + if (PerlACE::waitforfile_timed ($airplane_ior, 10) == -1) { + print STDERR "ERROR: cannot find $airplane_ior\n"; + $A_SVR->Kill (); + return 1; + } + + my $client = $A_CLI->SpawnWaitKill (10); + + if ($client != 0) { + print STDERR "ERROR: client returned $client\n"; + $status = 1; + } + + my $server = $A_SVR->TerminateWaitKill (5); + + if ($server != 0) { + print STDERR "ERROR: server returned $server\n"; + $status = 1; + } + + return $status; +} + +############################################################################### + +sub nestea_test +{ + my $status = 0; + + $N_SVR->Arguments ("-o $nestea_ior $refstyle"); + $N_SVR->Spawn (); + + if (PerlACE::waitforfile_timed ($nestea_ior, 10) == -1) { + print STDERR "ERROR: cannot find $nestea_ior\n"; + $N_SVR->Kill (); + return 1; + } + + my $client = $N_CLI->SpawnWaitKill (10); + + if ($client != 0) { + print STDERR "ERROR: client returned $client\n"; + $status = 1; + } + + my $server = $N_SVR->TerminateWaitKill (5); + + if ($server != 0) { + print STDERR "ERROR: server returned $server\n"; + $status = 1; + } + + return $status; +} + +sub nt_service_test_i +{ + my ($imr_initref, $BIN_IMR_ACTIVATOR, $BIN_IMR_LOCATOR) = @_; + + print "Installing TAO ImR Services\n"; + $BIN_IMR_ACTIVATOR->Arguments ("-c install $imr_initref -d 0"); + $BIN_IMR_LOCATOR->Arguments ("-c install -d 0 -orbendpoint iiop://:8888"); + + my $result = $BIN_IMR_LOCATOR->SpawnWaitKill (5); + if ($result != 0) { + print STDERR "ERROR: IMR Locator installation returned $result\n"; + return 1; + } + + $result = $BIN_IMR_ACTIVATOR->SpawnWaitKill (5); + if ($result != 0) { + print STDERR "ERROR: IMR Activator installation returned $result\n"; + return 1; + } + + # Starting the activator will also start the locator + print "Starting TAO Implementation Repository Services\n"; + # Starting the activator should start the ImR automatically + #system("net start taoimr 2>&1"); + system("net start taoimractivator 2>&1"); + + # No need to specify imr_initref or -orbuseimr 1 for servers spawned by activator + $TAO_IMR->Arguments ("$imr_initref add airplane_server -c \"" + . $A_SVR->Executable() . + "\" -w \"$ACE_ROOT/lib\""); + $result = $TAO_IMR->SpawnWaitKill (10); + if ($result != 0) { + print STDERR "ERROR: tao_imr add airplane_server returned $result\n"; + return 1; + } + + $TAO_IMR->Arguments ("$imr_initref list -v"); + $result = $TAO_IMR->SpawnWaitKill (10); + if ($result != 0) { + print STDERR "ERROR: tao_imr list -v returned $result\n"; + return 1; + } + + $TAO_IMR->Arguments ("$imr_initref ior airplane_server -f $airplane_ior"); + $result = $TAO_IMR->SpawnWaitKill (10); + if ($result != 0) { + print STDERR "ERROR: tao_imr ior airplane_server returned $result\n"; + return 1; + } + if (PerlACE::waitforfile_timed ($airplane_ior, 10) == -1) { + print STDERR "ERROR: cannot find $airplane_ior\n"; + $A_SVR->Kill (); + return 1; + } + + $result = $A_CLI->SpawnWaitKill (20); + if ($result != 0) { + print STDERR "ERROR: airplane client returned $result\n"; + return 1; + } + + $TAO_IMR->Arguments ("$imr_initref shutdown airplane_server"); + $result = $TAO_IMR->SpawnWaitKill (20); + if ($result != 0) { + print STDERR "ERROR: tao_imr shutdown airplane_server returned $result\n"; + return 1; + } + + return 0; +} + +sub nt_service_test +{ + my $result = 0; + + # Just to show that it's possible, this test uses corbaloc instead of ior file. + my $imr_initref = "-orbinitref ImplRepoService=corbaloc::localhost:8888/ImplRepoService"; + + # To avoid having to ensure that they LocalSystem account has the correct path + # we simply copy the imr executables to the same directory as the DLL's. + my $BIN_IMR_LOCATOR = new PerlACE::Process ("$ACE_ROOT/lib/ImplRepo_Service",""); + my $BIN_IMR_ACTIVATOR = new PerlACE::Process ("$ACE_ROOT/lib/ImR_Activator",""); + $BIN_IMR_LOCATOR->IgnoreExeSubDir(1); + $BIN_IMR_ACTIVATOR->IgnoreExeSubDir(1); + + print "Copying ImplRepo services to the same location as the dlls.\n"; + unlink $BIN_IMR_LOCATOR->Executable (); + copy ($IMR_LOCATOR->Executable (), $BIN_IMR_LOCATOR->Executable ()); + unlink $BIN_IMR_ACTIVATOR->Executable (); + copy ($IMR_ACTIVATOR->Executable (), $BIN_IMR_ACTIVATOR->Executable ()); + + print "Stopping any existing TAO ImR Services\n"; + system("net stop taoimractivator > nul 2>&1"); + system("net stop taoimr > nul 2>&1"); + + print "Removing any existing TAO ImR Services\n"; + $BIN_IMR_ACTIVATOR->Arguments ("-c remove"); + $BIN_IMR_LOCATOR->Arguments ("-c remove"); + $BIN_IMR_ACTIVATOR->SpawnWaitKill (5); + $BIN_IMR_LOCATOR->SpawnWaitKill (5); + + $result = nt_service_test_i ($imr_initref, $BIN_IMR_ACTIVATOR, $BIN_IMR_LOCATOR); + + print "Stopping TAO Implementation Repository Service\n"; + system("net stop taoimractivator 2>&1"); + system("net stop taoimr 2>&1"); + + print "Removing TAO ImR Services\n"; + $BIN_IMR_ACTIVATOR->Arguments ("-c remove"); + $BIN_IMR_ACTIVATOR->SpawnWaitKill (5); + $BIN_IMR_LOCATOR->Arguments ("-c remove"); + $BIN_IMR_LOCATOR->SpawnWaitKill (5); + + print "Removing ImplRepo_Service copy.\n"; + unlink $BIN_IMR_ACTIVATOR->Executable (); + unlink $BIN_IMR_LOCATOR->Executable (); + + return $result; +} + +############################################################################### + +sub airplane_ir_test +{ + my $status = 0; + my $result = 0; + + my $imr_initref = "-ORBInitRef ImplRepoService=file://$imr_locator_ior"; + + $IMR_LOCATOR->Arguments ("-d 2 -o $imr_locator_ior"); + $IMR_LOCATOR->Spawn (); + + if (PerlACE::waitforfile_timed ($imr_locator_ior, 5) == -1) { + print STDERR "ERROR: cannot find $imr_locator_ior\n"; + $IMR_LOCATOR->Kill (); + return 1; + } + + $IMR_ACTIVATOR->Arguments ("-d 2 -o $imr_activator_ior $imr_initref"); + $IMR_ACTIVATOR->Spawn (); + + if (PerlACE::waitforfile_timed ($imr_activator_ior, 5) == -1) { + print STDERR "ERROR: cannot find $imr_activator_ior\n"; + $IMR_ACTIVATOR->Kill (); + return 1; + } + + # No need to specify imr_initref or -orbuseimr 1 for servers spawned by activator + # Can use update to add servers. + $TAO_IMR->Arguments ("$imr_initref update airplane_server -c \"" + . $A_SVR->Executable () + . " -o $airplane_ior \""); + + $result = $TAO_IMR->SpawnWaitKill (5); + if ($result != 0) { + print STDERR "ERROR: tao_imr returned $result\n"; + $IMR_ACTIVATOR->Kill (); + $IMR_LOCATOR->Kill (); + return 1; + } + + $A_SVR->Arguments ("-ORBUseIMR 1 -o $airplane_ior $imr_initref"); + $A_SVR->Spawn (); + + if (PerlACE::waitforfile_timed ($airplane_ior, 10) == -1) { + print STDERR "ERROR: cannot find $airplane_ior\n"; + $IMR_ACTIVATOR->Kill (); + $IMR_LOCATOR->Kill (); + $A_SVR->Kill (); + return 1; + } + + $result = $A_CLI->SpawnWaitKill (10); + if ($result != 0) { + print STDERR "ERROR: airplane_client 1 returned $result\n"; + $status = 1; + } + + $TAO_IMR->Arguments ("$imr_initref shutdown airplane_server"); + + $result = $TAO_IMR->SpawnWaitKill (10); + if ($result != 0) { + print STDERR "ERROR: tao_imr 1 returned $result\n"; + $status = 1; + } + + # This client should force a new airplane_server to be started + $result = $A_CLI->SpawnWaitKill (10); + if ($result != 0) { + print STDERR "ERROR: airplane_client 2 returned $result\n"; + $status = 1; + } + + $result = $TAO_IMR->SpawnWaitKill (10); + if ($result != 0) { + print STDERR "ERROR: tao_imr 2 returned $result\n"; + $status = 1; + } + + my $server = $A_SVR->WaitKill (5); + if ($server != 0) { + print STDERR "ERROR: airplane server returned $server\n"; + $status = 1; + } + + my $imr_activator = $IMR_ACTIVATOR->TerminateWaitKill (5); + if ($imr_activator != 0) { + print STDERR "ERROR: Activator returned $imr_activator\n"; + $status = 1; + } + + my $imr_locator = $IMR_LOCATOR->TerminateWaitKill (5); + if ($imr_locator != 0) { + print STDERR "ERROR: ImR returned $imr_locator\n"; + $status = 1; + } + + return $status; +} + +############################################################################### + +sub nestea_ir_test +{ + my $status = 0; + my $result = 0; + + my $imr_initref = "-orbobjrefstyle URL -ORBInitRef ImplRepoService=file://$imr_locator_ior"; + + $IMR_LOCATOR->Arguments ("-d 2 -o $imr_locator_ior"); + $IMR_LOCATOR->Spawn (); + + if (PerlACE::waitforfile_timed ($imr_locator_ior, 10) == -1) { + print STDERR "ERROR: cannot find $imr_locator_ior\n"; + $IMR_LOCATOR->Kill (); + return 1; + } + + $IMR_ACTIVATOR->Arguments ("-d 2 -o $imr_activator_ior $imr_initref"); + $IMR_ACTIVATOR->Spawn (); + + if (PerlACE::waitforfile_timed ($imr_activator_ior, 30) == -1) { + print STDERR "ERROR: cannot find $imr_activator_ior\n"; + $IMR_ACTIVATOR->Kill (); + $IMR_LOCATOR->Kill (); + return 1; + } + + $N_SVR->Arguments ("-ORBUseIMR 1 -o $nestea_ior $imr_initref"); + $N_SVR->Spawn (); + + if (PerlACE::waitforfile_timed ($nestea_ior, 10) == -1) { + print STDERR "ERROR: cannot find $nestea_ior\n"; + $N_SVR->Kill (); + $IMR_ACTIVATOR->Kill (); + $IMR_LOCATOR->Kill (); + return 1; + } + + $result = $N_CLI->SpawnWaitKill (10); + if ($result != 0) { + print STDERR "ERROR: nestea client 1 returned $result\n"; + $status = 1; + } + + $TAO_IMR->Arguments ("$imr_initref shutdown nestea_server"); + + $result = $TAO_IMR->SpawnWaitKill (10); + if ($result != 0) { + print STDERR "ERROR: tao_imr 1 returned $result\n"; + $status = 1; + } + + my $server = $N_SVR->WaitKill (5); + if ($server != 0) { + print STDERR "ERROR: nestea server returned $server\n"; + $status = 1; + } + + # No need to specify imr_initref or -orbuseimr 1 for servers spawned by activator + $TAO_IMR->Arguments ("$imr_initref update nestea_server -l $host -c \"" + . $N_SVR->Executable () + . " -o $nestea_ior\""); + $result = $TAO_IMR->SpawnWaitKill (10); + if ($result != 0) { + print STDERR "ERROR: tao_imr returned $result\n"; + $IMR_ACTIVATOR->Kill (); + $IMR_LOCATOR->Kill (); + return 1; + } + + # This should cause the activator to spawn another server. + $result = $N_CLI->SpawnWaitKill (20); + if ($result != 0) { + print STDERR "ERROR: nestea client 2 returned $result\n"; + $status = 1; + } + + $TAO_IMR->Arguments ("$imr_initref shutdown nestea_server"); + $result = $TAO_IMR->SpawnWaitKill (10); + if ($result != 0) { + print STDERR "ERROR: tao_imr 1 returned $result\n"; + $status = 1; + } + + # This should destroy the POA, causing another to be created the next time + # the server is spawned. + $TAO_IMR->Arguments ("$imr_initref remove nestea_server"); + $result = $TAO_IMR->SpawnWaitKill (10); + if ($result != 0) { + print STDERR "ERROR: tao_imr 1 returned $result\n"; + $status = 1; + } + + # No need to specify imr_initref or -orbuseimr 1 for servers spawned by activator + $TAO_IMR->Arguments ("$imr_initref add nestea_server -c \"" + . $N_SVR->Executable () + . " -o $nestea_ior\""); + + $result = $TAO_IMR->SpawnWaitKill (10); + if ($result != 0) { + print STDERR "ERROR: tao_imr returned $result\n"; + $IMR_ACTIVATOR->Kill (); + $IMR_LOCATOR->Kill (); + return 1; + } + + # This should cause the activator to spawn another server. + $result = $N_CLI->SpawnWaitKill (20); + if ($result != 0) { + print STDERR "ERROR: nestea client 2 returned $result\n"; + $status = 1; + } + + # This call should block until the server shuts down + $TAO_IMR->Arguments ("$imr_initref shutdown nestea_server"); + $result = $TAO_IMR->SpawnWaitKill (10); + if ($result != 0) { + print STDERR "ERROR: tao_imr 1 returned $result\n"; + $status = 1; + } + + my $implrepo = $IMR_ACTIVATOR->TerminateWaitKill (5); + if ($implrepo != 0) { + print STDERR "ERROR: IMR_Activator returned $implrepo\n"; + $status = 1; + } + + $implrepo = $IMR_LOCATOR->TerminateWaitKill (5); + if ($implrepo != 0) { + print STDERR "ERROR: IMR_Locator returned $implrepo\n"; + $status = 1; + } + + return $status; +} + +############################################################################### + +sub perclient +{ + my $status = 0; + my $result = 0; + + my $imr_initref = "-orbobjrefstyle URL -ORBInitRef ImplRepoService=file://$imr_locator_ior"; + + # specify an endpoint so that we can use corbaloc url for the client. + $IMR_LOCATOR->Arguments ("-d 2 -orbendpoint iiop://:8888 -o $imr_locator_ior"); + $IMR_LOCATOR->Spawn (); + + if (PerlACE::waitforfile_timed ($imr_locator_ior, 10) == -1) { + print STDERR "ERROR: cannot find $imr_locator_ior\n"; + $IMR_LOCATOR->Kill (); + return 1; + } + + $IMR_ACTIVATOR->Arguments ("-d 2 -o $imr_activator_ior $imr_initref"); + $IMR_ACTIVATOR->Spawn (); + + if (PerlACE::waitforfile_timed ($imr_activator_ior, 30) == -1) { + print STDERR "ERROR: cannot find $imr_activator_ior\n"; + $IMR_ACTIVATOR->Kill (); + $IMR_LOCATOR->Kill (); + return 1; + } + + # No need to specify imr_initref or -orbuseimr 1 for servers spawned by activator + $TAO_IMR->Arguments ("$imr_initref add nestea_server -a PER_CLIENT -c \"" + . $N_SVR->Executable () + . " -o $nestea_ior\""); + $result = $TAO_IMR->SpawnWaitKill (10); + if ($result != 0) { + print STDERR "ERROR: tao_imr returned $result\n"; + $IMR_ACTIVATOR->Kill (); + $IMR_LOCATOR->Kill (); + return 1; + } + + $N_CLI->Arguments("-k corbaloc::localhost:8888/nestea_server"); + + # Running the client should start a server instance + $result = $N_CLI->SpawnWaitKill (10); + if ($result != 0) { + print STDERR "ERROR: nestea client 1 returned $result\n"; + $status = 1; + } + if (PerlACE::waitforfile_timed ($nestea_ior, 10) == -1) { + print STDERR "ERROR: cannot find $nestea_ior\n"; + $IMR_ACTIVATOR->Kill (); + $IMR_LOCATOR->Kill (); + return 1; + } + + unlink $nestea_ior; + + $N_CLI->Arguments("-s -k corbaloc::localhost:8888/nestea_server"); + + # Running the client again should start another server instance + $result = $N_CLI->SpawnWaitKill (10); + if ($result != 0) { + print STDERR "ERROR: nestea client 2 returned $result\n"; + $status = 1; + } + if (PerlACE::waitforfile_timed ($nestea_ior, 10) == -1) { + print STDERR "ERROR: cannot find $nestea_ior\n"; + $IMR_ACTIVATOR->Kill (); + $IMR_LOCATOR->Kill (); + return 1; + } + + # Note : We have to wait long enough for the first server to self-destruct + # or it will print out an exception when it can't notify the imr of its shutdown. + sleep 10; + + my $implrepo = $IMR_ACTIVATOR->TerminateWaitKill (5); + if ($implrepo != 0) { + print STDERR "ERROR: IMR_Activator returned $implrepo\n"; + $status = 1; + } + + $implrepo = $IMR_LOCATOR->TerminateWaitKill (5); + if ($implrepo != 0) { + print STDERR "ERROR: IMR_Locator returned $implrepo\n"; + $status = 1; + } + + return $status; +} + +############################################################################### + +sub shutdown_repo +{ + my $status = 0; + my $result = 0; + + my $imr_initref = "-orbobjrefstyle URL -ORBInitRef ImplRepoService=file://$imr_locator_ior"; + + unlink "test.repo"; + + # Specify an endpoint so that we can restart on the same port. + # Specify persistence so that we can test that shutdown-repo -a works after reconnect + $IMR_LOCATOR->Arguments ("-p test.repo -d 1 -orbendpoint iiop://:8888 -o $imr_locator_ior"); + + unlink $imr_locator_ior; + $IMR_LOCATOR->Spawn (); + if (PerlACE::waitforfile_timed ($imr_locator_ior, 10) == -1) { + print STDERR "ERROR: cannot find $imr_locator_ior\n"; + $IMR_LOCATOR->Kill (); + return 1; + } + + $IMR_ACTIVATOR->Arguments ("-d 1 -o $imr_activator_ior $imr_initref"); + $IMR_ACTIVATOR->Spawn (); + if (PerlACE::waitforfile_timed ($imr_activator_ior, 30) == -1) { + print STDERR "ERROR: cannot find $imr_activator_ior\n"; + $IMR_ACTIVATOR->Kill (); + $IMR_LOCATOR->Kill (); + return 1; + } + + # Kill the ImR, but leave the activator running + $TAO_IMR->Arguments ("$imr_initref shutdown-repo"); + $result = $TAO_IMR->SpawnWaitKill (5); + if ($result != 0) { + print STDERR "ERROR: tao_imr returned $result\n"; + $IMR_ACTIVATOR->Kill (); + $IMR_LOCATOR->Kill (); + return 1; + } + + my $imr_result = $IMR_LOCATOR->WaitKill (5); + if ($imr_result != 0) { + print STDERR "ERROR: ImR returned $imr_result\n"; + return 1; + } + + unlink $imr_locator_ior; + $IMR_LOCATOR->Spawn (); + if (PerlACE::waitforfile_timed ($imr_locator_ior, 10) == -1) { + print STDERR "ERROR: cannot find $imr_locator_ior\n"; + $IMR_LOCATOR->Kill (); + return 1; + } + + $TAO_IMR->Arguments ("$imr_initref shutdown-repo -a"); + $result = $TAO_IMR->SpawnWaitKill (5); + if ($result != 0) { + print STDERR "ERROR: tao_imr returned $result\n"; + $IMR_ACTIVATOR->Kill (); + $IMR_LOCATOR->Kill (); + return 1; + } + + $imr_result = $IMR_ACTIVATOR->WaitKill (5); + if ($imr_result != 0) { + print STDERR "ERROR: IMR_Activator returned $imr_result\n"; + return 1; + } + + $imr_result = $IMR_LOCATOR->WaitKill (5); + if ($imr_result != 0) { + print STDERR "ERROR: IMR_Locator returned $imr_result\n"; + return 1; + } + + unlink "test.repo"; + + return $status; +} + +############################################################################### + +sub persistent_ir_test +{ + my $result = 0; + + my $imr_initref = "-ORBInitRef ImplRepoService=file://$imr_locator_ior"; + + unlink $imr_locator_ior; + ## Be sure to start the ImR on a consistent endpoint, so that any created IORs + ## remain valid even if the ImR restarts. + $IMR_LOCATOR->Arguments ("-orbendpoint iiop://:8888 -x $backing_store -d 2 -o $imr_locator_ior"); + $IMR_LOCATOR->Spawn (); + if (PerlACE::waitforfile_timed ($imr_locator_ior, 10) == -1) { + print STDERR "ERROR: cannot find $imr_locator_ior\n"; + $IMR_LOCATOR->Kill (); + return 1; + } + + unlink $imr_activator_ior; + $IMR_ACTIVATOR->Arguments ("-d 2 -o $imr_activator_ior $imr_initref"); + $IMR_ACTIVATOR->Spawn (); + if (PerlACE::waitforfile_timed ($imr_activator_ior, 10) == -1) { + print STDERR "ERROR: cannot find $imr_activator_ior\n"; + $IMR_ACTIVATOR->Kill (); + $IMR_LOCATOR->Kill (); + return 1; + } + + unlink $P_SVR->Executable(); + # Copy the server to a path with spaces to ensure that these + # work corrrectly. + copy ($A_SVR->Executable(), $P_SVR->Executable()); + chmod(0755, $P_SVR->Executable()); + + # No need to specify imr_initref or -orbuseimr 1 for servers spawned by activator + $TAO_IMR->Arguments ("$imr_initref add airplane_server -c \"" + . '\"' . $P_SVR->Executable() . '\"' . "\" " . $refstyle); + $result = $TAO_IMR->SpawnWaitKill (10); + + if ($result != 0) { + print STDERR "ERROR: tao_imr returned $result\n"; + unlink $P_SVR->Executable(); + return 1; + } + + unlink $airplane_ior; + ## This will write out the imr-ified IOR. Note : If you don't use -orbendpoint + ## when starting the ImR, then this IOR will no longer be valid when the ImR + ## restarts below. You can fix this by creating a new valid IOR, or starting + ## the ImR on a consistent endpoint. + $A_SVR->Arguments ("-o $airplane_ior -ORBUseIMR 1 $refstyle $imr_initref"); + $A_SVR->Spawn (); + if (PerlACE::waitforfile_timed ($airplane_ior, 10) == -1) { + print STDERR "ERROR: cannot find $airplane_ior\n"; + $IMR_LOCATOR->Kill (); + $IMR_ACTIVATOR->Kill (); + $A_SVR->Kill (); + return 1; + } + + $result = $A_CLI->SpawnWaitKill (10); + if ($result != 0) { + print STDERR "ERROR: airplane client returned $result\n"; + $IMR_LOCATOR->Kill (); + $IMR_ACTIVATOR->Kill (); + $A_SVR->Kill (); + return 1; + } + + $TAO_IMR->Arguments ("$imr_initref shutdown airplane_server"); + $result = $TAO_IMR->SpawnWaitKill (10); + if ($result != 0) { + print STDERR "ERROR: tao_imr shutdown returned $result\n"; + $IMR_LOCATOR->Kill (); + $IMR_ACTIVATOR->Kill (); + $A_SVR->Kill (); + return 1; + } + + $result = $A_SVR->WaitKill (1); + if ($result != 0) { + print STDERR "ERROR: airplane server returned $result\n"; + $IMR_LOCATOR->Kill (); + $IMR_ACTIVATOR->Kill (); + return 1; + } + + # Should cause the activator to spawn another server. + $result = $A_CLI->SpawnWaitKill (20); + if ($result != 0) { + print STDERR "ERROR: airplane client 2 returned $result\n"; + $IMR_LOCATOR->Kill (); + $IMR_ACTIVATOR->Kill (); + return 1; + } + + # Shutdown airplane_server + $result = $TAO_IMR->SpawnWaitKill (10); + if ($result != 0) { + print STDERR "ERROR: tao_imr shutdown 2 returned $result\n"; + $IMR_LOCATOR->Kill (); + $IMR_ACTIVATOR->Kill (); + return 1; + } + + my $implrepo = $IMR_LOCATOR->TerminateWaitKill (5); + if ($implrepo != 0) { + print STDERR "ERROR: IMR_Locator returned $implrepo\n"; + $IMR_ACTIVATOR->Kill (); + return 1; + } + + # Unlink so that we can wait on them again to know the server started. + unlink $imr_locator_ior; + print "Restarting Implementation Repository.\n"; + $IMR_LOCATOR->Spawn (); + if (PerlACE::waitforfile_timed ($imr_locator_ior, 10) == -1) { + print STDERR "ERROR: cannot find $imr_locator_ior\n"; + $IMR_LOCATOR->Kill (); + return 1; + } + + # Should cause the activator to spawn another server. + $result = $A_CLI->SpawnWaitKill (20); + if ($result != 0) { + print STDERR "ERROR: airplane client 3 returned $result\n"; + $IMR_LOCATOR->Kill (); + $IMR_ACTIVATOR->Kill (); + return 1; + } + + # Shutdown airplane_server + $result = $TAO_IMR->SpawnWaitKill (10); + if ($result != 0) { + print STDERR "ERROR: tao_imr shutdown 3 returned $result\n"; + $IMR_LOCATOR->Kill (); + $IMR_ACTIVATOR->Kill (); + return 1; + } + + $result = $IMR_ACTIVATOR->TerminateWaitKill (5); + if ($result != 0) { + print STDERR "ERROR: IMR_Activator returned $result\n"; + $IMR_LOCATOR->Kill (); + return 1; + } + + $result = $IMR_LOCATOR->TerminateWaitKill (5); + if ($result != 0) { + print STDERR "ERROR: IMR_Locator returned $result\n"; + return 1; + } + + unlink $P_SVR->Executable(); + unlink $imr_locator_ior; + unlink $imr_activator_ior; + unlink $airplane_ior; + + return 0; +} + +############################################################################### + +sub both_ir_test +{ + my $status = 0; + + my $imr_initref = "-ORBInitRef ImplRepoService=file://$imr_locator_ior"; + + $IMR_LOCATOR->Arguments ("-d 2 -t 5 -o $imr_locator_ior $refstyle"); + $IMR_LOCATOR->Spawn (); + + if (PerlACE::waitforfile_timed ($imr_locator_ior, 10) == -1) { + print STDERR "ERROR: cannot find $imr_locator_ior\n"; + $IMR_LOCATOR->Kill (); + return 1; + } + + $IMR_ACTIVATOR->Arguments ("-o $imr_activator_ior $imr_initref $refstyle -d 2"); + $IMR_ACTIVATOR->Spawn (); + + if (PerlACE::waitforfile_timed ($imr_activator_ior, 10) == -1) { + print STDERR "ERROR: cannot find $imr_activator_ior\n"; + $IMR_ACTIVATOR->Kill (); + $IMR_LOCATOR->Kill (); + return 1; + } + + ## Note : It's crucial NOT to write out an IOR file when the activator + ## starts the server, or at least to write out a different file name + ## than the IOR files we're using for the clients. Otherwise a client + ## may attempt to use a partially written file. + # No need to specify imr_initref or -orbuseimr 1 for servers spawned by activator + $TAO_IMR->Arguments ("$imr_initref add nestea_server -c \"" + . $N_SVR->Executable () + . " $refstyle\""); + $TAO_IMR->SpawnWaitKill (10); + + # No need to specify imr_initref or -orbuseimr 1 for servers spawned by activator + $TAO_IMR->Arguments ("$imr_initref add airplane_server -c \"" + . $A_SVR->Executable () + . " $refstyle\""); + $TAO_IMR->SpawnWaitKill (10); + + $N_SVR->Arguments (" -o $nestea_ior -ORBUseIMR 1 $imr_initref $refstyle"); + $N_SVR->Spawn (); + if (PerlACE::waitforfile_timed ($nestea_ior, 10) == -1) { + print STDERR "ERROR: cannot find $nestea_ior\n"; + $IMR_ACTIVATOR->Kill (); + $IMR_LOCATOR->Kill (); + $A_SVR->Kill (); + $N_SVR->Kill (); + return 1; + } + + $A_SVR->Arguments (" -o $airplane_ior -ORBUseIMR 1 $imr_initref $refstyle"); + $A_SVR->Spawn (); + if (PerlACE::waitforfile_timed ($airplane_ior, 10) == -1) { + print STDERR "ERROR: cannot find $airplane_ior\n"; + $IMR_ACTIVATOR->Kill (); + $IMR_LOCATOR->Kill (); + $A_SVR->Kill (); + $N_SVR->Kill (); + return 1; + } + + my @clients; + + for (1 .. 5) { + push @clients, &create_acli(); + push @clients, &create_ncli(); + } + + print "\n## Spawning multiple simultaneous clients with both servers running.\n"; + map $_->Spawn(), @clients; + map $_->WaitKill(30), @clients; + + $TAO_IMR->Arguments ("$imr_initref shutdown nestea_server"); + $TAO_IMR->SpawnWaitKill (15); + + $TAO_IMR->Arguments ("$imr_initref shutdown airplane_server"); + $TAO_IMR->SpawnWaitKill (15); + + $A_SVR->WaitKill(1); + $N_SVR->WaitKill(1); + + print "\n\n\n\n## Spawning multiple simultaneous clients with no servers running.\n"; + + map $_->Spawn(), @clients; + map $_->WaitKill(30), @clients; + + $TAO_IMR->Arguments ("$imr_initref shutdown nestea_server"); + $TAO_IMR->SpawnWaitKill (15); + $TAO_IMR->Arguments ("$imr_initref shutdown airplane_server"); + $TAO_IMR->SpawnWaitKill (15); + + $IMR_ACTIVATOR->Kill (); + $IMR_LOCATOR->Kill (); +} + +############################################################################### +############################################################################### + +# Parse the arguments + +my $ret = 0; + +if ($#ARGV >= 0) { +for (my $i = 0; $i <= $#ARGV; $i++) { + if ($ARGV[$i] eq "-h" || $ARGV[$i] eq "-?") { + print "run_test test\n"; + print "\n"; + print "test -- Runs a specific test:\n"; + print " airplane, airplane_ir, nt_service_ir, ", + "nestea, nestea_ir,\n"; + print " both_ir, persistent_ir\n"; + exit 1; + } + elsif ($ARGV[$i] eq "airplane") { + $ret = airplane_test (); + } + elsif ($ARGV[$i] eq "airplane_ir") { + $ret = airplane_ir_test (); + } + elsif ($ARGV[$i] eq "nt_service_ir") { + $ret = nt_service_test (); + } + elsif ($ARGV[$i] eq "nestea") { + $ret = nestea_test (); + } + elsif ($ARGV[$i] eq "nestea_ir") { + $ret = nestea_ir_test (); + } + elsif ($ARGV[$i] eq "both_ir") { + $ret = both_ir_test (); + } + elsif ($ARGV[$i] eq "persistent_ir") { + $ret = persistent_ir_test (); + } + elsif ($ARGV[$i] eq "perclient") { + $ret = perclient(); + } + elsif ($ARGV[$i] eq "shutdown") { + $ret = shutdown_repo(); + } + else { + print "run_test: Unknown Option: ".$ARGV[$i]."\n"; + } +} +} else { + $ret = both_ir_test(); +} + + +# Make sure the files are gone, so we can wait on them. +unlink $airplane_ior; +unlink $nestea_ior; +unlink $imr_locator_ior; +unlink $imr_activator_ior; +unlink $backing_store; +unlink $nestea_dat; +unlink $P_SVR->Executable(); + +exit $ret; diff --git a/TAO/orbsvcs/tests/ImplRepo/scale/Makefile.am b/TAO/orbsvcs/tests/ImplRepo/scale/Makefile.am new file mode 100644 index 00000000000..7b336b7db96 --- /dev/null +++ b/TAO/orbsvcs/tests/ImplRepo/scale/Makefile.am @@ -0,0 +1,112 @@ +## 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_IDL = ACE_ROOT=$(ACE_ROOT) TAO_ROOT=$(TAO_ROOT) $(TAO_BUILDDIR)/TAO_IDL/tao_idl +TAO_IDL_DEP = $(TAO_BUILDDIR)/TAO_IDL/tao_idl +TAO_IDLFLAGS = -Ge 1 -Wb,pre_include=ace/pre.h -Wb,post_include=ace/post.h -I$(TAO_ROOT) -I$(srcdir) -g $(ACE_BUILDDIR)/apps/gperf/src/gperf +TAO_ROOT = $(top_srcdir) + +noinst_PROGRAMS = + +## Makefile.scaletest_idl.am + +BUILT_SOURCES = \ + testC.cpp \ + testC.h \ + testC.inl \ + testS.cpp \ + testS.h \ + testS.inl + +CLEANFILES = \ + test-stamp \ + testC.cpp \ + testC.h \ + testC.inl \ + testS.cpp \ + testS.h \ + testS.inl + +testC.cpp testC.h testC.inl testS.cpp testS.h testS.inl: test-stamp + +test-stamp: $(srcdir)/test.idl $(TAO_IDL_DEP) + $(TAO_IDL) $(TAO_IDLFLAGS) -Sa -St $(srcdir)/test.idl + @touch $@ + + +noinst_HEADERS = \ + test.idl + +## Makefile.scaletest_client.am + +if !BUILD_MINIMUM_CORBA + +noinst_PROGRAMS += client + +client_CPPFLAGS = \ + -I$(ACE_ROOT) \ + -I$(ACE_BUILDDIR) \ + -I$(TAO_ROOT) \ + -I$(TAO_BUILDDIR) + +client_SOURCES = \ + client.cpp \ + testC.cpp \ + testS.cpp \ + server_i.h + +client_LDADD = \ + $(TAO_BUILDDIR)/tao/libTAO_IORTable.la \ + $(TAO_BUILDDIR)/tao/libTAO_PortableServer.la \ + $(TAO_BUILDDIR)/tao/libTAO_AnyTypeCode.la \ + $(TAO_BUILDDIR)/tao/libTAO.la \ + $(ACE_BUILDDIR)/ace/libACE.la + +endif !BUILD_MINIMUM_CORBA + +## Makefile.scaletest_server.am + +if !BUILD_MINIMUM_CORBA + +noinst_PROGRAMS += server + +server_CPPFLAGS = \ + -I$(ACE_ROOT) \ + -I$(ACE_BUILDDIR) \ + -I$(TAO_ROOT) \ + -I$(TAO_BUILDDIR) + +server_SOURCES = \ + server.cpp \ + server_i.cpp \ + testC.cpp \ + testS.cpp \ + server_i.h + +server_LDADD = \ + $(TAO_BUILDDIR)/tao/libTAO_ImR_Client.la \ + $(TAO_BUILDDIR)/tao/libTAO_IORTable.la \ + $(TAO_BUILDDIR)/tao/libTAO_PortableServer.la \ + $(TAO_BUILDDIR)/tao/libTAO_AnyTypeCode.la \ + $(TAO_BUILDDIR)/tao/libTAO.la \ + $(ACE_BUILDDIR)/ace/libACE.la + +endif !BUILD_MINIMUM_CORBA + +## 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/ImplRepo/scale/client.conf b/TAO/orbsvcs/tests/ImplRepo/scale/client.conf new file mode 100644 index 00000000000..87e77efbd29 --- /dev/null +++ b/TAO/orbsvcs/tests/ImplRepo/scale/client.conf @@ -0,0 +1,4 @@ +# This file is here just in case you want to run some of the tests manually +# and don't want the client to jump back in the reactor during the +# invocation. +static Client_Strategy_Factory "-ORBClientConnectionHandler rw" diff --git a/TAO/orbsvcs/tests/ImplRepo/scale/client.cpp b/TAO/orbsvcs/tests/ImplRepo/scale/client.cpp new file mode 100644 index 00000000000..f5e1e660533 --- /dev/null +++ b/TAO/orbsvcs/tests/ImplRepo/scale/client.cpp @@ -0,0 +1,41 @@ +// $Id$ +// This is a simple test of an ImR using the corba interfaces +// Start with -orbinitref Test=... + +#include "testC.h" +#include "ace/Log_Msg.h" + +using namespace CORBA; + +int main(int argc, char* argv[]) { + + ACE_TRY_NEW_ENV + { + + ORB_var orb = ORB_init(argc, argv, 0 ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + Object_var obj = orb->resolve_initial_references("Test" ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + test_var test = test::_narrow(obj.in() ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + ACE_ASSERT(! is_nil(test.in())); + + Long n = test->get(ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_TRY_CHECK; + Long m = test->get(ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_TRY_CHECK; + if (m == n + 1) + ACE_DEBUG((LM_DEBUG, "Client: All tests ran successfully.\n")); + else + ACE_DEBUG((LM_DEBUG, "Error: Client Expected %d = %d + 1.\n", m, n)); + + return 0; + } + ACE_CATCHANY + { + ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, "client:"); + } + ACE_ENDTRY; + return -1; +} diff --git a/TAO/orbsvcs/tests/ImplRepo/scale/run_test.pl b/TAO/orbsvcs/tests/ImplRepo/scale/run_test.pl new file mode 100755 index 00000000000..ccbc5f6ba44 --- /dev/null +++ b/TAO/orbsvcs/tests/ImplRepo/scale/run_test.pl @@ -0,0 +1,217 @@ +eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}' + & eval 'exec perl -S $0 $argv:q' + if 0; + +# $Id$ +# -*- perl -*- + +############################################################################### +my $ACE_ROOT = $ENV{ACE_ROOT}; + +use lib "$ENV{ACE_ROOT}/bin"; +use PerlACE::Run_Test; +use Cwd; +use Sys::Hostname; +use File::Copy; + +use strict; + +my $cwd = getcwd(); + +if (!defined $ACE_ROOT) { + print "Error: ACE_ROOT not defined.\n"; + return 1; +} + +my $imr_activator_ior = PerlACE::LocalFile ("imr_activator.ior"); +my $imr_locator_ior = PerlACE::LocalFile ("imr_locator.ior"); + +my $refstyle = " -ORBobjrefstyle URL"; + +my $persistxml = PerlACE::LocalFile ("persist.xml"); +my $persist = PerlACE::LocalFile ("persist.dat"); + +my $IMR_LOCATOR = new PerlACE::Process ("$ACE_ROOT/TAO/orbsvcs/ImplRepo_Service/ImplRepo_Service"); +my $IMR_ACTIVATOR = new PerlACE::Process ("$ACE_ROOT/TAO/orbsvcs/ImplRepo_Service/ImR_Activator"); +my $TAO_IMR = new PerlACE::Process("$ACE_ROOT/bin/tao_imr"); + +my $SVR = new PerlACE::Process (PerlACE::LocalFile ("server")); +my $CLI = new PerlACE::Process (PerlACE::LocalFile ("client")); + +my $servers_count = 1; +my $obj_count = 1; +my $use_activator = 0; + +my $objprefix = "TstObj"; +my $client_wait_time = 5; + +# Make sure the files are gone, so we can wait on them. +unlink $imr_locator_ior; +unlink $imr_activator_ior; +unlink $persistxml; +unlink $persist; + +sub scale_test +{ + print "Running scale test with $servers_count servers and $obj_count objects.\n"; + + my $status = 0; + my $result = 0; + my $start_time = time(); + + my $imr_initref = "-ORBInitRef ImplRepoService=file://$imr_locator_ior"; + + $IMR_LOCATOR->Arguments ("-d 1 -o $imr_locator_ior -orbendpoint iiop://:9876"); + $IMR_LOCATOR->Spawn (); + if (PerlACE::waitforfile_timed ($imr_locator_ior, 5) == -1) { + print STDERR "ERROR: cannot find $imr_locator_ior\n"; + $IMR_LOCATOR->Kill (); + return 1; + } + + if ($use_activator) { + + $IMR_ACTIVATOR->Arguments ("-d 1 -o $imr_activator_ior $imr_initref"); + $IMR_ACTIVATOR->Spawn (); + if (PerlACE::waitforfile_timed ($imr_activator_ior, 5) == -1) { + print STDERR "ERROR: cannot find $imr_activator_ior\n"; + $IMR_ACTIVATOR->Kill (); + return 1; + } + + for(my $i = 0; $i < $servers_count; $i++) { + for (my $j = 0; $j < $obj_count; $j++) { + $TAO_IMR->Arguments ("$imr_initref add $objprefix" . '_' . $i . "_" . $j . " -c \"" + . $SVR->Executable () + . " -ORBUseIMR 1 -p $objprefix" . '_' . "$i -c $obj_count $imr_initref\""); + + $result = $TAO_IMR->SpawnWaitKill (5); + if ($result != 0) { + print STDERR "ERROR: tao_imr returned $result\n"; + $IMR_ACTIVATOR->Kill (); + $IMR_LOCATOR->Kill (); + return 1; + } + } + } + + $TAO_IMR->Arguments ("$imr_initref list"); + $result = $TAO_IMR->SpawnWaitKill (25); + if ($result != 0) { + print STDERR "ERROR: tao_imr list returned $result\n"; + $IMR_ACTIVATOR->Kill (); + $IMR_LOCATOR->Kill (); + return 1; + } + } + + for(my $i = 0; $i < $servers_count; $i++ ) { + + my $server_start_file = PerlACE::LocalFile ($objprefix . "_$i.status"); + unlink $server_start_file; + + if (! $use_activator) { + $SVR->Arguments ("-ORBUseIMR 1 -p $objprefix" . '_' . "$i -c $obj_count $imr_initref"); + $SVR->Spawn (); + if (PerlACE::waitforfile_timed ($server_start_file, 10) == -1) { + print STDERR "ERROR: cannot find $server_start_file\n"; + $IMR_ACTIVATOR->Kill (); + $IMR_LOCATOR->Kill (); + $SVR->Kill (); + return 1; + } + } else { + # For some reason the servers take forever to spawn when using the activator + $client_wait_time *= $obj_count; + } + unlink $server_start_file; + + for (my $j = 0; $j < $obj_count; $j++) { + $CLI->Arguments ("-orbinitref Test=corbaloc::localhost:9876/$objprefix" . '_' . $i . '_' . $j); + $result = $CLI->SpawnWaitKill ($client_wait_time); + if ($result != 0) { + print STDERR "ERROR: client returned $result\n"; + $status = 1; + last; + } + } + + # Shutting down any server object within the server will shutdown the whole server + $TAO_IMR->Arguments ("$imr_initref shutdown $objprefix" . '_' . $i . "_0"); + $result = $TAO_IMR->SpawnWaitKill (10); + if ($result != 0) { + print STDERR "ERROR: tao_imr shutdown returned $result\n"; + $status = 1; + last; + } + if (! $use_activator) { + $result = $SVR->WaitKill(5); + if ($result != 0) { + print STDERR "ERROR: server not shutdown correctly.\n"; + $status = 1; + last; + } + } + + if ($status == 1) { + last; + } + } + + if ($use_activator) { + my $imr_activator = $IMR_ACTIVATOR->TerminateWaitKill (5); + if ($imr_activator != 0) { + print STDERR "ERROR: IMR returned $imr_activator\n"; + $status = 1; + } + } + + my $imr_locator = $IMR_LOCATOR->TerminateWaitKill (5); + if ($imr_locator != 0) { + print STDERR "ERROR: IMR returned $imr_locator\n"; + $status = 1; + } + + my $test_time = time() - $start_time; + my $total_objs = $obj_count * $servers_count; + + print "\nFinished. The test took $test_time seconds for $total_objs imr-ified objects.\n"; + + return $status; +} + +sub usage() { + print "Usage: run_test.pl [-servers <num=1>] [-objects <num=1>] [-use_activator]\n"; +} + +############################################################################### +############################################################################### + +if ($#ARGV >= 0) { + for (my $i = 0; $i <= $#ARGV; $i++) { + if ($ARGV[$i] eq "-servers") { + $i++; + $servers_count = $ARGV[$i]; + } + elsif ($ARGV[$i] eq "-objects") { + $i++; + $obj_count = $ARGV[$i]; + } + elsif ($ARGV[$i] eq "-use_activator") { + $use_activator = 1; + } + else { + usage(); + exit 1; + } + } +} + +my $ret = scale_test(); + +unlink $imr_locator_ior; +unlink $imr_activator_ior; +unlink $persistxml; +unlink $persist; + +exit $ret; diff --git a/TAO/orbsvcs/tests/ImplRepo/scale/scaletest.mpc b/TAO/orbsvcs/tests/ImplRepo/scale/scaletest.mpc new file mode 100644 index 00000000000..5e8640bf068 --- /dev/null +++ b/TAO/orbsvcs/tests/ImplRepo/scale/scaletest.mpc @@ -0,0 +1,35 @@ +// $Id$ +project(*idl): taoidldefaults { + IDL_Files { + test.idl + } + + custom_only = 1 +} + +project(*server) : portableserver, orbsvcsexe, minimum_corba, iortable, imr_client { + after += *idl + + IDL_Files { + } + + Source_Files { + testC.cpp + testS.cpp + server_i.cpp + server.cpp + } +} + +project(*client) : portableserver, orbsvcsexe, minimum_corba, iortable { + after += *idl + + IDL_Files { + } + + Source_Files { + testC.cpp + testS.cpp + client.cpp + } +} diff --git a/TAO/orbsvcs/tests/ImplRepo/scale/server.cpp b/TAO/orbsvcs/tests/ImplRepo/scale/server.cpp new file mode 100644 index 00000000000..769d8126ae4 --- /dev/null +++ b/TAO/orbsvcs/tests/ImplRepo/scale/server.cpp @@ -0,0 +1,37 @@ +// $Id$ + +#include "server_i.h" + +int +main (int argc, char *argv[]) +{ + ACE_DECLARE_NEW_CORBA_ENV; + ACE_TRY + { + Server_i server; + + int retval = server.init (argc, argv ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + if (retval == -1) + return -1; + else + { + server.run (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_TRY_CHECK; + } + } + ACE_CATCH (CORBA::SystemException, sysex) + { + ACE_PRINT_EXCEPTION (sysex, "Server: System Exception"); + return -1; + } + ACE_CATCH (CORBA::UserException, userex) + { + ACE_PRINT_EXCEPTION (userex, "Server: User Exception"); + return -1; + } + ACE_ENDTRY; + + return 0; +} diff --git a/TAO/orbsvcs/tests/ImplRepo/scale/server_i.cpp b/TAO/orbsvcs/tests/ImplRepo/scale/server_i.cpp new file mode 100644 index 00000000000..21edebb203f --- /dev/null +++ b/TAO/orbsvcs/tests/ImplRepo/scale/server_i.cpp @@ -0,0 +1,230 @@ +// $Id$ + +#include "server_i.h" + +#include "tao/IORTable/IORTable.h" +#include "tao/PortableServer/Root_POA.h" +#include "tao/ImR_Client/ImR_Client.h" + +#include "ace/Get_Opt.h" +#include "ace/Read_Buffer.h" +#include "ace/streams.h" + +class test_i + : public virtual POA_test +{ + int n_; + CORBA::ORB_var orb_; +public: + test_i (CORBA::ORB_ptr orb) + : n_(0) + , orb_(CORBA::ORB::_duplicate(orb)) + { + } + virtual ~test_i () { + } + virtual CORBA::Long get (ACE_ENV_SINGLE_ARG_DECL) ACE_THROW_SPEC ((CORBA::SystemException)) { + ++n_; + CORBA::Object_var obj = orb_->resolve_initial_references("POACurrent" ACE_ENV_ARG_PARAMETER); + ACE_CHECK_RETURN(0); + PortableServer::Current_var cur = PortableServer::Current::_narrow(obj.in() ACE_ENV_ARG_PARAMETER); + ACE_CHECK_RETURN(0); + ACE_ASSERT(! CORBA::is_nil(cur.in())); + PortableServer::POA_var poa = cur->get_POA(ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_CHECK_RETURN(0); + CORBA::String_var poaname = poa->the_name(ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_CHECK_RETURN(0); + + ACE_DEBUG((LM_DEBUG, "%s: get() %d\n", poaname.in(), n_)); + return n_; + } +}; + +// The server name of the Aiprlane Server +static const char DEFAULT_SERVER_NAME[] = "TestObject"; + +Server_i::Server_i (void) +: server_name_(DEFAULT_SERVER_NAME) +, count_(1) +{ +} + +Server_i::~Server_i() +{ +} + +int +Server_i::parse_args (int argc, char* argv[]) +{ + ACE_Get_Opt get_opts (argc, argv, "p:c:h"); + int c; + + while ((c = get_opts ()) != -1) + { + switch (c) + { + case 'p': // prefix for all created objects + this->server_name_ = get_opts.opt_arg (); + break; + case 'c': // Number of imr-ified objects to create. + this->count_ = ACE_OS::atoi(get_opts.opt_arg()); + break; + case '?': // display help for use of the server. + case 'h': + default: + ACE_ERROR_RETURN ((LM_ERROR, + "usage: %s" + " [-c] <count=1> ImR-ified objects." + " [-p] <prefix=%s> To all ImR-ified object names." + "\n", + argv[0], + DEFAULT_SERVER_NAME),1); + } + } + + return 0; +} + +namespace +{ + ACE_CString toStr(int n) + { + char buf[20]; + return ACE_OS::itoa(n, buf, 10); + } +} + +int +Server_i::init (int argc, char** argv ACE_ENV_ARG_DECL) +{ + ACE_TRY + { + this->orb_ = CORBA::ORB_init (argc, argv, 0 ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + int retval = this->parse_args (argc, argv); + if (retval != 0) + return retval; + + CORBA::Object_var obj = + this->orb_->resolve_initial_references ("RootPOA" ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + this->root_poa_ = + PortableServer::POA::_narrow (obj.in () ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + ACE_ASSERT(! CORBA::is_nil(this->root_poa_.in())); + + PortableServer::POAManager_var poa_manager = + this->root_poa_->the_POAManager (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_TRY_CHECK; + + obj = this->orb_->resolve_initial_references ("IORTable" ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + IORTable::Table_var ior_table = + IORTable::Table::_narrow (obj.in () ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + ACE_ASSERT(! CORBA::is_nil(ior_table.in())); + + // If -orbuseimr 1 is specified then all persistent poas will be + // registered with the imr. + CORBA::PolicyList policies (2); + policies.length (2); + policies[0] = this->root_poa_->create_id_assignment_policy (PortableServer::USER_ID ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + policies[1] = this->root_poa_->create_lifespan_policy (PortableServer::PERSISTENT ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + test_i* test_svt; + ACE_NEW_RETURN (test_svt, test_i(orb_.in()), -1); + PortableServer::ServantBase_var scoped_svt(test_svt); + + PortableServer::ObjectId_var server_id = + PortableServer::string_to_ObjectId ("Test"); + + // Create count_ POAs, activate an object in each, and register the object with + // the IORTable. + for (int i = 0; i < this->count_; ++i) + { + ACE_CString name = this->server_name_ + "_" + toStr(i); + + PortableServer::POA_var poa = + this->root_poa_->create_POA (name.c_str(), + poa_manager.in (), + policies + ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + poa->activate_object_with_id (server_id.in (), test_svt ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + TAO_Root_POA* tmp_poa = dynamic_cast<TAO_Root_POA*>(poa.in()); + obj = tmp_poa->id_to_reference_i (server_id.in (), false ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + CORBA::String_var ior = this->orb_->object_to_string (obj.in () ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + ior_table->bind (name.c_str(), ior.in () ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + } + + policies[0]->destroy(ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_TRY_CHECK; + policies[1]->destroy(ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_TRY_CHECK; + } + ACE_CATCHANY + { + ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, "Server_i::init"); + ACE_RE_THROW; + } + ACE_ENDTRY; + + ACE_CHECK_RETURN (-1); + + return 0; +} + +int +Server_i::run (ACE_ENV_SINGLE_ARG_DECL) +{ + ACE_TRY + { + PortableServer::POAManager_var poa_manager = + this->root_poa_->the_POAManager (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_TRY_CHECK; + + poa_manager->activate (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_TRY_CHECK; + + // We have potentially lots of IORs, so just write out a simple text + // file that the run_test.pl can use to know we're done. + { + ACE_CString status = this->server_name_ + ACE_CString(".status"); + ofstream out(status.c_str()); + out << "started" << endl; + } + + ACE_DEBUG ((LM_DEBUG, + "\n Started Server %s with %d imr-ified objects.\n\n", + this->server_name_.c_str(), + this->count_)); + + this->orb_->run (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_TRY_CHECK; + + this->root_poa_->destroy(1, 1); + this->orb_->destroy(); + } + ACE_CATCHANY + { + ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, "Server_i::run"); + ACE_RE_THROW; + } + ACE_ENDTRY; + + ACE_CHECK_RETURN (-1); + + return 0; +} + diff --git a/TAO/orbsvcs/tests/ImplRepo/scale/server_i.h b/TAO/orbsvcs/tests/ImplRepo/scale/server_i.h new file mode 100644 index 00000000000..222b179634a --- /dev/null +++ b/TAO/orbsvcs/tests/ImplRepo/scale/server_i.h @@ -0,0 +1,32 @@ +// -*- C++ -*- +// $Id$ + +#if !defined (SERVER_I_H) +#define SERVER_I_H + +#include "testS.h" + +#include "ace/Auto_Ptr.h" +#include "ace/SString.h" + +class Server_i +{ +public: + Server_i (void); + ~Server_i (void); + + int init (int argc, char **argv ACE_ENV_ARG_DECL); + + int run (ACE_ENV_SINGLE_ARG_DECL); + +private: + int parse_args (int argc, char* argv[]); + + CORBA::ORB_var orb_; + PortableServer::POA_var root_poa_; + + ACE_CString server_name_; + int count_; +}; + +#endif /* SERVER_I_H */ diff --git a/TAO/orbsvcs/tests/ImplRepo/scale/test.idl b/TAO/orbsvcs/tests/ImplRepo/scale/test.idl new file mode 100644 index 00000000000..9ff40e9c6a9 --- /dev/null +++ b/TAO/orbsvcs/tests/ImplRepo/scale/test.idl @@ -0,0 +1,4 @@ +// $Id$ +interface test { + long get(); +}; |