1 /* $Id: test_thread_pool_observer.cpp,v 1.8 2005-12-02 12:21:07 adam Exp $
2 Copyright (c) 2005, Index Data.
6 /* $Id: test_thread_pool_observer.cpp,v 1.8 2005-12-02 12:21:07 adam Exp $
7 Copyright (c) 1998-2005, Index Data.
9 This file is part of the yaz-proxy.
11 YAZ proxy is free software; you can redistribute it and/or modify it under
12 the terms of the GNU General Public License as published by the Free
13 Software Foundation; either version 2, or (at your option) any later
16 YAZ proxy is distributed in the hope that it will be useful, but WITHOUT ANY
17 WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 You should have received a copy of the GNU General Public License
22 along with YAZ proxy; see the file LICENSE. If not, write to the
23 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
31 #include <yaz++/pdu-assoc.h>
32 #include <yaz++/socket-manager.h>
35 #include "thread_pool_observer.hpp"
37 #define BOOST_AUTO_TEST_MAIN
38 #include <boost/test/auto_unit_test.hpp>
40 using namespace boost::unit_test;
41 using namespace yazpp_1;
43 class My_Timer_Thread;
45 class My_Msg : public yp2::IThreadPoolMsg {
47 yp2::IThreadPoolMsg *handle();
50 My_Timer_Thread *m_timer;
53 class My_Timer_Thread : public ISocketObserver {
55 ISocketObservable *m_obs;
57 yp2::ThreadPoolSocketObserver *m_t;
62 My_Timer_Thread(ISocketObservable *obs, yp2::ThreadPoolSocketObserver *t);
63 void socketNotify(int event);
67 yp2::IThreadPoolMsg *My_Msg::handle()
69 My_Msg *res = new My_Msg;
75 res->m_timer = m_timer;
81 m_timer->m_sum += m_val;
82 m_timer->m_responses++;
85 My_Timer_Thread::My_Timer_Thread(ISocketObservable *obs,
86 yp2::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++;
106 BOOST_AUTO_UNIT_TEST( thread_pool_observer1 )
108 SocketManager mySocketManager;
110 yp2::ThreadPoolSocketObserver m(&mySocketManager, 3);
111 My_Timer_Thread t(&mySocketManager, &m) ;
112 while (t.m_responses < 30 && mySocketManager.processEvent() > 0)
114 BOOST_CHECK_EQUAL(t.m_responses, 30);
115 BOOST_CHECK(t.m_sum >= 435);
121 * indent-tabs-mode: nil
122 * c-file-style: "stroustrup"
124 * vim: shiftwidth=4 tabstop=8 expandtab