1 /* This file is part of Metaproxy.
2 Copyright (C) 2005-2013 Index Data
4 Metaproxy is free software; you can redistribute it and/or modify it under
5 the terms of the GNU General Public License as published by the Free
6 Software Foundation; either version 2, or (at your option) any later
9 Metaproxy is distributed in the hope that it will be useful, but WITHOUT ANY
10 WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23 #include <yazpp/pdu-assoc.h>
24 #include <yazpp/socket-manager.h>
27 #include "thread_pool_observer.hpp"
29 #define BOOST_AUTO_TEST_MAIN
30 #define BOOST_TEST_DYN_LINK
31 #include <boost/test/auto_unit_test.hpp>
33 using namespace boost::unit_test;
34 using namespace yazpp_1;
35 namespace mp = metaproxy_1;
37 class My_Timer_Thread;
39 class My_Msg : public mp::IThreadPoolMsg {
41 mp::IThreadPoolMsg *handle();
42 void result(const char *t_info);
43 bool cleanup(void *info);
45 My_Timer_Thread *m_timer;
48 class My_Timer_Thread : public ISocketObserver {
50 ISocketObservable *m_obs;
52 mp::ThreadPoolSocketObserver *m_t;
57 My_Timer_Thread(ISocketObservable *obs, mp::ThreadPoolSocketObserver *t);
58 void socketNotify(int event);
62 mp::IThreadPoolMsg *My_Msg::handle()
64 My_Msg *res = new My_Msg;
70 res->m_timer = m_timer;
74 bool My_Msg::cleanup(void *info)
79 void My_Msg::result(const char *t_info)
81 m_timer->m_sum += m_val;
82 m_timer->m_responses++;
85 My_Timer_Thread::My_Timer_Thread(ISocketObservable *obs,
86 mp::ThreadPoolSocketObserver *t) :
87 m_obs(obs), m_pipe(9123)
93 obs->addObserver(m_pipe.read_fd(), this);
94 obs->maskObserver(this, SOCKET_OBSERVE_READ);
95 obs->timeoutObserver(this, 0);
98 void My_Timer_Thread::socketNotify(int event)
100 My_Msg *m = new My_Msg;
101 m->m_val = m_requests++;
105 // prevent input queue from being filled up..
106 // bug #1064: Test test_thread_pool_observer hangs
107 // fortunately we don't need this hack. because put (ebove)
108 // will block itself if needed
110 m_obs->deleteObserver(this);
114 BOOST_AUTO_TEST_CASE( thread_pool_observer1 )
116 SocketManager mySocketManager;
118 mp::ThreadPoolSocketObserver m(&mySocketManager, 3);
119 My_Timer_Thread t(&mySocketManager, &m) ;
120 while (t.m_responses < 30 && mySocketManager.processEvent() > 0)
122 BOOST_CHECK_EQUAL(t.m_responses, 30);
123 BOOST_CHECK(t.m_sum >= 435); // = 29*30/2
129 * c-file-style: "Stroustrup"
130 * indent-tabs-mode: nil
132 * vim: shiftwidth=4 tabstop=8 expandtab