]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#1818] make http thread pool state private and add missing interface functions
authorRazvan Becheriu <razvan@isc.org>
Mon, 17 May 2021 11:16:20 +0000 (14:16 +0300)
committerThomas Markwalder <tmark@isc.org>
Mon, 17 May 2021 14:56:50 +0000 (10:56 -0400)
src/hooks/dhcp/high_availability/tests/ha_mt_unittest.cc
src/lib/asiolink/io_service.cc
src/lib/config/cmd_http_listener.cc
src/lib/config/cmd_http_listener.h
src/lib/config/tests/cmd_http_listener_unittests.cc
src/lib/http/client.cc
src/lib/http/client.h
src/lib/http/http_thread_pool.cc
src/lib/http/http_thread_pool.h
src/lib/http/tests/http_thread_pool_unittests.cc
src/lib/http/tests/mt_client_unittests.cc

index d6c046a1f7190c2ab67525ad313cfc81422f3f66..8313e0ca3e68f1e8830745b8abe465315f667e8e 100644 (file)
@@ -203,10 +203,12 @@ TEST_F(HAMtServiceTest, multiThreadingBasics) {
         // Client should exist but be stopped.
         ASSERT_TRUE(service->client_);
         ASSERT_TRUE(service->client_->isStopped());
+        EXPECT_TRUE(service->client_->getThreadIOService()->stopped());
 
-        // Listener should exist but be stopped..
+        // Listener should exist but be stopped.
         ASSERT_TRUE(service->listener_);
-        ASSERT_TRUE(service->client_->isStopped());
+        ASSERT_TRUE(service->listener_->isStopped());
+        EXPECT_TRUE(service->listener_->getThreadIOService()->stopped());
 
         // Start client and listener.
         ASSERT_NO_THROW_LOG(service->startClientAndListener());
@@ -402,6 +404,7 @@ TEST_F(HAMtServiceTest, multiThreadingConfigStartup) {
         EXPECT_TRUE(service->client_->isRunning());
         EXPECT_TRUE(service->client_->getThreadIOService());
         EXPECT_EQ(service->client_->getThreadPoolSize(), scenario.exp_client_threads_);
+
         // Currently thread count should be the same as thread pool size.  This might
         // change if we go to so some sort of dynamic thread instance management.
         EXPECT_EQ(service->client_->getThreadCount(), scenario.exp_client_threads_);
@@ -415,6 +418,7 @@ TEST_F(HAMtServiceTest, multiThreadingConfigStartup) {
         // We should have a running listener with the expected number of threads.
         ASSERT_TRUE(service->listener_);
         EXPECT_TRUE(service->listener_->isRunning());
+        ASSERT_TRUE(service->listener_->getThreadIOService());
         EXPECT_EQ(service->listener_->getThreadPoolSize(), scenario.exp_listener_threads_);
 
         // Currently thread count should be the same as thread pool size.  This might
index 927a1b1ba90968bdb72df0aafa3cb53654d25d88..aad5dc7070ae7b18e9bf0927ece8a190963ba823 100644 (file)
@@ -82,7 +82,9 @@ public:
     /// \brief Stop the underlying event loop.
     ///
     /// This will return the control to the caller of the \c run() method.
-    void stop() { io_service_.stop();} ;
+    void stop() {
+        io_service_.stop();
+    }
 
     /// \brief Indicates if the IOService has been stopped.
     ///
@@ -108,7 +110,9 @@ public:
     /// that share the same \c io_service with the authoritative server.
     /// It will eventually be removed once the wrapper interface is
     /// generalized.
-    boost::asio::io_service& get_io_service() { return io_service_; };
+    boost::asio::io_service& get_io_service() {
+        return (io_service_);
+    }
 
     /// \brief Post a callback on the IO service
     ///
@@ -117,6 +121,7 @@ public:
         const CallbackWrapper wrapper(callback);
         io_service_.post(wrapper);
     }
+
 private:
     boost::asio::io_service io_service_;
     boost::shared_ptr<boost::asio::io_service::work> work_;
index 55cb2d856dda8c42f28303f9238616fd853f3a80..7063e17b4eb3f1ec3b99bdb7f3d675662dcd8933 100644 (file)
@@ -29,7 +29,7 @@ namespace config {
 CmdHttpListener::CmdHttpListener(const IOAddress& address, const uint16_t port,
                                  const uint16_t thread_pool_size /* = 1 */)
     : address_(address), port_(port), thread_io_service_(), http_listener_(),
-      thread_pool_size_(thread_pool_size), threads_() {
+      thread_pool_size_(thread_pool_size), thread_pool_() {
 }
 
 CmdHttpListener::~CmdHttpListener() {
@@ -61,13 +61,12 @@ CmdHttpListener::start() {
         // Create the HTTP listener. It will open up a TCP socket and be
         // prepared to accept incoming connections.
         TlsContextPtr tls_context;
-        http_listener_.reset(new HttpListener(*thread_io_service_, address_, port_,
-                                              tls_context, rcf,
+        http_listener_.reset(new HttpListener(*thread_io_service_, address_, port_, tls_context, rcf,
                                               HttpListener::RequestTimeout(TIMEOUT_AGENT_RECEIVE_COMMAND),
                                               HttpListener::IdleTimeout(TIMEOUT_AGENT_IDLE_CONNECTION_TIMEOUT)));
 
         // Create the thread pool with immediate start.
-        threads_.reset(new HttpThreadPool(thread_io_service_, thread_pool_size_));
+        thread_pool_.reset(new HttpThreadPool(thread_io_service_, thread_pool_size_));
 
         // Instruct the HTTP listener to actually open socket, install
         // callback and start listening.
@@ -85,15 +84,15 @@ CmdHttpListener::start() {
 
 void
 CmdHttpListener::pause() {
-    if (threads_) {
-        threads_->pause();
+    if (thread_pool_) {
+        thread_pool_->pause();
     }
 }
 
 void
 CmdHttpListener::resume() {
-    if (threads_) {
-        threads_->run();
+    if (thread_pool_) {
+        thread_pool_->run();
     }
 }
 
@@ -109,7 +108,7 @@ CmdHttpListener::stop() {
               .arg(port_);
 
     // Stop the thread pool.
-    threads_->stop();
+    thread_pool_->stop();
 
     // Get rid of the listener.
     http_listener_.reset();
@@ -122,20 +121,10 @@ CmdHttpListener::stop() {
               .arg(port_);
 }
 
-HttpThreadPool::RunState
-CmdHttpListener::getRunState() const {
-    if (!threads_) {
-        isc_throw(InvalidOperation,
-                  "CmdHttpListener::getRunState - no thread pool!");
-    }
-
-    return (threads_->getRunState());
-}
-
 bool
 CmdHttpListener::isRunning() {
-    if (threads_) {
-        return (threads_->getRunState() == HttpThreadPool::RunState::RUNNING);
+    if (thread_pool_) {
+        return (thread_pool_->isRunning());
     }
 
     return (false);
@@ -143,8 +132,8 @@ CmdHttpListener::isRunning() {
 
 bool
 CmdHttpListener::isStopped() {
-    if (threads_) {
-        return (threads_->getRunState() == HttpThreadPool::RunState::STOPPED);
+    if (thread_pool_) {
+        return (thread_pool_->isStopped());
     }
 
     return (true);
@@ -152,8 +141,8 @@ CmdHttpListener::isStopped() {
 
 bool
 CmdHttpListener::isPaused() {
-    if (threads_) {
-        return (threads_->getRunState() == HttpThreadPool::RunState::PAUSED);
+    if (thread_pool_) {
+        return (thread_pool_->isPaused());
     }
 
     return (false);
index 0baacafbe6643c7d2dfd49c491cc6b70362591d9..0a1121b8100c0c108c424d2921887c9e3f344bfb 100644 (file)
@@ -50,14 +50,9 @@ public:
     /// @brief Stops the listener's thread pool.
     void stop();
 
-    /// @brief Fetches the run state of the thread pool.
+    /// @brief Indicates if the thread pool is running.
     ///
-    /// @return Run state of the pool.
-    http::HttpThreadPool::RunState getRunState() const;
-
-    /// @brief Indicates if the thread pool processing is running.
-    ///
-    /// @return True if the thread pool exists and is in the RUN state,
+    /// @return True if the thread pool exists and is in the RUNNING state,
     /// false otherwise.
     bool isRunning();
 
@@ -98,11 +93,11 @@ public:
     ///
     /// @return uint16_t containing the number of running threads.
     uint16_t getThreadCount() const {
-        if (!threads_) {
+        if (!thread_pool_) {
             return (0);
         }
 
-        return (threads_->getThreadCount());
+        return (thread_pool_->getThreadCount());
     }
 
     asiolink::IOServicePtr getThreadIOService() const {
@@ -126,7 +121,7 @@ private:
     std::size_t thread_pool_size_;
 
     /// @brief The pool of threads that do IO work.
-    http::HttpThreadPoolPtr threads_;
+    http::HttpThreadPoolPtr thread_pool_;
 };
 
 /// @brief Defines a shared pointer to CmdHttpListener.
index 13e12a0aa2223e01ae626488cb146b45d605158b..4abf781437cfdd92248050ff61af9a0208dca322 100644 (file)
@@ -753,8 +753,6 @@ TEST_F(CmdHttpListenerTest, basics) {
     ASSERT_FALSE(listener_->getThreadIOService());
     EXPECT_TRUE(listener_->isStopped());
     EXPECT_EQ(listener_->getThreadCount(), 0);
-    ASSERT_THROW_MSG(listener_->getRunState(), InvalidOperation,
-                     "CmdHttpListener::getRunState - no thread pool!");
 
     // Verify that we cannot start it when multi-threading is disabled.
     ASSERT_FALSE(MultiThreadingMgr::instance().getMode());
@@ -775,7 +773,7 @@ TEST_F(CmdHttpListenerTest, basics) {
     EXPECT_EQ(listener_->getThreadCount(), 1);
     ASSERT_TRUE(listener_->getThreadIOService());
     EXPECT_FALSE(listener_->getThreadIOService()->stopped());
-    EXPECT_EQ(listener_->getRunState(),  HttpThreadPool::RunState::RUNNING);
+    EXPECT_TRUE(listener_->isRunning());
 
     // Trying to start it again should fail.
     ASSERT_THROW_MSG(listener_->start(), InvalidOperation,
@@ -785,7 +783,7 @@ TEST_F(CmdHttpListenerTest, basics) {
     ASSERT_NO_THROW_LOG(listener_->stop());
     ASSERT_TRUE(listener_->isStopped());
     EXPECT_EQ(listener_->getThreadCount(), 0);
-    EXPECT_EQ(listener_->getRunState(),  HttpThreadPool::RunState::STOPPED);
+    EXPECT_TRUE(listener_->isStopped());
     ASSERT_FALSE(listener_->getThreadIOService());
 
     // Make sure we can call stop again without problems.
@@ -832,7 +830,7 @@ TEST_F(CmdHttpListenerTest, basics) {
     ASSERT_TRUE(listener_->isStopped());
     EXPECT_EQ(listener_->getThreadCount(), 0);
     ASSERT_FALSE(listener_->getThreadIOService());
-    EXPECT_EQ(listener_->getRunState(),  HttpThreadPool::RunState::STOPPED);
+    EXPECT_TRUE(listener_->isStopped());
 }
 
 // This test verifies that an HTTP connection can be established and used to
index cc1c5d23456f8746e976939c5991ca10366d9751..48df1b87b618eff00aa6a736acd3118ea96d7a19 100644 (file)
@@ -1749,14 +1749,14 @@ public:
     /// is greater than zero.
     HttpClientImpl(IOService& io_service, size_t thread_pool_size = 0,
                    bool defer_thread_start = false)
-        : thread_pool_size_(thread_pool_size), threads_() {
+        : thread_pool_size_(thread_pool_size), thread_pool_() {
         if (thread_pool_size_ > 0) {
             // Create our own private IOService.
             thread_io_service_.reset(new IOService());
 
             // Create the thread pool.
-            threads_.reset(new HttpThreadPool(thread_io_service_, thread_pool_size_,
-                                              defer_thread_start));
+            thread_pool_.reset(new HttpThreadPool(thread_io_service_, thread_pool_size_,
+                                                  defer_thread_start));
 
             // Create the connection pool. Note that we use the thread_pool_size
             // as the maximum connections per URL value.
@@ -1780,8 +1780,8 @@ public:
 
     /// @brief Starts client's thread pool, if multi-threaded.
     void start() {
-        if (threads_) {
-            threads_->run();
+        if (thread_pool_) {
+            thread_pool_->run();
         }
     }
 
@@ -1792,8 +1792,8 @@ public:
         conn_pool_->closeAll();
 
         // Stop the thread pool.
-        if (threads_) {
-            threads_->stop();
+        if (thread_pool_) {
+            thread_pool_->stop();
         }
     }
 
@@ -1801,35 +1801,24 @@ public:
     ///
     /// Suspends thread pool event processing.
     void pause() {
-        if (!threads_) {
+        if (!thread_pool_) {
             isc_throw(InvalidOperation, "HttpClient::pause - no thread pool");
         }
 
         // Pause the thread pool.
-        threads_->pause();
+        thread_pool_->pause();
     }
 
     /// @brief Resumes the thread pool operation.
     ///
     /// Resumes thread pool event processing.
     void resume() {
-        if (!threads_) {
+        if (!thread_pool_) {
             isc_throw(InvalidOperation, "HttpClient::resume - no thread pool");
         }
 
         // Resume running the thread pool.
-        threads_->run();
-    }
-
-    /// @brief Fetches the thread pool's run state.
-    ///
-    /// @return Operational state of the thread pool.
-    HttpThreadPool::RunState getRunState() const {
-        if (!threads_) {
-            isc_throw(InvalidOperation, "HttpClient::getRunState - no thread pool");
-        }
-
-        return (threads_->getRunState());
+        thread_pool_->run();
     }
 
     /// @brief Indicates if the thread pool processing is running.
@@ -1837,8 +1826,8 @@ public:
     /// @return True if the thread pool exists and is in the RUNNING state,
     /// false otherwise.
     bool isRunning() {
-        if (threads_) {
-            return (threads_->getRunState() == HttpThreadPool::RunState::RUNNING);
+        if (thread_pool_) {
+            return (thread_pool_->isRunning());
         }
 
         return (false);
@@ -1849,8 +1838,8 @@ public:
     /// @return True if the thread pool exists and is in the STOPPED state,
     /// false otherwise
     bool isStopped() {
-        if (threads_) {
-            return (threads_->getRunState() == HttpThreadPool::RunState::STOPPED);
+        if (thread_pool_) {
+            return (thread_pool_->isStopped());
         }
 
         return (false);
@@ -1861,8 +1850,8 @@ public:
     /// @return True if the thread pool exists and is in the PAUSED state,
     /// false otherwise.
     bool isPaused() {
-        if (threads_) {
-            return (threads_->getRunState() == HttpThreadPool::RunState::PAUSED);
+        if (thread_pool_) {
+            return (thread_pool_->isPaused());
         }
 
         return (false);
@@ -1887,10 +1876,10 @@ public:
     ///
     /// @return the number of running threads.
     uint16_t getThreadCount() {
-        if (!threads_) {
+        if (!thread_pool_) {
             return (0);
         }
-        return (threads_->getThreadCount());
+        return (thread_pool_->getThreadCount());
     }
 
     /// @brief Holds a pointer to the connection pool.
@@ -1906,7 +1895,7 @@ private:
 
     /// @brief Pool of threads used to service connections in multi-threaded
     /// mode.
-    HttpThreadPoolPtr threads_;
+    HttpThreadPoolPtr thread_pool_;
 };
 
 HttpClient::HttpClient(IOService& io_service, size_t thread_pool_size,
@@ -2002,11 +1991,6 @@ HttpClient::getThreadCount() const {
     return (impl_->getThreadCount());
 }
 
-HttpThreadPool::RunState
-HttpClient::getRunState() const {
-    return (impl_->getRunState());
-}
-
 bool
 HttpClient::isRunning() {
     return (impl_->isRunning());
index 2de0265f36d55dae868106ab68142c0fd6830c35..bfe85ab031fb00b8c2fa126ca32f512a8b9ced65 100644 (file)
@@ -304,13 +304,7 @@ public:
     /// @return the number of running threads.
     uint16_t getThreadCount() const;
 
-    /// @brief Fetches the thread pool's run state.
-    ///
-    /// @return Operational state of the thread pool.
-    /// @throw InvalidOperation if the thread pool does not exist.
-    HttpThreadPool::RunState getRunState() const;
-
-    /// @brief Indicates if the thread pool processing is running.
+    /// @brief Indicates if the thread pool is running.
     ///
     /// @return True if the thread pool exists and is in the RUNNING state,
     /// false otherwise.
index a709cb80c4b6daa92f5b02a148ac41a9a6b29d79..288bb912f5f0714482c6de03385c765cefb2ba3a 100644 (file)
@@ -33,7 +33,7 @@ using namespace isc::util;
 HttpThreadPool::HttpThreadPool(IOServicePtr io_service, size_t pool_size,
                                bool defer_start /* = false */)
     : pool_size_(pool_size), io_service_(io_service),
-      run_state_(RunState::STOPPED), mutex_(), thread_cv_(),
+      run_state_(State::STOPPED), mutex_(), thread_cv_(),
       main_cv_(), paused_(0), running_(0), exited_(0)  {
     if (!pool_size) {
         isc_throw(BadValue, "HttpThreadPool::ctor pool_size must be > 0");
@@ -56,37 +56,37 @@ HttpThreadPool::~HttpThreadPool() {
 
 void
 HttpThreadPool::run() {
-    setRunState(RunState::RUNNING);
+    setState(State::RUNNING);
 }
 
 void
 HttpThreadPool::pause() {
-    setRunState(RunState::PAUSED);
+    setState(State::PAUSED);
 }
 
 void
 HttpThreadPool::stop() {
-    setRunState(RunState::STOPPED);
+    setState(State::STOPPED);
 }
 
-HttpThreadPool::RunState
-HttpThreadPool::getRunState() {
+HttpThreadPool::State
+HttpThreadPool::getState() {
     std::lock_guard<std::mutex> lck(mutex_);
     return (run_state_);
 }
 
 bool
-HttpThreadPool::validateStateChange(RunState new_state) const {
+HttpThreadPool::validateStateChange(State new_state) const {
     bool is_valid = false;
     switch(run_state_) {
-    case RunState::STOPPED:
-        is_valid = (new_state == RunState::RUNNING);
+    case State::STOPPED:
+        is_valid = (new_state == State::RUNNING);
         break;
-    case RunState::RUNNING:
-        is_valid = (new_state != RunState::RUNNING);
+    case State::RUNNING:
+        is_valid = (new_state != State::RUNNING);
         break;
-    case RunState::PAUSED:
-        is_valid = (new_state != RunState::PAUSED);
+    case State::PAUSED:
+        is_valid = (new_state != State::PAUSED);
         break;
     }
 
@@ -94,7 +94,7 @@ HttpThreadPool::validateStateChange(RunState new_state) const {
 }
 
 void
-HttpThreadPool::setRunState (RunState new_state) {
+HttpThreadPool::setState(State new_state) {
     std::unique_lock<std::mutex> main_lck(mutex_);
 
     // Bail if the transition is invalid.
@@ -107,7 +107,7 @@ HttpThreadPool::setRunState (RunState new_state) {
     thread_cv_.notify_all();
 
     switch(new_state) {
-    case RunState::RUNNING: {
+    case State::RUNNING: {
         // Restart the IOService.
         io_service_->restart();
 
@@ -130,7 +130,7 @@ HttpThreadPool::setRunState (RunState new_state) {
         break;
     }
 
-    case RunState::PAUSED: {
+    case State::PAUSED: {
         // Stop IOService.
         if (!io_service_->stopped()) {
             io_service_->poll();
@@ -146,7 +146,7 @@ HttpThreadPool::setRunState (RunState new_state) {
         break;
     }
 
-    case RunState::STOPPED: {
+    case State::STOPPED: {
         // Stop IOService.
         if (!io_service_->stopped()) {
             io_service_->poll();
@@ -172,8 +172,8 @@ void
 HttpThreadPool::threadWork() {
     bool done = false;
     while (!done) {
-        switch (getRunState()) {
-        case RunState::RUNNING: {
+        switch (getState()) {
+        case State::RUNNING: {
             {
                 std::unique_lock<std::mutex> lck(mutex_);
                 running_++;
@@ -195,7 +195,7 @@ HttpThreadPool::threadWork() {
             break;
         }
 
-        case RunState::PAUSED: {
+        case State::PAUSED: {
             std::unique_lock<std::mutex> lck(mutex_);
             paused_++;
 
@@ -207,14 +207,14 @@ HttpThreadPool::threadWork() {
             // Wait here till I'm released.
             thread_cv_.wait(lck,
                 [&]() {
-                    return (run_state_ != RunState::PAUSED);
+                    return (run_state_ != State::PAUSED);
                 });
 
             paused_--;
             break;
         }
 
-        case RunState::STOPPED: {
+        case State::STOPPED: {
             done = true;
             break;
         }}
index e3bb91dc875e41120bbfc0ba76b7c113b29041bc..8f7dba5914e671f4f1bed9cc6db4dea616062c4e 100644 (file)
@@ -23,8 +23,8 @@ namespace http {
 /// @brief Implements a pausable pool of IOService driven threads.
 class HttpThreadPool {
 public:
-    /// @brief Describes the possible operational state of the pool.
-    enum class RunState {
+    /// @brief Describes the possible operational state of the thread pool.
+    enum class State {
         STOPPED,    /// Pool is not operational.
         RUNNING,    /// Pool is populated with running threads.
         PAUSED,     /// Pool is populated with threads that are paused.
@@ -45,19 +45,19 @@ public:
 
     /// @brief Destructor
     ///
-    /// Ensures the pool is stopped prior to destruction.
+    /// Ensures the thread pool is stopped prior to destruction.
     ~HttpThreadPool();
 
     /// @brief Transitions the pool from STOPPED or PAUSED to RUNNING.
     ///
-    /// When called from the STOPPED state, the pool threads are created
+    /// When called from the STOPPED state, the pool threads are created and
     /// begin processing events.
     /// When called from the PAUSED state, the pool threads are released
-    /// from PAUSED and resume processing event.s
+    /// from PAUSED and resume processing events.
     /// Has no effect if the pool is already in the RUNNING state.
     void run();
 
-    /// @brief Transitions the pool from RUNNING to PAUSED state.
+    /// @brief Transitions the pool from RUNNING to PAUSED.
     ///
     /// Pool threads suspend event processing and pause until they
     /// are released to either resume running or stop.
@@ -71,10 +71,26 @@ public:
     /// Has no effect if the pool is already in the STOPPED state.
     void stop();
 
-    /// @brief Thread-safe fetch of the pool's operational state.
+    /// @brief Check if the thread pool is running.
+    ///
+    /// @return True if the thread pool is running, false otherwise.
+    bool isRunning() {
+        return (getState() == State::RUNNING);
+    }
+
+    /// @brief Check if the thread pool is paused.
+    ///
+    /// @return True if the thread pool is paused, false otherwise.
+    bool isPaused() {
+        return (getState() == State::PAUSED);
+    }
+
+    /// @brief Check if the thread pool is stopped.
     ///
-    /// @return Pool run state.
-    RunState getRunState();
+    /// @return True if the thread pool is stopped, false otherwise.
+    bool isStopped() {
+        return (getState() == State::STOPPED);
+    }
 
 private:
     /// @brief Thread-safe change of the pool's run state.
@@ -86,7 +102,7 @@ private:
     /// -# Notifies threads of state change.
     /// -# Restarts the IOService.
     /// -# Creates the threads if they do not yet exist (true only
-    /// when transitioning from STOPPED).
+    ///    when transitioning from STOPPED).
     /// -# Waits until threads are running.
     /// -# Sets the count of exited threads to 0.
     /// -# Returns to caller.
@@ -109,14 +125,19 @@ private:
     /// -# Returns to caller.
     ///
     /// @param state new state for the pool.
-    void setRunState(RunState state);
+    void setState(State state);
+
+    /// @brief Thread-safe fetch of the pool's operational state.
+    ///
+    /// @return Thread pool state.
+    State getState();
 
     /// @brief Validates whether the pool can change to a given state.
     ///
     /// @param state new state for the pool.
-    /// @return true if the Chang's is valid, false otherwise.
+    /// @return true if the change is valid, false otherwise.
     /// @note Must be called from a thread-safe context.
-    bool validateStateChange(RunState state) const;
+    bool validateStateChange(State state) const;
 
     /// @brief Work function executed by each thread in the pool.
     ///
@@ -174,7 +195,7 @@ private:
     asiolink::IOServicePtr io_service_;
 
     /// @brief Tracks the operational state of the pool.
-    RunState run_state_;
+    State run_state_;
 
     /// @brief Mutex to protect the internal state.
     std::mutex mutex_;
@@ -198,7 +219,6 @@ private:
     /// @brief Pool of threads used to service connections in multi-threaded
     /// mode.
     std::list<boost::shared_ptr<std::thread> > threads_;
-
 };
 
 /// @brief Defines a pointer to a thread pool.
@@ -208,4 +228,3 @@ typedef boost::shared_ptr<HttpThreadPool> HttpThreadPoolPtr;
 } // end of namespace isc
 
 #endif
-
index 0f21d092edd7bd6901573013156abf3f5ec2af05..c3958c9734c184eb1862e9ab600d296ec2db5e0f 100644 (file)
@@ -61,7 +61,7 @@ TEST_F(HttpThreadPoolTest, deferredStartConstruction) {
     // IOService should be there.
     // IOService is new, so it should not be stopped,
     // No threads in the pool.
-    ASSERT_EQ(HttpThreadPool::RunState::STOPPED, pool->getRunState());
+    ASSERT_TRUE(pool->isStopped());
     EXPECT_EQ(pool->getPoolSize(), 3);
     ASSERT_TRUE(pool->getIOService());
     EXPECT_FALSE(pool->getIOService()->stopped());
@@ -79,7 +79,7 @@ TEST_F(HttpThreadPoolTest, startDuringConstruction) {
 
     // Pool size should be 3, state should be RUNNING, IOService should
     // set but not stopped, and we should have 3 threads in the pool.
-    ASSERT_EQ(HttpThreadPool::RunState::RUNNING, pool->getRunState());
+    ASSERT_TRUE(pool->isRunning());
     EXPECT_EQ(pool->getPoolSize(), 3);
     ASSERT_TRUE(pool->getIOService());
     EXPECT_FALSE(pool->getIOService()->stopped());
@@ -95,14 +95,14 @@ TEST_F(HttpThreadPoolTest, stoppedToRunning) {
 
     // Create a stopped pool.
     ASSERT_NO_THROW_LOG(pool.reset(new HttpThreadPool(io_service_, 3, true)));
-    ASSERT_EQ(HttpThreadPool::RunState::STOPPED, pool->getRunState());
+    ASSERT_TRUE(pool->isStopped());
 
     // Call run from STOPPED.
     ASSERT_NO_THROW_LOG(pool->run());
 
     // State should be RUNNING, IOService should not be stopped, we should
     // have 3 threads in the pool.
-    ASSERT_EQ(HttpThreadPool::RunState::RUNNING, pool->getRunState());
+    ASSERT_TRUE(pool->isRunning());
     EXPECT_FALSE(pool->getIOService()->stopped());
     EXPECT_EQ(pool->getThreadCount(), 3);
 
@@ -111,7 +111,7 @@ TEST_F(HttpThreadPoolTest, stoppedToRunning) {
 
     // State should be RUNNING, IOService should not be stopped, we should
     // have 3 threads in the pool.
-    ASSERT_EQ(HttpThreadPool::RunState::RUNNING, pool->getRunState());
+    ASSERT_TRUE(pool->isRunning());
     EXPECT_FALSE(pool->getIOService()->stopped());
     EXPECT_EQ(pool->getThreadCount(), 3);
 
@@ -125,14 +125,14 @@ TEST_F(HttpThreadPoolTest, runningToStopped) {
 
     // Create a running pool.
     ASSERT_NO_THROW_LOG(pool.reset(new HttpThreadPool(io_service_, 3, false)));
-    ASSERT_EQ(HttpThreadPool::RunState::RUNNING, pool->getRunState());
+    ASSERT_TRUE(pool->isRunning());
 
     // Call stop.
     ASSERT_NO_THROW_LOG(pool->stop());
 
     // State should be STOPPED, IOService should be stopped, we should
     // have 0 threads in the pool.
-    ASSERT_EQ(HttpThreadPool::RunState::STOPPED, pool->getRunState());
+    ASSERT_TRUE(pool->isStopped());
     EXPECT_TRUE(pool->getIOService()->stopped());
     EXPECT_EQ(pool->getThreadCount(), 0);
 
@@ -141,7 +141,7 @@ TEST_F(HttpThreadPoolTest, runningToStopped) {
 
     // State should be STOPPED, IOService should be stopped, we should
     // have 0 threads in the pool.
-    ASSERT_EQ(HttpThreadPool::RunState::STOPPED, pool->getRunState());
+    ASSERT_TRUE(pool->isStopped());
     EXPECT_TRUE(pool->getIOService()->stopped());
     EXPECT_EQ(pool->getThreadCount(), 0);
 
@@ -155,14 +155,14 @@ TEST_F(HttpThreadPoolTest, runningToPaused) {
 
     // Create a running pool.
     ASSERT_NO_THROW_LOG(pool.reset(new HttpThreadPool(io_service_, 3, false)));
-    ASSERT_EQ(HttpThreadPool::RunState::RUNNING, pool->getRunState());
+    ASSERT_TRUE(pool->isRunning());
 
     // Call pause from RUNNING.
     ASSERT_NO_THROW_LOG(pool->pause());
 
     // State should be PAUSED, IOService should be stopped, we should
     // have 3 threads in the pool.
-    ASSERT_EQ(HttpThreadPool::RunState::PAUSED, pool->getRunState());
+    ASSERT_TRUE(pool->isPaused());
     EXPECT_TRUE(pool->getIOService()->stopped());
     EXPECT_EQ(pool->getThreadCount(), 3);
 
@@ -171,7 +171,7 @@ TEST_F(HttpThreadPoolTest, runningToPaused) {
 
     // State should be PAUSED, IOService should be stopped, we should
     // have 3 threads in the pool.
-    ASSERT_EQ(HttpThreadPool::RunState::PAUSED, pool->getRunState());
+    ASSERT_TRUE(pool->isPaused());
     EXPECT_TRUE(pool->getIOService()->stopped());
     EXPECT_EQ(pool->getThreadCount(), 3);
 
@@ -185,18 +185,18 @@ TEST_F(HttpThreadPoolTest, pausedToRunning) {
 
     // Create a running pool.
     ASSERT_NO_THROW_LOG(pool.reset(new HttpThreadPool(io_service_, 3, false)));
-    ASSERT_EQ(HttpThreadPool::RunState::RUNNING, pool->getRunState());
+    ASSERT_TRUE(pool->isRunning());
 
     // Call pause from RUNNING.
     ASSERT_NO_THROW_LOG(pool->pause());
-    ASSERT_EQ(HttpThreadPool::RunState::PAUSED, pool->getRunState());
+    ASSERT_TRUE(pool->isPaused());
 
     // Call run.
     ASSERT_NO_THROW_LOG(pool->run());
 
     // State should be RUNNING, IOService should not be stopped, we should
     // have 3 threads in the pool.
-    ASSERT_EQ(HttpThreadPool::RunState::RUNNING, pool->getRunState());
+    ASSERT_TRUE(pool->isRunning());
     EXPECT_FALSE(pool->getIOService()->stopped());
     EXPECT_EQ(pool->getThreadCount(), 3);
 
@@ -210,18 +210,18 @@ TEST_F(HttpThreadPoolTest, pausedToStopped) {
 
     // Create a running pool.
     ASSERT_NO_THROW_LOG(pool.reset(new HttpThreadPool(io_service_, 3, false)));
-    ASSERT_EQ(HttpThreadPool::RunState::RUNNING, pool->getRunState());
+    ASSERT_TRUE(pool->isRunning());
 
     // Call pause from RUNNING.
     ASSERT_NO_THROW_LOG(pool->pause());
-    ASSERT_EQ(HttpThreadPool::RunState::PAUSED, pool->getRunState());
+    ASSERT_TRUE(pool->isPaused());
 
     // Call stop.
     ASSERT_NO_THROW_LOG(pool->stop());
 
     // State should be STOPPED, IOService should be stopped, we should
     // have 0 threads in the pool.
-    ASSERT_EQ(HttpThreadPool::RunState::STOPPED, pool->getRunState());
+    ASSERT_TRUE(pool->isStopped());
     EXPECT_TRUE(pool->getIOService()->stopped());
     EXPECT_EQ(pool->getThreadCount(), 0);
 
@@ -235,11 +235,11 @@ TEST_F(HttpThreadPoolTest, stoppedToPaused) {
 
     // Create a stopped pool.
     ASSERT_NO_THROW_LOG(pool.reset(new HttpThreadPool(io_service_, 3, true)));
-    ASSERT_EQ(HttpThreadPool::RunState::STOPPED, pool->getRunState());
+    ASSERT_TRUE(pool->isStopped());
 
     // State should be STOPPED, IOService won't be stopped because it was
     // never started. We should have 0 threads in the pool.
-    ASSERT_EQ(HttpThreadPool::RunState::STOPPED, pool->getRunState());
+    ASSERT_TRUE(pool->isStopped());
     EXPECT_FALSE(pool->getIOService()->stopped());
     EXPECT_EQ(pool->getThreadCount(), 0);
 
@@ -247,11 +247,11 @@ TEST_F(HttpThreadPoolTest, stoppedToPaused) {
     ASSERT_NO_THROW_LOG(pool->pause());
 
     // Should have no effect.
-    ASSERT_EQ(HttpThreadPool::RunState::STOPPED, pool->getRunState());
+    ASSERT_TRUE(pool->isStopped());
 
     // State should be STOPPED, IOService won't be stopped because it was
     // never started. We should have 0 threads in the pool.
-    ASSERT_EQ(HttpThreadPool::RunState::STOPPED, pool->getRunState());
+    ASSERT_TRUE(pool->isStopped());
     EXPECT_FALSE(pool->getIOService()->stopped());
     EXPECT_EQ(pool->getThreadCount(), 0);
 
index ab313e81d13af5ea9da8a7896a45f04f03f711d9..ed7adefc6f8930576630c9dc8d7dd76424ccdc4a 100644 (file)
@@ -809,9 +809,9 @@ TEST_F(MtHttpClientTest, basics) {
     // Verify that it has an internal IOService and that thread pool size
     // and thread count match.
     ASSERT_TRUE(client->getThreadIOService());
+    EXPECT_FALSE(client->getThreadIOService()->stopped());
     ASSERT_EQ(client->getThreadPoolSize(), 3);
     ASSERT_EQ(client->getThreadCount(), 3);
-    ASSERT_EQ(client->getRunState(), HttpThreadPool::RunState::RUNNING);
 
     // Check convenience functions.
     ASSERT_TRUE(client->isRunning());
@@ -859,7 +859,6 @@ TEST_F(MtHttpClientTest, deferredStart) {
     ASSERT_TRUE(client->getThreadIOService());
     ASSERT_EQ(client->getThreadPoolSize(), thread_pool_size);
     ASSERT_EQ(client->getThreadCount(), 0);
-    ASSERT_EQ(client->getRunState(), HttpThreadPool::RunState::STOPPED);
 
     // Check convenience functions.
     ASSERT_FALSE(client->isRunning());
@@ -873,7 +872,6 @@ TEST_F(MtHttpClientTest, deferredStart) {
     ASSERT_EQ(client->getThreadCount(), 3);
     ASSERT_TRUE(client->getThreadIOService());
     ASSERT_FALSE(client->getThreadIOService()->stopped());
-    ASSERT_EQ(client->getRunState(), HttpThreadPool::RunState::RUNNING);
 
     // Check convenience functions.
     ASSERT_TRUE(client->isRunning());
@@ -885,7 +883,7 @@ TEST_F(MtHttpClientTest, deferredStart) {
 
     // Verify we didn't break it.
     ASSERT_EQ(client->getThreadCount(), 3);
-    ASSERT_EQ(client->getRunState(), HttpThreadPool::RunState::RUNNING);
+    ASSERT_TRUE(client->isRunning());
 
     // Make sure destruction doesn't throw.
     ASSERT_NO_THROW_LOG(client.reset());
@@ -905,7 +903,7 @@ TEST_F(MtHttpClientTest, restartAfterStop) {
     ASSERT_EQ(client->getThreadCount(), 3);
     ASSERT_TRUE(client->getThreadIOService());
     ASSERT_FALSE(client->getThreadIOService()->stopped());
-    ASSERT_EQ(client->getRunState(), HttpThreadPool::RunState::RUNNING);
+    ASSERT_TRUE(client->isRunning());
 
     // Stop should succeed.
     ASSERT_NO_THROW_LOG(client->stop());
@@ -914,14 +912,14 @@ TEST_F(MtHttpClientTest, restartAfterStop) {
     ASSERT_EQ(client->getThreadCount(), 0);
     ASSERT_TRUE(client->getThreadIOService());
     ASSERT_TRUE(client->getThreadIOService()->stopped());
-    ASSERT_EQ(client->getRunState(), HttpThreadPool::RunState::STOPPED);
+    ASSERT_TRUE(client->isStopped());
 
     // Starting again should succeed.
     ASSERT_NO_THROW_LOG(client->start());
     ASSERT_EQ(client->getThreadCount(), 3);
     ASSERT_TRUE(client->getThreadIOService());
     ASSERT_FALSE(client->getThreadIOService()->stopped());
-    ASSERT_EQ(client->getRunState(), HttpThreadPool::RunState::RUNNING);
+    ASSERT_TRUE(client->isRunning());
 
     // Make sure destruction doesn't throw.
     ASSERT_NO_THROW_LOG(client.reset());