1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
|
// -*- C++ -*-
#include "ace/Get_Opt.h"
#include "ace/Task.h"
#include "tao/DynamicInterface/Request.h"
#include "tao/ORBInitializer_Registry.h"
#include "tao/TransportCurrent/Transport_Current.h"
#include "Client_Request_Interceptor.h"
#include "Current_TestC.h"
#include "Client_ORBInitializer.h"
// Prototype
int
test_transport_current (CORBA::ORB_ptr);
using namespace TAO;
const char* CLIENT_ORB_ID = "client orb";
const ACE_TCHAR* ior = ACE_TEXT("file://server.ior");
int nthreads = 1;
int niterations = 1;
int use_dii = 1;
int
parse_args (int argc, ACE_TCHAR *argv[])
{
ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("yt:n:k:"));
int c;
while ((c = get_opts ()) != -1)
switch (c)
{
case 'y':
use_dii = 0; // Do not use DII
break;
case 'k':
ior = get_opts.opt_arg ();
break;
case 't':
nthreads = ACE_OS::atoi (get_opts.opt_arg ());
break;
case 'n':
niterations = ACE_OS::atoi (get_opts.opt_arg ());
break;
default:
ACE_ERROR_RETURN ((LM_ERROR,
"Usage: %s "
"-k IOR "
"-t threads "
"-n iterations "
"-y "
"\n",
argv[0]),
-1);
}
return 0;
}
/// A helper class to encapsulate a task
class Worker : public ACE_Task_Base
{
public:
Worker (Test::Transport::CurrentTest_ptr server, int niterations, int use_dii_too);
virtual int svc ();
private:
// The server.
Test::Transport::CurrentTest_var server_;
// The number of iterations on each client thread.
int niterations_;
// Whether to use DII in addition to SII
int use_dii_too_;
};
/// Ctor
Worker::Worker (Test::Transport::CurrentTest_ptr server,
int niterations,
int use_dii_too)
: server_ (Test::Transport::CurrentTest::_duplicate (server))
, niterations_ (niterations)
, use_dii_too_ (use_dii_too)
{
}
/// Test referencing the TC data *inside* the context of a client-side
/// interceptor
int
Worker::svc (void)
{
try
{
for (int i = 0; i < this->niterations_; ++i)
{
// Minimum CORBA does not define Object::_request, so we're just
// skipping the DII part in those cases.
#if (!defined(TAO_HAS_MINIMUM_CORBA) || (TAO_HAS_MINIMUM_CORBA == 0))
if (this->use_dii_too_)
{
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT ("Client (%P|%t) Invoking server->invoked_by_client() via DII\n")));
CORBA::Request_var request =
this->server_->_request ("invoked_by_client");
request->set_return_type (CORBA::_tc_void);
request->invoke ();
}
#endif /* (!defined(TAO_HAS_MINIMUM_CORBA) || (TAO_HAS_MINIMUM_CORBA == 0)) */
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT ("Client (%P|%t) Invoking server->invoked_by_client() via SII\n")));
this->server_->invoked_by_client ();
if (TAO_debug_level > 0 && i % 100 == 0)
ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Client (%P|%t) Iteration = %d\n"),
i));
}
}
catch (const CORBA::Exception& ex)
{
ex._tao_print_exception ("Client: exception raised");
}
return 0;
}
/// The main driver
int
ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
#if TAO_HAS_TRANSPORT_CURRENT == 1
try
{
Test::Client_Request_Interceptor* cri = 0;
ACE_NEW_RETURN (cri,
Test::Client_Request_Interceptor (CLIENT_ORB_ID,
test_transport_current),
-1);
PortableInterceptor::ClientRequestInterceptor_var cri_safe (cri);
PortableInterceptor::ORBInitializer_ptr temp_initializer = 0;
ACE_NEW_RETURN (temp_initializer,
Test::Client_ORBInitializer (cri),
-1);
PortableInterceptor::ORBInitializer_var orb_initializer (temp_initializer);
PortableInterceptor::register_orb_initializer (orb_initializer.in ());
CORBA::ORB_var orb =
CORBA::ORB_init (argc,
argv,
CLIENT_ORB_ID);
if (parse_args (argc, argv) != 0)
ACE_ERROR_RETURN ((LM_ERROR,
ACE_TEXT ("Client (%P|%t) Failure to parse the command line.\n"),
ior),
-1);
try
{
test_transport_current (orb.in ());
ACE_ERROR_RETURN ((LM_ERROR,
ACE_TEXT ("Client (%P|%t) ERROR: ")
ACE_TEXT ("TC invocation, outside of ")
ACE_TEXT ("interceptor context is undefined.")
ACE_TEXT (" Expected exception was not thrown\n")),
-1);
}
catch (const Transport::NoContext& )
{
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT ("Client (%P|%t) Expected exception occurred when trying ")
ACE_TEXT ("to access traits outside the ")
ACE_TEXT ("interceptor or upcall context.\n")));
}
// Resolve the target object
CORBA::Object_var obj = orb->string_to_object (ior);
Test::Transport::CurrentTest_var server =
Test::Transport::CurrentTest::_narrow (obj.in ());
if (CORBA::is_nil (server.in ()))
ACE_ERROR_RETURN ((LM_ERROR,
ACE_TEXT ("Client (%P|%t) The server object reference <%s> is nil.\n"),
ior),
-1);
ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Client (%P|%t) Spawning %d threads\n"), nthreads));
// Spawn a number of clients doing the same thing for a
// predetermined number of times
Worker client (server.in (), niterations, use_dii);
#if defined (ACE_HAS_THREADS)
if (client.activate (THR_NEW_LWP | THR_JOINABLE,
nthreads) != 0)
ACE_ERROR_RETURN ((LM_ERROR,
ACE_TEXT ("Client (%P|%t) Cannot activate %d client threads\n"),
nthreads),
-1);
client.thr_mgr ()->wait ();
#else
if (nthreads > 1)
ACE_ERROR ((LM_WARNING,
ACE_TEXT ("Client (%P|%t) Cannot use threads other than ")
ACE_TEXT ("the only one available.\n")));
client.svc ();
#endif
ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Client (%P|%t) Collected any threads\n")));
CORBA::Long result = 0;
// Verify enough interception points have been triggered
if (cri->interceptions () != 2 * // request & response
niterations * // iterations
nthreads * // threads
(2*use_dii)) // sii and dii, if needed
{
ACE_ERROR ((LM_ERROR,
ACE_TEXT ("Client (%P|%t) Expected %d client-side interceptions, but detected %d\n"),
2 * niterations * nthreads * (2*use_dii),
cri->interceptions ()));
}
else
{
ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Client (%P|%t) Invoking server->self_test()\n")));
// Self-test the server side
result = server->self_test ();
if (result != 0)
ACE_ERROR ((LM_ERROR,
ACE_TEXT ("Client (%P|%t) Server self-test reported failure\n")));
}
ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Client (%P|%t) Invoking oneway server->shutdown()\n")));
server->shutdown ();
ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Client (%P|%t) Invoking orb->destroy ()\n")));
orb->destroy ();
ACE_DEBUG ((LM_INFO,
ACE_TEXT ("Client (%P|%t) Completed %s.\n"),
((result == 0) ? ACE_TEXT ("successfuly") : ACE_TEXT ("with failure"))));
return result;
}
catch (const CORBA::Exception& ex)
{
ex._tao_print_exception (
ACE_TEXT (
"Client: Transport Current test (client-side) failed:"));
return -1;
}
#else /* TAO_HAS_TRANSPORT_CURRENT == 1 */
ACE_DEBUG ((LM_INFO, ACE_TEXT ("Client (%P|%t) Need TAO_HAS_TRANSPORT_CURRENT enabled to run.\n")));
return 0;
#endif /* TAO_HAS_TRANSPORT_CURRENT == 1 */
}
|