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 const int TIME_THRESHOLD
= 50; //ms
14 int activate_delay
= 0000;
16 int request_delay
= 00;
23 const ACE_TCHAR
*server_ior
= ACE_TEXT ("test.ior");
26 : public virtual POA_Tester
27 , public virtual ACE_Event_Handler
30 Tester_i (CORBA::ORB_ptr orb
)
37 this->start_
= ACE_High_Res_Timer::gettimeofday_hr ();
44 virtual void test (CORBA::Long id
)
46 // Ignore the extra message that were used for making messages
47 // queued for SYNC_DELAYED_BUFFERING test cases.
54 virtual CORBA::Long
test2 (CORBA::Long id
)
58 // Special id used to force a connect. Ignore.
59 this->start_
= ACE_High_Res_Timer::gettimeofday_hr ();
62 return testShared (id
);
65 int testShared (CORBA::Long id
)
67 ACE_Time_Value now
= ACE_High_Res_Timer::gettimeofday_hr ();
70 // Signals the end of a test run
71 if (num_expected
> 0 && count_
!= num_expected
)
73 cerr
<< "Error: Expected " << num_expected
74 << ", but received " << count_
<< endl
;
77 long ms
= (last_
- first_
).msec ();
78 if (elapsed_max
> 0 && ms
> elapsed_max
)
80 cerr
<< "Error: Expected < " << elapsed_max
81 << "ms, but was " << ms
<< "ms" << endl
;
84 if (elapsed_min
> 0 && ms
< elapsed_min
)
86 cerr
<< "Error: Expected > " << elapsed_min
87 << "ms, but was " << ms
<< "ms" << endl
;
90 ms
= (first_
- start_
).msec ();
91 if (first_max
> 0 && ms
> first_max
)
93 cerr
<< "Error: Expected first < " << first_max
94 << "ms, but was " << ms
<< "ms" << endl
;
97 if (first_min
> 0 && ms
< first_min
)
99 cerr
<< "Error: Expected first > " << first_min
100 << "ms, but was " << ms
<< "ms" << endl
;
101 this->failed_
= true;
103 ACE_Time_Value
timeout (0, 50 * 1000);
104 this->orb_
->orb_core ()->reactor ()->schedule_timer (this, 0, timeout
);
115 cout
<< 's' << id
<< endl
;
116 if (abort_after
> 0 && this->count_
>= abort_after
)
118 cout
<< "\nAborting..." << endl
;
121 if (request_delay
> 0 && id
== 0)
123 ACE_OS::sleep (ACE_Time_Value (0, 1000 * request_delay
));
128 int handle_timeout (const ACE_Time_Value
&, const void *)
130 this->orb_
->shutdown (0);
134 bool failed () const {
135 return this->failed_
;
144 ACE_Time_Value start_
;
145 ACE_Time_Value first_
;
146 ACE_Time_Value last_
;
149 #include "tao/Messaging/Messaging.h"
150 #include "tao/Strategies/advanced_resource.h"
152 #include "ace/streams.h"
153 #include "ace/Log_Msg.h"
154 #include "ace/Arg_Shifter.h"
156 using namespace CORBA
;
157 using namespace PortableServer
;
163 //FUZZ: disable check_for_lack_ACE_OS
164 cout
<< "server [-activate_delay ms] [-run_delay ms] [-request_delay ms] "
165 "[-abort_after n] [-server_ior <ior>]\n"
166 "\t[-expected n=0] [-elapsed_max ms=0] [-elapsed_min ms=0] "
167 "[-first_min ms=0]\n"
168 "\t[-first_max ms=0]\n"
169 "\tactivate_delay Millisecond delay before POAManager::activate.\n"
170 "\trun_delay Millisecond delay before ORB::run ().\n"
171 "\trequest_delay Millisecond delay within each servant request.\n"
172 "\tabort_after abort () after N requests.\n"
173 "\tior Server ior.\n" << endl
;
174 //FUZZ: enable check_for_lack_ACE_OS
177 bool parse_command_line (int ac
, ACE_TCHAR
*av
[])
179 ACE_Arg_Shifter
args (ac
, av
);
181 while (args
.is_anything_left ())
183 if (args
.cur_arg_strncasecmp (ACE_TEXT ("-activate_delay")) == 0)
186 activate_delay
= ACE_OS::atoi (args
.get_current ());
189 else if (args
.cur_arg_strncasecmp (ACE_TEXT ("-run_delay")) == 0)
192 run_delay
= ACE_OS::atoi (args
.get_current ());
195 else if (args
.cur_arg_strncasecmp (ACE_TEXT ("-request_delay")) == 0)
198 request_delay
= ACE_OS::atoi (args
.get_current ());
201 else if (args
.cur_arg_strncasecmp (ACE_TEXT ("-expected")) == 0)
204 num_expected
= ACE_OS::atoi (args
.get_current ());
207 else if (args
.cur_arg_strncasecmp (ACE_TEXT ("-elapsed_max")) == 0)
210 elapsed_max
= ACE_OS::atoi (args
.get_current ());
213 else if (args
.cur_arg_strncasecmp (ACE_TEXT ("-elapsed_min")) == 0)
216 elapsed_min
= ACE_OS::atoi (args
.get_current ());
219 else if (args
.cur_arg_strncasecmp (ACE_TEXT ("-first_min")) == 0)
222 first_min
= ACE_OS::atoi (args
.get_current ());
225 else if (args
.cur_arg_strncasecmp (ACE_TEXT ("-first_max")) == 0)
228 first_max
= ACE_OS::atoi (args
.get_current ());
231 else if (args
.cur_arg_strncasecmp (ACE_TEXT ("-abort_after")) == 0)
234 abort_after
= ACE_OS::atoi (args
.get_current ());
237 else if (args
.cur_arg_strncasecmp (ACE_TEXT ("-server_ior")) == 0)
240 server_ior
= args
.get_current ();
245 cerr
<< "Error: Unknown argument \""
246 << args
.get_current () << "\"" << endl
;
254 void WriteIOR (const char *ior
)
256 ofstream
out (ACE_TEXT_ALWAYS_CHAR (server_ior
));
260 POA_ptr
create_poa (ORB_ptr orb
)
263 Object_var obj
= orb
->resolve_initial_references ("RootPOA");
264 POA_var root
= POA::_narrow (obj
.in ());
265 ACE_ASSERT (! is_nil (root
.in ()));
267 pols
[0] = root
->create_id_assignment_policy (PortableServer::USER_ID
);
268 pols
[1] = root
->create_lifespan_policy (PortableServer::PERSISTENT
);
269 POAManager_var man
= root
->the_POAManager ();
270 POA_var poa
= root
->create_POA ("X", man
.in (), pols
);
275 int ACE_TMAIN (int ac
, ACE_TCHAR
*av
[])
279 ORB_var orb
= ORB_init (ac
, av
);
281 if (!parse_command_line (ac
, av
))
286 POA_var poa
= create_poa (orb
.in ());
287 ACE_ASSERT (! is_nil (poa
.in ()));
289 Tester_i
svt (orb
.in ());
291 ObjectId_var id
= string_to_ObjectId ("tester");
293 poa
->activate_object_with_id (id
.in (), &svt
);
294 Object_var obj
= poa
->id_to_reference (id
.in ());
295 String_var ior
= orb
->object_to_string (obj
.in ());
296 WriteIOR (ior
.in ());
298 cout
<< "Servants registered and activated." << endl
;
300 if (activate_delay
> 0)
302 ACE_OS::sleep (ACE_Time_Value (0, activate_delay
* 1000));
304 POAManager_var man
= poa
->the_POAManager ();
307 cout
<< "POAManager activated." << endl
;
311 ACE_OS::sleep (ACE_Time_Value (0, run_delay
* 1000));
313 cout
<< "Running orb..." << endl
;
324 catch (const CORBA::Exception
&ex
)
326 ex
._tao_print_exception ("server:");