3 #include "tao/Strategies/advanced_resource.h"
4 #include "tao/Messaging/Messaging.h"
5 #include "tao/AnyTypeCode/TAOA.h"
6 #include "tao/AnyTypeCode/Any.h"
8 #include "ace/streams.h"
9 #include "ace/High_Res_Timer.h"
10 #include "ace/Reactor.h"
12 int activate_delay
= 0000;
14 int request_delay
= 00;
21 const ACE_TCHAR
*server_ior
= ACE_TEXT ("test.ior");
24 : public virtual POA_Tester
25 , public virtual ACE_Event_Handler
28 Tester_i (CORBA::ORB_ptr orb
)
33 this->start_
= ACE_High_Res_Timer::gettimeofday_hr ();
36 virtual ~Tester_i () = default;
38 virtual void test (CORBA::Long id
)
40 // Ignore the extra message that were used for making messages
41 // queued for SYNC_DELAYED_BUFFERING test cases.
48 virtual CORBA::Long
test2 (CORBA::Long id
)
52 // Special id used to force a connect. Ignore.
53 this->start_
= ACE_High_Res_Timer::gettimeofday_hr ();
56 return testShared (id
);
59 int testShared (CORBA::Long id
)
61 ACE_Time_Value now
= ACE_High_Res_Timer::gettimeofday_hr ();
64 // Signals the end of a test run
65 if (num_expected
> 0 && count_
!= num_expected
)
67 cerr
<< "Error: Expected " << num_expected
68 << ", but received " << count_
<< endl
;
71 long ms
= (last_
- first_
).msec ();
72 if (elapsed_max
> 0 && ms
> elapsed_max
)
74 cerr
<< "Error: Expected < " << elapsed_max
75 << "ms, but was " << ms
<< "ms" << endl
;
78 if (elapsed_min
> 0 && ms
< elapsed_min
)
80 cerr
<< "Error: Expected > " << elapsed_min
81 << "ms, but was " << ms
<< "ms" << endl
;
84 ms
= (first_
- start_
).msec ();
85 if (first_max
> 0 && ms
> first_max
)
87 cerr
<< "Error: Expected first < " << first_max
88 << "ms, but was " << ms
<< "ms" << endl
;
91 if (first_min
> 0 && ms
< first_min
)
93 cerr
<< "Error: Expected first > " << first_min
94 << "ms, but was " << ms
<< "ms" << endl
;
97 ACE_Time_Value
timeout (0, 50 * 1000);
98 this->orb_
->orb_core ()->reactor ()->schedule_timer (this, 0, timeout
);
109 cout
<< 's' << id
<< endl
;
110 if (abort_after
> 0 && this->count_
>= abort_after
)
112 cout
<< "\nAborting..." << endl
;
115 if (request_delay
> 0 && id
== 0)
117 ACE_OS::sleep (ACE_Time_Value (0, 1000 * request_delay
));
122 int handle_timeout (const ACE_Time_Value
&, const void *)
124 this->orb_
->shutdown (false);
128 bool failed () const {
129 return this->failed_
;
136 ACE_Time_Value start_
;
137 ACE_Time_Value first_
;
138 ACE_Time_Value last_
;
141 #include "tao/Messaging/Messaging.h"
142 #include "tao/Strategies/advanced_resource.h"
144 #include "ace/streams.h"
145 #include "ace/Log_Msg.h"
146 #include "ace/Arg_Shifter.h"
148 using namespace CORBA
;
149 using namespace PortableServer
;
154 //FUZZ: disable check_for_lack_ACE_OS
155 cout
<< "server [-activate_delay ms] [-run_delay ms] [-request_delay ms] "
156 "[-abort_after n] [-server_ior <ior>]\n"
157 "\t[-expected n=0] [-elapsed_max ms=0] [-elapsed_min ms=0] "
158 "[-first_min ms=0]\n"
159 "\t[-first_max ms=0]\n"
160 "\tactivate_delay Millisecond delay before POAManager::activate.\n"
161 "\trun_delay Millisecond delay before ORB::run ().\n"
162 "\trequest_delay Millisecond delay within each servant request.\n"
163 "\tabort_after abort () after N requests.\n"
164 "\tior Server ior.\n" << endl
;
165 //FUZZ: enable check_for_lack_ACE_OS
168 bool parse_command_line (int ac
, ACE_TCHAR
*av
[])
170 ACE_Arg_Shifter
args (ac
, av
);
172 while (args
.is_anything_left ())
174 if (args
.cur_arg_strncasecmp (ACE_TEXT ("-activate_delay")) == 0)
177 activate_delay
= ACE_OS::atoi (args
.get_current ());
180 else if (args
.cur_arg_strncasecmp (ACE_TEXT ("-run_delay")) == 0)
183 run_delay
= ACE_OS::atoi (args
.get_current ());
186 else if (args
.cur_arg_strncasecmp (ACE_TEXT ("-request_delay")) == 0)
189 request_delay
= ACE_OS::atoi (args
.get_current ());
192 else if (args
.cur_arg_strncasecmp (ACE_TEXT ("-expected")) == 0)
195 num_expected
= ACE_OS::atoi (args
.get_current ());
198 else if (args
.cur_arg_strncasecmp (ACE_TEXT ("-elapsed_max")) == 0)
201 elapsed_max
= ACE_OS::atoi (args
.get_current ());
204 else if (args
.cur_arg_strncasecmp (ACE_TEXT ("-elapsed_min")) == 0)
207 elapsed_min
= ACE_OS::atoi (args
.get_current ());
210 else if (args
.cur_arg_strncasecmp (ACE_TEXT ("-first_min")) == 0)
213 first_min
= ACE_OS::atoi (args
.get_current ());
216 else if (args
.cur_arg_strncasecmp (ACE_TEXT ("-first_max")) == 0)
219 first_max
= ACE_OS::atoi (args
.get_current ());
222 else if (args
.cur_arg_strncasecmp (ACE_TEXT ("-abort_after")) == 0)
225 abort_after
= ACE_OS::atoi (args
.get_current ());
228 else if (args
.cur_arg_strncasecmp (ACE_TEXT ("-server_ior")) == 0)
231 server_ior
= args
.get_current ();
236 cerr
<< "Error: Unknown argument \""
237 << args
.get_current () << "\"" << endl
;
245 void WriteIOR (const char *ior
)
247 ofstream
out (ACE_TEXT_ALWAYS_CHAR (server_ior
));
251 POA_ptr
create_poa (ORB_ptr orb
)
254 Object_var obj
= orb
->resolve_initial_references ("RootPOA");
255 POA_var root
= POA::_narrow (obj
.in ());
256 ACE_ASSERT (! is_nil (root
.in ()));
258 pols
[0] = root
->create_id_assignment_policy (PortableServer::USER_ID
);
259 pols
[1] = root
->create_lifespan_policy (PortableServer::PERSISTENT
);
260 POAManager_var man
= root
->the_POAManager ();
261 POA_var poa
= root
->create_POA ("X", man
.in (), pols
);
266 int ACE_TMAIN (int ac
, ACE_TCHAR
*av
[])
270 ORB_var orb
= ORB_init (ac
, av
);
272 if (!parse_command_line (ac
, av
))
277 POA_var poa
= create_poa (orb
.in ());
278 ACE_ASSERT (! is_nil (poa
.in ()));
280 Tester_i
svt (orb
.in ());
282 ObjectId_var id
= string_to_ObjectId ("tester");
284 poa
->activate_object_with_id (id
.in (), &svt
);
285 Object_var obj
= poa
->id_to_reference (id
.in ());
286 String_var ior
= orb
->object_to_string (obj
.in ());
287 WriteIOR (ior
.in ());
289 cout
<< "Servants registered and activated." << endl
;
291 if (activate_delay
> 0)
293 ACE_OS::sleep (ACE_Time_Value (0, activate_delay
* 1000));
295 POAManager_var man
= poa
->the_POAManager ();
298 cout
<< "POAManager activated." << endl
;
302 ACE_OS::sleep (ACE_Time_Value (0, run_delay
* 1000));
304 cout
<< "Running orb..." << endl
;
315 catch (const CORBA::Exception
&ex
)
317 ex
._tao_print_exception ("server:");