2 #include "ace/Get_Opt.h"
5 #include "tao/DynamicInterface/Request.h"
6 #include "tao/ORBInitializer_Registry.h"
8 #include "tao/TransportCurrent/Transport_Current.h"
10 #include "Client_Request_Interceptor.h"
11 #include "Current_TestC.h"
13 #include "Client_ORBInitializer.h"
18 test_transport_current (CORBA::ORB_ptr
);
22 const char* CLIENT_ORB_ID
= "client orb";
23 const ACE_TCHAR
* ior
= ACE_TEXT("file://server.ior");
31 parse_args (int argc
, ACE_TCHAR
*argv
[])
33 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("yt:n:k:"));
36 while ((c
= get_opts ()) != -1)
40 use_dii
= 0; // Do not use DII
43 ior
= get_opts
.opt_arg ();
46 nthreads
= ACE_OS::atoi (get_opts
.opt_arg ());
49 niterations
= ACE_OS::atoi (get_opts
.opt_arg ());
52 ACE_ERROR_RETURN ((LM_ERROR
,
66 /// A helper class to encapsulate a task
68 class Worker
: public ACE_Task_Base
71 Worker (Test::Transport::CurrentTest_ptr server
, int niterations
, int use_dii_too
);
72 virtual int svc (void);
76 Test::Transport::CurrentTest_var server_
;
78 // The number of iterations on each client thread.
81 // Whether to use DII in addition to SII
88 Worker::Worker (Test::Transport::CurrentTest_ptr server
,
91 : server_ (Test::Transport::CurrentTest::_duplicate (server
))
92 , niterations_ (niterations
)
93 , use_dii_too_ (use_dii_too
)
98 /// Test referencing the TC data *inside* the context of a client-side
107 for (int i
= 0; i
< this->niterations_
; ++i
)
110 // Minimum CORBA does not define Object::_request, so we're just
111 // skipping the DII part in those cases.
112 #if (!defined(TAO_HAS_MINIMUM_CORBA) || (TAO_HAS_MINIMUM_CORBA == 0))
114 if (this->use_dii_too_
)
116 ACE_DEBUG ((LM_DEBUG
,
117 ACE_TEXT ("Client (%P|%t) Invoking server->invoked_by_client() via DII\n")));
119 CORBA::Request_var request
=
120 this->server_
->_request ("invoked_by_client");
122 request
->set_return_type (CORBA::_tc_void
);
127 #endif /* (!defined(TAO_HAS_MINIMUM_CORBA) || (TAO_HAS_MINIMUM_CORBA == 0)) */
129 ACE_DEBUG ((LM_DEBUG
,
130 ACE_TEXT ("Client (%P|%t) Invoking server->invoked_by_client() via SII\n")));
132 this->server_
->invoked_by_client ();
134 if (TAO_debug_level
> 0 && i
% 100 == 0)
135 ACE_DEBUG ((LM_DEBUG
, ACE_TEXT ("Client (%P|%t) Iteration = %d\n"),
139 catch (const CORBA::Exception
& ex
)
141 ex
._tao_print_exception ("Client: exception raised");
149 ACE_TMAIN (int argc
, ACE_TCHAR
*argv
[])
151 #if TAO_HAS_TRANSPORT_CURRENT == 1
155 Test::Client_Request_Interceptor
* cri
= 0;
157 Test::Client_Request_Interceptor (CLIENT_ORB_ID
,
158 test_transport_current
),
160 PortableInterceptor::ClientRequestInterceptor_var
cri_safe (cri
);
162 PortableInterceptor::ORBInitializer_ptr temp_initializer
= 0;
163 ACE_NEW_RETURN (temp_initializer
,
164 Test::Client_ORBInitializer (cri
),
166 PortableInterceptor::ORBInitializer_var
orb_initializer (temp_initializer
);
168 PortableInterceptor::register_orb_initializer (orb_initializer
.in ());
171 CORBA::ORB_init (argc
,
175 if (parse_args (argc
, argv
) != 0)
176 ACE_ERROR_RETURN ((LM_ERROR
,
177 ACE_TEXT ("Client (%P|%t) Failure to parse the command line.\n"),
184 test_transport_current (orb
.in ());
186 ACE_ERROR_RETURN ((LM_ERROR
,
187 ACE_TEXT ("Client (%P|%t) ERROR: ")
188 ACE_TEXT ("TC invocation, outside of ")
189 ACE_TEXT ("interceptor context is undefined.")
190 ACE_TEXT (" Expected exception was not thrown\n")),
193 catch (const Transport::NoContext
& )
195 ACE_DEBUG ((LM_DEBUG
,
196 ACE_TEXT ("Client (%P|%t) Expected exception occurred when trying ")
197 ACE_TEXT ("to access traits outside the ")
198 ACE_TEXT ("interceptor or upcall context.\n")));
201 // Resolve the target object
202 CORBA::Object_var obj
= orb
->string_to_object (ior
);
204 Test::Transport::CurrentTest_var server
=
205 Test::Transport::CurrentTest::_narrow (obj
.in ());
207 if (CORBA::is_nil (server
.in ()))
208 ACE_ERROR_RETURN ((LM_ERROR
,
209 ACE_TEXT ("Client (%P|%t) The server object reference <%s> is nil.\n"),
213 ACE_DEBUG ((LM_DEBUG
, ACE_TEXT ("Client (%P|%t) Spawning %d threads\n"), nthreads
));
215 // Spawn a number of clients doing the same thing for a
216 // predetermined number of times
217 Worker
client (server
.in (), niterations
, use_dii
);
219 #if defined (ACE_HAS_THREADS)
220 if (client
.activate (THR_NEW_LWP
| THR_JOINABLE
,
222 ACE_ERROR_RETURN ((LM_ERROR
,
223 ACE_TEXT ("Client (%P|%t) Cannot activate %d client threads\n"),
226 client
.thr_mgr ()->wait ();
229 ACE_ERROR ((LM_WARNING
,
230 ACE_TEXT ("Client (%P|%t) Cannot use threads other than ")
231 ACE_TEXT ("the only one available.\n")));
235 ACE_DEBUG ((LM_DEBUG
, ACE_TEXT ("Client (%P|%t) Collected any threads\n")));
237 CORBA::Long result
= 0;
239 // Verify enough interception points have been triggered
240 if (cri
->interceptions () != 2 * // request & response
241 niterations
* // iterations
242 nthreads
* // threads
243 (2*use_dii
)) // sii and dii, if needed
245 ACE_ERROR ((LM_ERROR
,
246 ACE_TEXT ("Client (%P|%t) Expected %d client-side interceptions, but detected %d\n"),
247 2 * niterations
* nthreads
* (2*use_dii
),
248 cri
->interceptions ()));
253 ACE_DEBUG ((LM_DEBUG
, ACE_TEXT ("Client (%P|%t) Invoking server->self_test()\n")));
255 // Self-test the server side
256 result
= server
->self_test ();
259 ACE_ERROR ((LM_ERROR
,
260 ACE_TEXT ("Client (%P|%t) Server self-test reported failure\n")));
263 ACE_DEBUG ((LM_DEBUG
, ACE_TEXT ("Client (%P|%t) Invoking oneway server->shutdown()\n")));
270 ACE_TEXT ("Client (%P|%t) Completed %s\n"),
271 ((result
== 0) ? ACE_TEXT ("successfuly") : ACE_TEXT ("with failure"))));
274 catch (const CORBA::Exception
& ex
)
276 ex
._tao_print_exception (
278 "Client: Transport Current test (client-side) failed:"));
282 #else /* TAO_HAS_TRANSPORT_CURRENT == 1 */
283 ACE_DEBUG ((LM_INFO
, ACE_TEXT ("Client (%P|%t) Need TAO_HAS_TRANSPORT_CURRENT enabled to run.\n")));
285 #endif /* TAO_HAS_TRANSPORT_CURRENT == 1 */