diff options
Diffstat (limited to 'TAO/tests/AMI_Timeouts/timeout_client.cpp')
-rw-r--r-- | TAO/tests/AMI_Timeouts/timeout_client.cpp | 340 |
1 files changed, 88 insertions, 252 deletions
diff --git a/TAO/tests/AMI_Timeouts/timeout_client.cpp b/TAO/tests/AMI_Timeouts/timeout_client.cpp index bbeda7053b8..27010961a10 100644 --- a/TAO/tests/AMI_Timeouts/timeout_client.cpp +++ b/TAO/tests/AMI_Timeouts/timeout_client.cpp @@ -1,31 +1,32 @@ -//============================================================================= -/** - * @file timeout_client.cpp - * - * $Id$ - * - * Tests for proper handling of timeouts with AMI - * - * - * @author Michael Kircher <Michael.Kircher@mchp.siemens.de> - */ -//============================================================================= +// $Id$ + +// ============================================================================ +// +// = LIBRARY +// TAO/tests/AMI_Timeouts +// +// = FILENAME +// timeout_client.cpp +// +// = DESCRIPTION +// Tests for proper handling of timeouts with AMI +// +// = AUTHOR +// Michael Kircher <Michael.Kircher@mchp.siemens.de> +// +// ============================================================================ + #include "timeout_client.h" TimeoutClient::TimeoutClient (CORBA::ORB_ptr orb, Timeout_ptr timeoutObject, - AMI_TimeoutHandler_ptr replyHandlerObject, - TimeoutHandler_i *timeoutHandler_i, - unsigned long timeToWait) + AMI_TimeoutHandler_ptr replyHandlerObject) : orb_(CORBA::ORB::_duplicate (orb)) - , timeoutObject_(Timeout::_duplicate (timeoutObject)) - , replyHandlerObject_(AMI_TimeoutHandler::_duplicate (replyHandlerObject)) - , timeoutHandler_i_(timeoutHandler_i) - , local_reply_excep_counter_ (0) - , INVOKE_SYNCH(false) - , INVOKE_ASYNCH(true) - , timeToWait_ (timeToWait) +, timeoutObject_(Timeout::_duplicate (timeoutObject)) +, replyHandlerObject_(AMI_TimeoutHandler::_duplicate (replyHandlerObject)) +, INVOKE_SYNCH(false) +, INVOKE_ASYNCH(true) { } @@ -37,59 +38,10 @@ TimeoutClient::~TimeoutClient () } - int -TimeoutClient::svc () +TimeoutClient::init () { - this->initialize (); - - ACE_DECLARE_NEW_CORBA_ENV; - ACE_TRY - { - - // Tests timeouts for synchronous - this->synch_test (); - - // Tests AMI timeouts for influences on non-timeout calls - this->none_test (); - - // Tests AMI timeouts for accuracy - this->accuracy_test (); - - // Tests AMI timeouts for influences on non-timeout calls - this->none_test (); - - // shut down remote ORB - timeoutObject_->shutdown (ACE_TRY_ENV); - ACE_TRY_CHECK; - - ACE_Time_Value tv (0, 20); // wait for the ORB to deliver the shutdonw - ACE_OS::sleep (tv); - - // shut down local ORB - orb_->shutdown (false, ACE_TRY_ENV); - ACE_TRY_CHECK; - } - ACE_CATCHANY - { - ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, "Caught exception:"); - return 1; - } - ACE_ENDTRY; - ACE_CHECK_RETURN (-1); - - ACE_DEBUG ((LM_DEBUG, - "TimeoutClient::svc: Done\n\n")); - - return 0; -}; - - -int -TimeoutClient::initialize () -{ - ACE_DECLARE_NEW_CORBA_ENV; - ACE_TRY + ACE_TRY_NEW_ENV { CORBA::Object_var object = orb_->resolve_initial_references ("ORBPolicyManager", @@ -102,11 +54,10 @@ TimeoutClient::initialize () } ACE_CATCHANY { - ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, "Caught exception:"); + ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, "Catched exception:"); return 1; } ACE_ENDTRY; - ACE_CHECK_RETURN (-1); return 0; } @@ -114,225 +65,110 @@ TimeoutClient::initialize () void TimeoutClient::send (bool async, - unsigned long local_timeout, - unsigned long remote_sleep) + unsigned long msec) { - ACE_DEBUG ((LM_DEBUG, - "(%P|%t) Invoking ")); - if (async) - ACE_DEBUG ((LM_DEBUG, - "asynch ")); - else - ACE_DEBUG ((LM_DEBUG, - "synch ")); - - ACE_DEBUG ((LM_DEBUG, - "local: %dms remote: %dms ... ", - local_timeout, - remote_sleep)); - - CORBA::PolicyList policy_list (1); - - ACE_DECLARE_NEW_CORBA_ENV; - ACE_TRY_EX (normal) + ACE_TRY_NEW_ENV { - if (local_timeout != 0) - { - TimeBase::TimeT timeout = 10000 * local_timeout; - - CORBA::Any any_orb; - any_orb <<= timeout; - - policy_list.length (1); - policy_list[0] = - orb_->create_policy (Messaging::RELATIVE_RT_TIMEOUT_POLICY_TYPE, - any_orb, - ACE_TRY_ENV); - ACE_TRY_CHECK_EX (normal); - - policy_manager_->set_policy_overrides (policy_list, - CORBA::SET_OVERRIDE, - ACE_TRY_ENV); - ACE_TRY_CHECK_EX (normal); - } - else - { - policy_list.length (0); - policy_manager_->set_policy_overrides (policy_list, - CORBA::SET_OVERRIDE, - ACE_TRY_ENV); - ACE_TRY_CHECK_EX (normal); - } - - - // Start time measurement at the reply handler - timeoutHandler_i_->start (); - if (async) { - timeoutObject_->sendc_sendTimeToWait (replyHandlerObject_.in (), - remote_sleep, + timeoutObject_->sendc_sendTimeToWait (replyHandlerObject_, + msec, ACE_TRY_ENV); } else // synch { - timeoutObject_->sendTimeToWait (remote_sleep, + timeoutObject_->sendTimeToWait (msec, ACE_TRY_ENV); } - ACE_TRY_CHECK_EX (normal); + + ACE_TRY_CHECK; } ACE_CATCH (CORBA::TIMEOUT, timeout) { - local_reply_excep_counter_++; - // Trap this exception and continue... ACE_DEBUG ((LM_DEBUG, - "\n==> Trapped a TIMEOUT exception (expected)\n")); + "==> Trapped a TIMEOUT exception (expected)\n\n")); - } - ACE_ENDTRY; - ACE_CHECK; + // @@Michael: I took over these comments from the timeout example.. + // Sleep so the server can send the reply... + //ACE_Time_Value tv (0, (msec + 1) * 1000); + //orb_->run (tv); - // get rid of the policy, you created before. - ACE_TRY_EX (cleanup) - { - if (local_timeout != 0) - { - policy_list[0]->destroy (ACE_TRY_ENV); - ACE_TRY_CHECK_EX (cleanup); - } - } - ACE_CATCHANY - { - ACE_DEBUG ((LM_DEBUG, - "Unexpected exception\n\n")); } ACE_ENDTRY; - ACE_CHECK; - - // wait for responses - ACE_Time_Value tv (0, (local_timeout + remote_sleep)*2000); - ACE_OS::sleep (tv); - - ACE_Time_Value &elapsed_time = timeoutHandler_i_->elapsed_time (); - - if (async) - ACE_DEBUG ((LM_DEBUG, - " .. needed %dms\n", - elapsed_time.msec())); - else - ACE_DEBUG ((LM_DEBUG, - " .. done\n")); } int -TimeoutClient::synch_test () +TimeoutClient::svc () { - ACE_DEBUG ((LM_DEBUG, - "TimeoutClient::synch_test - Begin\n")); - timeoutHandler_i_->reset_reply_counter (); - timeoutHandler_i_->reset_reply_excep_counter (); - local_reply_excep_counter_ = 0; - - this->send (INVOKE_SYNCH, - 0, // local - 0); // remote - - this->send (INVOKE_SYNCH, - timeToWait_, // local - timeToWait_*2); // remote - // @@ Michael: In the collocated, but using the loopback interface, and - // if the reply to this request times out the replies to the - // asynch invocations do not get dispatched - // to the reply handler. Why? - this->send (INVOKE_SYNCH, - 0, // local - 0); // remote - - if (timeoutHandler_i_->reply_counter () != 0 - || timeoutHandler_i_->reply_excep_counter () != 0 - || local_reply_excep_counter_ != 1) - ACE_DEBUG ((LM_DEBUG, - "**** Failure in replies %d %d %d.\n\n", - timeoutHandler_i_->reply_counter (), - timeoutHandler_i_->reply_excep_counter (), - local_reply_excep_counter_)); - - ACE_DEBUG ((LM_DEBUG, - "TimeoutClient::synch_test - End\n\n")); + this->init (); - return 0; -}; + ACE_TRY_NEW_ENV + { + unsigned long msec = 10; + + TimeBase::TimeT timeout = 10000 * msec; + CORBA::Any any_orb; + any_orb <<= timeout; -int -TimeoutClient::accuracy_test () -{ - ACE_DEBUG ((LM_DEBUG, - "TimeoutClient::accuracy_test - Begin\n\n")); + CORBA::PolicyList policy_list (1); + policy_list.length (1); + policy_list[0] = + orb_->create_policy (Messaging::RELATIVE_RT_TIMEOUT_POLICY_TYPE, + any_orb, + ACE_TRY_ENV); + ACE_TRY_CHECK; - timeoutHandler_i_->reset_reply_counter (); - timeoutHandler_i_->reset_reply_excep_counter (); - local_reply_excep_counter_ = 0; + policy_manager_->set_policy_overrides (policy_list, + CORBA::SET_OVERRIDE, + ACE_TRY_ENV); + ACE_TRY_CHECK; - this->send (INVOKE_ASYNCH, - timeToWait_, - (unsigned long)(timeToWait_*1.5)); + ACE_DEBUG ((LM_DEBUG, + "TimeoutClient::svc : Invoking sendTimeToWait synchronously with server delay\n\n")); - this->send (INVOKE_ASYNCH, - timeToWait_, - (unsigned long)(timeToWait_*0.5)); + this->send (INVOKE_SYNCH, + msec); + // @@ Michael: If the reply to this request times out the replies to the asynch invocations + // do not get dispatched to the reply handler. Why? - if (timeoutHandler_i_->reply_counter () != 1 - || timeoutHandler_i_->reply_excep_counter () != 1 - || local_reply_excep_counter_ != 0) - ACE_DEBUG ((LM_DEBUG, - "**** Failure in replies %d %d %d.\n\n", - timeoutHandler_i_->reply_counter (), - timeoutHandler_i_->reply_excep_counter (), - local_reply_excep_counter_)); - ACE_DEBUG ((LM_DEBUG, - "TimeoutClient::accuracy_test - End\n\n")); + ACE_DEBUG ((LM_DEBUG, + "TimeoutClient::svc : Invoking sendTimeToWait asynchronously without server delay\n\n")); - return 0; -}; + this->send (INVOKE_ASYNCH, + 0); -int -TimeoutClient::none_test () -{ - ACE_DEBUG ((LM_DEBUG, - "TimeoutClient::none_test - Begin\n\n")); + ACE_DEBUG ((LM_DEBUG, + "TimeoutClient::svc : Invoking sendTimeToWait asynchronously with server delay\n\n")); - timeoutHandler_i_->reset_reply_counter (); - timeoutHandler_i_->reset_reply_excep_counter (); - local_reply_excep_counter_ = 0; + this->send (INVOKE_ASYNCH, + msec); - this->send (INVOKE_ASYNCH, - 0, - 0); + ACE_Time_Value tv (1, 0); // wait 1s to give the responses enough time. + ACE_OS::sleep (tv); - this->send (INVOKE_ASYNCH, - timeToWait_, - timeToWait_+10); // trigger a timeout + // shut down ORB + //timeoutObject_->shutdown (ACE_TRY_ENV); + ACE_TRY_CHECK; - this->send (INVOKE_ASYNCH, - timeToWait_, - 0); + policy_list[0]->destroy (ACE_TRY_ENV); + ACE_TRY_CHECK; - if (timeoutHandler_i_->reply_counter () != 2 - || timeoutHandler_i_->reply_excep_counter () != 1 - || local_reply_excep_counter_ != 0) - ACE_DEBUG ((LM_DEBUG, - "**** Failure in replies %d %d %d.\n\n", - timeoutHandler_i_->reply_counter (), - timeoutHandler_i_->reply_excep_counter (), - local_reply_excep_counter_)); + } + ACE_CATCHANY + { + ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, "Catched exception:"); + return 1; + } + ACE_ENDTRY; ACE_DEBUG ((LM_DEBUG, - "TimeoutClient::none_test - End\n\n")); + "TimeoutClient::svc: Done\n\n")); return 0; }; + |