diff options
author | William R. Otte <wotte@dre.vanderbilt.edu> | 2006-07-24 15:50:21 +0000 |
---|---|---|
committer | William R. Otte <wotte@dre.vanderbilt.edu> | 2006-07-24 15:50:21 +0000 |
commit | 3aff90f4a822fcf5d902bbfbcc9fa931d6191a8c (patch) | |
tree | 197c810e5f5bce17b1233a7cb8d7b50c0bcd25e2 /TAO/tests/AMH_Exceptions | |
parent | 6b846cf03c0bcbd8c276cb0af61a181e5f98eaae (diff) | |
download | ATCD-3aff90f4a822fcf5d902bbfbcc9fa931d6191a8c.tar.gz |
Repo restructuring
Diffstat (limited to 'TAO/tests/AMH_Exceptions')
-rw-r--r-- | TAO/tests/AMH_Exceptions/.cvsignore | 2 | ||||
-rw-r--r-- | TAO/tests/AMH_Exceptions/AMH_Exceptions.mpc | 15 | ||||
-rw-r--r-- | TAO/tests/AMH_Exceptions/Test.idl | 28 | ||||
-rw-r--r-- | TAO/tests/AMH_Exceptions/client.cpp | 57 | ||||
-rwxr-xr-x | TAO/tests/AMH_Exceptions/run_test.pl | 54 | ||||
-rw-r--r-- | TAO/tests/AMH_Exceptions/server.cpp | 241 |
6 files changed, 397 insertions, 0 deletions
diff --git a/TAO/tests/AMH_Exceptions/.cvsignore b/TAO/tests/AMH_Exceptions/.cvsignore new file mode 100644 index 00000000000..f2ad85300eb --- /dev/null +++ b/TAO/tests/AMH_Exceptions/.cvsignore @@ -0,0 +1,2 @@ +client +server diff --git a/TAO/tests/AMH_Exceptions/AMH_Exceptions.mpc b/TAO/tests/AMH_Exceptions/AMH_Exceptions.mpc new file mode 100644 index 00000000000..5188e4a669b --- /dev/null +++ b/TAO/tests/AMH_Exceptions/AMH_Exceptions.mpc @@ -0,0 +1,15 @@ +// -*- MPC -*- +// $Id$ + +project(*Server): taoserver, amh, strategies { + Source_Files { + server.cpp + } +} + +project(*Client): taoexe, amh, portableserver, strategies { + after += *Server + Source_Files { + client.cpp + } +} diff --git a/TAO/tests/AMH_Exceptions/Test.idl b/TAO/tests/AMH_Exceptions/Test.idl new file mode 100644 index 00000000000..c3ffd609ca4 --- /dev/null +++ b/TAO/tests/AMH_Exceptions/Test.idl @@ -0,0 +1,28 @@ +// +// $Id$ +// + +/// A simple module to avoid namespace pollution +module Test +{ + + exception InvalidTimestamp {}; + exception ServerOverload {}; + + /// Use a timestamp to measure the roundtrip delay + typedef unsigned long long Timestamp; + + valuetype Red_Herring + { + Timestamp test_method (in Timestamp send_time) + raises (InvalidTimestamp, ServerOverload); + }; + + /// Measure roundtrip Delay + interface Roundtrip + { + Timestamp test_method (in Timestamp send_time) + raises (InvalidTimestamp, ServerOverload); + }; + +}; diff --git a/TAO/tests/AMH_Exceptions/client.cpp b/TAO/tests/AMH_Exceptions/client.cpp new file mode 100644 index 00000000000..9ff92b2933d --- /dev/null +++ b/TAO/tests/AMH_Exceptions/client.cpp @@ -0,0 +1,57 @@ +// $Id$ + +#include "TestC.h" + +const char *ior = "file://test.ior"; + +int +main (int argc, char *argv[]) +{ + int received_expected_exception = 0; + ACE_TRY_NEW_ENV + { + CORBA::ORB_var orb = + CORBA::ORB_init (argc, argv, "" ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + CORBA::Object_var object = + orb->string_to_object (ior ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + Test::Roundtrip_var roundtrip = + Test::Roundtrip::_narrow (object.in () ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + if (CORBA::is_nil (roundtrip.in ())) + { + ACE_ERROR_RETURN ((LM_ERROR, + "Nil Test::Roundtrip reference <%s>\n", + ior), + 1); + } + + Test::Timestamp time = 10; + roundtrip->test_method (time ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + } + ACE_CATCH(Test::ServerOverload, ov) + { + ACE_DEBUG ((LM_DEBUG, "Received expected exception\n")); + received_expected_exception = 1; + } + ACE_CATCHANY + { + ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, ""); + return 1; + } + ACE_ENDTRY; + + if(!received_expected_exception) + { + ACE_ERROR_RETURN ((LM_ERROR, + "ERROR, expecting a ServerOverload exception!!\n"), + 1); + } + + return 0; +} diff --git a/TAO/tests/AMH_Exceptions/run_test.pl b/TAO/tests/AMH_Exceptions/run_test.pl new file mode 100755 index 00000000000..4c78cd27121 --- /dev/null +++ b/TAO/tests/AMH_Exceptions/run_test.pl @@ -0,0 +1,54 @@ +eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}' + & eval 'exec perl -S $0 $argv:q' + if 0; + +# $Id$ +# -*- perl -*- + +# This is a Perl script that tests AMH exceptions + +use lib "../../../bin"; +use PerlACE::Run_Test; + +# Amount of delay (in seconds) between starting a server and a client. +$sleeptime = $PerlACE::wait_interval_for_process_creation; + +# File used to pass AMH server ior to its clients. +# This file name is hard-coded in the server.cpp and client.cpp files +$iorfile = PerlACE::LocalFile("test.ior"); + +unlink $iorfile; + +if (PerlACE::is_vxworks_test()) { + $AMH = new PerlACE::ProcessVX ("server", ""); +} +else { + $AMH = new PerlACE::Process ("server", ""); +} +$CL = new PerlACE::Process ("client", ""); + +# Run the AMH server. +$AMH->Spawn (); + +if (PerlACE::waitforfile_timed ($iorfile, $sleeptime) == -1) { + print STDERR "ERROR: File containing AMH Server ior,". + " <$iorfile>, cannot be found\n"; + $AMH->Kill (); + exit 1; +} + + +# Run client. +$client = $CL->SpawnWaitKill (30); + +# Clean up. +$amhserver= $AMH->TerminateWaitKill (5); + +if ($amhserver != 0) { + print STDERR "ERROR: AMH Server returned $amhserver\n"; + $status = 1; +} + +unlink $iorfile; + +exit $status; diff --git a/TAO/tests/AMH_Exceptions/server.cpp b/TAO/tests/AMH_Exceptions/server.cpp new file mode 100644 index 00000000000..05d82934074 --- /dev/null +++ b/TAO/tests/AMH_Exceptions/server.cpp @@ -0,0 +1,241 @@ + +// $Id$ + +#include "ace/OS_NS_stdio.h" +#include "TestS.h" + +/***************************/ +/*** Servant Declaration ***/ + +class ST_AMH_Servant + : public virtual POA_Test::AMH_Roundtrip +{ +public: + ST_AMH_Servant (CORBA::ORB_ptr orb); + + void test_method (Test::AMH_RoundtripResponseHandler_ptr _tao_rh, + Test::Timestamp send_time + ACE_ENV_ARG_DECL) + ACE_THROW_SPEC ((CORBA::SystemException)); + +protected: + CORBA::ORB_ptr orb_; +}; + + +/***************************/ +/*** Servant Definition ***/ + +ST_AMH_Servant::ST_AMH_Servant (CORBA::ORB_ptr orb) + : orb_ (CORBA::ORB::_duplicate (orb)) +{ +} + +void +ST_AMH_Servant::test_method (Test::AMH_RoundtripResponseHandler_ptr _tao_rh, + Test::Timestamp send_time + ACE_ENV_ARG_DECL) + ACE_THROW_SPEC ((CORBA::SystemException)) +{ + // Throw an overload exception + + Test::ServerOverload *ts = new Test::ServerOverload; + + // Calee owns the memory now. Need not delete 'ts' + Test::AMH_RoundtripExceptionHolder holder (ts); + + ACE_TRY + { + _tao_rh->test_method_excep (&holder ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + } + ACE_CATCHALL + {} + ACE_ENDTRY; + + ACE_UNUSED_ARG (send_time); +} + + +/*** Server Declaration ***/ + +/** + Class that performs all 'dirty' initialisation work that is common to + all the AMH servers and 'hides' all the common ORB functions. + */ +class ST_AMH_Server +{ +public: + ST_AMH_Server (int *argc, char **argv); + virtual ~ST_AMH_Server (); + + /// ORB inititalisation stuff + int start_orb_and_poa (void); + + /// register the servant with the poa + virtual void register_servant (ST_AMH_Servant *servant); + + /// orb-perform_work () abstraction + virtual void run_event_loop (); + +public: + /// Accesor method (for servants) to the initialised ORB + CORBA::ORB_ptr orb () { return this->orb_.in (); } + +protected: + int *argc_; + char **argv_; + char *ior_output_file_; + CORBA::ORB_var orb_; + PortableServer::POA_var root_poa_; + +private: + /// Write servant IOR to file specified with the '-o' option + int write_ior_to_file (CORBA::String_var ior); +}; + + + +/*** Server Declaration ***/ + +ST_AMH_Server::ST_AMH_Server (int* argc, char **argv) + : argc_ (argc) + , argv_ (argv) +{ + this->ior_output_file_ = const_cast<char*> ("test.ior"); +} + +ST_AMH_Server::~ST_AMH_Server () +{ + ACE_TRY_NEW_ENV + { + this->root_poa_->destroy (1, 1 ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + this->orb_->destroy (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_TRY_CHECK; + } + ACE_CATCHANY + { + ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, "Exception caught:"); + } + ACE_ENDTRY; + +} + +int +ST_AMH_Server::start_orb_and_poa (void) +{ + ACE_TRY_NEW_ENV + { + this->orb_ = CORBA::ORB_init (*(this->argc_), + this->argv_, + "" ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + CORBA::Object_var poa_object = + this->orb_->resolve_initial_references("RootPOA" ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + if (CORBA::is_nil (poa_object.in ())) + ACE_ERROR_RETURN ((LM_ERROR, + " (%P|%t) Unable to initialize the POA.\n"), + 1); + + this->root_poa_ = PortableServer::POA::_narrow (poa_object.in () + ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + 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; + } + ACE_CATCHANY + { + ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, "Exception caught:"); + return -1; + } + ACE_ENDTRY; + + return 0; +} + +void +ST_AMH_Server::register_servant (ST_AMH_Servant *servant) +{ + ACE_TRY_NEW_ENV + { + Test::Roundtrip_var roundtrip = + servant->_this (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_TRY_CHECK; + + CORBA::String_var ior = + this->orb_->object_to_string (roundtrip.in () ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + (void) this->write_ior_to_file (ior); + } + ACE_CATCHANY + { + ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, "Exception caught:"); + } + ACE_ENDTRY; +} + +void +ST_AMH_Server::run_event_loop () +{ + ACE_DECLARE_NEW_CORBA_ENV; + ACE_TRY + { + ACE_Time_Value period (0, 11000); + while (1) + { + this->orb_->perform_work (&period); + ACE_TRY_CHECK; + } + ACE_TRY_CHECK; + } + ACE_CATCHANY + {} + ACE_ENDTRY; +} + +int +ST_AMH_Server::write_ior_to_file (CORBA::String_var ior) +{ + // If the ior_output_file exists, output the ior to it + FILE *output_file= ACE_OS::fopen (ST_AMH_Server::ior_output_file_, + "w"); + if (output_file == 0) + { + ACE_ERROR ((LM_ERROR, + "Cannot open output file for writing IOR: %s", + ST_AMH_Server::ior_output_file_)); + return -1; + } + + ACE_OS::fprintf (output_file, "%s", ior.in ()); + ACE_OS::fclose (output_file); + return 0; +} + + +int +main (int argc, char *argv[]) +{ + ST_AMH_Server amh_server (&argc, argv); + + amh_server.start_orb_and_poa (); + + ST_AMH_Servant servant (amh_server.orb ()); + + amh_server.register_servant (&servant); + + amh_server.run_event_loop (); + + return 0; +} |