3 #include "tao/Messaging/Messaging.h"
4 #include "tao/AnyTypeCode/Any.h"
5 #include "ace/Get_Opt.h"
7 const ACE_TCHAR
*ior
= ACE_TEXT ("file://test.ior");
12 parse_args (int argc
, ACE_TCHAR
*argv
[])
14 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("k:l:h:"));
17 while ((c
= get_opts ()) != -1)
21 ior
= get_opts
.opt_arg ();
25 min_timeout
= ACE_OS::atoi (get_opts
.opt_arg ());
29 max_timeout
= ACE_OS::atoi (get_opts
.opt_arg ());
34 ACE_ERROR_RETURN ((LM_ERROR
,
43 // Indicates successful parsing of the command line
47 enum TO_TYPE
{none
= 0, orb1
= 1, thread1
= 2, object1
= 3};
48 const char *to_type_names
[4] ={"none", "orb", "thread", "object"};
50 static int timeout_count
[4] = {0, 0, 0, 0};
51 static int in_time_count
[4] = {0, 0, 0, 0};
54 send_echo (TO_TYPE ctype
, CORBA::ORB_ptr orb
,
55 Simple_Server_ptr server
,
62 in_time_count
[ctype
]++;
64 catch (const CORBA::TIMEOUT
& )
66 timeout_count
[ctype
]++;
68 // Trap this exception and continue...
70 "==> Trapped a TIMEOUT exception (expected)\n"));
72 // Sleep so the server can send the reply...
73 ACE_Time_Value
tv (max_timeout
/ 1000, // max_timeout is in msec, so get seconds
74 (max_timeout
% 1000) * 1000); // and usec
76 // This is a non-standard TAO call that's used to give the
77 // client ORB a chance to cleanup the reply that's come back
84 int ACE_TMAIN (int argc
, ACE_TCHAR
*argv
[])
89 CORBA::ORB_init (argc
, argv
);
91 if (parse_args (argc
, argv
) != 0)
94 CORBA::Object_var object
=
95 orb
->string_to_object (ior
);
97 Simple_Server_var server
=
98 Simple_Server::_narrow (object
.in ());
100 if (CORBA::is_nil (server
.in ()))
102 ACE_ERROR_RETURN ((LM_ERROR
,
103 "Object reference <%s> is nil.\n",
109 orb
->resolve_initial_references ("ORBPolicyManager");
111 CORBA::PolicyManager_var policy_manager
=
112 CORBA::PolicyManager::_narrow (object
.in ());
115 orb
->resolve_initial_references ("PolicyCurrent");
117 CORBA::PolicyCurrent_var policy_current
=
118 CORBA::PolicyCurrent::_narrow (object
.in ());
120 TimeBase::TimeT mid_value
=
121 10000 * (min_timeout
+ max_timeout
) / 2; // convert from msec to "TimeT" (0.1 usec units)
124 any_orb
<<= mid_value
;
125 CORBA::Any any_thread
;
126 any_thread
<<= mid_value
+ 10000; // midvalue + 1 msec
127 CORBA::Any any_object
;
128 any_object
<<= mid_value
+ 20000; // midvalue + 2 msec
130 CORBA::PolicyList
policy_list (1);
131 policy_list
.length (1);
133 orb
->create_policy (Messaging::RELATIVE_RT_TIMEOUT_POLICY_TYPE
,
136 server
->_set_policy_overrides (policy_list
,
137 CORBA::SET_OVERRIDE
);
139 Simple_Server_var timeout_server
=
140 Simple_Server::_narrow (object
.in ());
142 policy_list
[0]->destroy ();
143 policy_list
[0] = CORBA::Policy::_nil ();
145 ACE_DEBUG ((LM_DEBUG
,
146 "client (%P) testing from %d to %d milliseconds\n",
147 min_timeout
, max_timeout
));
149 for (CORBA::Long t
= min_timeout
; t
< max_timeout
; ++t
)
151 ACE_DEBUG ((LM_DEBUG
,
152 "\n================================\n"
153 "Trying with timeout = %d msec\n", t
));
155 ACE_DEBUG ((LM_DEBUG
,
156 "Cleanup ORB/Thread/Object policies\n"));
158 policy_list
.length (0);
159 policy_manager
->set_policy_overrides (policy_list
,
160 CORBA::SET_OVERRIDE
);
161 policy_current
->set_policy_overrides (policy_list
,
162 CORBA::SET_OVERRIDE
);
164 send_echo (none
, orb
.in (), server
.in (), t
);
168 ACE_DEBUG ((LM_DEBUG
,
169 "client(%P) Set the ORB policies\n"));
171 policy_list
.length (1);
173 orb
->create_policy (Messaging::RELATIVE_RT_TIMEOUT_POLICY_TYPE
,
176 policy_manager
->set_policy_overrides (policy_list
,
177 CORBA::SET_OVERRIDE
);
179 send_echo (orb1
, orb
.in (), server
.in (), t
);
181 policy_list
[0]->destroy ();
187 ACE_DEBUG ((LM_DEBUG
,
188 "client(%P) Set the thread policies\n"));
190 policy_list
.length (1);
192 orb
->create_policy (Messaging::RELATIVE_RT_TIMEOUT_POLICY_TYPE
,
195 policy_current
->set_policy_overrides (policy_list
,
196 CORBA::SET_OVERRIDE
);
198 send_echo (thread1
, orb
.in (), server
.in (), t
);
200 policy_list
[0]->destroy ();
206 ACE_DEBUG ((LM_DEBUG
,
207 "client(%P) Use the object policies\n"));
208 send_echo (object1
, orb
.in (), timeout_server
.in (), t
);
211 ACE_DEBUG ((LM_DEBUG
,
212 "\n\n\nclient(%P) Test completed, "
213 "resynch with server\n"));
214 policy_list
.length (0);
215 policy_manager
->set_policy_overrides (policy_list
,
216 CORBA::SET_OVERRIDE
);
217 policy_current
->set_policy_overrides (policy_list
,
218 CORBA::SET_OVERRIDE
);
220 send_echo (none
, orb
.in (), server
.in (), 0);
224 int timeout_count_total
= 0;
225 int in_time_count_total
= 0;
226 for (int i
= 0; i
< 4; i
++) {
227 timeout_count_total
+= timeout_count
[i
];
228 in_time_count_total
+= in_time_count
[i
];
229 ACE_DEBUG ((LM_DEBUG
, "in_time_count[%C]= %d timeout_count[%C]= %d\n",
230 to_type_names
[i
], in_time_count
[i
],
231 to_type_names
[i
], timeout_count
[i
]));
234 if (timeout_count_total
== 0)
235 ACE_ERROR ((LM_ERROR
,
236 "ERROR: No messages timed out\n"));
238 //FUZZ: disable check_for_lack_ACE_OS
239 if (in_time_count_total
== 0)
240 ACE_ERROR ((LM_ERROR
,
241 "ERROR: No messages on time (within time limit)\n"));
242 //FUZZ: enable check_for_lack_ACE_OS
244 ACE_DEBUG ((LM_DEBUG
, "in_time_count_total = %d, timeout_count_total = %d\n",
245 in_time_count_total
, timeout_count_total
));
249 catch (const CORBA::Exception
& ex
)
251 ex
._tao_print_exception ("Exception caught:");