summaryrefslogtreecommitdiff
path: root/TAO/tests/MT_Server
diff options
context:
space:
mode:
authorWilliam R. Otte <wotte@dre.vanderbilt.edu>2006-07-24 15:50:21 +0000
committerWilliam R. Otte <wotte@dre.vanderbilt.edu>2006-07-24 15:50:21 +0000
commit3aff90f4a822fcf5d902bbfbcc9fa931d6191a8c (patch)
tree197c810e5f5bce17b1233a7cb8d7b50c0bcd25e2 /TAO/tests/MT_Server
parent6b846cf03c0bcbd8c276cb0af61a181e5f98eaae (diff)
downloadATCD-3aff90f4a822fcf5d902bbfbcc9fa931d6191a8c.tar.gz
Repo restructuring
Diffstat (limited to 'TAO/tests/MT_Server')
-rw-r--r--TAO/tests/MT_Server/.cvsignore2
-rw-r--r--TAO/tests/MT_Server/MT_Server.mpc18
-rw-r--r--TAO/tests/MT_Server/README19
-rw-r--r--TAO/tests/MT_Server/client.cpp105
-rwxr-xr-xTAO/tests/MT_Server/run_test.pl78
-rw-r--r--TAO/tests/MT_Server/server.conf2
-rw-r--r--TAO/tests/MT_Server/server.conf.xml6
-rw-r--r--TAO/tests/MT_Server/server.cpp163
-rw-r--r--TAO/tests/MT_Server/test.idl10
-rw-r--r--TAO/tests/MT_Server/test_i.cpp29
-rw-r--r--TAO/tests/MT_Server/test_i.h49
-rw-r--r--TAO/tests/MT_Server/test_i.i7
12 files changed, 488 insertions, 0 deletions
diff --git a/TAO/tests/MT_Server/.cvsignore b/TAO/tests/MT_Server/.cvsignore
new file mode 100644
index 00000000000..f2ad85300eb
--- /dev/null
+++ b/TAO/tests/MT_Server/.cvsignore
@@ -0,0 +1,2 @@
+client
+server
diff --git a/TAO/tests/MT_Server/MT_Server.mpc b/TAO/tests/MT_Server/MT_Server.mpc
new file mode 100644
index 00000000000..bfb96e8b536
--- /dev/null
+++ b/TAO/tests/MT_Server/MT_Server.mpc
@@ -0,0 +1,18 @@
+// -*- MPC -*-
+// $Id$
+
+project(*Server): taoserver {
+ Source_Files {
+ test_i.cpp
+ server.cpp
+ }
+}
+
+project(*Client): taoclient, anytypecode {
+ after += *Server
+ Source_Files {
+ testC.cpp
+ client.cpp
+ }
+}
+
diff --git a/TAO/tests/MT_Server/README b/TAO/tests/MT_Server/README
new file mode 100644
index 00000000000..7820727a22f
--- /dev/null
+++ b/TAO/tests/MT_Server/README
@@ -0,0 +1,19 @@
+# $Id$
+
+Description:
+
+ This is a simple test for a thread-pool server. It creates a
+server process with a variable number of threads, multiple clients can
+send requests to it, the requests are handled in different threads.
+
+Expected output:
+ The server prints out the IOR of the object it serves and the
+thread that handles each request.
+
+How to run:
+ You can use the run_test.pl script to run it or:
+
+$ server -o test.ior -n 4 -ORBSvcConf server.conf
+$ client -k file://test.ior -i 1000
+$ client -k file://test.ior -i 1000
+$ client -k file://test.ior -i 1000
diff --git a/TAO/tests/MT_Server/client.cpp b/TAO/tests/MT_Server/client.cpp
new file mode 100644
index 00000000000..3948231f376
--- /dev/null
+++ b/TAO/tests/MT_Server/client.cpp
@@ -0,0 +1,105 @@
+// $Id$
+
+#include "ace/Get_Opt.h"
+#include "ace/Task.h"
+#include "testC.h"
+
+ACE_RCSID(MT_Server, client, "$Id$")
+
+const char *ior = "file://test.ior";
+int niterations = 5;
+int do_shutdown = 0;
+
+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 = 1;
+ 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> "
+ "\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;
+
+ Simple_Server_var server =
+ Simple_Server::_narrow (object.in () ACE_ENV_ARG_PARAMETER);
+ ACE_TRY_CHECK;
+
+ if (CORBA::is_nil (server.in ()))
+ {
+ ACE_ERROR_RETURN ((LM_ERROR,
+ "Object reference <%s> is nil\n",
+ ior),
+ 1);
+ }
+
+ for (int i = 0; i != niterations; ++i)
+ {
+ CORBA::Long r =
+ server->test_method (i ACE_ENV_ARG_PARAMETER);
+ ACE_TRY_CHECK;
+
+ if (r != i)
+ {
+ ACE_DEBUG ((LM_DEBUG,
+ "(%P|%t) unexpected result = %d for %d",
+ r, i));
+ }
+ }
+
+ if (do_shutdown)
+ {
+ server->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/MT_Server/run_test.pl b/TAO/tests/MT_Server/run_test.pl
new file mode 100755
index 00000000000..f806a1750f7
--- /dev/null
+++ b/TAO/tests/MT_Server/run_test.pl
@@ -0,0 +1,78 @@
+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;
+
+$status = 0;
+$threads = '8';
+$iorfile = PerlACE::LocalFile ("test.ior");
+$sv_conf = PerlACE::LocalFile ("server$PerlACE::svcconf_ext");
+
+unlink $iorfile;
+
+if (PerlACE::is_vxworks_test()) {
+ $SV = new PerlACE::ProcessVX ("server", "-ORBsvcconf server$PerlACE::svcconf_ext -o test.ior -n $threads");
+}
+else {
+ $SV = new PerlACE::Process ("server", "-ORBsvcconf $sv_conf -o $iorfile -n $threads");
+}
+$CL1 = new PerlACE::Process ("client", "-k file://$iorfile -i 100");
+$CL2 = new PerlACE::Process ("client", "-k file://$iorfile -i 100");
+$CL3 = new PerlACE::Process ("client", "-k file://$iorfile -i 100");
+$CLS = new PerlACE::Process ("client", "-k file://$iorfile -i 100 -x ");
+
+$SV->Spawn ();
+
+if (PerlACE::waitforfile_timed ($iorfile,
+ $PerlACE::wait_interval_for_process_creation) == -1) {
+ print STDERR "ERROR: cannot find file <$iorfile>\n";
+ $SV->Kill ();
+ exit 1;
+}
+
+$CL1->Spawn ();
+$CL2->Spawn ();
+$CL3->Spawn ();
+
+$client = $CL1->WaitKill (60);
+
+if ($client != 0) {
+ print STDERR "ERROR: client returned $client\n";
+ $status = 1;
+}
+$client = $CL2->WaitKill (30);
+
+if ($client != 0) {
+ print STDERR "ERROR: client returned $client\n";
+ $status = 1;
+}
+
+$client = $CL3->WaitKill (30);
+
+if ($client != 0) {
+ print STDERR "ERROR: client returned $client\n";
+ $status = 1;
+}
+
+$client = $CLS->SpawnWaitKill (60);
+
+if ($client != 0) {
+ print STDERR "ERROR: client returned $client\n";
+ $status = 1;
+}
+
+$server = $SV->WaitKill (5);
+
+if ($server != 0) {
+ print STDERR "ERROR: server returned $server\n";
+ $status = 1;
+}
+
+unlink $iorfile;
+
+exit $status
diff --git a/TAO/tests/MT_Server/server.conf b/TAO/tests/MT_Server/server.conf
new file mode 100644
index 00000000000..0bd3f27be15
--- /dev/null
+++ b/TAO/tests/MT_Server/server.conf
@@ -0,0 +1,2 @@
+# $Id$
+#
diff --git a/TAO/tests/MT_Server/server.conf.xml b/TAO/tests/MT_Server/server.conf.xml
new file mode 100644
index 00000000000..9c53575413f
--- /dev/null
+++ b/TAO/tests/MT_Server/server.conf.xml
@@ -0,0 +1,6 @@
+<?xml version='1.0'?>
+<!-- Converted from ./tests/MT_Server/server.conf by svcconf-convert.pl -->
+<ACE_Svc_Conf>
+ <!-- $Id$ -->
+ <!-- -->
+</ACE_Svc_Conf>
diff --git a/TAO/tests/MT_Server/server.cpp b/TAO/tests/MT_Server/server.cpp
new file mode 100644
index 00000000000..982fc2cbc28
--- /dev/null
+++ b/TAO/tests/MT_Server/server.cpp
@@ -0,0 +1,163 @@
+// $Id$
+
+#include "test_i.h"
+#include "ace/Get_Opt.h"
+#include "ace/Task.h"
+
+ACE_RCSID(MT_Server, server, "$Id$")
+
+const char *ior_output_file = 0;
+
+int nthreads = 4;
+
+int
+parse_args (int argc, char *argv[])
+{
+ ACE_Get_Opt get_opts (argc, argv, "o:n:");
+ int c;
+
+ while ((c = get_opts ()) != -1)
+ switch (c)
+ {
+ case 'o':
+ ior_output_file = get_opts.opt_arg ();
+ break;
+
+ case 'n':
+ nthreads = ACE_OS::atoi (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;
+}
+
+class Worker : public ACE_Task_Base
+{
+ // = TITLE
+ // Run a server thread
+ //
+ // = DESCRIPTION
+ // Use the ACE_Task_Base class to run server threads
+ //
+public:
+ Worker (CORBA::ORB_ptr orb);
+ // ctor
+
+ virtual int svc (void);
+ // The thread entry point.
+
+private:
+ CORBA::ORB_var orb_;
+ // The orb
+};
+
+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;
+
+ Simple_Server_i server_impl (orb.in ());
+
+ Simple_Server_var server =
+ server_impl._this (ACE_ENV_SINGLE_ARG_PARAMETER);
+ ACE_TRY_CHECK;
+
+ CORBA::String_var ior =
+ orb->object_to_string (server.in () ACE_ENV_ARG_PARAMETER);
+ ACE_TRY_CHECK;
+
+ ACE_DEBUG ((LM_DEBUG, "Activated as <%s>\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 (ACE_ENV_SINGLE_ARG_PARAMETER);
+ ACE_TRY_CHECK;
+
+ Worker worker (orb.in ());
+ if (worker.activate (THR_NEW_LWP | THR_JOINABLE,
+ nthreads) != 0)
+ ACE_ERROR_RETURN ((LM_ERROR,
+ "Cannot activate client threads\n"),
+ 1);
+
+ worker.thr_mgr ()->wait ();
+
+ ACE_DEBUG ((LM_DEBUG, "event loop finished\n"));
+ }
+ ACE_CATCHANY
+ {
+ ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION,
+ "Exception caught:");
+ return 1;
+ }
+ ACE_ENDTRY;
+
+ return 0;
+}
+
+// ****************************************************************
+
+Worker::Worker (CORBA::ORB_ptr orb)
+ : orb_ (CORBA::ORB::_duplicate (orb))
+{
+}
+
+int
+Worker::svc (void)
+{
+ ACE_DECLARE_NEW_CORBA_ENV;
+ ACE_TRY
+ {
+ this->orb_->run (ACE_ENV_SINGLE_ARG_PARAMETER);
+ ACE_TRY_CHECK;
+ }
+ ACE_CATCHANY
+ {
+ }
+ ACE_ENDTRY;
+ return 0;
+}
diff --git a/TAO/tests/MT_Server/test.idl b/TAO/tests/MT_Server/test.idl
new file mode 100644
index 00000000000..aa227c3b110
--- /dev/null
+++ b/TAO/tests/MT_Server/test.idl
@@ -0,0 +1,10 @@
+//
+// $Id$
+//
+
+interface Simple_Server
+{
+ long test_method (in long x);
+
+ oneway void shutdown ();
+};
diff --git a/TAO/tests/MT_Server/test_i.cpp b/TAO/tests/MT_Server/test_i.cpp
new file mode 100644
index 00000000000..b3bd0d017d6
--- /dev/null
+++ b/TAO/tests/MT_Server/test_i.cpp
@@ -0,0 +1,29 @@
+// $Id$
+
+#include "test_i.h"
+#include "tao/debug.h"
+#include "ace/OS_NS_unistd.h"
+
+#if !defined(__ACE_INLINE__)
+#include "test_i.i"
+#endif /* __ACE_INLINE__ */
+
+ACE_RCSID(MT_Server, test_i, "$Id$")
+
+CORBA::Long
+Simple_Server_i::test_method (CORBA::Long x ACE_ENV_ARG_DECL_NOT_USED)
+ ACE_THROW_SPEC ((CORBA::SystemException))
+{
+ if (TAO_debug_level > 0)
+ ACE_DEBUG ((LM_DEBUG, "Request in thread %t\n"));
+ ACE_Time_Value tv (0, 15000);
+ ACE_OS::sleep (tv);
+ return x;
+}
+
+void
+Simple_Server_i::shutdown (ACE_ENV_SINGLE_ARG_DECL)
+ ACE_THROW_SPEC ((CORBA::SystemException))
+{
+ this->orb_->shutdown (0 ACE_ENV_ARG_PARAMETER);
+}
diff --git a/TAO/tests/MT_Server/test_i.h b/TAO/tests/MT_Server/test_i.h
new file mode 100644
index 00000000000..65fa40ed8b2
--- /dev/null
+++ b/TAO/tests/MT_Server/test_i.h
@@ -0,0 +1,49 @@
+// $Id$
+
+// ============================================================================
+//
+// = LIBRARY
+// TAO/tests/MT_Server
+//
+// = FILENAME
+// test_i.h
+//
+// = AUTHOR
+// Carlos O'Ryan
+//
+// ============================================================================
+
+#ifndef TAO_MT_SERVER_TEST_I_H
+#define TAO_MT_SERVER_TEST_I_H
+
+#include "testS.h"
+
+class Simple_Server_i : public POA_Simple_Server
+{
+ // = TITLE
+ // Simpler Server implementation
+ //
+ // = DESCRIPTION
+ // Implements the Simple_Server interface in test.idl
+ //
+public:
+ Simple_Server_i (CORBA::ORB_ptr orb);
+ // ctor
+
+ // = The Simple_Server methods.
+ CORBA::Long test_method (CORBA::Long x ACE_ENV_ARG_DECL_NOT_USED)
+ ACE_THROW_SPEC ((CORBA::SystemException));
+
+ void shutdown (ACE_ENV_SINGLE_ARG_DECL_NOT_USED)
+ ACE_THROW_SPEC ((CORBA::SystemException));
+
+private:
+ CORBA::ORB_var orb_;
+ // The ORB
+};
+
+#if defined(__ACE_INLINE__)
+#include "test_i.i"
+#endif /* __ACE_INLINE__ */
+
+#endif /* TAO_MT_SERVER_TEST_I_H */
diff --git a/TAO/tests/MT_Server/test_i.i b/TAO/tests/MT_Server/test_i.i
new file mode 100644
index 00000000000..97524552ff4
--- /dev/null
+++ b/TAO/tests/MT_Server/test_i.i
@@ -0,0 +1,7 @@
+// $Id$
+
+ACE_INLINE
+Simple_Server_i::Simple_Server_i (CORBA::ORB_ptr orb)
+ : orb_ (CORBA::ORB::_duplicate (orb))
+{
+}