Use =default for skeleton copy constructor
[ACE_TAO.git] / ACE / tests / Reactor_Notification_Queue_Test.cpp
blob8b643af240f1437dee7a6cda931da3197210b0d8
1 /**
2 * @file Reactor_Notification_Queue_Test.cpp
4 * Verify that the notification queue can be used with large numbers
5 * of events.
7 * Normally the ACE_Reactor uses a pipe to implement the notify()
8 * methods. ACE can be compiled with
9 * ACE_HAS_REACTOR_NOTIFICATION_QUEUE, with this configuration flag
10 * the Reactor uses a user-space queue to contain the notifications.
11 * A single message is sent through the pipe to indicate "pipe not
12 * empty."
14 * @author Carlos O'Ryan <coryan@atdesk.com>
17 #include "test_config.h"
18 #include "ace/Reactor.h"
19 #include "ace/TP_Reactor.h"
20 #include "ace/Select_Reactor.h"
21 #include "ace/WFMO_Reactor.h"
23 class Event_Handler : public ACE_Event_Handler
25 public:
26 Event_Handler(ACE_Reactor * reactor,
27 int max_notifications,
28 char const *test_name);
30 /// Run the test
31 void run();
33 /// Receive the notifications.
34 int handle_exception(ACE_HANDLE) override;
36 private:
37 /**
38 * @brief Implement a single iteration.
40 * Each iteration of the test consists of sending multiple
41 * notifications simultaneously.
43 void send_notifications ();
45 /**
46 * @brief Return true if the test is finished.
48 bool done () const;
50 private:
51 /**
52 * @brief The maximum number of notifications in any single
53 * iteration.
55 int max_notifications_;
57 /**
58 * @brief The name of the test
60 char const * test_name_;
61 /**
62 * @brief Number of notifications received
64 int notifications_sent_;
65 /**
66 * @brief Number of notifications sent
68 int notifications_recv_;
70 /**
71 * @brief Number of notifications sent on each iteration
73 int notifications_curr_;
76 int
77 run_main (int, ACE_TCHAR *[])
79 ACE_START_TEST (ACE_TEXT ("Reactor_Notification_Queue_Test"));
81 #if !defined(ACE_HAS_REACTOR_NOTIFICATION_QUEUE)
82 ACE_DEBUG ((LM_INFO,
83 ACE_TEXT ("Notification queue disabled, ")
84 ACE_TEXT ("small test version, ")
85 ACE_TEXT ("which is of no practical use\n")));
87 int max_notifications = 16;
88 #else
89 int max_notifications = 1024 * 1024;
90 #endif /* ACE_HAS_THREADS */
93 ACE_Reactor select_reactor (
94 new ACE_Select_Reactor,
95 1);
97 Event_Handler handler(&select_reactor,
98 max_notifications,
99 "Select_Reactor");
101 handler.run ();
105 ACE_Reactor tp_reactor (new ACE_TP_Reactor,
107 Event_Handler handler(&tp_reactor,
108 max_notifications,
109 "TP_Reactor");
110 handler.run();
113 #if 0
114 /// @@todo: Need to talk to Irfan to see how the WFMO handles this.
115 #if defined (ACE_WIN32)
117 ACE_Reactor wfmo_reactor (new ACE_WFMO_Reactor,
120 Event_Handler handler(&wfmo_reactor,
121 max_notifications,
122 "WFMO_Reactor");
123 handler.run();
125 #endif /*ACE_WIN32*/
126 #endif /*if 0 */
127 ACE_END_TEST;
128 return 0;
131 Event_Handler::Event_Handler (
132 ACE_Reactor * reactor,
133 int max_notifications,
134 char const * test_name)
135 : ACE_Event_Handler(reactor)
136 , max_notifications_(max_notifications)
137 , test_name_(test_name)
138 , notifications_sent_(0)
139 , notifications_recv_(0)
140 , notifications_curr_(1)
144 void
145 Event_Handler::run ()
147 send_notifications ();
149 // Run for 30 seconds or until the test is done.
150 for(int i = 0; i != 30 && !done(); ++i)
152 ACE_Time_Value tv (1,0);
153 reactor ()->run_reactor_event_loop(tv);
156 if(!done())
158 ACE_ERROR ((LM_ERROR,
159 ACE_TEXT ("Test %C failed due to timeout ")
160 ACE_TEXT (" sent=%d,recv=%d\n"),
161 test_name_,
162 notifications_sent_,
163 notifications_recv_));
165 else
167 ACE_DEBUG ((LM_INFO,
168 ACE_TEXT ("Test %C passed sent=%d, recv=%d\n"),
169 test_name_,
170 notifications_sent_,
171 notifications_recv_));
176 Event_Handler::handle_exception (ACE_HANDLE)
178 ++notifications_recv_;
179 if(notifications_recv_ == notifications_sent_)
181 if(notifications_curr_ >= max_notifications_)
183 return 0;
185 send_notifications();
187 return 0;
190 void
191 Event_Handler::send_notifications ()
193 for (int i = 0; i != notifications_curr_; ++i)
195 if(reactor()->notify (this) == -1)
197 ACE_ERROR((LM_ERROR,
198 ACE_TEXT ("Cannot send notifications in %C test (%d/%d)\n"),
199 test_name_, i, notifications_curr_));
200 return;
203 ++notifications_sent_;
205 // ACE_ERROR((LM_ERROR,
206 // "Started iteration with %d notify() calls in test %C\n",
207 // notifications_curr_, test_name_));
208 notifications_curr_ *= 2;
211 bool
212 Event_Handler::done () const
214 return (notifications_curr_ >= max_notifications_)
215 && (notifications_sent_ == notifications_recv_);