1 #include "tao/Messaging/Messaging.h"
2 #include "tao/AnyTypeCode/Any.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())) {
24 orb_
->shutdown (true);
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 ();
70 // Timeout with SYNC_SCOPE SYNC_NONE
71 Messaging::SyncScope sync_none
= Messaging::SYNC_NONE
;
72 CORBA::Any sync_none_any
;
73 sync_none_any
<<= sync_none
;
74 policy_list
[1] = orb_
->create_policy
75 (Messaging::SYNC_SCOPE_POLICY_TYPE
, sync_none_any
);
76 // Apply the policy at the object level
77 obj
= test_obj_
->_set_policy_overrides
78 (policy_list
, CORBA::SET_OVERRIDE
);
79 test_obj_none_timeout_
= Test::_narrow (obj
.in ());
80 policy_list
[1]->destroy ();
83 // Timeout with TAO specific SYNC_SCOPE SYNC_EAGER_BUFFERING
84 //Messaging::SyncScope eager_buffering = TAO::SYNC_EAGER_BUFFERING;
85 Messaging::SyncScope eager_buffering
= Messaging::SYNC_NONE
;
87 eager_any
<<= eager_buffering
;
88 policy_list
[1] = orb_
->create_policy
89 (Messaging::SYNC_SCOPE_POLICY_TYPE
, eager_any
);
90 obj
= test_obj_
->_set_policy_overrides
91 (policy_list
, CORBA::SET_OVERRIDE
);
92 test_obj_eager_timeout_
= Test::_narrow (obj
.in ());
93 policy_list
[1]->destroy ();
96 // Timeout with TAO specific SYNC_SCOPE SYNC_DELAYED_BUFFERING
97 Messaging::SyncScope delayed_buffering
= TAO::SYNC_DELAYED_BUFFERING
;
98 CORBA::Any delayed_any
;
99 delayed_any
<<= delayed_buffering
;
100 policy_list
[1] = orb_
->create_policy
101 (Messaging::SYNC_SCOPE_POLICY_TYPE
, delayed_any
);
102 obj
= test_obj_
->_set_policy_overrides
103 (policy_list
, CORBA::SET_OVERRIDE
);
104 test_obj_delayed_timeout_
= Test::_narrow (obj
.in ());
105 policy_list
[1]->destroy ();
108 // Timeout with default SYNC_SCOPE SYNC_WITH_SERVER
109 Messaging::SyncScope sync_with_server
= Messaging::SYNC_WITH_SERVER
;
110 CORBA::Any sync_with_server_any
;
111 sync_with_server_any
<<= sync_with_server
;
112 policy_list
[1] = orb_
->create_policy
113 (Messaging::SYNC_SCOPE_POLICY_TYPE
, sync_with_server_any
);
114 obj
= test_obj_
->_set_policy_overrides
115 (policy_list
, CORBA::SET_OVERRIDE
);
116 test_obj_server_timeout_
= Test::_narrow (obj
.in ());
117 policy_list
[1]->destroy ();
120 // Timeout with default SYNC_SCOPE (SYNC_WITH_TARGET)
121 Messaging::SyncScope sync_with_target
= Messaging::SYNC_WITH_TARGET
;
122 CORBA::Any sync_with_target_any
;
123 sync_with_target_any
<<= sync_with_target
;
124 policy_list
[1] = orb_
->create_policy
125 (Messaging::SYNC_SCOPE_POLICY_TYPE
, sync_with_target_any
);
126 // Apply the policy at the object level
127 obj
= test_obj_
->_set_policy_overrides
128 (policy_list
, CORBA::SET_OVERRIDE
);
129 test_obj_target_timeout_
= Test::_narrow (obj
.in ());
131 policy_list
[0]->destroy ();
132 policy_list
[1]->destroy ();
133 policy_list
.length(0);
135 catch( CORBA::Exception
& ex
) {
136 ACE_ERROR ((LM_ERROR
, "(%P|%t) Client::Init> Caught CORBA::Exception %s"
137 , ex
._info().c_str()));
145 Client::parse_args (int argc
, ACE_TCHAR
* argv
[])
147 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("b:k:1::f:"), 0);
149 std::string test_ior
;
150 std::string back_ior
;
151 std::string
flush_strategy ("lf");
153 while ((c
= get_opts ()) != -1) {
157 one_way_test_
= true;
160 test_ior
= ACE_TEXT_ALWAYS_CHAR(get_opts
.opt_arg ());
163 back_ior
= ACE_TEXT_ALWAYS_CHAR(get_opts
.opt_arg ());
166 flush_strategy
= ACE_TEXT_ALWAYS_CHAR(get_opts
.opt_arg ());
169 ACE_ERROR_RETURN ((LM_ERROR
, "Invalid option \'-%c\'\n", c
)
174 CORBA::Object_var obj
= orb_
->string_to_object (test_ior
.c_str());
175 test_obj_
= Test::_narrow (obj
.in ());
177 obj
= orb_
->string_to_object (back_ior
.c_str());
178 management_
= Test::_narrow (obj
.in ());
180 if (ACE_OS::strcasecmp ("lf", flush_strategy
.c_str()) == 0) {
181 flush_strategy_
= LF
;
183 else if (ACE_OS::strcasecmp ("blocking", flush_strategy
.c_str()) == 0) {
184 flush_strategy_
= BLOCKING
;
186 else if (ACE_OS::strcasecmp ("reactive", flush_strategy
.c_str()) == 0) {
187 flush_strategy_
= REACTIVE
;
198 if (CORBA::is_nil (orb_
.in())) {
199 ACE_ERROR ((LM_ERROR
, "Client::run> nil ORB found.\n"));
207 if (!this->test_oneway_timeout (true)) {
208 ACE_ERROR ((LM_ERROR
, "(%P|%t) ERROR: Client::run> "
209 "test_oneway_timeout failed.\n"));
214 // now run same test without the transport flooded.
215 if (!this->test_oneway_timeout (false)) {
216 ACE_ERROR ((LM_ERROR
, "(%P|%t) ERROR: Client::run> "
217 "test_oneway_timeout 2 failed.\n"));
221 test_obj_
->shutdown ();
223 catch( CORBA::Exception
& ex
) {
224 management_
->unsleep (); // remote side could be asleep
225 ACE_ERROR ((LM_ERROR
, "(%P|%t) Client::run> Caught during test logic CORBA::Exception %s"
226 , ex
._info().c_str()));
230 catch( CORBA::Exception
& ex
) {
231 ACE_ERROR ((LM_ERROR
, "(%P|%t) Client::run> Caught during test shutdown CORBA::Exception %s"
232 , ex
._info().c_str()));
240 Client::test_oneway_timeout (bool flood
)
244 std::unique_ptr
<char[]> tmp (new char [6000000]);
245 char* msg
= tmp
.get();
247 ACE_OS::memset (msg
,'A',5999999);
250 test_obj_
->dummy_two_way (); // connection establishment
252 ACE_Time_Value
tv (0);
253 if (flood
&& !this->flood_connection(tv
)) {
254 ACE_ERROR ((LM_ERROR
, "(%P|%t) ERROR: test_oneway_timeout> flooding failed.\n"));
257 // Timeout with SYNC_SCOPE SYNC_NONE
259 std::string
scope_name ("SYNC_NONE");
260 ACE_OS::strncpy (msg
, scope_name
.c_str(), scope_name
.length());
261 test_obj_none_timeout_
->dummy_one_way (msg
);
263 if (flood
&& flush_strategy_
== BLOCKING
) {
264 // block flushing gives a oneway SYNCH_WITH_TRANSPORT semantics
265 ACE_ERROR ((LM_ERROR
, "(%P|%t) ERROR: A Timeout was expected for SYNC_NONE.\n"));
268 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) As expected no Timeout received for SYNC_NONE\n"));
271 catch (const CORBA::TIMEOUT
&) {
272 if (flood
&& flush_strategy_
== BLOCKING
) {
273 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) As expected a timeout was received for SYNC_NONE.\n"));
276 ACE_ERROR ((LM_ERROR
, "(%P|%t) ERROR: test_oneway_timeout> Unexpected "
277 "timeout exception with synch scope SYNC_NONE.\n"));
283 // Timeout with TAO specific SYNC_SCOPE SYNC_EAGER_BUFFERING
285 std::string
scope_name ("SYNC_EAGER_BUFFERING");
286 ACE_OS::strncpy (msg
, scope_name
.c_str(), scope_name
.length());
288 /* BLOCKed flushing has SYNCH_WITH_TRANSPORT semantics. With flooding turned on
289 you would have received a TIMEOUT in the previous test (SYNC_NONE). Even without
290 flooding there is a chance to get back a TIMEOUT. The TIMEOUT has the side-effect
291 closing out the connection. Therefore when flush_strategy is set to BLOCK we want
292 to re-establish connection before each test. With flooding turned on we need
293 to first unsleep the test server, re-establish connection and put it back to sleep.
294 With flooding=0 we simple re-establish connection. This trick is performed at beginning
295 of every test for flush_strategy == BLOCKING.
297 if (flush_strategy_
== BLOCKING
) {
299 management_
->unsleep ();
300 test_obj_
->sleep (0, 0); // rebuild connection and put server thread to sleep
303 // else simply re-establish connection
304 test_obj_
->dummy_two_way ();
308 test_obj_eager_timeout_
->dummy_one_way (msg
);
310 if (flood
&& flush_strategy_
== BLOCKING
) {
311 ACE_ERROR ((LM_ERROR
, "(%P|%t) ERROR: A Timeout was expected for SYNC_EAGER_BUFFERING\n"));
314 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) As expected no Timeout received for SYNC_EAGER_BUFFERING\n"));
317 catch (const CORBA::TIMEOUT
&) {
318 if (flood
&& flush_strategy_
== BLOCKING
) {
319 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) As expected a timeout was received for SYNC_EAGER_BUFFERING\n"));
322 ACE_ERROR ((LM_ERROR
, "(%P|%t) ERROR: test_oneway_timeout> Unexpected "
323 "timeout exception with synch scope SYNC_EAGER_BUFFERING.\n"));
328 // Timeout with TAO specific SYNC_SCOPE SYNC_DELAYED_BUFFERING
330 std::string
scope_name ("SYNC_DELAYED_BUFFERING");
331 ACE_OS::strncpy (msg
, scope_name
.c_str(), scope_name
.length());
333 if (flush_strategy_
== BLOCKING
) {
335 management_
->unsleep ();
336 test_obj_
->sleep (0, 0);
339 test_obj_
->dummy_two_way ();
343 test_obj_delayed_timeout_
->dummy_one_way (msg
);
345 if (flood
&& flush_strategy_
== BLOCKING
) {
346 ACE_ERROR ((LM_ERROR
, "(%P|%t) ERROR: A Timeout was expected for SYNC_DELAYED_BUFFERING\n"));
349 test_obj_delayed_timeout_
->dummy_one_way ("SYNC_DELAYED_BUFFERING");
350 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) As expected no Timeout received for SYNC_DELAYED_BUFFERING\n"));
353 catch (const CORBA::TIMEOUT
&) {
354 if (flood
&& flush_strategy_
== BLOCKING
) {
355 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) Expected timeout received for SYNC_DELAYED_BUFFERING\n"));
358 ACE_ERROR ((LM_ERROR
, "(%P|%t) ERROR: test_oneway_timeout> Unexpected "
359 "timeout exception with synch scope SYNC_DELAYED_BUFFERING.\n"));
364 /* Cleanup queue before the synchronous tests. We don't want the test
365 results affected by leftovers from previous runs.
367 ACE_Time_Value
tv_tmp (1);
370 // Timeout with SYNC_SCOPE SYNC_WITH_TRANSPORT
372 std::string
scope_name ("SYNC_WITH_TRANSPORT");
373 ACE_OS::strncpy (msg
, scope_name
.c_str(), scope_name
.length());
375 if (flush_strategy_
== BLOCKING
) {
377 management_
->unsleep ();
378 test_obj_
->sleep (0, 0);
381 test_obj_
->dummy_two_way ();
385 test_obj_transport_timeout_
->dummy_one_way (msg
);
388 ACE_ERROR ((LM_ERROR
, "(%P|%t) ERROR: test_oneway_timeout> Expected "
389 "timeout not received for synch scope SYNC_WITH_TRANSPORT.\n"
394 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) As expected no Timeout received for SYNC_WITH_TRANSPORT\n"));
397 catch (const CORBA::TIMEOUT
&) {
399 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) Expected Timeout received for SYNC_WITH_TRANSPORT\n"));
402 ACE_ERROR ((LM_ERROR
, "(%P|%t) ERROR: test_oneway_timeout> Unexpected "
403 "timeout exception with synch scope SYNC_WITH_TRANSPORT.\n"));
408 // Timeout with default SYNC_SCOPE SYNC_WITH_SERVER
410 std::string
scope_name ("SYNC_WITH_SERVER");
411 ACE_OS::strncpy (msg
, scope_name
.c_str(), scope_name
.length());
413 if (flush_strategy_
== BLOCKING
) {
415 management_
->unsleep ();
416 test_obj_
->sleep (0, 0);
419 test_obj_
->dummy_two_way ();
423 test_obj_server_timeout_
->dummy_one_way (msg
);
426 ACE_ERROR ((LM_ERROR
, "(%P|%t) ERROR: test_oneway_timeout> Expected "
427 "timeout not received for SYNC_SCOPE SYNC_WITH_SERVER.\n"));
431 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) As expected no Timeout received for SYNC_WITH_SERVER\n"));
434 catch (const CORBA::TIMEOUT
&) {
436 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) Expected Timeout received for SYNC_WITH_SERVER\n"));
439 ACE_ERROR ((LM_ERROR
, "(%P|%t) ERROR: test_oneway_timeout> Unexpected "
440 "timeout exception with synch scope SYNC_WITH_SERVER.\n"));
446 // Timeout with default SYNC_SCOPE (SYNC_WITH_TARGET)
448 std::string
scope_name ("SYNC_WITH_TARGET");
449 ACE_OS::strncpy (msg
, scope_name
.c_str(), scope_name
.length());
451 if (flush_strategy_
== BLOCKING
) {
453 management_
->unsleep ();
454 test_obj_
->sleep (0, 0);
457 test_obj_
->dummy_two_way ();
461 test_obj_target_timeout_
->dummy_one_way (msg
);
464 ACE_ERROR ((LM_ERROR
, "(%P|%t) ERROR: test_oneway_timeout> Expected "
465 "timeout not received for SYNC_SCOPE SYNC_WITH_TARGET.\n"));
469 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) As expected no Timeout received for SYNC_WITH_TARGET\n"));
472 catch (const CORBA::TIMEOUT
&) {
474 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) Expected Timeout received for SYNC_WITH_TARGET\n"));
477 ACE_ERROR ((LM_ERROR
, "(%P|%t) ERROR: test_oneway_timeout> Unexpected "
478 "timeout exception with synch scope SYNC_WITH_TARGET.\n"));
484 management_
->unsleep ();
491 Client::flood_connection (ACE_Time_Value
& tv
)
493 // Block flushing currently blocks even on SYNC_DELAYED_BUFFERING
494 // so we can't use it to flood connections.
496 // Set the policy value.
497 // SYNC_DELAYED_BUFFERING is used to ensure that the tcp buffer gets filled before
499 Messaging::SyncScope sync_scope
= TAO::SYNC_DELAYED_BUFFERING
;
500 //Messaging::SyncScope sync_scope = Messaging::SYNC_NONE;
501 CORBA::Any sync_scope_any
;
502 sync_scope_any
<<= sync_scope
;
504 CORBA::PolicyList
policy_list (1);
505 policy_list
.length (1);
506 policy_list
[0] = orb_
->create_policy
507 (Messaging::SYNC_SCOPE_POLICY_TYPE
, sync_scope_any
);
508 // Apply the policy at the object level
509 CORBA::Object_var obj
= test_obj_
->_set_policy_overrides
510 (policy_list
, CORBA::SET_OVERRIDE
);
511 Test_var mod_test_obj
= Test::_narrow (obj
.in ());
513 policy_list
[0]->destroy ();
514 policy_list
.length(0);
516 std::unique_ptr
<char[]> tmp (new char [2000000]);
517 char* msg
= tmp
.get();
519 ACE_OS::memset (msg
,'A',1999999);
522 test_obj_
->sleep (static_cast<CORBA::Long
>(tv
.sec())
523 , static_cast<CORBA::Long
>(tv
.msec()));
525 /* BLOCK flush startegy always has SYNC_WITH_TRANSPORT semantics.
526 Trying to flood a BLOCKed flushing connection can lead to a TIMEOUT
527 exception being thrown. This will close out the connection and
528 the whole flooding attempt fails. Therefore in BLOCK flushing case
529 don't attempt to flood (unless BLOCK flush accepts SYNC_WITH_TRANSPORT
532 if (flush_strategy_
!= BLOCKING
)
534 mod_test_obj
->dummy_one_way (msg
);
536 // attempt again to flood connection.
537 ACE_Time_Value
tv_tmp (2);
538 orb_
->perform_work (tv_tmp
);