diff options
5 files changed, 270 insertions, 41 deletions
diff --git a/TAO/orbsvcs/FT_ReplicationManager/FT_ReplicationManager.cpp b/TAO/orbsvcs/FT_ReplicationManager/FT_ReplicationManager.cpp index ec007311810..f7669d1e79e 100644 --- a/TAO/orbsvcs/FT_ReplicationManager/FT_ReplicationManager.cpp +++ b/TAO/orbsvcs/FT_ReplicationManager/FT_ReplicationManager.cpp @@ -44,6 +44,7 @@ TAO::FT_ReplicationManager::FT_ReplicationManager () , fault_notifier_(FT::FaultNotifier::_nil()) , fault_notifier_ior_(0) , fault_consumer_() + , quit_(0) { //@@Note: this->init() is not called here (in the constructor) // since it may throw an exception. Throwing an exception in @@ -255,8 +256,7 @@ int TAO::FT_ReplicationManager::init (CORBA::ORB_ptr orb ACE_ENV_ARG_DECL) int TAO::FT_ReplicationManager::idle (int & result) { ACE_UNUSED_ARG (result); - int quit = 0; // never quit - return quit; + return this->quit_; } @@ -282,6 +282,8 @@ int TAO::FT_ReplicationManager::fini (ACE_ENV_SINGLE_ARG_DECL) result = this->fault_consumer_.fini (ACE_ENV_SINGLE_ARG_PARAMETER); ACE_CHECK_RETURN (-1); + this->quit_ = 1; + return result; } @@ -444,7 +446,7 @@ void TAO::FT_ReplicationManager::shutdown_i ( result = this->fini (ACE_ENV_SINGLE_ARG_PARAMETER); ACE_CHECK; - this->orb_->shutdown (0 ACE_ENV_SINGLE_ARG_PARAMETER); + // this->orb_->shutdown (0 ACE_ENV_SINGLE_ARG_PARAMETER); } ////////////////////////////////////////////////////// diff --git a/TAO/orbsvcs/FT_ReplicationManager/FT_ReplicationManager.h b/TAO/orbsvcs/FT_ReplicationManager/FT_ReplicationManager.h index c58f901ca56..86dcd75b190 100644 --- a/TAO/orbsvcs/FT_ReplicationManager/FT_ReplicationManager.h +++ b/TAO/orbsvcs/FT_ReplicationManager/FT_ReplicationManager.h @@ -479,6 +479,8 @@ namespace TAO /// The fault consumer. TAO::FT_FaultConsumer fault_consumer_; + /// Quit flag. + int quit_; }; } // namespace TAO diff --git a/TAO/orbsvcs/tests/FT_App/FT_App.mpc b/TAO/orbsvcs/tests/FT_App/FT_App.mpc index ef4230d9be0..28d7e8931f4 100644 --- a/TAO/orbsvcs/tests/FT_App/FT_App.mpc +++ b/TAO/orbsvcs/tests/FT_App/FT_App.mpc @@ -131,3 +131,17 @@ project(*Creator): taoclient, fault_tolerance, orbsvcsexe { run_test_rmregistry.pl } } + +project(*RMController): taoclient, fault_tolerance, orbsvcsexe { + exename = replmgr_controller + Source_Files { + FT_ReplicationManagerController.cpp + } + // explicitly omit IDL files + IDL_Files { + } + Documentation_Files { + // pretend the pl file is documentation for now + run_test_replication_mgr.pl + } +} diff --git a/TAO/orbsvcs/tests/FT_App/FT_ReplicationManagerController.cpp b/TAO/orbsvcs/tests/FT_App/FT_ReplicationManagerController.cpp new file mode 100755 index 00000000000..eff4137be20 --- /dev/null +++ b/TAO/orbsvcs/tests/FT_App/FT_ReplicationManagerController.cpp @@ -0,0 +1,196 @@ +// $Id$ + +#include "orbsvcs/FT_ReplicationManagerC.h" +#include <ace/Get_Opt.h> +#include <iostream> + +// A simple class for building a client that "controls' the +// Replication Manager (right now it just shuts it down). +class TAO_FT_ReplicationManagerController +{ +///////////////////////////// +// Public interface. +public: + TAO_FT_ReplicationManagerController (); + virtual ~TAO_FT_ReplicationManagerController (); + + int init (int & argc, char * argv[]); + int parse_args (int & argc, char* argv[]); + int run (); + +///////////////////////////// +// Forbidden. +private: + TAO_FT_ReplicationManagerController ( + const TAO_FT_ReplicationManagerController & rhs); + TAO_FT_ReplicationManagerController & operator = ( + const TAO_FT_ReplicationManagerController & rhs); + +///////////////////////////// +// Private implementation. +private: + void usage (ostream & out) const; + +///////////////////////////// +// Data members. +private: + CORBA::ORB_var orb_; + FT::ReplicationManager_var replication_manager_; + const char * rm_ior_; + int shutdown_; + +}; + +TAO_FT_ReplicationManagerController::TAO_FT_ReplicationManagerController () + : orb_ (CORBA::ORB::_nil()) + , replication_manager_ (FT::ReplicationManager::_nil()) + , rm_ior_ (0) + , shutdown_ (0) +{ +} + +TAO_FT_ReplicationManagerController::~TAO_FT_ReplicationManagerController () +{ +} + +int TAO_FT_ReplicationManagerController::init (int & argc, char * argv[]) +{ + int result = 0; + + ACE_TRY_NEW_ENV + { + // Initialize the ORB. + this->orb_ = CORBA::ORB_init (argc, argv, "" ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + // Parse arguments. + result = this->parse_args (argc, argv); + if (result == 0) + { + CORBA::Object_var obj = CORBA::Object::_nil (); + if (rm_ior_ != 0) + { + obj = this->orb_->string_to_object (rm_ior_ ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + } + else + { + obj = this->orb_->resolve_initial_references ( + "ReplicationManager" ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + } + this->replication_manager_ = FT::ReplicationManager::_narrow ( + obj.in() ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + if (CORBA::is_nil (this->replication_manager_.in())) + { + ACE_ERROR ((LM_ERROR, + ACE_TEXT ( + "TAO_FT_ReplicationManagerController::init: " + "Could not get Replication Manager's IOR.\n") + )); + result = -1; + } + } + } + ACE_CATCHANY + { + ACE_PRINT_EXCEPTION ( + ACE_ANY_EXCEPTION, + ACE_TEXT ( + "TAO_FT_ReplicationManagerController::init: \n") + ); + result = -1; + } + ACE_ENDTRY; + + return result; +} + + +int TAO_FT_ReplicationManagerController::parse_args (int & argc, char * argv[]) +{ + int result = 0; + + ACE_Get_Opt get_opts (argc, argv, "k:x"); + int c; + + while (result == 0 && (c = get_opts ()) != -1) + { + switch (c) + { + case 'k': + { + this->rm_ior_ = get_opts.opt_arg (); + break; + } + + case 'x': + { + this->shutdown_ = 1; + break; + } + + default: + std::cerr << argv[0] << ": Unknown argument -" << (char) c << std::endl; + this->usage(std::cerr); + result = -1; + break; + + case '?': + this->usage(std::cerr); + result = -1; + } + } + + return result; +} + +void TAO_FT_ReplicationManagerController::usage (ostream & out) const +{ + out << "usage" + << " -k <replication manager ior file>" + << " -x (shutdown the Replication Manager)" + << std::endl; +} + +int TAO_FT_ReplicationManagerController::run () +{ + int result = 0; + + ACE_TRY_NEW_ENV + { + if (this->shutdown_ == 1) + { + this->replication_manager_->shutdown (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_TRY_CHECK; + ACE_Time_Value tv (0, 500000); + ACE_OS::sleep (tv); + } + } + ACE_CATCHANY + { + ACE_PRINT_EXCEPTION ( + ACE_ANY_EXCEPTION, + ACE_TEXT ( + "TAO_FT_ReplicationManagerController::run: \n") + ); + result = -1; + } + ACE_ENDTRY; + + return result; +} + +int main (int argc, char * argv[]) +{ + int result = 0; + TAO_FT_ReplicationManagerController rmctrl; + result = rmctrl.init (argc, argv); + if (result == 0) + { + result = rmctrl.run (); + } + return result; +} + diff --git a/TAO/orbsvcs/tests/FT_App/run_test_replication_mgr.pl b/TAO/orbsvcs/tests/FT_App/run_test_replication_mgr.pl index 4325c4e7060..8d23d46c7f7 100755 --- a/TAO/orbsvcs/tests/FT_App/run_test_replication_mgr.pl +++ b/TAO/orbsvcs/tests/FT_App/run_test_replication_mgr.pl @@ -139,12 +139,13 @@ unlink $client_data; my($status) = 0; -my($REP1) = new PerlACE::Process (".$build_directory/ft_replica", "-o $factory1_ior -t $replica1_ior -l loc1 -i type1 -q"); -my($REP2) = new PerlACE::Process (".$build_directory/ft_replica", "-o $factory2_ior -t $replica2_ior -l loc2 -i type1 -q"); +my($REP1) = new PerlACE::Process (".$build_directory/ft_replica", "-o $factory1_ior -t $replica1_ior -l loc1 -i type1 -q -ORBInitRef ReplicationManager=file://$replmgr_ior"); +my($REP2) = new PerlACE::Process (".$build_directory/ft_replica", "-o $factory2_ior -t $replica2_ior -l loc2 -i type1 -q -ORBInitRef ReplicationManager=file://$replmgr_ior"); my($DET) = new PerlACE::Process ("$ENV{'TAO_ROOT'}/orbsvcs/Fault_Detector$build_directory/Fault_Detector", "-o $detector_ior -q"); my($NOT) = new PerlACE::Process ("$ENV{'TAO_ROOT'}/orbsvcs/Fault_Notifier$build_directory/Fault_Notifier", "-o $notifier_ior -v -q"); my($CONS) = new PerlACE::Process (".$build_directory/ft_fault_consumer", "-o $ready_file -n file://$notifier_ior -q -d file://$detector_ior -r file://$replica1_ior -r file://$replica2_ior"); my($REPLM) = new PerlACE::Process ("$ENV{'TAO_ROOT'}/orbsvcs/FT_ReplicationManager$build_directory/FT_ReplicationManager", "-o $replmgr_ior -f file://$notifier_ior"); +my($REPLM_CTRL) = new PerlACE::Process (".$build_directory/replmgr_controller", "-k file://$replmgr_ior -x"); my($CL); if (simulated) { @@ -154,35 +155,12 @@ if (simulated) { $CL = new PerlACE::Process (".$build_directory/ft_client", "-f -f file://$replica1_iogr -c testscript"); } -print "TEST: starting replica1 " . $REP1->CommandLine . "\n" if ($verbose); -$REP1->Spawn (); - -print "TEST: waiting for replica 1's IOR\n" if ($verbose); -if (PerlACE::waitforfile_timed ($replica1_ior, 5) == -1) { - print STDERR "ERROR: cannot find file <$replica1_ior>\n"; - $REP1->Kill (); $REP1->TimedWait (1); - exit 1; -} - -print "\nTEST: starting replica2 " . $REP2->CommandLine . "\n" if ($verbose); -$REP2->Spawn (); - -print "TEST: waiting for replica 2's IOR\n" if ($verbose); -if (PerlACE::waitforfile_timed ($replica2_ior, 5) == -1) { - print STDERR "ERROR: cannot find file <$replica2_ior>\n"; - $REP1->Kill (); $REP1->TimedWait (1); - $REP2->Kill (); $REP2->TimedWait (1); - exit 1; -} - print "\nTEST: starting detector factory " . $DET->CommandLine . "\n" if ($verbose); $DET->Spawn (); print "TEST: waiting for detector's IOR\n" if ($verbose); if (PerlACE::waitforfile_timed ($detector_ior, 5) == -1) { print STDERR "ERROR: cannot find file <$detector_ior>\n"; - $REP1->Kill (); $REP1->TimedWait (1); - $REP2->Kill (); $REP2->TimedWait (1); $DET->Kill (); $DET->TimedWait(1); exit 1; } @@ -193,8 +171,6 @@ $NOT->Spawn (); print "TEST: waiting for notifier's IOR\n" if ($verbose); if (PerlACE::waitforfile_timed ($notifier_ior, 5) == -1) { print STDERR "ERROR: cannot find file <$notifier_ior>\n"; - $REP1->Kill (); $REP1->TimedWait (1); - $REP2->Kill (); $REP2->TimedWait (1); $DET->Kill (); $DET->TimedWait(1); $NOT->Kill (); $NOT->TimedWait(1); exit 1; @@ -206,11 +182,36 @@ $REPLM->Spawn (); print "TEST: waiting for Replication Manager's IOR file\n" if ($verbose); if (PerlACE::waitforfile_timed ($replmgr_ior, 5) == -1) { print STDERR "ERROR: cannot find file <$replmgr_ior>\n"; + $DET->Kill (); $DET->TimedWait(1); + $NOT->Kill (); $NOT->TimedWait(1); + $REPLM->Kill (); $REPLM->TimedWait(1); + exit 1; +} + +print "TEST: starting replica1 " . $REP1->CommandLine . "\n" if ($verbose); +$REP1->Spawn (); + +print "TEST: waiting for replica 1's IOR\n" if ($verbose); +if (PerlACE::waitforfile_timed ($replica1_ior, 5) == -1) { + print STDERR "ERROR: cannot find file <$replica1_ior>\n"; + $DET->Kill (); $DET->TimedWait(1); + $NOT->Kill (); $NOT->TimedWait(1); + $REPLM->Kill (); $REPLM->TimedWait(1); $REP1->Kill (); $REP1->TimedWait (1); - $REP2->Kill (); $REP2->TimedWait (1); + exit 1; +} + +print "\nTEST: starting replica2 " . $REP2->CommandLine . "\n" if ($verbose); +$REP2->Spawn (); + +print "TEST: waiting for replica 2's IOR\n" if ($verbose); +if (PerlACE::waitforfile_timed ($replica2_ior, 5) == -1) { + print STDERR "ERROR: cannot find file <$replica2_ior>\n"; $DET->Kill (); $DET->TimedWait(1); $NOT->Kill (); $NOT->TimedWait(1); $REPLM->Kill (); $REPLM->TimedWait(1); + $REP1->Kill (); $REP1->TimedWait (1); + $REP2->Kill (); $REP2->TimedWait (1); exit 1; } @@ -220,12 +221,12 @@ $CONS->Spawn (); print "TEST: waiting for READY.FILE from fault consumer\n" if ($verbose); if (PerlACE::waitforfile_timed ($ready_file, 5) == -1) { print STDERR "ERROR: cannot find file <$ready_file>\n"; - $REP1->Kill (); $REP1->TimedWait (1); - $REP2->Kill (); $REP2->TimedWait (1); $DET->Kill (); $DET->TimedWait(1); $NOT->Kill (); $NOT->TimedWait(1); - $CONS->Kill (); $CONS->TimedWait(1); $REPLM->Kill (); $REPLM->TimedWait(1); + $REP1->Kill (); $REP1->TimedWait (1); + $REP2->Kill (); $REP2->TimedWait (1); + $CONS->Kill (); $CONS->TimedWait(1); exit 1; } @@ -258,13 +259,6 @@ if ($detector != 0) { $status = 1; } -print "\nTEST: wait for notifier to leave.\n" if ($verbose); -$notifier = $NOT->WaitKill (20); -if ($notifier != 0) { - print STDERR "ERROR: notifier returned $notifier\n"; - $status = 1; -} - print "\nTEST: wait for fault consumer to leave.\n" if ($verbose); $consumer = $CONS->WaitKill (20); if ($consumer != 0) { @@ -272,6 +266,27 @@ if ($consumer != 0) { $status = 1; } +print "\nTEST: shutting down the replication manager.\n" if ($verbose); +$controller = $REPLM_CTRL->SpawnWaitKill (300); +if ($controller != 0) { + print STDERR "ERROR: replication manager controller returned $controller\n"; + $status = 1; +} + +print "\nTEST: wait for replication manager to leave.\n" if ($verbose); +$rm = $REPLM->WaitKill (30); +if ($rm != 0) { + print STDERR "ERROR: replication manager returned $rm\n"; + $status = 1; +} + +print "\nTEST: wait for notifier to leave.\n" if ($verbose); +$notifier = $NOT->WaitKill (20); +if ($notifier != 0) { + print STDERR "ERROR: notifier returned $notifier\n"; + $status = 1; +} + print "\nTEST: releasing scratch files.\n" if ($verbose); unlink $replica1_ior; unlink $replica2_ior; |