2 #include "tao/Messaging/Messaging.h"
3 #include "tao/AnyTypeCode/Any.h"
4 #include "ace/Get_Opt.h"
5 #include "ace/OS_NS_sys_time.h"
7 const ACE_TCHAR
*ior
= ACE_TEXT("file://test.ior");
8 int test_sync_with_target
= 0;
9 int test_sync_with_server
= 0;
10 int test_sync_with_transport
= 0;
11 int test_sync_none
= 0;
15 const int DESTROYED
= 1;
16 const int SHUTDOWN
= 2;
17 int server_status
= ALIVE
;
19 int successful_calls
= 0;
23 parse_args (int argc
, ACE_TCHAR
*argv
[])
25 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("k:i:ntsr"));
28 while ((c
= get_opts ()) != -1)
32 ior
= get_opts
.opt_arg ();
36 iterations
= ACE_OS::atoi (get_opts
.opt_arg ());
44 test_sync_with_transport
= 1;
48 test_sync_with_server
= 1;
52 test_sync_with_target
= 1;
57 ACE_ERROR_RETURN ((LM_ERROR
,
65 // Indicates successful parsing of the command line
69 void run_test_sync_with_target (Test::Oneway_Receiver_ptr oneway_receiver
);
70 void run_test_sync_with_server (Test::Oneway_Receiver_ptr oneway_receiver
);
71 void run_test_sync_with_transport (Test::Oneway_Receiver_ptr oneway_receiver
);
72 void run_test_sync_none (Test::Oneway_Receiver_ptr oneway_receiver
);
76 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
81 CORBA::ORB_init (argc
, argv
);
83 if (parse_args (argc
, argv
) != 0)
86 CORBA::Object_var tmp
=
87 orb
->string_to_object(ior
);
89 Test::Oneway_Receiver_var oneway_receiver
=
90 Test::Oneway_Receiver::_narrow(tmp
.in ());
92 if (CORBA::is_nil (oneway_receiver
.in ()))
94 ACE_ERROR_RETURN ((LM_DEBUG
,
95 "Nil oneway receiver reference <%s>\n",
100 if (test_sync_with_target
)
102 ACE_DEBUG ((LM_DEBUG
, "Running SYNC_WITH_TARGET\n"));
103 run_test_sync_with_target (oneway_receiver
.in ());
105 else if (test_sync_with_server
)
107 ACE_DEBUG ((LM_DEBUG
, "Running SYNC_WITH_SERVER\n"));
108 run_test_sync_with_server (oneway_receiver
.in ());
110 else if (test_sync_with_transport
)
112 ACE_DEBUG ((LM_DEBUG
, "Running SYNC_WITH_TRANSPORT\n"));
113 run_test_sync_with_transport (oneway_receiver
.in ());
117 ACE_DEBUG ((LM_DEBUG
, "Running SYNC_NONE\n"));
118 run_test_sync_none (oneway_receiver
.in ());
121 //FUZZ: disable check_for_lack_ACE_OS
122 // Run the orb for 3 seconds, this way we make sure things are flushed
124 ACE_Time_Value
time (3, 0);
125 //FUZZ: enable check_for_lack_ACE_OS
129 if (successful_calls
== 0)
130 ACE_ERROR ((LM_ERROR
, "ERROR: No requests were successful\n"));
132 if (failed_calls
!= 0)
133 ACE_ERROR ((LM_ERROR
, "ERROR: At least %d requests failed\n",
136 if (failed_calls
+ successful_calls
!= iterations
)
137 ACE_ERROR ((LM_ERROR
,
138 "ERROR: Mismatched number of calls (%d + %d != %d)\n",
139 successful_calls
, failed_calls
, iterations
));
143 catch (const CORBA::Exception
& ex
)
145 ex
._tao_print_exception ("Exception caught:");
153 set_sync_scope_policy (Messaging::SyncScope sync_scope
)
156 ACE_TCHAR
**argv
= 0;
157 CORBA::ORB_var orb
= CORBA::ORB_init (argc
, argv
);
159 CORBA::Object_var object
=
160 orb
->resolve_initial_references ("PolicyCurrent");
162 CORBA::PolicyCurrent_var policy_current
=
163 CORBA::PolicyCurrent::_narrow (object
.in ());
165 if (CORBA::is_nil (policy_current
.in ()))
167 ACE_ERROR ((LM_ERROR
, "ERROR: Nil policy current\n"));
170 CORBA::Any scope_as_any
;
171 scope_as_any
<<= sync_scope
;
173 CORBA::PolicyList
policies(1); policies
.length (1);
175 orb
->create_policy (Messaging::SYNC_SCOPE_POLICY_TYPE
,
178 policy_current
->set_policy_overrides (policies
, CORBA::ADD_OVERRIDE
);
180 policies
[0]->destroy ();
184 run_one_iteration (int i
,
185 Test::Oneway_Receiver_ptr oneway_receiver
,
186 Test::Shutdown_Helper_ptr shutdown_helper
)
190 if (i
== iterations
/ 3)
192 ACE_DEBUG ((LM_DEBUG
, "Destroying object\n"));
193 server_status
= DESTROYED
;
194 oneway_receiver
->destroy ();
196 if (i
== 2 * iterations
/ 3)
198 ACE_DEBUG ((LM_DEBUG
, "Shutting down server process\n"));
199 server_status
= SHUTDOWN
;
200 shutdown_helper
->shutdown ();
203 catch (const CORBA::Exception
&)
207 oneway_receiver
->raise_no_permission ();
210 /// Helper routine to set breakpoints during failures
212 call_failed (const CORBA::SystemException
&ex
)
216 ex
._tao_print_exception ("Exception raised");
220 run_test_sync_with_target (Test::Oneway_Receiver_ptr oneway_receiver
)
222 set_sync_scope_policy (Messaging::SYNC_WITH_TARGET
);
224 Test::Shutdown_Helper_var shutdown_helper
=
225 oneway_receiver
->get_shutdown_helper ();
227 int had_comm_failure
= 0;
228 for (int i
= 0; i
!= iterations
; ++i
)
232 run_one_iteration (i
, oneway_receiver
, shutdown_helper
.in ());
234 catch (const CORBA::NO_PERMISSION
& ex
)
236 if (server_status
== ALIVE
)
241 catch (const CORBA::OBJECT_NOT_EXIST
& ex
)
243 if (server_status
== DESTROYED
)
248 catch (const CORBA::COMM_FAILURE
& ex
)
250 if (server_status
== SHUTDOWN
&& had_comm_failure
== 0)
254 had_comm_failure
= 1;
256 catch (const CORBA::TRANSIENT
& ex
)
258 if (server_status
== SHUTDOWN
)
263 catch (const CORBA::SystemException
& ex
)
271 run_test_sync_with_server (Test::Oneway_Receiver_ptr oneway_receiver
)
273 set_sync_scope_policy (Messaging::SYNC_WITH_SERVER
);
275 Test::Shutdown_Helper_var shutdown_helper
=
276 oneway_receiver
->get_shutdown_helper ();
278 int had_comm_failure
= 0;
279 for (int i
= 0; i
!= iterations
; ++i
)
283 run_one_iteration (i
, oneway_receiver
, shutdown_helper
.in ());
285 if (server_status
== DESTROYED
286 || server_status
== SHUTDOWN
)
291 catch (const CORBA::NO_PERMISSION
& ex
)
295 catch (const CORBA::OBJECT_NOT_EXIST
& ex
)
297 if (server_status
== DESTROYED
)
302 catch (const CORBA::COMM_FAILURE
& ex
)
304 if (server_status
== SHUTDOWN
&& had_comm_failure
== 0)
308 had_comm_failure
= 1;
310 catch (const CORBA::TRANSIENT
& ex
)
312 if (server_status
== SHUTDOWN
)
317 catch (const CORBA::SystemException
& ex
)
324 /// Helper routine to run the sync_with_transport and sync_none tests.
326 run_test_unreliable (Test::Oneway_Receiver_ptr oneway_receiver
);
329 run_test_sync_with_transport (Test::Oneway_Receiver_ptr oneway_receiver
)
331 set_sync_scope_policy (Messaging::SYNC_WITH_TRANSPORT
);
333 run_test_unreliable (oneway_receiver
);
337 run_test_sync_none (Test::Oneway_Receiver_ptr oneway_receiver
)
339 set_sync_scope_policy (Messaging::SYNC_NONE
);
341 run_test_unreliable (oneway_receiver
);
346 run_test_unreliable (Test::Oneway_Receiver_ptr oneway_receiver
)
348 Test::Shutdown_Helper_var shutdown_helper
=
349 oneway_receiver
->get_shutdown_helper ();
352 int had_transient
= 0;
353 for (int i
= 0; i
!= iterations
; ++i
)
357 run_one_iteration (i
, oneway_receiver
, shutdown_helper
.in ());
359 // A few failures can go undetected...
360 if (server_status
== SHUTDOWN
)
363 // Once a TRANSIENT is raised all future calls should fail.
369 catch (const CORBA::NO_PERMISSION
& ex
)
373 catch (const CORBA::OBJECT_NOT_EXIST
& ex
)
377 catch (const CORBA::COMM_FAILURE
& ex
)
381 catch (const CORBA::TRANSIENT
& ex
)
383 if (server_status
== SHUTDOWN
)
389 catch (const CORBA::SystemException
& ex
)
394 ACE_DEBUG ((LM_DEBUG
, "Undetected TRANSIENT count = %d\n",