1 #include "tao/Messaging/Messaging.h"
2 #include "tao/AnyTypeCode/Any.h"
4 #include "ace/Auto_Ptr.h"
5 #include "ace/Get_Opt.h"
6 #include "ace/Time_Value.h"
7 #include "ace/OS_NS_unistd.h"
8 #include "ace/OS_NS_strings.h"
13 Client::Client (int argc
, ACE_TCHAR
* argv
[])
14 : init_ (false), one_way_test_ (false)
16 if (this->init (argc
, argv
)) {
23 if (!CORBA::is_nil (orb_
.in())) {
26 orb_
= CORBA::ORB::_nil();
29 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) ~Client>\n"));
33 Client::init (int argc
, ACE_TCHAR
* argv
[])
36 orb_
= CORBA::ORB_init (argc
, argv
, "Client");
37 if (CORBA::is_nil (orb_
.in())) {
38 ACE_ERROR ((LM_ERROR
, "Client::init> ORB initialization failed.\n"));
42 if (!this->parse_args (argc
, argv
)) {
47 TimeBase::TimeT timeout
= 5 * 1000000; // 5 seconds
48 CORBA::Any any_object
;
49 any_object
<<= timeout
;
51 CORBA::PolicyList
policy_list (2);
52 policy_list
.length (2);
54 orb_
->create_policy (Messaging::RELATIVE_RT_TIMEOUT_POLICY_TYPE
,
58 // Timeout with SYNC_SCOPE SYNC_WITH_TRANSPORT
59 Messaging::SyncScope sync_with_transport
= Messaging::SYNC_WITH_TRANSPORT
;
60 CORBA::Any sync_with_transport_any
;
61 sync_with_transport_any
<<= sync_with_transport
;
62 policy_list
[1] = orb_
->create_policy
63 (Messaging::SYNC_SCOPE_POLICY_TYPE
, sync_with_transport_any
);
64 CORBA::Object_var obj
= test_obj_
->_set_policy_overrides
65 (policy_list
, CORBA::SET_OVERRIDE
);
66 test_obj_transport_timeout_
= Test::_narrow (obj
.in ());
67 policy_list
[1]->destroy ();
71 // Timeout with SYNC_SCOPE SYNC_NONE
72 Messaging::SyncScope sync_none
= Messaging::SYNC_NONE
;
73 CORBA::Any sync_none_any
;
74 sync_none_any
<<= sync_none
;
75 policy_list
[1] = orb_
->create_policy
76 (Messaging::SYNC_SCOPE_POLICY_TYPE
, sync_none_any
);
77 // Apply the policy at the object level
78 obj
= test_obj_
->_set_policy_overrides
79 (policy_list
, CORBA::SET_OVERRIDE
);
80 test_obj_none_timeout_
= Test::_narrow (obj
.in ());
81 policy_list
[1]->destroy ();
84 // Timeout with TAO specific SYNC_SCOPE SYNC_EAGER_BUFFERING
85 //Messaging::SyncScope eager_buffering = TAO::SYNC_EAGER_BUFFERING;
86 Messaging::SyncScope eager_buffering
= Messaging::SYNC_NONE
;
88 eager_any
<<= eager_buffering
;
89 policy_list
[1] = orb_
->create_policy
90 (Messaging::SYNC_SCOPE_POLICY_TYPE
, eager_any
);
91 obj
= test_obj_
->_set_policy_overrides
92 (policy_list
, CORBA::SET_OVERRIDE
);
93 test_obj_eager_timeout_
= Test::_narrow (obj
.in ());
94 policy_list
[1]->destroy ();
97 // Timeout with TAO specific SYNC_SCOPE SYNC_DELAYED_BUFFERING
98 Messaging::SyncScope delayed_buffering
= TAO::SYNC_DELAYED_BUFFERING
;
99 CORBA::Any delayed_any
;
100 delayed_any
<<= delayed_buffering
;
101 policy_list
[1] = orb_
->create_policy
102 (Messaging::SYNC_SCOPE_POLICY_TYPE
, delayed_any
);
103 obj
= test_obj_
->_set_policy_overrides
104 (policy_list
, CORBA::SET_OVERRIDE
);
105 test_obj_delayed_timeout_
= Test::_narrow (obj
.in ());
106 policy_list
[1]->destroy ();
109 // Timeout with default SYNC_SCOPE SYNC_WITH_SERVER
110 Messaging::SyncScope sync_with_server
= Messaging::SYNC_WITH_SERVER
;
111 CORBA::Any sync_with_server_any
;
112 sync_with_server_any
<<= sync_with_server
;
113 policy_list
[1] = orb_
->create_policy
114 (Messaging::SYNC_SCOPE_POLICY_TYPE
, sync_with_server_any
);
115 obj
= test_obj_
->_set_policy_overrides
116 (policy_list
, CORBA::SET_OVERRIDE
);
117 test_obj_server_timeout_
= Test::_narrow (obj
.in ());
118 policy_list
[1]->destroy ();
121 // Timeout with default SYNC_SCOPE (SYNC_WITH_TARGET)
122 Messaging::SyncScope sync_with_target
= Messaging::SYNC_WITH_TARGET
;
123 CORBA::Any sync_with_target_any
;
124 sync_with_target_any
<<= sync_with_target
;
125 policy_list
[1] = orb_
->create_policy
126 (Messaging::SYNC_SCOPE_POLICY_TYPE
, sync_with_target_any
);
127 // Apply the policy at the object level
128 obj
= test_obj_
->_set_policy_overrides
129 (policy_list
, CORBA::SET_OVERRIDE
);
130 test_obj_target_timeout_
= Test::_narrow (obj
.in ());
132 policy_list
[0]->destroy ();
133 policy_list
[1]->destroy ();
134 policy_list
.length(0);
137 catch( CORBA::Exception
& ex
) {
138 ACE_ERROR ((LM_ERROR
, "(%P|%t) Client::Init> Caught CORBA::Exception %s"
139 , ex
._info().c_str()));
147 Client::parse_args (int argc
, ACE_TCHAR
* argv
[])
149 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("b:k:1::f:"), 0);
151 std::string test_ior
;
152 std::string back_ior
;
153 std::string
flush_strategy ("lf");
155 while ((c
= get_opts ()) != -1) {
159 one_way_test_
= true;
162 test_ior
= ACE_TEXT_ALWAYS_CHAR(get_opts
.opt_arg ());
165 back_ior
= ACE_TEXT_ALWAYS_CHAR(get_opts
.opt_arg ());
168 flush_strategy
= ACE_TEXT_ALWAYS_CHAR(get_opts
.opt_arg ());
171 ACE_ERROR_RETURN ((LM_ERROR
, "Invalid option \'-%c\'\n", c
)
176 CORBA::Object_var obj
= orb_
->string_to_object (test_ior
.c_str());
177 test_obj_
= Test::_narrow (obj
.in ());
179 obj
= orb_
->string_to_object (back_ior
.c_str());
180 management_
= Test::_narrow (obj
.in ());
182 if (ACE_OS::strcasecmp ("lf", flush_strategy
.c_str()) == 0) {
183 flush_strategy_
= LF
;
185 else if (ACE_OS::strcasecmp ("blocking", flush_strategy
.c_str()) == 0) {
186 flush_strategy_
= BLOCKING
;
188 else if (ACE_OS::strcasecmp ("reactive", flush_strategy
.c_str()) == 0) {
189 flush_strategy_
= REACTIVE
;
200 if (CORBA::is_nil (orb_
.in())) {
201 ACE_ERROR ((LM_ERROR
, "Client::run> nil ORB found.\n"));
209 if (!this->test_oneway_timeout (true)) {
210 ACE_ERROR ((LM_ERROR
, "(%P|%t) ERROR: Client::run> "
211 "test_oneway_timeout failed.\n"));
216 // now run same test without the transport flooded.
217 if (!this->test_oneway_timeout (false)) {
218 ACE_ERROR ((LM_ERROR
, "(%P|%t) ERROR: Client::run> "
219 "test_oneway_timeout 2 failed.\n"));
223 test_obj_
->shutdown ();
225 catch( CORBA::Exception
& ex
) {
226 management_
->unsleep (); // remote side could be asleep
227 ACE_ERROR ((LM_ERROR
, "(%P|%t) Client::run> Caught during test logic CORBA::Exception %s"
228 , ex
._info().c_str()));
232 catch( CORBA::Exception
& ex
) {
233 ACE_ERROR ((LM_ERROR
, "(%P|%t) Client::run> Caught during test shutdown CORBA::Exception %s"
234 , ex
._info().c_str()));
242 Client::test_oneway_timeout (bool flood
)
246 ACE_Auto_Array_Ptr
<char> tmp (new char [6000000]);
247 char* msg
= tmp
.get();
249 ACE_OS::memset (msg
,'A',5999999);
252 test_obj_
->dummy_two_way (); // connection establishment
254 ACE_Time_Value
tv (0);
255 if (flood
&& !this->flood_connection(tv
)) {
256 ACE_ERROR ((LM_ERROR
, "(%P|%t) ERROR: test_oneway_timeout> flooding failed.\n"));
259 // Timeout with SYNC_SCOPE SYNC_NONE
261 std::string
scope_name ("SYNC_NONE");
262 ACE_OS::strncpy (msg
, scope_name
.c_str(), scope_name
.length());
263 test_obj_none_timeout_
->dummy_one_way (msg
);
265 if (flood
&& flush_strategy_
== BLOCKING
) {
266 // block flushing gives a oneway SYNCH_WITH_TRANSPORT semantics
267 ACE_ERROR ((LM_ERROR
, "(%P|%t) ERROR: A Timeout was expected for SYNC_NONE.\n"));
270 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) As expected no Timeout received for SYNC_NONE\n"));
273 catch (const CORBA::TIMEOUT
&) {
274 if (flood
&& flush_strategy_
== BLOCKING
) {
275 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) As expected a timeout was received for SYNC_NONE.\n"));
278 ACE_ERROR ((LM_ERROR
, "(%P|%t) ERROR: test_oneway_timeout> Unexpected "
279 "timeout exception with synch scope SYNC_NONE.\n"));
285 // Timeout with TAO specific SYNC_SCOPE SYNC_EAGER_BUFFERING
287 std::string
scope_name ("SYNC_EAGER_BUFFERING");
288 ACE_OS::strncpy (msg
, scope_name
.c_str(), scope_name
.length());
290 /* BLOCKed flushing has SYNCH_WITH_TRANSPORT semantics. With flooding turned on
291 you would have received a TIMEOUT in the previous test (SYNC_NONE). Even without
292 flooding there is a chance to get back a TIMEOUT. The TIMEOUT has the side-effect
293 closing out the connection. Therefore when flush_strategy is set to BLOCK we want
294 to re-establish connection before each test. With flooding turned on we need
295 to first unsleep the test server, re-establish connection and put it back to sleep.
296 With flooding=0 we simple re-establish connection. This trick is performed at beginning
297 of every test for flush_strategy == BLOCKING.
299 if (flush_strategy_
== BLOCKING
) {
301 management_
->unsleep ();
302 test_obj_
->sleep (0, 0); // rebuild connection and put server thread to sleep
305 // else simply re-establish connection
306 test_obj_
->dummy_two_way ();
310 test_obj_eager_timeout_
->dummy_one_way (msg
);
312 if (flood
&& flush_strategy_
== BLOCKING
) {
313 ACE_ERROR ((LM_ERROR
, "(%P|%t) ERROR: A Timeout was expected for SYNC_EAGER_BUFFERING\n"));
316 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) As expected no Timeout received for SYNC_EAGER_BUFFERING\n"));
319 catch (const CORBA::TIMEOUT
&) {
320 if (flood
&& flush_strategy_
== BLOCKING
) {
321 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) As expected a timeout was received for SYNC_EAGER_BUFFERING\n"));
324 ACE_ERROR ((LM_ERROR
, "(%P|%t) ERROR: test_oneway_timeout> Unexpected "
325 "timeout exception with synch scope SYNC_EAGER_BUFFERING.\n"));
330 // Timeout with TAO specific SYNC_SCOPE SYNC_DELAYED_BUFFERING
332 std::string
scope_name ("SYNC_DELAYED_BUFFERING");
333 ACE_OS::strncpy (msg
, scope_name
.c_str(), scope_name
.length());
335 if (flush_strategy_
== BLOCKING
) {
337 management_
->unsleep ();
338 test_obj_
->sleep (0, 0);
341 test_obj_
->dummy_two_way ();
345 test_obj_delayed_timeout_
->dummy_one_way (msg
);
347 if (flood
&& flush_strategy_
== BLOCKING
) {
348 ACE_ERROR ((LM_ERROR
, "(%P|%t) ERROR: A Timeout was expected for SYNC_DELAYED_BUFFERING\n"));
351 test_obj_delayed_timeout_
->dummy_one_way ("SYNC_DELAYED_BUFFERING");
352 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) As expected no Timeout received for SYNC_DELAYED_BUFFERING\n"));
355 catch (const CORBA::TIMEOUT
&) {
356 if (flood
&& flush_strategy_
== BLOCKING
) {
357 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) Expected timeout received for SYNC_DELAYED_BUFFERING\n"));
360 ACE_ERROR ((LM_ERROR
, "(%P|%t) ERROR: test_oneway_timeout> Unexpected "
361 "timeout exception with synch scope SYNC_DELAYED_BUFFERING.\n"));
366 /* Cleanup queue before the synchronous tests. We don't want the test
367 results affected by leftovers from previous runs.
369 ACE_Time_Value
tv_tmp (1);
372 // Timeout with SYNC_SCOPE SYNC_WITH_TRANSPORT
374 std::string
scope_name ("SYNC_WITH_TRANSPORT");
375 ACE_OS::strncpy (msg
, scope_name
.c_str(), scope_name
.length());
377 if (flush_strategy_
== BLOCKING
) {
379 management_
->unsleep ();
380 test_obj_
->sleep (0, 0);
383 test_obj_
->dummy_two_way ();
387 test_obj_transport_timeout_
->dummy_one_way (msg
);
390 ACE_ERROR ((LM_ERROR
, "(%P|%t) ERROR: test_oneway_timeout> Expected "
391 "timeout not received for synch scope SYNC_WITH_TRANSPORT.\n"
396 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) As expected no Timeout received for SYNC_WITH_TRANSPORT\n"));
399 catch (const CORBA::TIMEOUT
&) {
401 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) Expected Timeout received for SYNC_WITH_TRANSPORT\n"));
404 ACE_ERROR ((LM_ERROR
, "(%P|%t) ERROR: test_oneway_timeout> Unexpected "
405 "timeout exception with synch scope SYNC_WITH_TRANSPORT.\n"));
410 // Timeout with default SYNC_SCOPE SYNC_WITH_SERVER
412 std::string
scope_name ("SYNC_WITH_SERVER");
413 ACE_OS::strncpy (msg
, scope_name
.c_str(), scope_name
.length());
415 if (flush_strategy_
== BLOCKING
) {
417 management_
->unsleep ();
418 test_obj_
->sleep (0, 0);
421 test_obj_
->dummy_two_way ();
425 test_obj_server_timeout_
->dummy_one_way (msg
);
428 ACE_ERROR ((LM_ERROR
, "(%P|%t) ERROR: test_oneway_timeout> Expected "
429 "timeout not received for SYNC_SCOPE SYNC_WITH_SERVER.\n"));
433 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) As expected no Timeout received for SYNC_WITH_SERVER\n"));
436 catch (const CORBA::TIMEOUT
&) {
438 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) Expected Timeout received for SYNC_WITH_SERVER\n"));
441 ACE_ERROR ((LM_ERROR
, "(%P|%t) ERROR: test_oneway_timeout> Unexpected "
442 "timeout exception with synch scope SYNC_WITH_SERVER.\n"));
448 // Timeout with default SYNC_SCOPE (SYNC_WITH_TARGET)
450 std::string
scope_name ("SYNC_WITH_TARGET");
451 ACE_OS::strncpy (msg
, scope_name
.c_str(), scope_name
.length());
453 if (flush_strategy_
== BLOCKING
) {
455 management_
->unsleep ();
456 test_obj_
->sleep (0, 0);
459 test_obj_
->dummy_two_way ();
463 test_obj_target_timeout_
->dummy_one_way (msg
);
466 ACE_ERROR ((LM_ERROR
, "(%P|%t) ERROR: test_oneway_timeout> Expected "
467 "timeout not received for SYNC_SCOPE SYNC_WITH_TARGET.\n"));
471 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) As expected no Timeout received for SYNC_WITH_TARGET\n"));
474 catch (const CORBA::TIMEOUT
&) {
476 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) Expected Timeout received for SYNC_WITH_TARGET\n"));
479 ACE_ERROR ((LM_ERROR
, "(%P|%t) ERROR: test_oneway_timeout> Unexpected "
480 "timeout exception with synch scope SYNC_WITH_TARGET.\n"));
486 management_
->unsleep ();
493 Client::flood_connection (ACE_Time_Value
& tv
)
495 // Block flushing currently blocks even on SYNC_DELAYED_BUFFERING
496 // so we can't use it to flood connections.
498 // Set the policy value.
499 // SYNC_DELAYED_BUFFERING is used to ensure that the tcp buffer gets filled before
501 Messaging::SyncScope sync_scope
= TAO::SYNC_DELAYED_BUFFERING
;
502 //Messaging::SyncScope sync_scope = Messaging::SYNC_NONE;
503 CORBA::Any sync_scope_any
;
504 sync_scope_any
<<= sync_scope
;
506 CORBA::PolicyList
policy_list (1);
507 policy_list
.length (1);
508 policy_list
[0] = orb_
->create_policy
509 (Messaging::SYNC_SCOPE_POLICY_TYPE
, sync_scope_any
);
510 // Apply the policy at the object level
511 CORBA::Object_var obj
= test_obj_
->_set_policy_overrides
512 (policy_list
, CORBA::SET_OVERRIDE
);
513 Test_var mod_test_obj
= Test::_narrow (obj
.in ());
515 policy_list
[0]->destroy ();
516 policy_list
.length(0);
518 ACE_Auto_Array_Ptr
<char> tmp (new char [2000000]);
519 char* msg
= tmp
.get();
521 ACE_OS::memset (msg
,'A',1999999);
524 test_obj_
->sleep (static_cast<CORBA::Long
>(tv
.sec())
525 , static_cast<CORBA::Long
>(tv
.msec()));
527 /* BLOCK flush startegy always has SYNC_WITH_TRANSPORT semantics.
528 Trying to flood a BLOCKed flushing connection can lead to a TIMEOUT
529 exception being thrown. This will close out the connection and
530 the whole flooding attempt fails. Therefore in BLOCK flushing case
531 don't attempt to flood (unless BLOCK flush accepts SYNC_WITH_TRANSPORT
534 if (flush_strategy_
!= BLOCKING
)
536 mod_test_obj
->dummy_one_way (msg
);
538 // attempt again to flood connection.
539 ACE_Time_Value
tv_tmp (2);
540 orb_
->perform_work (tv_tmp
);