2 * @file Reactor_Notification_Queue_Test.cpp
4 * Verify that the notification queue can be used with large numbers
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
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
26 Event_Handler(ACE_Reactor
* reactor
,
27 int max_notifications
,
28 char const *test_name
);
33 /// Receive the notifications.
34 virtual int handle_exception(ACE_HANDLE
);
38 * @brief Implement a single iteration.
40 * Each iteration of the test consists of sending multiple
41 * notifications simultaneously.
43 void send_notifications (void);
46 * @brief Return true if the test is finished.
48 bool done (void) const;
52 * @brief The maximum number of notifications in any single
55 int max_notifications_
;
58 * @brief The name of the test
60 char const * test_name_
;
62 * @brief Number of notifications received
64 int notifications_sent_
;
66 * @brief Number of notifications sent
68 int notifications_recv_
;
71 * @brief Number of notifications sent on each iteration
73 int notifications_curr_
;
77 run_main (int, ACE_TCHAR
*[])
79 ACE_START_TEST (ACE_TEXT ("Reactor_Notification_Queue_Test"));
81 #if !defined(ACE_HAS_REACTOR_NOTIFICATION_QUEUE)
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;
89 int max_notifications
= 1024 * 1024;
90 #endif /* ACE_HAS_THREADS */
93 ACE_Reactor
select_reactor (
94 new ACE_Select_Reactor
,
97 Event_Handler
handler(&select_reactor
,
105 ACE_Reactor
tp_reactor (new ACE_TP_Reactor
,
107 Event_Handler
handler(&tp_reactor
,
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
,
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)
145 Event_Handler::run (void)
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
);
158 ACE_ERROR ((LM_ERROR
,
159 ACE_TEXT ("Test %C failed due to timeout ")
160 ACE_TEXT (" sent=%d,recv=%d\n"),
163 notifications_recv_
));
168 ACE_TEXT ("Test %C passed sent=%d, recv=%d\n"),
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_
)
186 send_notifications();
192 Event_Handler::send_notifications (void)
194 for (int i
= 0; i
!= notifications_curr_
; ++i
)
196 if(reactor()->notify (this) == -1)
199 ACE_TEXT ("Cannot send notifications in %C test (%d/%d)\n"),
200 test_name_
, i
, notifications_curr_
));
204 ++notifications_sent_
;
206 // ACE_ERROR((LM_ERROR,
207 // "Started iteration with %d notify() calls in test %C\n",
208 // notifications_curr_, test_name_));
209 notifications_curr_
*= 2;
213 Event_Handler::done (void) const
215 return (notifications_curr_
>= max_notifications_
)
216 && (notifications_sent_
== notifications_recv_
);