1 //=============================================================================
3 * @file timeout_client.cpp
5 * Tests for proper handling of timeouts with AMI
7 * @author Michael Kircher <Michael.Kircher@mchp.siemens.de>
9 //=============================================================================
11 #include "timeout_client.h"
12 #include "tao/Messaging/Messaging.h"
13 #include "tao/PolicyC.h"
14 #include "tao/AnyTypeCode/Any.h"
15 #include "ace/OS_NS_unistd.h"
17 TimeoutClient::TimeoutClient (CORBA::ORB_ptr orb
,
18 TimeoutObj_ptr timeoutObject
,
19 AMI_TimeoutObjHandler_ptr replyHandlerObject
,
20 TimeoutHandler_i
*timeoutHandler_i
,
21 unsigned long timeToWait
)
22 : orb_ (CORBA::ORB::_duplicate (orb
))
23 , timeoutObject_ (TimeoutObj::_duplicate (timeoutObject
))
24 , replyHandlerObject_ (AMI_TimeoutObjHandler::_duplicate (replyHandlerObject
))
25 , timeoutHandler_i_ (timeoutHandler_i
)
26 , local_reply_excep_counter_ (0)
29 , timeToWait_ (timeToWait
)
33 TimeoutClient::~TimeoutClient ()
44 // Tests timeouts for synchronous
47 // Tests AMI timeouts for influences on non-timeout calls
50 // Tests AMI timeouts for accuracy
51 this->accuracy_test ();
53 // Tests AMI timeouts for influences on non-timeout calls
56 // shut down remote ORB
57 timeoutObject_
->shutdown ();
59 ACE_Time_Value
tv (0, 20); // wait for the ORB to deliver the shutdown
62 // shut down local ORB
63 orb_
->shutdown (false);
65 catch (const CORBA::Exception
& ex
)
67 ex
._tao_print_exception ("Caught exception:");
72 "TimeoutClient::svc: Done\n\n"));
78 TimeoutClient::initialize ()
82 CORBA::Object_var object
=
83 orb_
->resolve_initial_references ("ORBPolicyManager");
86 CORBA::PolicyManager::_narrow (object
.in ());
88 catch (const CORBA::Exception
& ex
)
90 ex
._tao_print_exception ("Caught exception:");
99 TimeoutClient::send (CORBA::Boolean async
,
100 unsigned long local_timeout
,
101 unsigned long remote_sleep
)
103 ACE_DEBUG ((LM_DEBUG
,
104 "(%P|%t) Invoking "));
106 ACE_DEBUG ((LM_DEBUG
,
109 ACE_DEBUG ((LM_DEBUG
,
112 ACE_DEBUG ((LM_DEBUG
,
113 "local: %dms remote: %dms ... ",
117 CORBA::PolicyList
policy_list (1);
121 if (local_timeout
!= 0)
123 TimeBase::TimeT timeout
= 10000 * local_timeout
;
128 policy_list
.length (1);
130 orb_
->create_policy (Messaging::RELATIVE_RT_TIMEOUT_POLICY_TYPE
,
133 policy_manager_
->set_policy_overrides (policy_list
,
134 CORBA::SET_OVERRIDE
);
138 policy_list
.length (0);
139 policy_manager_
->set_policy_overrides (policy_list
,
140 CORBA::SET_OVERRIDE
);
144 // Start time measurement at the reply handler
145 timeoutHandler_i_
->start ();
149 timeoutObject_
->sendc_sendTimeToWait (replyHandlerObject_
.in (),
154 timeoutObject_
->sendTimeToWait (remote_sleep
);
157 catch (const CORBA::TIMEOUT
& )
159 local_reply_excep_counter_
++;
161 // Trap this exception and continue...
162 ACE_DEBUG ((LM_DEBUG
,
166 // get rid of the policy, you created before.
169 if (local_timeout
!= 0)
171 policy_list
[0]->destroy ();
174 catch (const CORBA::Exception
&)
176 ACE_DEBUG ((LM_DEBUG
,
177 "Error: Unexpected exception\n\n"));
180 // wait for responses
181 ACE_Time_Value
tv (0, (local_timeout
+ remote_sleep
)*2000 + 4000);
184 ACE_Time_Value
&elapsed_time
= timeoutHandler_i_
->elapsed_time ();
187 ACE_DEBUG ((LM_DEBUG
,
189 elapsed_time
.msec()));
191 ACE_DEBUG ((LM_DEBUG
,
197 TimeoutClient::synch_test ()
199 ACE_DEBUG ((LM_DEBUG
,
200 "TimeoutClient::synch_test - Begin\n"));
201 timeoutHandler_i_
->reset_reply_counter ();
202 timeoutHandler_i_
->reset_reply_excep_counter ();
203 local_reply_excep_counter_
= 0;
205 this->send (INVOKE_SYNCH
,
209 this->send (INVOKE_SYNCH
,
210 timeToWait_
, // local
211 timeToWait_
*2); // remote
213 this->send (INVOKE_SYNCH
,
217 if (timeoutHandler_i_
->reply_counter () != 0
218 || timeoutHandler_i_
->reply_excep_counter () != 0
219 || local_reply_excep_counter_
!= 1)
220 ACE_DEBUG ((LM_DEBUG
,
221 "**** Error in replies %d %d %d.\n\n",
222 timeoutHandler_i_
->reply_counter (),
223 timeoutHandler_i_
->reply_excep_counter (),
224 local_reply_excep_counter_
));
226 ACE_DEBUG ((LM_DEBUG
,
227 "TimeoutClient::synch_test - End\n\n"));
233 TimeoutClient::accuracy_test ()
235 ACE_DEBUG ((LM_DEBUG
,
236 "TimeoutClient::accuracy_test - Begin\n\n"));
238 timeoutHandler_i_
->reset_reply_counter ();
239 timeoutHandler_i_
->reset_reply_excep_counter ();
240 local_reply_excep_counter_
= 0;
242 this->send (INVOKE_ASYNCH
,
244 (unsigned long)(timeToWait_
*1.5));
246 this->send (INVOKE_ASYNCH
,
248 (unsigned long)(timeToWait_
*0.5));
250 if (timeoutHandler_i_
->reply_counter () != 1
251 || timeoutHandler_i_
->reply_excep_counter () != 1
252 || local_reply_excep_counter_
!= 0)
253 ACE_DEBUG ((LM_DEBUG
,
254 "**** Error in replies %d %d %d.\n\n",
255 timeoutHandler_i_
->reply_counter (),
256 timeoutHandler_i_
->reply_excep_counter (),
257 local_reply_excep_counter_
));
259 ACE_DEBUG ((LM_DEBUG
,
260 "TimeoutClient::accuracy_test - End\n\n"));
266 TimeoutClient::none_test ()
268 ACE_DEBUG ((LM_DEBUG
,
269 "TimeoutClient::none_test - Begin\n\n"));
271 timeoutHandler_i_
->reset_reply_counter ();
272 timeoutHandler_i_
->reset_reply_excep_counter ();
273 local_reply_excep_counter_
= 0;
275 this->send (INVOKE_ASYNCH
,
279 this->send (INVOKE_ASYNCH
,
281 timeToWait_
+10); // trigger a timeout
283 this->send (INVOKE_ASYNCH
,
287 if (timeoutHandler_i_
->reply_counter () != 2
288 || timeoutHandler_i_
->reply_excep_counter () != 1
289 || local_reply_excep_counter_
!= 0)
290 ACE_DEBUG ((LM_DEBUG
,
291 "**** Error in replies %d %d %d.\n\n",
292 timeoutHandler_i_
->reply_counter (),
293 timeoutHandler_i_
->reply_excep_counter (),
294 local_reply_excep_counter_
));
296 ACE_DEBUG ((LM_DEBUG
,
297 "TimeoutClient::none_test - End\n\n"));