diff options
author | zhangw <zhangw@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 2007-01-26 15:51:30 +0000 |
---|---|---|
committer | zhangw <zhangw@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 2007-01-26 15:51:30 +0000 |
commit | 4f9eabb01d728645e31fcfb30b9524f5f122d9a8 (patch) | |
tree | 4cad22290bcf9bf66532f66abf54d24e11b27ccd | |
parent | 356797cee679a3f7a2963554d7edf67c4c51498d (diff) | |
download | ATCD-4f9eabb01d728645e31fcfb30b9524f5f122d9a8.tar.gz |
Fri Jan 26 15:43:49 UTC 2007 Wallace Zhang <zhang_w@ociweb.com>
* tests/DSI_AMH:
* tests/DSI_AMH/DSI_AMH.mpc:
* tests/DSI_AMH/README:
* tests/DSI_AMH/Roundtrip.h:
* tests/DSI_AMH/Roundtrip.cpp:
* tests/DSI_AMH/Test.idl:
* tests/DSI_AMH/client.cpp:
* tests/DSI_AMH/run_test.pl:
* tests/DSI_AMH/server.cpp:
Adding a simple test of the DSI+AMH feature in TAO.
-rw-r--r-- | TAO/ChangeLog.oci_rt9734 | 14 | ||||
-rw-r--r-- | TAO/tests/DSI_AMH/DSI_AMH.mpc | 19 | ||||
-rw-r--r-- | TAO/tests/DSI_AMH/README | 1 | ||||
-rw-r--r-- | TAO/tests/DSI_AMH/Roundtrip.cpp | 178 | ||||
-rw-r--r-- | TAO/tests/DSI_AMH/Roundtrip.h | 57 | ||||
-rw-r--r-- | TAO/tests/DSI_AMH/Test.idl | 18 | ||||
-rw-r--r-- | TAO/tests/DSI_AMH/client.cpp | 102 | ||||
-rwxr-xr-x | TAO/tests/DSI_AMH/run_test.pl | 48 | ||||
-rw-r--r-- | TAO/tests/DSI_AMH/server.cpp | 115 |
9 files changed, 552 insertions, 0 deletions
diff --git a/TAO/ChangeLog.oci_rt9734 b/TAO/ChangeLog.oci_rt9734 index 6d6a913994f..d23c4f97990 100644 --- a/TAO/ChangeLog.oci_rt9734 +++ b/TAO/ChangeLog.oci_rt9734 @@ -1,3 +1,17 @@ +Fri Jan 26 15:43:49 UTC 2007 Wallace Zhang <zhang_w@ociweb.com> + + * tests/DSI_AMH: + * tests/DSI_AMH/DSI_AMH.mpc: + * tests/DSI_AMH/README: + * tests/DSI_AMH/Roundtrip.h: + * tests/DSI_AMH/Roundtrip.cpp: + * tests/DSI_AMH/Test.idl: + * tests/DSI_AMH/client.cpp: + * tests/DSI_AMH/run_test.pl: + * tests/DSI_AMH/server.cpp: + + Adding a simple test of the DSI+AMH feature in TAO. + Tue Jan 23 17:04:06 UTC 2007 Wallace Zhang <zhang_w@ociweb.com> * tao/DynamicInterface/AMH_DSI_Response_Handler.h: diff --git a/TAO/tests/DSI_AMH/DSI_AMH.mpc b/TAO/tests/DSI_AMH/DSI_AMH.mpc new file mode 100644 index 00000000000..8bb25921184 --- /dev/null +++ b/TAO/tests/DSI_AMH/DSI_AMH.mpc @@ -0,0 +1,19 @@ +// -*- MPC -*- +// $Id$ + +project(*Server): taoserver, dynamicinterface, avoids_minimum_corba, avoids_corba_e_compact, avoids_corba_e_micro { + IDL_Files { + } + Source_Files { + Roundtrip.cpp + server.cpp + } +} + +project(*Client): taoclient, avoids_minimum_corba, avoids_corba_e_compact, avoids_corba_e_micro { + Source_Files { + TestC.cpp + client.cpp + } +} + diff --git a/TAO/tests/DSI_AMH/README b/TAO/tests/DSI_AMH/README new file mode 100644 index 00000000000..20ea8d8b9cf --- /dev/null +++ b/TAO/tests/DSI_AMH/README @@ -0,0 +1 @@ +This is a simple test of the DSI+AMH feature in TAO. To run it, just execute the script run_test.pl. diff --git a/TAO/tests/DSI_AMH/Roundtrip.cpp b/TAO/tests/DSI_AMH/Roundtrip.cpp new file mode 100644 index 00000000000..83dc7be4f2f --- /dev/null +++ b/TAO/tests/DSI_AMH/Roundtrip.cpp @@ -0,0 +1,178 @@ +// +// $Id$ +// +#include "Roundtrip.h" +#include "tao/AnyTypeCode/TypeCode_Constants.h" +#include "tao/AnyTypeCode/NVList.h" +#include "tao/AnyTypeCode/SystemExceptionA.h" +#include "tao/DynamicInterface/Server_Request.h" +#include "tao/ORB_Core.h" +#include "tao/Thread_Lane_Resources.h" + +Roundtrip::Roundtrip (CORBA::ORB_ptr orb) + : orb_ (CORBA::ORB::_duplicate (orb)) +{ +} + +void +Roundtrip::invoke (CORBA::ServerRequest_ptr request, + TAO_AMH_DSI_Response_Handler_ptr rh + ACE_ENV_ARG_DECL) +{ + if (ACE_OS::strcmp ("shutdown", request->operation ()) == 0) + { + this->orb_->shutdown (0 ACE_ENV_ARG_PARAMETER); + ACE_CHECK; + + return; + } + + else if (ACE_OS::strcmp ("_is_a", request->operation ()) == 0) + { + CORBA::NVList_ptr list; + this->orb_->create_list (0, list ACE_ENV_ARG_PARAMETER); + ACE_CHECK; + + CORBA::Any type_id; + type_id._tao_set_typecode (CORBA::_tc_string); + list->add_value ("type_id", type_id, CORBA::ARG_IN + ACE_ENV_ARG_PARAMETER); + ACE_CHECK; + + request->arguments (list ACE_ENV_ARG_PARAMETER); + ACE_CHECK; + + CORBA::NamedValue_ptr nv = list->item (0 ACE_ENV_ARG_PARAMETER); + ACE_CHECK; + + const char *arg; + *(nv->value ()) >>= arg; + + CORBA::Boolean type_matches = 0; + if (ACE_OS::strcmp (arg, "IDL:Test/Roundtrip:1.0") == 0 + || ACE_OS::strcmp (arg, "IDL:omg.org/CORBA/Object:1.0") == 0 + || ACE_OS::strcmp (arg, "") == 0) + type_matches = 1; + + CORBA::Any result; + result <<= CORBA::Any::from_boolean (type_matches); + + request->set_result (result ACE_ENV_ARG_PARAMETER); + ACE_CHECK; + + // AMH way of replying + rh->invoke_reply (list, nv); + return; + } + + else if (ACE_OS::strcmp ("test_method", request->operation ()) == 0) + { + CORBA::NVList_ptr list; + this->orb_->create_list (0, list ACE_ENV_ARG_PARAMETER); + ACE_CHECK; + + CORBA::Any send_time; + send_time._tao_set_typecode (CORBA::_tc_ulonglong); + list->add_value ("send_time", send_time, CORBA::ARG_IN + ACE_ENV_ARG_PARAMETER); + ACE_CHECK; + + request->arguments (list ACE_ENV_ARG_PARAMETER); + ACE_CHECK; + + CORBA::NamedValue_ptr nv = list->item (0 ACE_ENV_ARG_PARAMETER); + ACE_CHECK; + + request->set_result (*(nv->value ()) ACE_ENV_ARG_PARAMETER); + + // AMH way of replying + rh->invoke_reply (list, nv); + + return; + } + + CORBA::Any bad_operation; + CORBA::BAD_OPERATION exception; + bad_operation <<= exception; + request->set_exception (bad_operation ACE_ENV_ARG_PARAMETER); + ACE_CHECK; +} + +CORBA::RepositoryId +Roundtrip::_primary_interface (const PortableServer::ObjectId &, + PortableServer::POA_ptr + ACE_ENV_ARG_DECL_NOT_USED) +{ + return CORBA::string_dup ("IDL:Test/Roundtrip:1.0"); +} + +void +Roundtrip::_dispatch (TAO_ServerRequest &request, + void * //context + ) +{ + // No need to do any of this if the client isn't waiting. + if (request.response_expected ()) + { + if (!CORBA::is_nil (request.forward_location ())) + { + request.init_reply (); + request.tao_send_reply (); + + // No need to invoke in this case. + return; + } + else if (request.sync_with_server ()) + { + // The last line before the call to this function + // was an ACE_CHECK_RETURN, so if we're here, we + // know there is no exception so far, and that's all + // a SYNC_WITH_SERVER client request cares about. + request.send_no_exception_reply (); + } + } + + // Create DSI request object. + CORBA::ServerRequest *dsi_request = 0; + ACE_NEW (dsi_request, + CORBA::ServerRequest (request)); + + ACE_TRY + { + TAO_AMH_DSI_Response_Handler_ptr rh_ptr = 0; + ACE_NEW (rh_ptr, TAO_AMH_DSI_Response_Handler(request)); + + TAO_AMH_DSI_Response_Handler_var rh = rh_ptr; + + // init the handler + TAO_AMH_BUFFER_ALLOCATOR* amh_allocator = + request.orb()->orb_core ()->lane_resources().amh_response_handler_allocator(); + rh->init (request, amh_allocator); + // Delegate to user. + this->invoke (dsi_request, + rh.in() + ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + } + ACE_CATCH (CORBA::Exception, ex) + + { + // Only if the client is waiting. + if (request.response_expected () && !request.sync_with_server ()) + { + request.tao_send_reply_exception (ex); + } + } + ACE_ENDTRY; + + CORBA::release (dsi_request); +} + +void +Roundtrip::invoke (CORBA::ServerRequest_ptr request + ACE_ENV_ARG_NOT_USED) + throw (CORBA::SystemException) +{ + ACE_UNUSED_ARG (request); + throw CORBA::NO_IMPLEMENT(); +} diff --git a/TAO/tests/DSI_AMH/Roundtrip.h b/TAO/tests/DSI_AMH/Roundtrip.h new file mode 100644 index 00000000000..cce16e837ac --- /dev/null +++ b/TAO/tests/DSI_AMH/Roundtrip.h @@ -0,0 +1,57 @@ +// +// $Id$ +// + +#ifndef ROUNDTRIP_H +#define ROUNDTRIP_H +#include /**/ "ace/pre.h" + +#include "tao/DynamicInterface/Dynamic_Implementation.h" +#include "tao/PortableServer/PortableServer.h" +#include "tao/DynamicInterface/AMH_DSI_Response_Handler.h" + +#include "tao/ORB.h" + +#if defined (_MSC_VER) +# pragma warning(push) +# pragma warning (disable:4250) +#endif /* _MSC_VER */ + +/// Implement the Test::Roundtrip interface +class Roundtrip + : public virtual PortableServer::DynamicImplementation +{ +public: + /// Constructor + Roundtrip (CORBA::ORB_ptr orb); + + // = The DSI methods + + virtual void _dispatch (TAO_ServerRequest &request, + void *context); + // Turns around and calls invoke, but using AMH style handler + + void invoke (CORBA::ServerRequest_ptr request + ACE_ENV_ARG_DECL_WITH_DEFAULTS) + ACE_THROW_SPEC ((CORBA::SystemException)); + + virtual void invoke (CORBA::ServerRequest_ptr request, + TAO_AMH_DSI_Response_Handler_ptr rh + ACE_ENV_ARG_DECL); + virtual CORBA::RepositoryId _primary_interface ( + const PortableServer::ObjectId &oid, + PortableServer::POA_ptr poa + ACE_ENV_ARG_DECL); + +private: + /// Use an ORB reference to conver strings to objects and shutdown + /// the application. + CORBA::ORB_var orb_; +}; + +#if defined(_MSC_VER) +# pragma warning(pop) +#endif /* _MSC_VER */ + +#include /**/ "ace/post.h" +#endif /* ROUNDTRIP_H */ diff --git a/TAO/tests/DSI_AMH/Test.idl b/TAO/tests/DSI_AMH/Test.idl new file mode 100644 index 00000000000..fb38537f0b7 --- /dev/null +++ b/TAO/tests/DSI_AMH/Test.idl @@ -0,0 +1,18 @@ +// +// $Id$ +// + +/// A simple module to avoid namespace pollution +module Test +{ + typedef unsigned long long Timestamp; + + interface Roundtrip + { + /// The operation simply returns its argument. + Timestamp test_method (in Timestamp send_time); + + /// Shutdown the ORB + oneway void shutdown (); + }; +}; diff --git a/TAO/tests/DSI_AMH/client.cpp b/TAO/tests/DSI_AMH/client.cpp new file mode 100644 index 00000000000..a429bed027d --- /dev/null +++ b/TAO/tests/DSI_AMH/client.cpp @@ -0,0 +1,102 @@ +// $Id$ + +#include "TestC.h" +#include "ace/Get_Opt.h" +#include "ace/High_Res_Timer.h" + +const char *ior = "file://test.ior"; +int niterations = 100; +int do_shutdown = 1; + +int +parse_args (int argc, char *argv[]) +{ + ACE_Get_Opt get_opts (argc, argv, "xk:i:"); + int c; + + while ((c = get_opts ()) != -1) + switch (c) + { + case 'x': + do_shutdown = 0; + break; + + case 'k': + ior = get_opts.opt_arg (); + break; + + case 'i': + niterations = ACE_OS::atoi (get_opts.opt_arg ()); + break; + + case '?': + default: + ACE_ERROR_RETURN ((LM_ERROR, + "usage: %s " + "-k <ior> " + "-i <niterations> " + "-x (disable shutdown) " + "\n", + argv [0]), + -1); + } + // Indicates sucessful parsing of the command line + return 0; +} + +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; + + if (parse_args (argc, argv) != 0) + return 1; + + 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); + } + + for (int i = 0; i < niterations; ++i) + { + ACE_hrtime_t start = ACE_OS::gethrtime (); + ACE_hrtime_t retval = roundtrip->test_method (start ACE_ENV_ARG_PARAMETER); + ACE_DEBUG ((LM_DEBUG, "test return value: %Q\n", retval)); + ACE_TRY_CHECK; + } + + + ACE_DEBUG ((LM_DEBUG, "test finished\n")); + + + if (do_shutdown) + { + roundtrip->shutdown (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_TRY_CHECK; + } + } + ACE_CATCHANY + { + ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, "Exception caught:"); + return 1; + } + ACE_ENDTRY; + + return 0; +} diff --git a/TAO/tests/DSI_AMH/run_test.pl b/TAO/tests/DSI_AMH/run_test.pl new file mode 100755 index 00000000000..cd346f9833d --- /dev/null +++ b/TAO/tests/DSI_AMH/run_test.pl @@ -0,0 +1,48 @@ +eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}' + & eval 'exec perl -S $0 $argv:q' + if 0; + +# $Id$ +# -*- perl -*- + +use lib "$ENV{ACE_ROOT}/bin"; +use PerlACE::Run_Test; + +$status = 0; +$iorfile = PerlACE::LocalFile ("test.ior"); + +print STDERR "================ DSI Latency test\n"; + +unlink $iorfile; + +$SV = new PerlACE::Process ("server", + "-o $iorfile"); + +$CL = new PerlACE::Process ("client", + "-k file://$iorfile " + . " -i 25" ); + +$SV->Spawn (); + +if (PerlACE::waitforfile_timed ($iorfile, 15) == -1) { + print STDERR "ERROR: cannot find file <$iorfile>\n"; + $SV->Kill (); + exit 1; +} + +$client = $CL->SpawnWaitKill (300); +$server = $SV->WaitKill (10); + +unlink $iorfile; + +if ($client != 0) { + print STDERR "ERROR: client returned $client\n"; + $status = 1; +} + +if ($server != 0) { + print STDERR "ERROR: server returned $server\n"; + $status = 1; +} + +exit $status; diff --git a/TAO/tests/DSI_AMH/server.cpp b/TAO/tests/DSI_AMH/server.cpp new file mode 100644 index 00000000000..670781e257a --- /dev/null +++ b/TAO/tests/DSI_AMH/server.cpp @@ -0,0 +1,115 @@ +// $Id$ + +#include "Roundtrip.h" +#include "ace/Get_Opt.h" + +const char *ior_output_file = "test.ior"; + +int +parse_args (int argc, char *argv[]) +{ + ACE_Get_Opt get_opts (argc, argv, "o:"); + int c; + + while ((c = get_opts ()) != -1) + switch (c) + { + case 'o': + ior_output_file = get_opts.opt_arg (); + break; + + case '?': + default: + ACE_ERROR_RETURN ((LM_ERROR, + "usage: %s " + "-o <iorfile>" + "\n", + argv [0]), + -1); + } + // Indicates sucessful parsing of the command line + return 0; +} + +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 poa_object = + 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); + + PortableServer::POA_var root_poa = + PortableServer::POA::_narrow (poa_object.in () ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + PortableServer::POAManager_var poa_manager = + root_poa->the_POAManager (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_TRY_CHECK; + + if (parse_args (argc, argv) != 0) + return 1; + + Roundtrip *roundtrip_impl; + ACE_NEW_RETURN (roundtrip_impl, + Roundtrip (orb.in ()), + 1); + PortableServer::ServantBase_var owner_transfer(roundtrip_impl); + + PortableServer::ObjectId_var oid = + root_poa->activate_object (roundtrip_impl + ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + CORBA::Object_var roundtrip = + root_poa->id_to_reference (oid.in () + ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + CORBA::String_var ior = + orb->object_to_string (roundtrip.in () ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + // If the ior_output_file exists, output the ior to it + FILE *output_file= ACE_OS::fopen (ior_output_file, "w"); + if (output_file == 0) + ACE_ERROR_RETURN ((LM_ERROR, + "Cannot open output file for writing IOR: %s", + ior_output_file), + 1); + ACE_OS::fprintf (output_file, "%s", ior.in ()); + ACE_OS::fclose (output_file); + + poa_manager->activate (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_TRY_CHECK; + + orb->run (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_TRY_CHECK; + + ACE_DEBUG ((LM_DEBUG, "(%P|%t) server - event loop finished\n")); + + root_poa->destroy (1, 1 ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + orb->destroy (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_TRY_CHECK; + } + ACE_CATCHANY + { + ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, "Exception caught:"); + return 1; + } + ACE_ENDTRY; + + return 0; +} |