summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormsmit <msmit@remedy.nl>2009-07-22 11:13:44 +0000
committermsmit <msmit@remedy.nl>2009-07-22 11:13:44 +0000
commit819ed6ab80d3f0d02249b46495b95884dbb8e3c8 (patch)
tree183c0d4326e59fa83d6085bf4aff6346c90f67ff
parent8640d872738b83ae1d47b761a809503712cf793c (diff)
downloadATCD-819ed6ab80d3f0d02249b46495b95884dbb8e3c8.tar.gz
Wed Jul 22 11:13:50 UTC 2009 Marcel Smit <msmit@remedy.nl>
* tests/AMI_CCM/README: * tests/AMI_CCM/ami_ccm.idl: * tests/AMI_CCM/ami_ccm.mpc: * tests/AMI_CCM/ami_ccm_i.h: * tests/AMI_CCM/ami_ccm_i.cpp: * tests/AMI_CCM/client.cpp: * tests/AMI_CCM/exclusive.conf: * tests/AMI_CCM/muxed.conf: * tests/AMI_CCM/run_test.pl: * tests/AMI_CCM/server.conf: * tests/AMI_CCM/server.cpp: Added test to prepare AMI for ccm.
-rw-r--r--modules/TAO/ChangeLog15
-rw-r--r--modules/TAO/tests/AMI_CCM/README39
-rw-r--r--modules/TAO/tests/AMI_CCM/ami_ccm.idl29
-rw-r--r--modules/TAO/tests/AMI_CCM/ami_ccm.mpc33
-rw-r--r--modules/TAO/tests/AMI_CCM/ami_ccm_i.cpp42
-rw-r--r--modules/TAO/tests/AMI_CCM/ami_ccm_i.h36
-rw-r--r--modules/TAO/tests/AMI_CCM/client.cpp246
-rw-r--r--modules/TAO/tests/AMI_CCM/exclusive.conf2
-rw-r--r--modules/TAO/tests/AMI_CCM/muxed.conf2
-rwxr-xr-xmodules/TAO/tests/AMI_CCM/run_test.pl75
-rw-r--r--modules/TAO/tests/AMI_CCM/server.conf3
-rw-r--r--modules/TAO/tests/AMI_CCM/server.cpp107
12 files changed, 629 insertions, 0 deletions
diff --git a/modules/TAO/ChangeLog b/modules/TAO/ChangeLog
index f2f9b51ac2a..dbf84852a30 100644
--- a/modules/TAO/ChangeLog
+++ b/modules/TAO/ChangeLog
@@ -1,3 +1,18 @@
+Wed Jul 22 11:13:50 UTC 2009 Marcel Smit <msmit@remedy.nl>
+
+ * tests/AMI_CCM/README:
+ * tests/AMI_CCM/ami_ccm.idl:
+ * tests/AMI_CCM/ami_ccm.mpc:
+ * tests/AMI_CCM/ami_ccm_i.h:
+ * tests/AMI_CCM/ami_ccm_i.cpp:
+ * tests/AMI_CCM/client.cpp:
+ * tests/AMI_CCM/exclusive.conf:
+ * tests/AMI_CCM/muxed.conf:
+ * tests/AMI_CCM/run_test.pl:
+ * tests/AMI_CCM/server.conf:
+ * tests/AMI_CCM/server.cpp:
+ Added test to prepare AMI for ccm.
+
Mon Jul 20 07:51:47 UTC 2009 Johnny Willemsen <jwillemsen@remedy.nl>
* tests/Sequence_Unit_Tests/string_sequence_tester.hpp:
diff --git a/modules/TAO/tests/AMI_CCM/README b/modules/TAO/tests/AMI_CCM/README
new file mode 100644
index 00000000000..04117a71d7d
--- /dev/null
+++ b/modules/TAO/tests/AMI_CCM/README
@@ -0,0 +1,39 @@
+# $Id$
+
+Description:
+This is a simple test for AMI callback model.
+
+Note:
+Use TAO_HAS_CORBA_MESSAGING
+and TAO_HAS_AMI_CALLBACK
+to compile TAO. This enables the AMI code in it.
+
+Use -GC on the TAO IDL compiler to generate code for AMI callbacks.
+
+Usage:
+=====
+$ server -o ior
+$ simple_client -ORBSvcConf muxed.conf -k file://ior -i 10
+
+simple-client:
+=============
+
+$ simple_client -k file://test_ior [-i <niterations] [-x] [-d] \
+ -ORBSvcConf {muxed.conf,
+ exclusive.conf}
+
+-d Enable debug messages.
+-i Number of iterations.
+-k IOR.
+-x Call shutdown method.
+
+Issues <i> number of asynchronous requests. Then it issues a
+synchronous request, which collects the replies.
+
+If you choose Muxed Transport configuration, then the synchronous
+request will collect all the asynchronous replies also, since the
+replies will arrive in order. In the Exclusive Transport, however,
+the synchronous request might not collect all the AMI replies.
+Instead, it might return as soon as its reply arrives.
+
+
diff --git a/modules/TAO/tests/AMI_CCM/ami_ccm.idl b/modules/TAO/tests/AMI_CCM/ami_ccm.idl
new file mode 100644
index 00000000000..0964be442f0
--- /dev/null
+++ b/modules/TAO/tests/AMI_CCM/ami_ccm.idl
@@ -0,0 +1,29 @@
+
+//=============================================================================
+/**
+ * @file ami_msm.idl
+ *
+ * $Id$
+ *
+ * IDL description of the AMI Test interface
+ *
+ */
+//=============================================================================
+
+
+
+module A
+ {
+ exception InternalError {
+ long id;
+ string error;
+ };
+
+ interface AMI_Msm
+ {
+ void foo (in string hello, out string answer)
+ raises (InternalError);
+
+ oneway void shutdown ();
+ };
+ };
diff --git a/modules/TAO/tests/AMI_CCM/ami_ccm.mpc b/modules/TAO/tests/AMI_CCM/ami_ccm.mpc
new file mode 100644
index 00000000000..25fed969ce7
--- /dev/null
+++ b/modules/TAO/tests/AMI_CCM/ami_ccm.mpc
@@ -0,0 +1,33 @@
+// -*- MPC -*-
+// $Id$
+
+project(*idl): taoidldefaults, ami {
+ IDL_Files {
+ ami_msm.idl
+ }
+ custom_only = 1
+}
+
+project(*Server): taoserver, messaging, ami {
+ after += *idl
+ Source_Files {
+ ami_msm_i.cpp
+ ami_msmC.cpp
+ ami_msmS.cpp
+ server.cpp
+ }
+ IDL_Files {
+ }
+}
+
+project(*Client): messaging, taoserver, ami {
+ exename = client
+ after += *idl
+ Source_Files {
+ client.cpp
+ ami_msmS.cpp
+ ami_msmC.cpp
+ }
+ IDL_Files {
+ }
+}
diff --git a/modules/TAO/tests/AMI_CCM/ami_ccm_i.cpp b/modules/TAO/tests/AMI_CCM/ami_ccm_i.cpp
new file mode 100644
index 00000000000..250747206b7
--- /dev/null
+++ b/modules/TAO/tests/AMI_CCM/ami_ccm_i.cpp
@@ -0,0 +1,42 @@
+#include "ami_msm_i.h"
+#include "tao/debug.h"
+
+ACE_RCSID(AMI, ami_test_i, "$Id$")
+
+AMI_Msm_i::AMI_Msm_i (CORBA::ORB_ptr orb)
+ : orb_ (CORBA::ORB::_duplicate (orb)),
+ answer_count_ (0)
+{
+}
+
+void
+AMI_Msm_i::foo (const char* string, ::CORBA::String_out answer)
+{
+ try
+ {
+ ACE_OS::sleep (1);
+ ++answer_count_;
+ ACE_DEBUG ((LM_DEBUG,
+ ACE_TEXT ("%N:%l:(%P:%t):AMI_Msm_i::foo: %d %C\n"),
+ answer_count_,
+ string));
+ char tmp[255] = {0};
+ ACE_OS::sprintf(tmp, "Hello World %d", answer_count_);
+ answer = CORBA::string_dup (tmp);
+ }
+ catch (const CORBA::Exception& e)
+ {
+ throw A::InternalError (123, ACE_TEXT ("CORBA exception"));
+ }
+ catch (...)
+ {
+ throw A::InternalError (456, ACE_TEXT ("Unknow exception"));
+ }
+ //answer = answer_count_;
+}
+
+void
+AMI_Msm_i::shutdown (void)
+{
+ this->orb_->shutdown (0);
+}
diff --git a/modules/TAO/tests/AMI_CCM/ami_ccm_i.h b/modules/TAO/tests/AMI_CCM/ami_ccm_i.h
new file mode 100644
index 00000000000..9628838d78f
--- /dev/null
+++ b/modules/TAO/tests/AMI_CCM/ami_ccm_i.h
@@ -0,0 +1,36 @@
+
+//=============================================================================
+/**
+ * @file ami_test_i.h
+ *
+ * $Id$
+ *
+ * @author Michael Kircher <Michael.Kircher@mchp.siemens.de>
+ */
+//=============================================================================
+
+
+#ifndef TAO_AMI_MSM_I_H
+#define TAO_AMI_MSM_I_H
+
+#include "ami_msmS.h"
+
+class AMI_Msm_i : public POA_A::AMI_Msm
+{
+public:
+ /// ctor
+ AMI_Msm_i (CORBA::ORB_ptr orb);
+
+ // The AMI_Test methods.
+ void foo (const char* string, ::CORBA::String_out answer);
+
+ void shutdown (void);
+
+private:
+ CORBA::ORB_var orb_;
+
+ long answer_count_;
+};
+
+#endif /* TAO_AMI_TEST_I_H */
+
diff --git a/modules/TAO/tests/AMI_CCM/client.cpp b/modules/TAO/tests/AMI_CCM/client.cpp
new file mode 100644
index 00000000000..432547aa83b
--- /dev/null
+++ b/modules/TAO/tests/AMI_CCM/client.cpp
@@ -0,0 +1,246 @@
+
+#include "ace/Get_Opt.h"
+#include "ace/Task.h"
+#include "ami_msmC.h"
+#include "ami_msmS.h"
+
+ACE_RCSID (AMI,
+ client,
+ "$")
+
+const ACE_TCHAR *ior = ACE_TEXT("file://test.ior");
+const char * in_str = "Let's talk AMI.";
+const int nthreads_ = 1;
+const int niterations_ = 5;
+int number_of_replies_ = 0;
+
+
+int
+parse_args (int argc, ACE_TCHAR *argv[])
+{
+ ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("k:"));
+ int c;
+
+ while ((c = get_opts ()) != -1)
+ switch (c)
+ {
+ case 'k':
+ ior = get_opts.opt_arg ();
+ break;
+ case '?':
+ default:
+ ACE_ERROR_RETURN ((LM_ERROR,
+ "usage: %s "
+ "-k <ior> "
+ "\n",
+ argv [0]),
+ -1);
+ }
+ // Indicates sucessful parsing of the command line
+ return 0;
+}
+
+
+/**
+ * @class Client
+ *
+ * @brief Run the client thread
+ *
+ * Use the ACE_Task_Base class to run the client threads.
+ */
+class Client : public ACE_Task_Base
+{
+public:
+ /// ctor
+ Client (A::AMI_Msm_ptr server, int niterations);
+
+ /// The thread entry point.
+ virtual int svc (void);
+
+ // private:
+ /// Var for the AMI_Msm object.
+ A::AMI_Msm_var ami_test_var_;
+
+ /// The number of iterations on each client thread.
+ int niterations_;
+
+ /// Var for AMI_AMI_Msm_ReplyHandler object.
+ A::AMI_AMI_MsmHandler_var the_handler_var_;
+};
+
+
+//+++++++++++++++++++++++++++++++++++++++++++++
+//+++++++++++++++++++++++++++++++++++++++++++++
+//+++++++++++++++++++++++++++++++++++++++++++++
+//+++++++++++++++++++++++++++++++++++++++++++++
+//+++++++++++++++ REPLY HANDLER+++++++++++++++
+//+++++++++++++++++++++++++++++++++++++++++++++
+//+++++++++++++++++++++++++++++++++++++++++++++
+//+++++++++++++++++++++++++++++++++++++++++++++
+
+class Handler : public POA_A::AMI_AMI_MsmHandler
+{
+public:
+ Handler (void)
+ {
+ };
+
+ //callback implementation
+ void foo (const char * answer)
+ {
+ --number_of_replies_;
+
+ ACE_DEBUG ((LM_DEBUG,
+ "(%P | %t) : Callback method called: Replies to go <%d>, out_arg <%s>\n",
+ number_of_replies_,
+ answer));
+ };
+
+ void foo_excep (::Messaging::ExceptionHolder * excep_holder)
+ {
+ ACE_DEBUG ((LM_DEBUG,
+ "Callback method <foo_excep> called:\n"));
+ try
+ {
+ excep_holder->raise_exception ();
+ }
+ catch (const CORBA::Exception& ex)
+ {
+ ex._tao_print_exception ("Caught exception:");
+ }
+ };
+ ~Handler (void)
+ {
+ };
+};
+
+// ReplyHandler.
+Handler handler;
+
+int
+ACE_TMAIN(int argc, ACE_TCHAR *argv[])
+{
+ try
+ {
+ CORBA::ORB_var orb =
+ CORBA::ORB_init (argc, argv);
+
+ if (parse_args (argc, argv) != 0)
+ return 1;
+
+ A::AMI_Msm_var server;
+
+ CORBA::Object_var object =
+ orb->string_to_object (ior);
+ server = A::AMI_Msm::_narrow (object.in ());
+
+ if (CORBA::is_nil (server.in ()))
+ {
+ ACE_ERROR_RETURN ((LM_ERROR,
+ "Object reference <%s> is nil.\n",
+ ior),
+ 1);
+ }
+
+ // Activate POA to handle the call back.
+
+ CORBA::Object_var poa_object =
+ orb->resolve_initial_references("RootPOA");
+
+ 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 ());
+
+ PortableServer::POAManager_var poa_manager =
+ root_poa->the_POAManager ();
+
+ poa_manager->activate ();
+
+ // Let the client perform the test in a separate thread
+
+ Client client (server.in (), niterations_);
+ if (client.activate (THR_NEW_LWP | THR_JOINABLE,
+ nthreads_) != 0)
+ ACE_ERROR_RETURN ((LM_ERROR,
+ "Cannot activate client threads\n"),
+ 1);
+
+ // Main thread collects replies. It needs to collect
+ // <nthreads*niterations> replies.
+ number_of_replies_ = nthreads_ *niterations_;
+
+ ACE_DEBUG ((LM_DEBUG,
+ "(%P|%t) : Entering perform_work loop to receive <%d> replies\n",
+ number_of_replies_));
+
+ // ORB loop.
+
+ while (number_of_replies_ > 0)
+ {
+ CORBA::Boolean pending = orb->work_pending();
+
+ if (pending)
+ {
+ orb->perform_work();
+ }
+ }
+
+ ACE_DEBUG ((LM_DEBUG,
+ "(%P|%t) : Exited perform_work loop Received <%d> replies\n",
+ (nthreads_*niterations_) - number_of_replies_));
+
+ client.thr_mgr ()->wait ();
+
+ ACE_DEBUG ((LM_DEBUG, "threads finished\n"));
+
+ root_poa->destroy (1, // ethernalize objects
+ 0 // wait for completion
+ );
+
+ orb->destroy ();
+ }
+ catch (const CORBA::Exception& ex)
+ {
+ ex._tao_print_exception ("Caught exception:");
+ return 1;
+ }
+
+ return 0;
+}
+
+// ****************************************************************
+
+Client::Client (A::AMI_Msm_ptr server,
+ int niterations)
+ : ami_test_var_ (A::AMI_Msm::_duplicate (server)),
+ niterations_ (niterations)
+{
+ the_handler_var_ = handler._this (/* */);
+}
+
+int
+Client::svc (void)
+{
+ try
+ {
+ for (int i = 0; i < this->niterations_; ++i)
+ {
+ ACE_DEBUG ((LM_DEBUG,
+ "(%P | %t):Start <%d>\n",
+ i));
+ ami_test_var_->sendc_foo (the_handler_var_.in (), in_str);
+ }
+ ACE_DEBUG ((LM_DEBUG,
+ "(%P | %t):<%d> Asynchronous methods issued\n",
+ this->niterations_));
+ }
+ catch (const CORBA::Exception& ex)
+ {
+ ex._tao_print_exception ("MT_Client: exception raised");
+ }
+ return 0;
+}
diff --git a/modules/TAO/tests/AMI_CCM/exclusive.conf b/modules/TAO/tests/AMI_CCM/exclusive.conf
new file mode 100644
index 00000000000..b269154099f
--- /dev/null
+++ b/modules/TAO/tests/AMI_CCM/exclusive.conf
@@ -0,0 +1,2 @@
+
+static Client_Strategy_Factory "-ORBTransportMuxStrategy EXCLUSIVE -ORBProfileLock null -ORBclientconnectionhandler ST"
diff --git a/modules/TAO/tests/AMI_CCM/muxed.conf b/modules/TAO/tests/AMI_CCM/muxed.conf
new file mode 100644
index 00000000000..a7f2f5f608a
--- /dev/null
+++ b/modules/TAO/tests/AMI_CCM/muxed.conf
@@ -0,0 +1,2 @@
+
+static Client_Strategy_Factory "-ORBTransportMuxStrategy MUXED -ORBProfileLock null -ORBClientConnectionHandler ST"
diff --git a/modules/TAO/tests/AMI_CCM/run_test.pl b/modules/TAO/tests/AMI_CCM/run_test.pl
new file mode 100755
index 00000000000..1c46bc5ff74
--- /dev/null
+++ b/modules/TAO/tests/AMI_CCM/run_test.pl
@@ -0,0 +1,75 @@
+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::TestTarget;
+
+my $server = PerlACE::TestTarget::create_target (1) || die "Create target 1 failed\n";
+my $client = PerlACE::TestTarget::create_target (2) || die "Create target 2 failed\n";
+
+$client_conf = $client->LocalFile ("muxed$PerlACE::svcconf_ext");
+
+$debug_level = '0';
+$iterations = '1';
+
+foreach $i (@ARGV) {
+ if ($i eq '-mux') {
+ $client_conf = $client->LocalFile ("muxed$PerlACE::svcconf_ext");
+ }
+ elsif ($i eq '-debug') {
+ $debug_level = '1';
+ }
+ elsif ($i eq '-exclusive') {
+ $client_conf = $client->LocalFile ("exclusive$PerlACE::svcconf_ext");
+ }
+}
+
+my $iorbase = "server.ior";
+my $server_iorfile = $server->LocalFile ($iorbase);
+my $client_iorfile = $client->LocalFile ($iorbase);
+$server->DeleteFile($iorbase);
+$client->DeleteFile($iorbase);
+
+$SV = $server->CreateProcess ("server", "-ORBdebuglevel $debug_level -o $server_iorfile");
+
+$server_status = $SV->Spawn ();
+
+if ($server_status != 0) {
+ print STDERR "ERROR: server returned $server_status\n";
+ exit 1;
+}
+
+if ($server->WaitForFileTimed ($iorbase,
+ $server->ProcessStartWaitInterval()) == -1) {
+ print STDERR "ERROR: cannot find file <$server_iorfile>\n";
+ $SV->Kill (); $SV->TimedWait (1);
+ exit 1;
+}
+
+$CL = $client->CreateProcess ("client",
+ "-ORBsvcconf $client_conf "
+ . "-ORBdebuglevel $debug_level"
+ . " -k file://$client_iorfile ");
+
+$client_status = $CL->SpawnWaitKill ($client->ProcessStartWaitInterval());
+
+if ($client_status != 0) {
+ print STDERR "ERROR: client returned $client_status\n";
+ $status = 1;
+}
+
+$server_status = $SV->WaitKill ($server->ProcessStopWaitInterval());
+
+if ($server_status != 0) {
+ print STDERR "ERROR: server returned $server_status\n";
+ $status = 1;
+}
+
+$server->DeleteFile($iorbase);
+$client->DeleteFile($iorbase);
+
+exit $status;
diff --git a/modules/TAO/tests/AMI_CCM/server.conf b/modules/TAO/tests/AMI_CCM/server.conf
new file mode 100644
index 00000000000..faf9c6c874b
--- /dev/null
+++ b/modules/TAO/tests/AMI_CCM/server.conf
@@ -0,0 +1,3 @@
+# $Id$
+#
+static Server_Strategy_Factory "-ORBconcurrency thread-per-connection"
diff --git a/modules/TAO/tests/AMI_CCM/server.cpp b/modules/TAO/tests/AMI_CCM/server.cpp
new file mode 100644
index 00000000000..2c8587846b4
--- /dev/null
+++ b/modules/TAO/tests/AMI_CCM/server.cpp
@@ -0,0 +1,107 @@
+#include "ami_msm_i.h"
+#include "tao/debug.h"
+#include "ace/OS_NS_stdio.h"
+#include "ace/Get_Opt.h"
+
+ACE_RCSID(AMI, server, "$Id$")
+
+const ACE_TCHAR *ior_output_file = 0;
+
+int
+parse_args (int argc, ACE_TCHAR *argv[])
+{
+ ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("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
+ACE_TMAIN(int argc, ACE_TCHAR *argv[])
+{
+ try
+ {
+ CORBA::ORB_var orb =
+ CORBA::ORB_init (argc, argv);
+
+ CORBA::Object_var poa_object =
+ orb->resolve_initial_references("RootPOA");
+
+ 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 ());
+
+ PortableServer::POAManager_var poa_manager =
+ root_poa->the_POAManager ();
+
+ if (parse_args (argc, argv) != 0)
+ return 1;
+
+ AMI_Msm_i ami_test_i (orb.in ());
+
+ PortableServer::ObjectId_var id =
+ root_poa->activate_object (&ami_test_i);
+
+ CORBA::Object_var object = root_poa->id_to_reference (id.in ());
+
+ A::AMI_Msm_var ami_test_var =
+ A::AMI_Msm::_narrow (object.in ());
+
+ CORBA::String_var ior =
+ orb->object_to_string (ami_test_var.in ());
+
+ ACE_DEBUG ((LM_DEBUG, "Activated as <%C>\n", ior.in ()));
+
+ // If the ior_output_file exists, output the ior to it
+ if (ior_output_file != 0)
+ {
+ 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 ();
+
+ orb->run ();
+
+ root_poa->destroy (1, // ethernalize objects
+ 0 // wait for completion
+ );
+
+ orb->destroy ();
+
+ ACE_DEBUG ((LM_DEBUG, "event loop finished\n"));
+ }
+ catch (const CORBA::Exception& ex)
+ {
+ ex._tao_print_exception ("Caught exception:");
+ return 1;
+ }
+
+ return 0;
+}