1 /* $Id: test_thread_pool_observer.cpp,v 1.11 2006-06-10 14:29:13 adam Exp $
2 Copyright (c) 2005-2006, Index Data.
4 See the LICENSE file for details
11 #include <yazpp/pdu-assoc.h>
12 #include <yazpp/socket-manager.h>
15 #include "thread_pool_observer.hpp"
17 #define BOOST_AUTO_TEST_MAIN
18 #include <boost/test/auto_unit_test.hpp>
20 using namespace boost::unit_test;
21 using namespace yazpp_1;
22 namespace mp = metaproxy_1;
24 class My_Timer_Thread;
26 class My_Msg : public mp::IThreadPoolMsg {
28 mp::IThreadPoolMsg *handle();
31 My_Timer_Thread *m_timer;
34 class My_Timer_Thread : public ISocketObserver {
36 ISocketObservable *m_obs;
38 mp::ThreadPoolSocketObserver *m_t;
43 My_Timer_Thread(ISocketObservable *obs, mp::ThreadPoolSocketObserver *t);
44 void socketNotify(int event);
48 mp::IThreadPoolMsg *My_Msg::handle()
50 My_Msg *res = new My_Msg;
56 res->m_timer = m_timer;
62 m_timer->m_sum += m_val;
63 m_timer->m_responses++;
66 My_Timer_Thread::My_Timer_Thread(ISocketObservable *obs,
67 mp::ThreadPoolSocketObserver *t) :
68 m_obs(obs), m_pipe(9123)
74 obs->addObserver(m_pipe.read_fd(), this);
75 obs->maskObserver(this, SOCKET_OBSERVE_READ);
76 obs->timeoutObserver(this, 0);
79 void My_Timer_Thread::socketNotify(int event)
81 My_Msg *m = new My_Msg;
82 m->m_val = m_requests++;
87 BOOST_AUTO_UNIT_TEST( thread_pool_observer1 )
89 SocketManager mySocketManager;
91 mp::ThreadPoolSocketObserver m(&mySocketManager, 3);
92 My_Timer_Thread t(&mySocketManager, &m) ;
93 while (t.m_responses < 30 && mySocketManager.processEvent() > 0)
95 BOOST_CHECK_EQUAL(t.m_responses, 30);
96 BOOST_CHECK(t.m_sum >= 435);
102 * indent-tabs-mode: nil
103 * c-file-style: "stroustrup"
105 * vim: shiftwidth=4 tabstop=8 expandtab