[asterisk-scf-commits] asterisk-scf/integration/util-cpp.git branch "route_replica" updated.

Commits to the Asterisk SCF project code repositories asterisk-scf-commits at lists.digium.com
Fri Apr 22 13:41:04 CDT 2011


branch "route_replica" has been updated
       via  02001bfcdaafd6eae7d02d3a7d92fe087b3c7d83 (commit)
      from  d2ea2f1f04fd9ad34552d5c79f806d2b9bd952af (commit)

Summary of changes:
 CMakeLists.txt                                     |    7 +
 StateMachine/CMakeLists.txt                        |   24 +--
 .../AsteriskSCF/StateMachine/SimpleStateMachine.h  |   15 +-
 StateMachine/src/CMakeLists.txt                    |   13 +
 StateMachine/test/CMakeLists.txt                   |   14 ++
 StateMachine/test/StateMachineTest.cpp             |  241 ++++++++++++++++++++
 Threading/CMakeLists.txt                           |    1 +
 .../AsteriskSCF/Threading/PausibleWorkQueue.h      |    2 +-
 .../AsteriskSCF/Threading/SimpleWorkQueue.h        |    9 +-
 .../include/AsteriskSCF/Threading/WorkQueue.h      |    2 +-
 Threading/src/SimpleWorkQueue.cpp                  |   50 +----
 Threading/test/CMakeLists.txt                      |   22 ++
 Threading/test/SimpleWorkQueueTest.cpp             |   73 ++++++
 13 files changed, 400 insertions(+), 73 deletions(-)
 create mode 100644 StateMachine/src/CMakeLists.txt
 create mode 100644 StateMachine/test/CMakeLists.txt
 create mode 100644 StateMachine/test/StateMachineTest.cpp
 create mode 100644 Threading/test/CMakeLists.txt
 create mode 100644 Threading/test/SimpleWorkQueueTest.cpp


- Log -----------------------------------------------------------------
commit 02001bfcdaafd6eae7d02d3a7d92fe087b3c7d83
Author: Ken Hunt <ken.hunt at digium.com>
Date:   Fri Apr 22 13:34:35 2011 -0500

    Added unit tests for release branch creation.

diff --git a/CMakeLists.txt b/CMakeLists.txt
index bb1db1d..eebab3a 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,3 +1,10 @@
+#
+# Asterisk Scalable Communications Framework
+#
+# Copyright (C) 2010, 2011 -- Digium, Inc.
+#
+# All rights reserved.
+#
 if (integrated_build STREQUAL "true")
 	set(util_cpp_dir ${CMAKE_CURRENT_SOURCE_DIR} PARENT_SCOPE)
 	set(util_cpp_bindir ${CMAKE_CURRENT_BINARY_DIR} PARENT_SCOPE)
diff --git a/StateMachine/CMakeLists.txt b/StateMachine/CMakeLists.txt
index 8c4b205..0042652 100644
--- a/StateMachine/CMakeLists.txt
+++ b/StateMachine/CMakeLists.txt
@@ -6,25 +6,5 @@
 # All rights reserved.
 #
 
-asterisk_scf_component_init(StateMachine CXX)
-
-include_directories(include)
-
-asterisk_scf_component_add_slice(StateMachine LoggerIf)
-asterisk_scf_component_add_file(StateMachine include/AsteriskSCF/StateMachine/SimpleStateMachine.h)
-asterisk_scf_component_add_file(StateMachine src/SimpleStateMachine.cpp)
-asterisk_scf_component_add_boost_libraries(StateMachine core)
-
-if(NOT logger_dir)
-   message(FATAL_ERROR "The logger directory could not be found ${logger_dir}")
-endif()
-
-include_directories(${logger_dir}/common)
-include_directories(${logger_dir}/client/src)
-
-asterisk_scf_component_build_library(StateMachine)
-
-target_link_libraries(StateMachine logging-client)
-
-asterisk_scf_component_install(StateMachine LIBRARY lib "State Machine" StateMachine ARCHIVE DESTINATION lib)
-
+add_subdirectory(src)
+add_subdirectory(test)
\ No newline at end of file
diff --git a/StateMachine/include/AsteriskSCF/StateMachine/SimpleStateMachine.h b/StateMachine/include/AsteriskSCF/StateMachine/SimpleStateMachine.h
index 673c93b..58e9a0a 100644
--- a/StateMachine/include/AsteriskSCF/StateMachine/SimpleStateMachine.h
+++ b/StateMachine/include/AsteriskSCF/StateMachine/SimpleStateMachine.h
@@ -20,6 +20,7 @@
 #include <boost/function.hpp>
 #include <map>
 #include <vector>
+#include <algorithm>
 
 namespace AsteriskSCF
 {
@@ -59,7 +60,7 @@ public:
     class ExecutionGuard
     {
     public:
-        ExecutionGuard(bool &val) : mGuard(val) {mGuard = true;}
+        ExecutionGuard(bool &refToGuardVar) : mGuard(refToGuardVar) {mGuard = true;}
         ~ExecutionGuard() {mGuard = false;}
 
     private:
@@ -94,7 +95,12 @@ public:
 
     void removeListener(const boost::shared_ptr<StateMachineListener >& listener)
     {
-        mListeners.remove(listener);
+        mListeners.erase(std::remove(mListeners.begin(), mListeners.end(), listener), mListeners.end());
+    }
+
+    int getNumListeners()
+    {
+        return mListeners.size();
     }
 
     /// State management.
@@ -107,6 +113,11 @@ public:
         mStates[state] = handler;
     }
 
+    int getNumStates()
+    {
+        return mStates.size();
+    }
+
     /** 
      * Sets the next state. State transitions occur after the current state's execution is complete. 
      */
diff --git a/StateMachine/src/CMakeLists.txt b/StateMachine/src/CMakeLists.txt
new file mode 100644
index 0000000..98bd14f
--- /dev/null
+++ b/StateMachine/src/CMakeLists.txt
@@ -0,0 +1,13 @@
+
+asterisk_scf_component_init(StateMachine CXX)
+
+include_directories(../include)
+
+asterisk_scf_component_add_slice(StateMachine LoggerIf)
+asterisk_scf_component_add_file(StateMachine ../include/AsteriskSCF/StateMachine/SimpleStateMachine.h)
+asterisk_scf_component_add_file(StateMachine SimpleStateMachine.cpp)
+asterisk_scf_component_add_boost_libraries(StateMachine core)
+
+asterisk_scf_component_build_library(StateMachine)
+
+asterisk_scf_component_install(StateMachine LIBRARY lib "State Machine" StateMachine ARCHIVE DESTINATION lib)
diff --git a/StateMachine/test/CMakeLists.txt b/StateMachine/test/CMakeLists.txt
new file mode 100644
index 0000000..3013313
--- /dev/null
+++ b/StateMachine/test/CMakeLists.txt
@@ -0,0 +1,14 @@
+# Create State Machine test project.
+asterisk_scf_component_init(StateMachineTest CXX)
+
+include_directories(../include)
+
+asterisk_scf_component_add_file(StateMachineTest  StateMachineTest.cpp)
+
+asterisk_scf_component_add_boost_libraries(StateMachineTest unit_test_framework date_time)
+
+include_directories(${util_cpp_dir}/StateMachine/include)
+
+asterisk_scf_component_build_standalone(StateMachineTest)
+
+boost_add_test(StateMachineTest)
diff --git a/StateMachine/test/StateMachineTest.cpp b/StateMachine/test/StateMachineTest.cpp
new file mode 100644
index 0000000..12fa477
--- /dev/null
+++ b/StateMachine/test/StateMachineTest.cpp
@@ -0,0 +1,241 @@
+/*
+ * Asterisk SCF -- An open-source communications framework.
+ *
+ * Copyright (C) 2010-2011, Digium, Inc.
+ *
+ * See http://www.asterisk.org for more information about
+ * the Asterisk SCF project. Please do not directly contact
+ * any of the maintainers of this project for assistance;
+ * the project provides a web site, mailing lists and IRC
+ * channels for your use.
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License Version 2. See the LICENSE.txt file
+ * at the top of the source tree.
+ */
+
+#define BOOST_TEST_MODULE StateMachine
+
+#include <boost/test/unit_test.hpp>
+#include <boost/test/debug.hpp>
+
+// #include "../include/AsteriskSCF/StateMachine/SimpleStateMachine.h"
+#include <AsteriskSCF/StateMachine/SimpleStateMachine.h>
+
+using namespace std;
+using namespace AsteriskSCF::StateMachine;
+
+namespace Mock
+{
+
+enum MockMachineStates
+{
+    CYAN,
+    MAGENTA,
+    YELLOW,
+    INVALID  // Just for testing. Something unused to init values to.
+};
+
+const MockMachineStates DEFAULT_STATE(CYAN);
+
+class MockStateMachineClient 
+{
+public:
+    MockStateMachineClient() : mYellowCount(0), mCyanCount(0), mMagentaCount(0), mStateMachine(DEFAULT_STATE)
+    {
+        mStateMachine.addState(CYAN, boost::bind(&MockStateMachineClient::cyanState, this));
+        mStateMachine.addState(MAGENTA, boost::bind(&MockStateMachineClient::magentaState, this));
+        mStateMachine.addState(YELLOW, boost::bind(&MockStateMachineClient::yellowState, this));
+    }
+
+    void cyanState()
+    {
+        mCyanCount++;
+        mStateMachine.setNextState(Mock::MAGENTA);
+    }
+
+    void magentaState()
+    {
+        mMagentaCount++;
+        mStateMachine.setNextState(Mock::YELLOW);
+    }
+
+    void yellowState()
+    {
+        mYellowCount++;
+        mStateMachine.shutdown();
+    }
+
+    void reset()
+    {
+        mYellowCount = 0;
+        mCyanCount = 0;
+        mMagentaCount = 0;
+    }
+
+    int mYellowCount;
+    int mCyanCount;
+    int mMagentaCount;
+
+public:
+    AsteriskSCF::StateMachine::SimpleStateMachine<MockMachineStates> mStateMachine;
+};
+
+class MockListener : public AsteriskSCF::StateMachine::SimpleStateMachine<MockMachineStates>::StateMachineListener
+{
+public:
+    MockListener()
+    {
+        reset();
+    }
+
+    ~MockListener()
+    {
+    }
+
+    void stateExecutionStart(MockMachineStates state)
+    {
+        mStartNotice = state;
+    }
+
+    void stateExecutionComplete(MockMachineStates state)
+    {
+        mCompleteNotice = state;
+    }
+
+    void shutdown()
+    {
+        mShutdownNotice = true;
+    }
+
+    void stateTransition(MockMachineStates oldState, MockMachineStates newState)
+    {
+        mTransitionOld = oldState;
+        mTransitionNew = newState;
+    }
+
+    void reset()
+    {
+        mStartNotice = INVALID;
+        mCompleteNotice = INVALID;
+        mTransitionOld = INVALID;
+        mTransitionNew = INVALID;
+        mShutdownNotice = false;
+    }
+
+    MockMachineStates mStartNotice;
+    MockMachineStates mCompleteNotice;
+    MockMachineStates mTransitionOld;
+    MockMachineStates mTransitionNew;
+    bool mShutdownNotice;
+};
+typedef boost::shared_ptr<MockListener> MockListenerPtr;
+
+} // end Mock namespace
+
+BOOST_AUTO_TEST_SUITE(StateMachineTest)
+
+BOOST_AUTO_TEST_CASE(addRemoveListener)
+{
+    Mock::MockListenerPtr listener(new Mock::MockListener());
+    Mock::MockStateMachineClient c;
+
+    BOOST_CHECK(c.mStateMachine.getNumListeners() == 0);
+
+    c.mStateMachine.addListener(listener);
+
+    BOOST_CHECK(c.mStateMachine.getNumListeners() == 1);
+
+    c.mStateMachine.removeListener(listener);
+
+    BOOST_CHECK(c.mStateMachine.getNumListeners() == 0);
+}
+
+BOOST_AUTO_TEST_CASE(executeState)
+{
+    Mock::MockListenerPtr listener(new Mock::MockListener());
+    Mock::MockStateMachineClient c;
+    c.mStateMachine.addListener(listener);
+
+    BOOST_CHECK(c.mStateMachine.getNumStates() == 3);
+
+    BOOST_CHECK(listener->mStartNotice == Mock::INVALID);
+    BOOST_CHECK(listener->mCompleteNotice == Mock::INVALID);
+    BOOST_CHECK(listener->mTransitionOld == Mock::INVALID);
+    BOOST_CHECK(listener->mTransitionNew == Mock::INVALID);
+
+    // Execute the default state.
+    c.mStateMachine.execute();
+
+    BOOST_CHECK(listener->mStartNotice == Mock::CYAN);
+    BOOST_CHECK(listener->mCompleteNotice == Mock::CYAN);
+    BOOST_CHECK(listener->mTransitionOld == Mock::CYAN);
+    BOOST_CHECK(listener->mTransitionNew == Mock::MAGENTA);
+
+    BOOST_CHECK(c.mCyanCount == 1);
+    BOOST_CHECK(c.mYellowCount == 0);
+    BOOST_CHECK(c.mMagentaCount == 0);
+
+}
+
+BOOST_AUTO_TEST_CASE(transitionStates)
+{
+    Mock::MockListenerPtr listener(new Mock::MockListener());
+    Mock::MockStateMachineClient c;
+    c.mStateMachine.addListener(listener);
+
+    BOOST_CHECK(listener->mStartNotice == Mock::INVALID);
+    BOOST_CHECK(listener->mCompleteNotice == Mock::INVALID);
+    BOOST_CHECK(listener->mTransitionOld == Mock::INVALID);
+    BOOST_CHECK(listener->mTransitionNew == Mock::INVALID);
+
+    // Execute the deafult state.
+    c.mStateMachine.execute();
+
+    BOOST_CHECK(listener->mStartNotice == Mock::CYAN);
+    BOOST_CHECK(listener->mCompleteNotice == Mock::CYAN);
+    BOOST_CHECK(listener->mTransitionOld == Mock::CYAN);
+    BOOST_CHECK(listener->mTransitionNew == Mock::MAGENTA);
+
+    BOOST_CHECK(listener->mShutdownNotice == false);
+
+    BOOST_CHECK(c.mCyanCount == 1);
+    BOOST_CHECK(c.mYellowCount == 0);
+    BOOST_CHECK(c.mMagentaCount == 0);
+
+    listener->reset();
+
+    // Execute the magenta state.
+    c.mStateMachine.execute();
+
+    BOOST_CHECK(listener->mStartNotice == Mock::MAGENTA);
+    BOOST_CHECK(listener->mCompleteNotice == Mock::MAGENTA);
+    BOOST_CHECK(listener->mTransitionOld == Mock::MAGENTA);
+    BOOST_CHECK(listener->mTransitionNew == Mock::YELLOW);
+
+    BOOST_CHECK(listener->mShutdownNotice == false);
+
+    BOOST_CHECK(c.mCyanCount == 1);
+    BOOST_CHECK(c.mYellowCount == 0);
+    BOOST_CHECK(c.mMagentaCount == 1);
+
+
+    listener->reset();
+
+    // Execute the final state.
+    c.mStateMachine.execute();
+
+    BOOST_CHECK(listener->mStartNotice == Mock::YELLOW);
+    BOOST_CHECK(listener->mCompleteNotice == Mock::YELLOW);
+    BOOST_CHECK(listener->mTransitionOld == Mock::INVALID);
+    BOOST_CHECK(listener->mTransitionNew == Mock::INVALID);
+
+    BOOST_CHECK(listener->mShutdownNotice == true);
+
+    BOOST_CHECK(c.mCyanCount == 1);
+    BOOST_CHECK(c.mYellowCount == 1);
+    BOOST_CHECK(c.mMagentaCount == 1);
+
+}
+
+BOOST_AUTO_TEST_SUITE_END()
diff --git a/Threading/CMakeLists.txt b/Threading/CMakeLists.txt
index 7e60fb4..f00c977 100644
--- a/Threading/CMakeLists.txt
+++ b/Threading/CMakeLists.txt
@@ -33,3 +33,4 @@ target_link_libraries(Threading logging-client)
 
 asterisk_scf_component_install(Threading LIBRARY lib "Threading" Threading ARCHIVE DESTINATION lib)
 
+add_subdirectory(test)
\ No newline at end of file
diff --git a/Threading/include/AsteriskSCF/Threading/PausibleWorkQueue.h b/Threading/include/AsteriskSCF/Threading/PausibleWorkQueue.h
index 36187e8..153042a 100644
--- a/Threading/include/AsteriskSCF/Threading/PausibleWorkQueue.h
+++ b/Threading/include/AsteriskSCF/Threading/PausibleWorkQueue.h
@@ -25,7 +25,7 @@ namespace Threading
  * is not derived, so implementations of this interface should derive from 
  * both WorkQueue and PausibleWorkQueue. 
  */
-class PausibleWorkQueue
+class ASTERISK_SCF_ICEBOX_EXPORT PausibleWorkQueue
 {
 public:
     virtual bool isRunning() = 0;
diff --git a/Threading/include/AsteriskSCF/Threading/SimpleWorkQueue.h b/Threading/include/AsteriskSCF/Threading/SimpleWorkQueue.h
index 3ecc00c..a03be58 100644
--- a/Threading/include/AsteriskSCF/Threading/SimpleWorkQueue.h
+++ b/Threading/include/AsteriskSCF/Threading/SimpleWorkQueue.h
@@ -20,8 +20,6 @@
 #include <boost/thread/condition.hpp>
 #include <boost/shared_ptr.hpp>
 
-#include <AsteriskSCF/logger.h>
-
 #include "WorkQueue.h"
 #include "PausibleWorkQueue.h"
 
@@ -36,11 +34,11 @@ namespace Threading
  */
 class SimpleWorkQueuePriv;
 
-class ASTERISK_SCF_ICEBOX_EXPORT SimpleWorkQueue : public WorkQueue,  public PausibleWorkQueue, boost::noncopyable
+class ASTERISK_SCF_ICEBOX_EXPORT SimpleWorkQueue : public WorkQueue,  public PausibleWorkQueue
 {
 public:
 
-    SimpleWorkQueue(const std::string& id, const AsteriskSCF::System::Logging::Logger& logger);
+    SimpleWorkQueue(const std::string& id);
     ~SimpleWorkQueue();
 
     // Overrides for the WorkQueue interface. 
@@ -56,7 +54,8 @@ public:
     virtual void pause();
     virtual void resume();
 
-private:    boost::shared_ptr<SimpleWorkQueuePriv> mImpl;
+private:    
+    boost::shared_ptr<SimpleWorkQueuePriv> mImpl;
 };
 
 } // end namespace Threading
diff --git a/Threading/include/AsteriskSCF/Threading/WorkQueue.h b/Threading/include/AsteriskSCF/Threading/WorkQueue.h
index 65c7f88..262b437 100644
--- a/Threading/include/AsteriskSCF/Threading/WorkQueue.h
+++ b/Threading/include/AsteriskSCF/Threading/WorkQueue.h
@@ -26,7 +26,7 @@ namespace Threading
  * This class defines an interface to a work queue. A work queue manages one or 
  * more processing threads, and allows work to be enqueued. 
  */
-class WorkQueue
+class ASTERISK_SCF_ICEBOX_EXPORT WorkQueue
 {
 public:
 
diff --git a/Threading/src/SimpleWorkQueue.cpp b/Threading/src/SimpleWorkQueue.cpp
index 77fe099..e059035 100644
--- a/Threading/src/SimpleWorkQueue.cpp
+++ b/Threading/src/SimpleWorkQueue.cpp
@@ -25,14 +25,11 @@
 #include <boost/thread.hpp>
 #include <list>
 
-#include <AsteriskSCF/logger.h>
-
 #include "AsteriskSCF/Threading/SimpleWorkQueue.h"
 
 using namespace boost;
 using namespace AsteriskSCF;
 using namespace AsteriskSCF::Threading;
-using namespace AsteriskSCF::System::Logging;
 
 namespace 
 {
@@ -56,20 +53,17 @@ namespace Threading
 class SimpleWorkQueuePriv
 {
 public:
-    SimpleWorkQueuePriv(const std::string& id, const Logger& logger) 
-         : mLogger(logger),
-           mQid(id),
+    SimpleWorkQueuePriv(const std::string& id) 
+         : mQid(id),
            mFinished(false), 
            mPaused(false),      // runs by default. 
-           mNoOpPoolIdPtr (new WorkQueue::PoolId),
-           mThread(boost::bind(&SimpleWorkQueuePriv::execute, this))
+           mNoOpPoolIdPtr (new WorkQueue::PoolId)
     {
-        mLogger(Debug) << BOOST_CURRENT_FUNCTION << ": called. Queue ID:" << mQid;
+        mThread.reset(new boost::thread(boost::bind(&SimpleWorkQueuePriv::execute, this)));
     }
 
     ~SimpleWorkQueuePriv()
     {
-        mLogger(Debug) << BOOST_CURRENT_FUNCTION << ": called. Queue ID:" << mQid;
     }
 
     /** 
@@ -77,8 +71,6 @@ public:
      */
     void terminate()
     {
-        mLogger(Debug) << BOOST_CURRENT_FUNCTION << ": called for queue " << mQid ;
-        
         mFinished = true;
         mPaused = false;
 
@@ -101,7 +93,7 @@ public:
      */
     void join()
     {
-        mThread.join();
+        mThread->join();
     }
 
     WorkPtr dequeue();
@@ -109,7 +101,6 @@ public:
     void execute();
     bool isPaused();
 
-    const Logger& mLogger;
     std::string mQid;
     bool mFinished;
     bool mPaused;
@@ -120,18 +111,16 @@ public:
     boost::condition mPauseCondition;
     boost::shared_ptr<WorkQueue::PoolId> mNoOpPoolIdPtr;
 
-    boost::thread mThread;     // This variable is last so that the class is fully initialized before the thread executes. 
+    boost::shared_ptr<boost::thread> mThread;     // This variable is last so that the class is fully initialized before the thread executes. 
 };
 
 
-SimpleWorkQueue::SimpleWorkQueue(const std::string& qid, const Logger& logger) : mImpl(new SimpleWorkQueuePriv(qid, logger))
+SimpleWorkQueue::SimpleWorkQueue(const std::string& qid) : mImpl(new SimpleWorkQueuePriv(qid))
 {
-    mImpl->mLogger(Debug) << BOOST_CURRENT_FUNCTION << ": called. Queue ID:" << mImpl->mQid;
 }
 
 SimpleWorkQueue::~SimpleWorkQueue()
 {
-    mImpl->mLogger(Debug) << BOOST_CURRENT_FUNCTION << ": called. Queue ID:" << mImpl->mQid;
     mImpl->terminate();
 
     // Wait for worker thread to shut down. 
@@ -148,8 +137,6 @@ bool SimpleWorkQueue::isRunning()
  */
 void SimpleWorkQueue::pause()
 {
-    mImpl->mLogger(Debug) << BOOST_CURRENT_FUNCTION << ": called for queue " << mImpl->mQid;
-
     boost::lock_guard<boost::mutex> lock(mImpl->mPauseMutex);
     mImpl->mPaused = true;
 }
@@ -159,8 +146,6 @@ void SimpleWorkQueue::pause()
  */
 void SimpleWorkQueue::resume()
 {
-    mImpl->mLogger(Debug) << BOOST_CURRENT_FUNCTION << ": called for queue " << mImpl->mQid;
-
     boost::lock_guard<boost::mutex> lock(mImpl->mPauseMutex);
     mImpl->mPaused = false;
     mImpl->mPauseCondition.notify_all();
@@ -205,19 +190,14 @@ WorkPtr SimpleWorkQueuePriv::waitAndDequeue()
 
     while (mQueue.empty())
     {
-        mLogger(Debug) << BOOST_CURRENT_FUNCTION << ": Waiting on empty queue. Queue ID:" << mQid;
-
         if (mFinished)
         {
-            mLogger(Debug) << BOOST_CURRENT_FUNCTION << ": Returning the NO_WORK token. Queue ID:" << mQid;
             return HiddenNoWorkPtr;
         }
 
         mEmptyQueueCondition.wait(lock);
     }
 
-    mLogger(Debug) << BOOST_CURRENT_FUNCTION << ": Dequeuing some work. Queue ID:" << mQid;
-
     shared_ptr<WorkQueue::Work> work = mQueue.front();
     mQueue.pop_front();
 
@@ -241,8 +221,6 @@ void SimpleWorkQueuePriv::execute()
             boost::unique_lock<boost::mutex> lock(mPauseMutex);
             while(mPaused)
             {
-                mLogger(Debug) << BOOST_CURRENT_FUNCTION << ": Waiting while paused. Queue ID:" << mQid;
-
                 mPauseCondition.wait(lock);
             }
 
@@ -251,31 +229,19 @@ void SimpleWorkQueuePriv::execute()
                 break;
             }
         } // end lock scope
-
-        mLogger(Debug) << BOOST_CURRENT_FUNCTION << ": Pinging the work queue. Queue ID:" << mQid;
-
         WorkPtr work  = waitAndDequeue();
  
-        mLogger(Debug) << BOOST_CURRENT_FUNCTION << ": Doing the work. Queue ID:" << mQid;
-
         try
         {
             work->doWork();
         }
-        catch(const std::exception& e)
-        {
-            // Workers should be catching/managing their own exceptions!
-            mLogger(Warning) << BOOST_CURRENT_FUNCTION << ": Work item threw exception for queue " << mQid;
-            mLogger(Warning) << "  Details: " << e.what(); 
-        }
         catch(...)
         {
-            mLogger(Warning) << BOOST_CURRENT_FUNCTION << ": Work item threw non-standard exception. ";
+            // Workers should be catching/managing their own exceptions!
         }
 
     } // while !mFinished
 
-    mLogger(Debug) << BOOST_CURRENT_FUNCTION << ": Exiting the thread for good. Queue ID:" << mQid;
 }
 
 } // end namespace Threading
diff --git a/Threading/test/CMakeLists.txt b/Threading/test/CMakeLists.txt
new file mode 100644
index 0000000..a20d74d
--- /dev/null
+++ b/Threading/test/CMakeLists.txt
@@ -0,0 +1,22 @@
+# Create State Machine test project.
+asterisk_scf_component_init(SimpleWorkQueueTest CXX)
+
+include_directories(../include)
+
+asterisk_scf_component_add_file(SimpleWorkQueueTest  SimpleWorkQueueTest.cpp)
+
+asterisk_scf_component_add_boost_libraries(SimpleWorkQueueTest unit_test_framework)
+
+include_directories(${util_cpp_dir}/Threading/include)
+
+if(NOT logger_dir)
+   message(FATAL_ERROR "The logger directory could not be found ${logger_dir}")
+endif()
+include_directories(${logger_dir}/include)
+
+asterisk_scf_component_build_standalone(SimpleWorkQueueTest)
+target_link_libraries(SimpleWorkQueueTest logging-client)
+
+target_link_libraries(SimpleWorkQueueTest Threading)
+
+boost_add_test(SimpleWorkQueueTest)
diff --git a/Threading/test/SimpleWorkQueueTest.cpp b/Threading/test/SimpleWorkQueueTest.cpp
new file mode 100644
index 0000000..b9b374c
--- /dev/null
+++ b/Threading/test/SimpleWorkQueueTest.cpp
@@ -0,0 +1,73 @@
+/*
+ * Asterisk SCF -- An open-source communications framework.
+ *
+ * Copyright (C) 2010-2011, Digium, Inc.
+ *
+ * See http://www.asterisk.org for more information about
+ * the Asterisk SCF project. Please do not directly contact
+ * any of the maintainers of this project for assistance;
+ * the project provides a web site, mailing lists and IRC
+ * channels for your use.
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License Version 2. See the LICENSE.txt file
+ * at the top of the source tree.
+ */
+
+#define BOOST_TEST_MODULE SimpleWorkQueue
+
+#include <boost/test/unit_test.hpp>
+#include <boost/test/debug.hpp>
+
+#include <AsteriskSCF/Threading/SimpleWorkQueue.h>
+
+using namespace std;
+using namespace AsteriskSCF::Threading;
+
+class MockWork : public AsteriskSCF::Threading::WorkQueue::Work
+{
+public: 
+    MockWork() : mWorkDone(false) {}
+
+    /** 
+     * An implementation of the WorkQueue::Work interface. 
+     */
+    virtual void doWork()
+    {
+        mWorkDone = true;
+    }
+
+bool mWorkDone;
+};
+typedef boost::shared_ptr<MockWork> MockWorkPtr;
+
+BOOST_AUTO_TEST_SUITE(SimpleWorkQueueTest)
+
+BOOST_AUTO_TEST_CASE(enqueueWork)
+{
+
+    MockWorkPtr w1(new MockWork()); 
+    MockWorkPtr w2(new MockWork()); 
+    MockWorkPtr w3(new MockWork()); 
+
+    SimpleWorkQueue wq("TestWorkQueue");
+
+    BOOST_CHECK(wq.workPending() == false);
+
+    BOOST_CHECK(wq.isRunning() == true);
+
+    wq.enqueue(w1);
+    wq.enqueue(w2);
+    wq.enqueue(w3);
+
+    boost::this_thread::sleep( boost::get_system_time() + 
+        boost::posix_time::milliseconds( std::max<long>(100,0) )); 
+
+    BOOST_CHECK(w1->mWorkDone == true);
+    BOOST_CHECK(w2->mWorkDone == true);
+    BOOST_CHECK(w3->mWorkDone == true);
+
+}
+
+
+BOOST_AUTO_TEST_SUITE_END()

-----------------------------------------------------------------------


-- 
asterisk-scf/integration/util-cpp.git



More information about the asterisk-scf-commits mailing list