diff options
author | dai_y <dai_y@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 2009-04-25 06:33:24 +0000 |
---|---|---|
committer | dai_y <dai_y@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 2009-04-25 06:33:24 +0000 |
commit | a141ce4fafb180b7c43fb54aa2712e21e84c1421 (patch) | |
tree | 45376633c5911f7f225057cffa8905f09cf6a19e /TAO/orbsvcs/tests | |
parent | 7823aa89f51dbc0c20dc07c9e4db1077da4f4825 (diff) | |
download | ATCD-a141ce4fafb180b7c43fb54aa2712e21e84c1421.tar.gz |
Sat Apr 25 06:25:37 UTC 2009 Yan Dai <dai_y@ociweb.com>
Diffstat (limited to 'TAO/orbsvcs/tests')
8 files changed, 754 insertions, 0 deletions
diff --git a/TAO/orbsvcs/tests/ImplRepo/ReconnectServer/ReconnectServer.mpc b/TAO/orbsvcs/tests/ImplRepo/ReconnectServer/ReconnectServer.mpc new file mode 100755 index 00000000000..e5c946e4951 --- /dev/null +++ b/TAO/orbsvcs/tests/ImplRepo/ReconnectServer/ReconnectServer.mpc @@ -0,0 +1,49 @@ +// $Id$ +// +// Really the server is the only one that needs to avoid minimum_corba and +// the lot. But there's no sense in building anything if you can't build +// the server. + +project(*idl): taoidldefaults, avoids_minimum_corba, avoids_corba_e_compact, avoids_corba_e_micro { + custom_only = 1 + IDL_Files { + test.idl + } +} + +project(*serverA): taoserver, imr_client, avoids_minimum_corba, avoids_corba_e_compact, avoids_corba_e_micro { + exename = serverA + after += *idl + IDL_Files { + } + Source_Files { + testC.cpp + testS.cpp + serverA.cpp + test_i.cpp + } +} + +project(*serverB): taoserver, imr_client, avoids_minimum_corba, avoids_corba_e_compact, avoids_corba_e_micro { + exename = serverB + after += *idl + IDL_Files { + } + Source_Files { + testC.cpp + testS.cpp + serverB.cpp + test_i.cpp + } +} + +project(*client): taoserver, avoids_minimum_corba, avoids_corba_e_compact, avoids_corba_e_micro { + exename = client + after += *idl + IDL_Files { + } + Source_Files { + testC.cpp + client.cpp + } +} diff --git a/TAO/orbsvcs/tests/ImplRepo/ReconnectServer/client.cpp b/TAO/orbsvcs/tests/ImplRepo/ReconnectServer/client.cpp new file mode 100755 index 00000000000..3b64fbddf4a --- /dev/null +++ b/TAO/orbsvcs/tests/ImplRepo/ReconnectServer/client.cpp @@ -0,0 +1,164 @@ +#include "testS.h" +#include "tao/AnyTypeCode/Any.h" +#include "ace/Get_Opt.h" +#include <ace/Task.h> +#include <ace/OS.h> + + +const ACE_TCHAR *ior_input_file = "file://serverA.ior"; +int test_duration_sec = 15; + +class Client_Task : public ACE_Task_Base +{ + public: + Client_Task (Test::Time_ptr obj) + : test_ (Test::Time::_duplicate (obj)), + communication_failed_ (false), + reconnected_ (false), + caught_object_not_exist_ (false) + {} + + virtual int svc (void) + { + ACE_Time_Value start = ACE_OS::gettimeofday (); + ACE_Time_Value elapsed; + int i = 0; + while (elapsed < ACE_Time_Value (test_duration_sec)) + { + try + { + ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%P|%t)Request %d\n"), i )); + test_->current_time(); + ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%P|%t)Done request %d\n"), i )); + if (communication_failed_) + { + communication_failed_ = false; + reconnected_ = true; + } + ACE_OS::sleep (1); + } + catch (const CORBA::OBJECT_NOT_EXIST &) + { + ACE_ERROR ((LM_ERROR, ACE_TEXT ("(%P|%t)caught OBJECT_NOT_EXIST exception for request %d\n"), i )); + caught_object_not_exist_ = false; + ACE_OS::sleep (1); + break; + } + catch (const CORBA::Exception & /*ex*/) + { + //ex._tao_print_exception ("Exception caught:"); + communication_failed_ = true; + ACE_OS::sleep (1); + } + ++i; + elapsed = ACE_OS::gettimeofday () - start; + } + + ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%P|%t)Client thread exit \n"))); + return 0; + } + + bool test_passed () const + { + return ! communication_failed_ && reconnected_ && ! caught_object_not_exist_; + } + + private: + + Test::Time_var test_; + bool communication_failed_; + bool reconnected_; + bool caught_object_not_exist_; +}; + + +int +parse_args (int argc, ACE_TCHAR* argv[]) +{ + ACE_Get_Opt get_opts (argc, argv, "i:t:"); + int c; + + + while ((c = get_opts ()) != -1) + switch (c) + { + case 'i': + ior_input_file = get_opts.opt_arg (); + break; + case 't': + test_duration_sec = ACE_OS::atoi (get_opts.opt_arg ()); + break; + case '?': + default: + ACE_ERROR_RETURN ((LM_ERROR, + "usage: %s " + "-i <iorfile> -t <test_duration>" + "\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); + + if (parse_args (argc, argv) != 0) + { + return 1; + } + + CORBA::Object_var object = orb->resolve_initial_references ("RootPOA"); + PortableServer::POA_var rootPOA = PortableServer::POA::_narrow (object.in ()); + + PortableServer::POAManager_var poa_manager = rootPOA->the_POAManager (); + poa_manager->activate (); + + object = orb->string_to_object(ior_input_file); + + Test::Time_var test = Test::Time::_narrow(object.in ()); + + if (CORBA::is_nil(test.in ())) + { + ACE_ERROR_RETURN ((LM_ERROR, + "(%P|%t) Object reference is nil \n"), + 1); + } + + Client_Task task (test.in ()); + task.activate (THR_NEW_LWP | THR_JOINABLE, 1, 1); + + ACE_Time_Value tv(test_duration_sec); + orb->run (&tv); + + task.wait (); + + // Destroy the POA, waiting until the destruction terminates + rootPOA->destroy (1, 1); + orb->destroy (); + + if (task.test_passed ()) + { + ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%P|%t)Client test passed \n"))); + } + else + { + ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("(%P|%t)Client test failed.\n")), 1); + } + } + catch (const CORBA::Exception &ex) + { + ex._tao_print_exception ("Exception caught by client:"); + return 1; + } + + return 0; +} + + diff --git a/TAO/orbsvcs/tests/ImplRepo/ReconnectServer/run_test.pl b/TAO/orbsvcs/tests/ImplRepo/ReconnectServer/run_test.pl new file mode 100755 index 00000000000..f3a2ac8c079 --- /dev/null +++ b/TAO/orbsvcs/tests/ImplRepo/ReconnectServer/run_test.pl @@ -0,0 +1,151 @@ +eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}' + & eval 'exec perl -S $0 $argv:q' + if 0; + +# $Id$ +# -*- perl -*- + +############################################################################### + +use strict; +use Sys::Hostname; +use lib "$ENV{ACE_ROOT}/bin"; +use PerlACE::Run_Test; + +my $imr_locator_ior = PerlACE::LocalFile ("imr_locator.ior"); +my $protocol = "iiop"; +my $host = hostname(); +my $port = PerlACE::uniqueid () + 10001; +my $imr_endpoint = "-ORBEndpoint " . "$protocol" . "://:" . $port; +my $imr_db = PerlACE::LocalFile ("imr.db"); +# -ORBDebugLevel 10 -ORBVerboseLogging 1 -ORBLogFile imr.log +my $imr_locator_args = "$imr_endpoint -UnregisterIfAddressReused -d 1 -o $imr_locator_ior -p $imr_db"; +my $IMR_LOCATOR = new PerlACE::Process ("../../../ImplRepo_Service/ImplRepo_Service", $imr_locator_args); +my $TAO_IMR = new PerlACE::Process("$ENV{ACE_ROOT}/bin/tao_imr"); +my $svr_port_base = PerlACE::uniqueid () + 9000; +my $svr_a_id = "AAA"; +my $svr_b_id = "BBB"; +my $svr_a_ior = PerlACE::LocalFile ("A.ior"); +my $svr_b_ior = PerlACE::LocalFile ("B.ior"); +my $client_duration = 30; +my $svr_endpoint = "-ORBEndpoint " . "$protocol" . "://:" . "$svr_port_base/portspan=20"; +my $imr_initref = "-ORBInitRef ImplRepoService=file://$imr_locator_ior"; +my $svr_a_args = "$svr_endpoint $imr_initref -ORBServerId $svr_a_id -ORBUseIMR 1 -o $svr_a_ior"; +my $svr_b_args = "$svr_endpoint $imr_initref -ORBServerId $svr_b_id -ORBUseIMR 1 -o $svr_b_ior"; +my $cli_args = "-ORBForwardInvocationOnObjectNotExist 1 -i file://$svr_a_ior -t $client_duration"; + +my $SVR_A = new PerlACE::Process ("serverA", $svr_a_args); +my $SVR_B = new PerlACE::Process ("serverB", $svr_b_args); +my $CLI = new PerlACE::Process ("client", $cli_args); +my $delay = 3; + +# Make sure the files are gone, so we can wait on them. +unlink $svr_a_ior; +unlink $svr_b_ior; +unlink $imr_db; +unlink $imr_locator_ior; + +my $status = 0; +print STDERR $IMR_LOCATOR->CommandLine () . "\n"; +$IMR_LOCATOR->Spawn (); + +if (PerlACE::waitforfile_timed ($imr_locator_ior, 10) == -1) { + print STDERR "ERROR: cannot find $imr_locator_ior\n"; + $IMR_LOCATOR->Kill (); + $status = 1; +} + +sleep (2); +print STDERR "=== start server A: " . $SVR_A->CommandLine () . "\n"; +$SVR_A->Spawn (); + +if (PerlACE::waitforfile_timed ($svr_a_ior, 10) == -1) { + print STDERR "ERROR: cannot find $svr_a_ior\n"; + $IMR_LOCATOR->Kill (); + $SVR_A->Kill (); + $status = 1; +} + +print STDERR "=== start server B: " . $SVR_B->CommandLine () . "\n"; +$SVR_B->Spawn (); + +if (PerlACE::waitforfile_timed ($svr_b_ior, 10) == -1) { + print STDERR "ERROR: cannot find $svr_b_ior\n"; + $IMR_LOCATOR->Kill (); + $SVR_A->Kill (); + $SVR_B->Kill (); + $status = 1; +} + +print STDERR "=== start client: " . $CLI->CommandLine () . "\n"; +my $client = $CLI->Spawn (); + +if ($client != 0) { + print STDERR "ERROR: client returned $client\n"; + $IMR_LOCATOR->Kill (); + $SVR_A->Kill (); + $SVR_B->Kill (); + $status = 1; +} + +sleep (5); + +print STDERR "=== kill server A\n"; +my $server = $SVR_A->TerminateWaitKill (5); + +if ($server != 0) { + print STDERR "ERROR: server A returned $server\n"; + $status = 1; +} + +print STDERR "=== kill server B\n"; +$server = $SVR_B->TerminateWaitKill (5); + +if ($server != 0) { + print STDERR "ERROR: server B returned $server\n"; + $status = 1; +} + +sleep (5); +unlink $svr_a_ior; +unlink $svr_b_ior; + +print STDERR "=== restart server B\n"; +$svr_b_args = $svr_b_args . " -l $delay"; +# Run -ORBDebugLevel 10 to see server raise OBJECT_NOT_EXIST exception. +$SVR_B = new PerlACE::Process ("serverB", $svr_b_args); +$SVR_B->Spawn (); +if (PerlACE::waitforfile_timed ($svr_b_ior, 10) == -1) { + print STDERR "ERROR: cannot find $svr_b_ior\n"; + $IMR_LOCATOR->Kill (); + $SVR_B->Kill (); + $CLI->Kill (); + $status = 1; +} + +sleep ($delay * 2); + +print STDERR "=== restart server A\n"; +$SVR_A->Spawn (); +if (PerlACE::waitforfile_timed ($svr_a_ior, 10) == -1) { + print STDERR "ERROR: cannot find $svr_a_ior\n"; + $IMR_LOCATOR->Kill (); + $SVR_A->Kill (); + $SVR_B->Kill (); + $CLI->Kill (); + $status = 1; +} + +$CLI->WaitKill ($client_duration); + +$IMR_LOCATOR->Kill(); +$SVR_A->Kill(); +$SVR_B->Kill(); + +# Make sure the files are gone, so we can wait on them. +unlink $svr_a_ior; +unlink $svr_b_ior; +unlink $imr_db; +unlink $imr_locator_ior; + +exit $status; diff --git a/TAO/orbsvcs/tests/ImplRepo/ReconnectServer/serverA.cpp b/TAO/orbsvcs/tests/ImplRepo/ReconnectServer/serverA.cpp new file mode 100755 index 00000000000..eff5140b8b1 --- /dev/null +++ b/TAO/orbsvcs/tests/ImplRepo/ReconnectServer/serverA.cpp @@ -0,0 +1,127 @@ +#include "test_i.h" +#include "tao/ImR_Client/ImR_Client.h" +#include <ace/Task.h> +#include <ace/Get_Opt.h> + +const ACE_TCHAR * ior_output_file = ACE_TEXT ("serverA.ior"); + +int +parse_args (int argc, ACE_TCHAR *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); + } + + return 0; +}; + +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; + } + + CORBA::Object_var object = + orb->resolve_initial_references ("RootPOA"); + PortableServer::POA_var rootPOA = + PortableServer::POA::_narrow (object.in ()); + PortableServer::POAManager_var poa_manager = + rootPOA->the_POAManager (); + + CORBA::PolicyList policies (5); + policies.length (5); + + // Lifespan policy + policies[0] = + rootPOA->create_lifespan_policy (PortableServer::PERSISTENT); + + // Servant Retention Policy + policies[1] = + rootPOA->create_servant_retention_policy (PortableServer::RETAIN ); + + // ID Assignment Policy + policies[2] = + rootPOA->create_id_assignment_policy (PortableServer::USER_ID ); + + // Request Processing Policy + policies[3] = + rootPOA->create_request_processing_policy (PortableServer::USE_ACTIVE_OBJECT_MAP_ONLY ); + + // Threading policy + policies[4] = + rootPOA->create_thread_policy (PortableServer::ORB_CTRL_MODEL); + + PortableServer::POA_var poa_a = rootPOA->create_POA ("poaA", + poa_manager.in (), + policies + ); + PortableServer::POA_var poa_c = rootPOA->create_POA ("poaC", + poa_manager.in (), + policies + ); + + for (CORBA::ULong i = 0; + i < policies.length (); + ++i) + { + CORBA::Policy_ptr policy = policies[i]; + policy->destroy (); + } + + Test_Time_i* time = new Test_Time_i(); + + PortableServer::ObjectId_var oid = + PortableServer::string_to_ObjectId ("Server_A"); + poa_a->activate_object_with_id (oid.in (), time); + CORBA::Object_var time_obj = poa_a->id_to_reference(oid.in()); + CORBA::String_var ior = + orb->object_to_string (time_obj.in ()); + + poa_manager->activate (); + + // Output the IOR to the <ior_output_file> + 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); + + orb->run (); + + rootPOA->destroy (1, 1); + orb->destroy (); + } + catch (const CORBA::Exception &ex) + { + ex._tao_print_exception ("Exception caught by serverA:"); + return 1; + } + + return 0; +} + + diff --git a/TAO/orbsvcs/tests/ImplRepo/ReconnectServer/serverB.cpp b/TAO/orbsvcs/tests/ImplRepo/ReconnectServer/serverB.cpp new file mode 100755 index 00000000000..fd4f207447f --- /dev/null +++ b/TAO/orbsvcs/tests/ImplRepo/ReconnectServer/serverB.cpp @@ -0,0 +1,134 @@ +#include "test_i.h" +#include "tao/ImR_Client/ImR_Client.h" +#include <ace/Task.h> +#include <ace/Get_Opt.h> +#include <ace/OS.h> + +const ACE_TCHAR * ior_output_file = ACE_TEXT ("serverB.ior"); +// delay between resolving RootPOA init ref and create_POA. +int delay = 0; + +int +parse_args (int argc, ACE_TCHAR *argv[]) +{ + ACE_Get_Opt get_opts (argc, argv, "o:l:"); + int c; + + + while ((c = get_opts ()) != -1) + switch (c) + { + case 'o': + ior_output_file = get_opts.opt_arg (); + break; + case 'l': + delay = ACE_OS::atoi (get_opts.opt_arg ()); + break; + case '?': + default: + ACE_ERROR_RETURN ((LM_ERROR, + "usage: %s " + "-o <iorfile> -l <delay>" + "\n", + argv [0]), + -1); + } + + return 0; +}; + +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; + } + + CORBA::Object_var object = + orb->resolve_initial_references ("RootPOA"); + PortableServer::POA_var rootPOA = + PortableServer::POA::_narrow (object.in ()); + PortableServer::POAManager_var poa_manager = + rootPOA->the_POAManager (); + + CORBA::PolicyList policies (5); + policies.length (5); + + // Lifespan policy + policies[0] = + rootPOA->create_lifespan_policy (PortableServer::PERSISTENT); + + // Servant Retention Policy + policies[1] = + rootPOA->create_servant_retention_policy (PortableServer::RETAIN ); + + // ID Assignment Policy + policies[2] = + rootPOA->create_id_assignment_policy (PortableServer::USER_ID ); + + // Request Processing Policy + policies[3] = + rootPOA->create_request_processing_policy (PortableServer::USE_ACTIVE_OBJECT_MAP_ONLY ); + + // Threading policy + policies[4] = + rootPOA->create_thread_policy (PortableServer::ORB_CTRL_MODEL); + + if (delay > 0) + { + ACE_OS::sleep (delay); + } + + PortableServer::POA_var poa_a = rootPOA->create_POA ("poaB", + poa_manager.in (), + policies + ); + + for (CORBA::ULong i = 0; + i < policies.length (); + ++i) + { + CORBA::Policy_ptr policy = policies[i]; + policy->destroy (); + } + + Test_Dummy_i* dummy = new Test_Dummy_i(); + + PortableServer::ObjectId_var oid = + PortableServer::string_to_ObjectId ("Server_B"); + poa_a->activate_object_with_id (oid.in (), dummy); + CORBA::Object_var dummy_obj = poa_a->id_to_reference(oid.in()); + CORBA::String_var ior = + orb->object_to_string (dummy_obj.in ()); + + poa_manager->activate (); + + // Output the IOR to the <ior_output_file> + 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); + + orb->run (); + + rootPOA->destroy (1, 1); + orb->destroy (); + } + catch (const CORBA::Exception &ex) + { + ex._tao_print_exception ("Exception caught by serverB:"); + return 1; + } + + return 0; +} + + diff --git a/TAO/orbsvcs/tests/ImplRepo/ReconnectServer/test.idl b/TAO/orbsvcs/tests/ImplRepo/ReconnectServer/test.idl new file mode 100755 index 00000000000..b29892067a6 --- /dev/null +++ b/TAO/orbsvcs/tests/ImplRepo/ReconnectServer/test.idl @@ -0,0 +1,14 @@ +module Test +{ + interface Dummy + { + string getMessage(); + }; + + interface Time + { + long current_time (); + oneway void shutdown (); + }; + +}; diff --git a/TAO/orbsvcs/tests/ImplRepo/ReconnectServer/test_i.cpp b/TAO/orbsvcs/tests/ImplRepo/ReconnectServer/test_i.cpp new file mode 100755 index 00000000000..703d319472b --- /dev/null +++ b/TAO/orbsvcs/tests/ImplRepo/ReconnectServer/test_i.cpp @@ -0,0 +1,59 @@ +#include "test_i.h" +#include "ace/OS_NS_time.h" + + +// Implementation skeleton constructor +Test_Dummy_i::Test_Dummy_i (void) +{ +} + +// Implementation skeleton destructor +Test_Dummy_i::~Test_Dummy_i (void) +{ +} + +char * Test_Dummy_i::getMessage ( + void + ) + throw ( + ::CORBA::SystemException + ) +{ + // Add your implementation here + return CORBA::string_dup("Test::Dummy---->Hello World"); +} + +Test_Time_i::Test_Time_i (void) +{ +} + +// Implementation skeleton destructor +Test_Time_i::~Test_Time_i (void) +{ +} + +::CORBA::Long Test_Time_i::current_time ( + void + ) + throw ( + ::CORBA::SystemException + ) +{ + ACE_DEBUG ((LM_DEBUG, "(%P|%t)Test_Time_i::current_time called\n")); + return CORBA::Long (ACE_OS::time (0)); +} + +void Test_Time_i::shutdown ( + void + ) + throw ( + ::CORBA::SystemException + ) +{ + ACE_DEBUG ((LM_DEBUG, + "%s\n", + "Time_i is shutting down")); + +} + + diff --git a/TAO/orbsvcs/tests/ImplRepo/ReconnectServer/test_i.h b/TAO/orbsvcs/tests/ImplRepo/ReconnectServer/test_i.h new file mode 100755 index 00000000000..165c90becf9 --- /dev/null +++ b/TAO/orbsvcs/tests/ImplRepo/ReconnectServer/test_i.h @@ -0,0 +1,56 @@ +#ifndef IMR_SWITCHSERVER_H +#define IMR_SWITCHSERVER_H + +#include "testS.h" + +#if !defined (ACE_LACKS_PRAGMA_ONCE) +#pragma once +#endif /* ACE_LACKS_PRAGMA_ONCE */ + + +class Test_Dummy_i + : public virtual POA_Test::Dummy +{ +public: + // Constructor + Test_Dummy_i (void); + + // Destructor + virtual ~Test_Dummy_i (void); + + virtual char * getMessage (void) + throw ( + ::CORBA::SystemException + ); +}; + +class Test_Time_i + : public virtual POA_Test::Time +{ +public: + // Constructor + Test_Time_i (void); + + // Destructor + virtual ~Test_Time_i (void); + + virtual + ::CORBA::Long current_time ( + void + ) + throw ( + ::CORBA::SystemException + ); + + virtual + void shutdown ( + void + ) + throw ( + ::CORBA::SystemException + ); +}; + + +#endif /* IMR_SWITCHSERVER_H */ + |