2 #include "ace/Get_Opt.h"
4 #include "tao/RTCORBA/RTCORBA.h"
5 #include "tao/ORB_Core.h"
6 #include "../check_supported_priorities.cpp"
9 const ACE_TCHAR
*ior1
= ACE_TEXT("file://test1.ior");
10 const ACE_TCHAR
*ior2
= ACE_TEXT("file://test2.ior");
13 parse_args (int argc
, ACE_TCHAR
*argv
[])
15 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("n:o:"));
18 while ((c
= get_opts ()) != -1)
22 ior1
= get_opts
.opt_arg ();
25 ior2
= get_opts
.opt_arg ();
30 ACE_ERROR_RETURN ((LM_ERROR
,
43 get_server_priority (Test_ptr server
)
45 // Get the Priority Model Policy from the stub.
46 CORBA::Policy_var policy
=
47 server
->_get_policy (RTCORBA::PRIORITY_MODEL_POLICY_TYPE
);
49 // Narrow down to correct type.
50 RTCORBA::PriorityModelPolicy_var priority_policy
=
51 RTCORBA::PriorityModelPolicy::_narrow (policy
.in ());
53 // Make sure that we have the SERVER_DECLARED priority model.
54 RTCORBA::PriorityModel priority_model
=
55 priority_policy
->priority_model ();
56 if (priority_model
!= RTCORBA::SERVER_DECLARED
)
57 ACE_ERROR_RETURN ((LM_ERROR
,
58 "ERROR: priority_model != "
59 "RTCORBA::SERVER_DECLARED!\n"),
62 // Return the server priority.
63 return priority_policy
->server_priority ();
67 invocation_exception_test (Test_ptr obj
,
68 CORBA::Short priority
)
72 // Invoke method on test object.
76 // This next line of code should not run because an exception
77 // should have been raised.
78 ACE_DEBUG ((LM_DEBUG
, "ERROR: no exception caught\n"));
80 catch (const CORBA::INV_POLICY
& )
82 // Expected exception.
84 "INV_POLICY exception is caught as expected.\n"));
86 catch (const CORBA::Exception
&)
88 // Unexpected exception.
89 ACE_DEBUG ((LM_DEBUG
, "Error: unexpected exception caught\n"));
94 class Task
: public ACE_Task_Base
97 Task (ACE_Thread_Manager
&thread_manager
,
105 Task::Task (ACE_Thread_Manager
&thread_manager
,
107 : ACE_Task_Base (&thread_manager
),
108 orb_ (CORBA::ORB::_duplicate (orb
))
118 CORBA::Object_var object
=
119 this->orb_
->resolve_initial_references ("RTORB");
121 RTCORBA::RTORB_var rt_orb
=
122 RTCORBA::RTORB::_narrow (object
.in ());
124 // Get the RTCurrent.
126 this->orb_
->resolve_initial_references ("RTCurrent");
128 RTCORBA::Current_var current
=
129 RTCORBA::Current::_narrow (object
.in ());
131 // We need to set the client thread CORBA priority
132 current
->the_priority (get_implicit_thread_CORBA_priority (this->orb_
.in ()));
134 // Test object 1 (with CLIENT_PROPAGATED priority model).
136 this->orb_
->string_to_object (ior1
);
138 Test_var client_propagated_obj
=
139 Test::_narrow (object
.in ());
141 // Test object 2 (with SERVER_DECLARED priority model).
142 object
= this->orb_
->string_to_object (ior2
);
144 Test_var server_declared_obj
=
145 Test::_narrow (object
.in ());
147 // Test: Attempt to set priority bands that do not match server
148 // resource configuration on the <client_propagated_obj>.
149 // Should get INV_POLICY exception.
150 ACE_DEBUG ((LM_DEBUG
,
151 "\n<---Test--->: Client bands do not match server lanes\n\n"));
154 RTCORBA::PriorityBands false_bands
;
155 false_bands
.length (2);
156 false_bands
[0].low
= 10000;
157 false_bands
[0].high
= 10005;
158 false_bands
[1].low
= 26000;
159 false_bands
[1].high
= 30000;
160 CORBA::PolicyList policies
;
163 rt_orb
->create_priority_banded_connection_policy (false_bands
);
165 // Set false bands at the object level. Note that a new object
168 client_propagated_obj
->_set_policy_overrides (policies
,
169 CORBA::SET_OVERRIDE
);
171 client_propagated_obj
=
172 Test::_narrow (object
.in ());
174 // Invoking on this object with false bands should produce an
176 invocation_exception_test (client_propagated_obj
.in (),
179 // Get the correct bands from the <server_declared_obj>.
181 server_declared_obj
->_get_policy (RTCORBA::PRIORITY_BANDED_CONNECTION_POLICY_TYPE
);
183 RTCORBA::PriorityBandedConnectionPolicy_var bands_policy
=
184 RTCORBA::PriorityBandedConnectionPolicy::_narrow (policies
[0]);
186 RTCORBA::PriorityBands_var bands
=
187 bands_policy
->priority_bands ();
189 // Set the proper bands at the object level. Note that a new
190 // object is returned.
192 client_propagated_obj
->_set_policy_overrides (policies
,
193 CORBA::SET_OVERRIDE
);
195 // Overwrite existing <client_propagated_obj>.
196 client_propagated_obj
=
197 Test::_narrow (object
.in ());
199 // Test: Attempt invocation on <client_propagated_obj> with
200 // client thread priority not matching any of the bands. Should
201 // get INV_POLICY exception.
202 ACE_DEBUG ((LM_DEBUG
,
203 "\n<---Test--->: Client threads does not match band\n\n"));
205 // Choose a priority one higher than the high priority of the
207 CORBA::Short client_priority
=
208 bands
[bands
->length () - 1].high
+ 1;
210 // Reset the current thread's priority.
211 current
->the_priority (client_priority
);
213 // Invoking on this object with an invalid client thread
214 // priority should produce an exception.
215 invocation_exception_test (client_propagated_obj
.in (),
218 // Test: Make invocations on the <client_propagated_obj>.
219 ACE_DEBUG ((LM_DEBUG
,
220 "\n<---Test--->: Invoking on client propagated object\n\n"));
222 // Make an invocation for each band.
223 for (CORBA::ULong i
= 0;
224 i
< bands
->length ();
227 // Select a priority in the middle of the band.
228 CORBA::Short client_priority
=
229 (bands
[i
].low
+ bands
[i
].high
) / 2;
231 // Reset the current thread's priority.
232 current
->the_priority (client_priority
);
234 // Invoke test method on server.
235 client_propagated_obj
->test_method (1, // CLIENT_PROPAGATED
239 // Test: Attempt invocation with the same thread priority, but
240 // now on the <server_declared_obj>. This should succeed.
241 ACE_DEBUG ((LM_DEBUG
,
242 "\n<---Test--->: Invoking on server declared object\n\n"));
244 // Get the <server_priority> from the stub.
245 CORBA::Short server_priority
=
246 get_server_priority (server_declared_obj
.in ());
248 // Invoke test method on server.
249 server_declared_obj
->test_method (0, // SERVER_DECLARED
252 // Testing over. Shut down Server ORB.
253 server_declared_obj
->shutdown ();
255 catch (const CORBA::Exception
& ex
)
257 ex
._tao_print_exception (
258 "Unexpected exception in Banded_Connections test client:");
266 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
271 CORBA::ORB_var orb
= CORBA::ORB_init (argc
, argv
);
274 int result
= parse_args (argc
, argv
);
278 // Make sure we can support multiple priorities that are required
280 if (!check_supported_priorities (orb
.in ()))
283 // Thread Manager for managing task.
284 ACE_Thread_Manager thread_manager
;
287 Task
task (thread_manager
,
290 // Task activation flags.
294 orb
->orb_core ()->orb_params ()->thread_creation_flags ();
298 task
.activate (flags
);
303 ACE_ERROR_RETURN ((LM_ERROR
,
304 "Cannot create thread with scheduling policy %s\n"
305 "because the user does not have the appropriate privileges, terminating program....\n"
306 "Check svc.conf options and/or run as root\n",
307 sched_policy_name (orb
->orb_core ()->orb_params ()->ace_sched_policy ())),
315 // Wait for task to exit.
317 thread_manager
.wait ();
318 ACE_ASSERT (result
!= -1);
322 catch (const CORBA::Exception
& ex
)
324 ex
._tao_print_exception (
325 "Unexpected exception in Banded_Connections test client:");