Parcourir la source

[2205] added a test case using a real thread

JINMEI Tatuya il y a 12 ans
Parent
commit
ae89f6e491

+ 6 - 0
src/bin/auth/auth_messages.mes

@@ -268,3 +268,9 @@ This is a debug message output during the processing of a NOTIFY
 request. The zone manager component has been informed of the request,
 but has returned an error response (which is included in the message). The
 NOTIFY request will not be honored.
+
+% AUTH_DATASRC_CLIENT_BUILDER_STARTED data source builder thread started
+
+% AUTH_DATASRC_CLIENT_BUILDER_STOPPED data source builder thread stopped
+
+% AUTH_DATASRC_CLIENT_BUILDER_COMMAND data source builder received command, ID: %1

+ 27 - 2
src/bin/auth/datasrc_clients_mgr.h

@@ -15,10 +15,16 @@
 #ifndef DATASRC_CLIENTS_MGR_H
 #define DATASRC_CLIENTS_MGR_H 1
 
+#include <util/threads/thread.h>
 #include <util/threads/lock.h>
 
+#include <log/logger_support.h>
+#include <log/log_dbglevels.h>
+
 #include <cc/data.h>
 
+#include <auth/auth_log.h>
+
 #include <boost/bind.hpp>
 
 #include <list>
@@ -67,6 +73,10 @@ private:
     //boost::shared_ptr<DataSrcClientListMap>* map;
     //MutexType* data_mutex_;
 };
+
+// Shortcut typedef for normal use
+typedef DataSrcClientsBuilderBase<util::thread::Mutex, util::thread::CondVar>
+DataSrcClientsBuilder;
 }
 
 template <typename ThreadType, typename BuilderType, typename MutexType,
@@ -101,6 +111,8 @@ namespace internal {
 template <typename MutexType, typename CondVarType>
 void
 DataSrcClientsBuilderBase<MutexType, CondVarType>::run() {
+    LOG_INFO(auth_logger, AUTH_DATASRC_CLIENT_BUILDER_STARTED);
+
     bool keep_running = true;
     while (keep_running) {
         std::list<Command> current_commands;
@@ -119,6 +131,8 @@ DataSrcClientsBuilderBase<MutexType, CondVarType>::run() {
             current_commands.pop_front();
         }
     }
+
+    LOG_INFO(auth_logger, AUTH_DATASRC_CLIENT_BUILDER_STOPPED);
 }
 
 template <typename MutexType, typename CondVarType>
@@ -126,6 +140,9 @@ bool
 DataSrcClientsBuilderBase<MutexType, CondVarType>::handleCommand(
     const Command& command)
 {
+    LOG_DEBUG(auth_logger, DBGLVL_TRACE_BASIC,
+              AUTH_DATASRC_CLIENT_BUILDER_COMMAND).arg(command.first);
+
     switch (command.first) {
     case SHUTDOWN:
         return (false);
@@ -134,8 +151,16 @@ DataSrcClientsBuilderBase<MutexType, CondVarType>::handleCommand(
     }
     return (true);
 }
-}
-
+} // namespace internal
+
+/// \brief Shortcut type for normal data source clients manager.
+///
+/// In fact, for non test applications this is the only type of this kind
+/// to be considered.
+typedef DataSrcClientsMgrBase<util::thread::Thread,
+                              internal::DataSrcClientsBuilder,
+                              util::thread::Mutex, util::thread::CondVar>
+DataSrcClientsMgr;
 } // namespace auth
 } // namespace isc
 

+ 9 - 5
src/bin/auth/tests/datasrc_clients_mgr_unittest.cc

@@ -25,10 +25,7 @@ using namespace isc::auth;
 using namespace isc::auth::internal;
 
 namespace {
-class DataSrcClientsMgrTest : public ::testing::Test {
-};
-
-TEST_F(DataSrcClientsMgrTest, start) {
+TEST(DataSrcClientsMgrTest, start) {
     // When we create a manager, builder's run() method should be called.
     FakeDataSrcClientsBuilder::started = false;
     TestDataSrcClientsMgr mgr;
@@ -36,7 +33,7 @@ TEST_F(DataSrcClientsMgrTest, start) {
     EXPECT_TRUE(FakeDataSrcClientsBuilder::command_queue->empty());
 }
 
-TEST_F(DataSrcClientsMgrTest, shutdown) {
+TEST(DataSrcClientsMgrTest, shutdown) {
     // Invoke shutdown on the manager.
     TestDataSrcClientsMgr mgr;
     EXPECT_TRUE(FakeDataSrcClientsBuilder::started);
@@ -58,4 +55,11 @@ TEST_F(DataSrcClientsMgrTest, shutdown) {
     EXPECT_TRUE(FakeDataSrcClientsBuilder::thread_waited);
 }
 
+TEST(DataSrcClientsMgrTest, realThread) {
+    // Using the non-test definition with a real thread.  Just checking
+    // no disruption happens.
+    DataSrcClientsMgr mgr;
+    mgr.shutdown();
+}
+
 } // unnamed namespace