Changes to attempt to silence bcc64x
[ACE_TAO.git] / TAO / tests / Oneway_Timeouts / server.cpp
blobee7ab003514edc86f50dd902c67ddb0b7006d3f2
1 #include "TestS.h"
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;
13 int run_delay = 00;
14 int request_delay = 00;
15 int abort_after = 0;
16 int num_expected = 0;
17 int elapsed_max = 0;
18 int elapsed_min = 0;
19 int first_min = 0;
20 int first_max = 0;
21 const ACE_TCHAR *server_ior = ACE_TEXT ("test.ior");
23 class Tester_i
24 : public virtual POA_Tester
25 , public virtual ACE_Event_Handler
27 public:
28 Tester_i (CORBA::ORB_ptr orb)
29 : orb_ (orb)
30 , count_ (0)
31 , failed_ (false)
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.
42 if (id == -3)
43 return;
45 testShared (id);
48 virtual CORBA::Long test2 (CORBA::Long id)
50 if (id == -2)
52 // Special id used to force a connect. Ignore.
53 this->start_ = ACE_High_Res_Timer::gettimeofday_hr ();
54 return id;
56 return testShared (id);
59 int testShared (CORBA::Long id)
61 ACE_Time_Value now = ACE_High_Res_Timer::gettimeofday_hr ();
62 if (id == -1)
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;
69 this->failed_ = true;
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;
76 this->failed_ = true;
78 if (elapsed_min > 0 && ms < elapsed_min)
80 cerr << "Error: Expected > " << elapsed_min
81 << "ms, but was " << ms << "ms" << endl;
82 this->failed_ = true;
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;
89 this->failed_ = true;
91 if (first_min > 0 && ms < first_min)
93 cerr << "Error: Expected first > " << first_min
94 << "ms, but was " << ms << "ms" << endl;
95 this->failed_ = true;
97 ACE_Time_Value timeout (0, 50 * 1000);
98 this->orb_->orb_core ()->reactor ()->schedule_timer (this, 0, timeout);
99 return id;
103 this->last_ = now;
104 if (id == 0)
106 this->first_ = now;
108 ++this->count_;
109 cout << 's' << id << endl;
110 if (abort_after > 0 && this->count_ >= abort_after)
112 cout << "\nAborting..." << endl;
113 ACE_OS::abort ();
115 if (request_delay > 0 && id == 0)
117 ACE_OS::sleep (ACE_Time_Value (0, 1000 * request_delay));
119 return id;
122 int handle_timeout (const ACE_Time_Value &, const void *)
124 this->orb_->shutdown (false);
125 return 0;
128 bool failed () const {
129 return this->failed_;
132 private:
133 CORBA::ORB_ptr orb_;
134 int count_;
135 bool 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;
151 namespace {
152 void print_usage ()
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);
171 args.consume_arg ();
172 while (args.is_anything_left ())
174 if (args.cur_arg_strncasecmp (ACE_TEXT ("-activate_delay")) == 0)
176 args.consume_arg ();
177 activate_delay = ACE_OS::atoi (args.get_current ());
178 args.consume_arg ();
180 else if (args.cur_arg_strncasecmp (ACE_TEXT ("-run_delay")) == 0)
182 args.consume_arg ();
183 run_delay = ACE_OS::atoi (args.get_current ());
184 args.consume_arg ();
186 else if (args.cur_arg_strncasecmp (ACE_TEXT ("-request_delay")) == 0)
188 args.consume_arg ();
189 request_delay = ACE_OS::atoi (args.get_current ());
190 args.consume_arg ();
192 else if (args.cur_arg_strncasecmp (ACE_TEXT ("-expected")) == 0)
194 args.consume_arg ();
195 num_expected = ACE_OS::atoi (args.get_current ());
196 args.consume_arg ();
198 else if (args.cur_arg_strncasecmp (ACE_TEXT ("-elapsed_max")) == 0)
200 args.consume_arg ();
201 elapsed_max = ACE_OS::atoi (args.get_current ());
202 args.consume_arg ();
204 else if (args.cur_arg_strncasecmp (ACE_TEXT ("-elapsed_min")) == 0)
206 args.consume_arg ();
207 elapsed_min = ACE_OS::atoi (args.get_current ());
208 args.consume_arg ();
210 else if (args.cur_arg_strncasecmp (ACE_TEXT ("-first_min")) == 0)
212 args.consume_arg ();
213 first_min = ACE_OS::atoi (args.get_current ());
214 args.consume_arg ();
216 else if (args.cur_arg_strncasecmp (ACE_TEXT ("-first_max")) == 0)
218 args.consume_arg ();
219 first_max = ACE_OS::atoi (args.get_current ());
220 args.consume_arg ();
222 else if (args.cur_arg_strncasecmp (ACE_TEXT ("-abort_after")) == 0)
224 args.consume_arg ();
225 abort_after = ACE_OS::atoi (args.get_current ());
226 args.consume_arg ();
228 else if (args.cur_arg_strncasecmp (ACE_TEXT ("-server_ior")) == 0)
230 args.consume_arg ();
231 server_ior = args.get_current ();
232 args.consume_arg ();
234 else
236 cerr << "Error: Unknown argument \""
237 << args.get_current () << "\"" << endl;
238 print_usage ();
239 return false;
242 return true;
245 void WriteIOR (const char *ior)
247 ofstream out (ACE_TEXT_ALWAYS_CHAR (server_ior));
248 out << ior;
251 POA_ptr create_poa (ORB_ptr orb)
253 PolicyList pols (2);
254 Object_var obj = orb->resolve_initial_references ("RootPOA");
255 POA_var root = POA::_narrow (obj.in ());
256 ACE_ASSERT (! is_nil (root.in ()));
257 pols.length (2);
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);
262 return poa._retn ();
266 int ACE_TMAIN (int ac, ACE_TCHAR *av[])
270 ORB_var orb = ORB_init (ac, av);
272 if (!parse_command_line (ac, av))
274 return 1;
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 ();
296 man->activate ();
298 cout << "POAManager activated." << endl;
300 if (run_delay > 0)
302 ACE_OS::sleep (ACE_Time_Value (0, run_delay * 1000));
304 cout << "Running orb..." << endl;
306 orb->run ();
308 if (svt.failed ())
310 return 1;
313 return 0;
315 catch (const CORBA::Exception &ex)
317 ex._tao_print_exception ("server:");
320 return 1;