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
);
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
106 for (int i
= 0; i
< this->niterations_
; ++i
)
108 // Minimum CORBA does not define Object::_request, so we're just
109 // skipping the DII part in those cases.
110 #if (!defined(TAO_HAS_MINIMUM_CORBA) || (TAO_HAS_MINIMUM_CORBA == 0))
112 if (this->use_dii_too_
)
114 ACE_DEBUG ((LM_DEBUG
,
115 ACE_TEXT ("Client (%P|%t) Invoking server->invoked_by_client() via DII\n")));
117 CORBA::Request_var request
=
118 this->server_
->_request ("invoked_by_client");
120 request
->set_return_type (CORBA::_tc_void
);
125 #endif /* (!defined(TAO_HAS_MINIMUM_CORBA) || (TAO_HAS_MINIMUM_CORBA == 0)) */
127 ACE_DEBUG ((LM_DEBUG
,
128 ACE_TEXT ("Client (%P|%t) Invoking server->invoked_by_client() via SII\n")));
130 this->server_
->invoked_by_client ();
132 if (TAO_debug_level
> 0 && i
% 100 == 0)
133 ACE_DEBUG ((LM_DEBUG
, ACE_TEXT ("Client (%P|%t) Iteration = %d\n"),
137 catch (const CORBA::Exception
& ex
)
139 ex
._tao_print_exception ("Client: exception raised");
147 ACE_TMAIN (int argc
, ACE_TCHAR
*argv
[])
149 #if TAO_HAS_TRANSPORT_CURRENT == 1
153 Test::Client_Request_Interceptor
* cri
= 0;
155 Test::Client_Request_Interceptor (CLIENT_ORB_ID
,
156 test_transport_current
),
158 PortableInterceptor::ClientRequestInterceptor_var
cri_safe (cri
);
160 PortableInterceptor::ORBInitializer_ptr temp_initializer
= 0;
161 ACE_NEW_RETURN (temp_initializer
,
162 Test::Client_ORBInitializer (cri
),
164 PortableInterceptor::ORBInitializer_var
orb_initializer (temp_initializer
);
166 PortableInterceptor::register_orb_initializer (orb_initializer
.in ());
169 CORBA::ORB_init (argc
,
173 if (parse_args (argc
, argv
) != 0)
174 ACE_ERROR_RETURN ((LM_ERROR
,
175 ACE_TEXT ("Client (%P|%t) Failure to parse the command line.\n"),
182 test_transport_current (orb
.in ());
184 ACE_ERROR_RETURN ((LM_ERROR
,
185 ACE_TEXT ("Client (%P|%t) ERROR: ")
186 ACE_TEXT ("TC invocation, outside of ")
187 ACE_TEXT ("interceptor context is undefined.")
188 ACE_TEXT (" Expected exception was not thrown\n")),
191 catch (const Transport::NoContext
& )
193 ACE_DEBUG ((LM_DEBUG
,
194 ACE_TEXT ("Client (%P|%t) Expected exception occurred when trying ")
195 ACE_TEXT ("to access traits outside the ")
196 ACE_TEXT ("interceptor or upcall context.\n")));
199 // Resolve the target object
200 CORBA::Object_var obj
= orb
->string_to_object (ior
);
202 Test::Transport::CurrentTest_var server
=
203 Test::Transport::CurrentTest::_narrow (obj
.in ());
205 if (CORBA::is_nil (server
.in ()))
206 ACE_ERROR_RETURN ((LM_ERROR
,
207 ACE_TEXT ("Client (%P|%t) The server object reference <%s> is nil.\n"),
211 ACE_DEBUG ((LM_DEBUG
, ACE_TEXT ("Client (%P|%t) Spawning %d threads\n"), nthreads
));
213 // Spawn a number of clients doing the same thing for a
214 // predetermined number of times
215 Worker
client (server
.in (), niterations
, use_dii
);
217 #if defined (ACE_HAS_THREADS)
218 if (client
.activate (THR_NEW_LWP
| THR_JOINABLE
,
220 ACE_ERROR_RETURN ((LM_ERROR
,
221 ACE_TEXT ("Client (%P|%t) Cannot activate %d client threads\n"),
224 client
.thr_mgr ()->wait ();
227 ACE_ERROR ((LM_WARNING
,
228 ACE_TEXT ("Client (%P|%t) Cannot use threads other than ")
229 ACE_TEXT ("the only one available.\n")));
233 ACE_DEBUG ((LM_DEBUG
, ACE_TEXT ("Client (%P|%t) Collected any threads\n")));
235 CORBA::Long result
= 0;
237 // Verify enough interception points have been triggered
238 if (cri
->interceptions () != 2 * // request & response
239 niterations
* // iterations
240 nthreads
* // threads
241 (2*use_dii
)) // sii and dii, if needed
243 ACE_ERROR ((LM_ERROR
,
244 ACE_TEXT ("Client (%P|%t) Expected %d client-side interceptions, but detected %d\n"),
245 2 * niterations
* nthreads
* (2*use_dii
),
246 cri
->interceptions ()));
250 ACE_DEBUG ((LM_DEBUG
, ACE_TEXT ("Client (%P|%t) Invoking server->self_test()\n")));
252 // Self-test the server side
253 result
= server
->self_test ();
256 ACE_ERROR ((LM_ERROR
,
257 ACE_TEXT ("Client (%P|%t) Server self-test reported failure\n")));
260 ACE_DEBUG ((LM_DEBUG
, ACE_TEXT ("Client (%P|%t) Invoking oneway server->shutdown()\n")));
264 ACE_DEBUG ((LM_DEBUG
, ACE_TEXT ("Client (%P|%t) Invoking orb->destroy ()\n")));
269 ACE_TEXT ("Client (%P|%t) Completed %s.\n"),
270 ((result
== 0) ? ACE_TEXT ("successfuly") : ACE_TEXT ("with failure"))));
273 catch (const CORBA::Exception
& ex
)
275 ex
._tao_print_exception (
277 "Client: Transport Current test (client-side) failed:"));
281 #else /* TAO_HAS_TRANSPORT_CURRENT == 1 */
282 ACE_DEBUG ((LM_INFO
, ACE_TEXT ("Client (%P|%t) Need TAO_HAS_TRANSPORT_CURRENT enabled to run.\n")));
284 #endif /* TAO_HAS_TRANSPORT_CURRENT == 1 */