summaryrefslogtreecommitdiff
path: root/TAO/tests/UNKNOWN_Exception
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/UNKNOWN_Exception
parent6b846cf03c0bcbd8c276cb0af61a181e5f98eaae (diff)
downloadATCD-3aff90f4a822fcf5d902bbfbcc9fa931d6191a8c.tar.gz
Repo restructuring
Diffstat (limited to 'TAO/tests/UNKNOWN_Exception')
-rw-r--r--TAO/tests/UNKNOWN_Exception/.cvsignore2
-rw-r--r--TAO/tests/UNKNOWN_Exception/README32
-rw-r--r--TAO/tests/UNKNOWN_Exception/UNKNOWN_Exception.mpc17
-rw-r--r--TAO/tests/UNKNOWN_Exception/client.cpp101
-rwxr-xr-xTAO/tests/UNKNOWN_Exception/run_test.pl49
-rw-r--r--TAO/tests/UNKNOWN_Exception/server.cpp257
-rw-r--r--TAO/tests/UNKNOWN_Exception/test.idl18
7 files changed, 476 insertions, 0 deletions
diff --git a/TAO/tests/UNKNOWN_Exception/.cvsignore b/TAO/tests/UNKNOWN_Exception/.cvsignore
new file mode 100644
index 00000000000..f2ad85300eb
--- /dev/null
+++ b/TAO/tests/UNKNOWN_Exception/.cvsignore
@@ -0,0 +1,2 @@
+client
+server
diff --git a/TAO/tests/UNKNOWN_Exception/README b/TAO/tests/UNKNOWN_Exception/README
new file mode 100644
index 00000000000..ee867ed21f7
--- /dev/null
+++ b/TAO/tests/UNKNOWN_Exception/README
@@ -0,0 +1,32 @@
+# $Id$
+
+Description:
+
+This is a test for UNKNOWN exceptions raised by the server. There are
+two places where this example tests for UNKNOWN exceptions: (a)
+UNKNOWN exception raised in an upcall and (b) UNKNOWN exception raised
+while a servant is being cleaned up after deactivation. The number of
+outstanding requests in the POA are checked after each unit of work
+performed by the server. The assumption is that if the number of
+outstanding requests are correct, then the server correctly handled
+the UNKNOWN exceptions.
+
+Expected output:
+
+A successful run is one without any asserts.
+
+The server should say:
+
+- test_i::normal_method() called
+
+- test_i::unknown_exception_in_method() called
+ Unknown exception being generated: should be propagated to the client
+
+- test_i::unknown_exception_during_deactivation() called
+ Unknown exception being generated: should be gobbled up by the POA
+
+
+And the client should say:
+
+CORBA::UNKNOWN was thrown by the server during test::unknown_exception_in_method()
+ This is expected behavior
diff --git a/TAO/tests/UNKNOWN_Exception/UNKNOWN_Exception.mpc b/TAO/tests/UNKNOWN_Exception/UNKNOWN_Exception.mpc
new file mode 100644
index 00000000000..0fe69a4a621
--- /dev/null
+++ b/TAO/tests/UNKNOWN_Exception/UNKNOWN_Exception.mpc
@@ -0,0 +1,17 @@
+// -*- MPC -*-
+// $Id$
+
+project(*Server): taoserver, exceptions {
+ Source_Files {
+ server.cpp
+ }
+}
+
+project(*Client): taoclient, anytypecode, exceptions {
+ after += *Server
+ Source_Files {
+ testC.cpp
+ client.cpp
+ }
+}
+
diff --git a/TAO/tests/UNKNOWN_Exception/client.cpp b/TAO/tests/UNKNOWN_Exception/client.cpp
new file mode 100644
index 00000000000..548b4b99e94
--- /dev/null
+++ b/TAO/tests/UNKNOWN_Exception/client.cpp
@@ -0,0 +1,101 @@
+// $Id$
+
+#include "ace/Get_Opt.h"
+#include "testC.h"
+
+ACE_RCSID (UNKNOWN_Exception, client, "$Id$")
+
+static const char *ior = "file://ior";
+static int shutdown_server = 1;
+
+static int
+parse_args (int argc, char **argv)
+{
+ ACE_Get_Opt get_opts (argc, argv, "k:x:");
+ int c;
+
+ while ((c = get_opts ()) != -1)
+ switch (c)
+ {
+ case 'k':
+ ior = get_opts.opt_arg ();
+ break;
+
+ case 'x':
+ shutdown_server = ACE_OS::atoi (get_opts.opt_arg ());
+ break;
+
+ case '?':
+ default:
+ ACE_ERROR_RETURN ((LM_ERROR,
+ "\nusage %s:\n"
+ "\t-k <ior> [defaults to %s]\n"
+ "\t-x <shutdown server> [defaults to %d]\n"
+ "\n",
+ argv [0],
+ ior,
+ shutdown_server),
+ -1);
+ }
+
+ return 0;
+}
+
+int
+main (int argc, char **argv)
+{
+ try
+ {
+ CORBA::ORB_var orb =
+ CORBA::ORB_init (argc,
+ argv,
+ 0);
+
+ int result =
+ parse_args (argc, argv);
+ if (result != 0)
+ return result;
+
+ CORBA::Object_var object =
+ orb->string_to_object (ior);
+
+ test_factory_var test_factory =
+ test_factory::_narrow (object.in ());
+
+ test_var test =
+ test_factory->create_test ();
+
+ test->normal_method ();
+
+ int unknown_exception_raised = 0;
+
+ try
+ {
+ test->unknown_exception_in_method ();
+ }
+ catch (CORBA::UNKNOWN)
+ {
+ unknown_exception_raised = 1;
+
+ ACE_DEBUG ((LM_DEBUG,
+ "\nCORBA::UNKNOWN was thrown by the server during test::unknown_exception_in_method()\n"
+ "\tThis is expected behavior\n\n"));
+ }
+
+ ACE_ASSERT (unknown_exception_raised == 1);
+ unknown_exception_raised = 0;
+
+ test->unknown_exception_during_deactivation ();
+
+ if (shutdown_server)
+ test_factory->shutdown ();
+ }
+ catch (...)
+ {
+ ACE_ERROR_RETURN ((LM_ERROR,
+ "Failure: Unexpected exception caught\n"),
+ -1);
+ }
+
+ return 0;
+}
diff --git a/TAO/tests/UNKNOWN_Exception/run_test.pl b/TAO/tests/UNKNOWN_Exception/run_test.pl
new file mode 100755
index 00000000000..9334b4edbd4
--- /dev/null
+++ b/TAO/tests/UNKNOWN_Exception/run_test.pl
@@ -0,0 +1,49 @@
+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;
+$iorfile = PerlACE::LocalFile ("server.ior");
+
+unlink $iorfile;
+
+if (PerlACE::is_vxworks_test()) {
+ $SV = new PerlACE::ProcessVX ("server", "-o server.ior");
+}
+else {
+ $SV = new PerlACE::Process ("server", "-o $iorfile");
+}
+$CL = new PerlACE::Process ("client", "-k file://$iorfile -x 1");
+
+$SV->Spawn ();
+
+if (PerlACE::waitforfile_timed ($iorfile, 10) == -1) {
+ print STDERR "ERROR: cannot find file <$iorfile>\n";
+ $SV->Kill (); $SV->TimedWait (1);
+ exit 1;
+}
+
+$client = -1;
+$client = $CL->SpawnWaitKill (200);
+
+if ($client != 0) {
+ print STDERR "ERROR: client returned $client\n";
+ $status = 1;
+}
+
+$server = $SV->WaitKill (10);
+
+if ($server != 0) {
+ print STDERR "ERROR: server returned $server\n";
+ $status = 1;
+}
+
+unlink $iorfile;
+
+exit $status;
diff --git a/TAO/tests/UNKNOWN_Exception/server.cpp b/TAO/tests/UNKNOWN_Exception/server.cpp
new file mode 100644
index 00000000000..2beb08f85fa
--- /dev/null
+++ b/TAO/tests/UNKNOWN_Exception/server.cpp
@@ -0,0 +1,257 @@
+// $Id$
+
+#include "ace/Get_Opt.h"
+#include "testS.h"
+#include "tao/PortableServer/Root_POA.h"
+#include "ace/OS_NS_stdio.h"
+
+ACE_RCSID (UNKNOWN_Exception, server, "$Id$")
+
+const char *ior_output_file = "ior";
+static int done = 0;
+
+void
+throw_exception (void)
+{
+ throw 1;
+}
+
+class test_i :
+ public POA_test
+{
+public:
+
+ test_i (CORBA::ORB_ptr orb);
+
+ void normal_method (void)
+ ACE_THROW_SPEC ((CORBA::SystemException));
+
+ void unknown_exception_in_method (void)
+ ACE_THROW_SPEC ((CORBA::SystemException));
+
+ void unknown_exception_during_deactivation (void)
+ ACE_THROW_SPEC ((CORBA::SystemException));
+
+ void _add_ref (ACE_ENV_SINGLE_ARG_DECL_WITH_DEFAULTS);
+ void _remove_ref (ACE_ENV_SINGLE_ARG_DECL_WITH_DEFAULTS);
+
+ CORBA::ORB_var orb_;
+
+ int reference_count_;
+};
+
+test_i::test_i (CORBA::ORB_ptr orb)
+ : orb_ (CORBA::ORB::_duplicate (orb)),
+ reference_count_ (1)
+{
+}
+
+void
+test_i::normal_method (void)
+ ACE_THROW_SPEC ((CORBA::SystemException))
+{
+ ACE_DEBUG ((LM_DEBUG,
+ "test_i::normal_method() called\n"));
+}
+
+void
+test_i::unknown_exception_in_method (void)
+ ACE_THROW_SPEC ((CORBA::SystemException))
+{
+ ACE_DEBUG ((LM_DEBUG,
+ "test_i::unknown_exception_in_method() called\n"));
+
+ ACE_DEBUG ((LM_DEBUG,
+ "Unknown exception being generated: should be propagated to the client\n"));
+
+ throw_exception ();
+}
+
+void
+test_i::unknown_exception_during_deactivation (void)
+ ACE_THROW_SPEC ((CORBA::SystemException))
+{
+ ACE_DEBUG ((LM_DEBUG,
+ "test_i::unknown_exception_during_deactivation() called\n"));
+
+ PortableServer::POA_var poa =
+ this->_default_POA ();
+
+ PortableServer::ObjectId_var id =
+ poa->servant_to_id (this);
+
+ poa->deactivate_object (id.in ());
+}
+
+void
+test_i::_add_ref (ACE_ENV_SINGLE_ARG_DECL)
+{
+ ACE_DEBUG ((LM_DEBUG,
+ "test_i::_add_ref() called; current refcount = %d\n",
+ this->reference_count_++));
+}
+
+void
+test_i::_remove_ref (ACE_ENV_SINGLE_ARG_DECL)
+{
+ ACE_DEBUG ((LM_DEBUG,
+ "test_i::_remove_ref() called; current refcount = %d\n",
+ this->reference_count_--));
+
+ if (this->reference_count_ == 0)
+ {
+ delete this;
+
+ ACE_DEBUG ((LM_DEBUG,
+ "Unknown exception being generated: should be gobbled up by the POA\n"));
+
+ throw_exception ();
+ }
+}
+
+class test_factory_i :
+ public POA_test_factory
+{
+public:
+
+ test_factory_i (CORBA::ORB_ptr orb);
+
+ test_ptr create_test (void)
+ ACE_THROW_SPEC ((CORBA::SystemException));
+
+ void shutdown (void)
+ ACE_THROW_SPEC ((CORBA::SystemException));
+
+ CORBA::ORB_var orb_;
+};
+
+test_factory_i::test_factory_i (CORBA::ORB_ptr orb)
+ : orb_ (CORBA::ORB::_duplicate (orb))
+{
+}
+
+test_ptr
+test_factory_i::create_test (void)
+ ACE_THROW_SPEC ((CORBA::SystemException))
+{
+ test_i *servant =
+ new test_i (this->orb_.in ());
+
+ PortableServer::ServantBase_var safe_servant (servant);
+ ACE_UNUSED_ARG (safe_servant);
+
+ test_var test =
+ servant->_this ();
+
+ return test._retn ();
+}
+
+void
+test_factory_i::shutdown (void)
+ ACE_THROW_SPEC ((CORBA::SystemException))
+{
+ ACE_DEBUG ((LM_DEBUG,
+ "factory_i::shutdown() called\n"));
+
+ done = 1;
+ this->orb_->shutdown (0);
+}
+
+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,
+ "\nusage %s:\n"
+ "\t-o <ior output file> [defaults to %s]\n"
+ "\n",
+ argv [0],
+ ior_output_file),
+ -1);
+ }
+
+ return 0;
+}
+
+int
+main (int argc, char *argv[])
+{
+ try
+ {
+ CORBA::ORB_var orb =
+ CORBA::ORB_init (argc,
+ argv,
+ "");
+
+ CORBA::Object_var poa_object =
+ orb->resolve_initial_references ("RootPOA");
+
+ 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;
+
+ {
+ test_factory_i *servant =
+ new test_factory_i (orb.in ());
+
+ PortableServer::ServantBase_var safe_servant (servant);
+ ACE_UNUSED_ARG (safe_servant);
+
+ test_factory_var test_factory =
+ servant->_this ();
+
+ CORBA::String_var ior =
+ orb->object_to_string (test_factory.in ());
+
+ 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 ();
+
+ TAO_Root_POA *tao_poa = dynamic_cast <TAO_Root_POA*> (root_poa.in ());
+
+ while (!done)
+ {
+ CORBA::ULong outstanding_requests =
+ tao_poa->outstanding_requests ();
+
+ ACE_DEBUG ((LM_DEBUG,
+ "Number of outstanding requests before ORB::perform_work(): %d\n",
+ outstanding_requests));
+
+ ACE_ASSERT (outstanding_requests == 0);
+
+ orb->perform_work ();
+ }
+ }
+ catch (...)
+ {
+ ACE_ERROR_RETURN ((LM_ERROR,
+ "Failure: Unexpected exception caught\n"),
+ -1);
+ }
+
+ return 0;
+}
diff --git a/TAO/tests/UNKNOWN_Exception/test.idl b/TAO/tests/UNKNOWN_Exception/test.idl
new file mode 100644
index 00000000000..8502c8d5cd8
--- /dev/null
+++ b/TAO/tests/UNKNOWN_Exception/test.idl
@@ -0,0 +1,18 @@
+//
+// $Id$
+//
+
+
+interface test
+{
+ void normal_method ();
+ void unknown_exception_in_method ();
+ void unknown_exception_during_deactivation ();
+};
+
+interface test_factory
+{
+ test create_test ();
+ void shutdown ();
+};
+