From ae89f6e491d018953ac03d1810c1b467564c281b Mon Sep 17 00:00:00 2001 From: JINMEI Tatuya Date: Mon, 15 Oct 2012 16:04:46 -0700 Subject: [PATCH] [2205] added a test case using a real thread --- src/bin/auth/auth_messages.mes | 6 +++++ src/bin/auth/datasrc_clients_mgr.h | 27 ++++++++++++++++++- .../tests/datasrc_clients_mgr_unittest.cc | 14 ++++++---- 3 files changed, 41 insertions(+), 6 deletions(-) diff --git a/src/bin/auth/auth_messages.mes b/src/bin/auth/auth_messages.mes index ae7be1e3ed..c57240ecc4 100644 --- a/src/bin/auth/auth_messages.mes +++ b/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 diff --git a/src/bin/auth/datasrc_clients_mgr.h b/src/bin/auth/datasrc_clients_mgr.h index 6b5d0172be..794b515b3e 100644 --- a/src/bin/auth/datasrc_clients_mgr.h +++ b/src/bin/auth/datasrc_clients_mgr.h @@ -15,10 +15,16 @@ #ifndef DATASRC_CLIENTS_MGR_H #define DATASRC_CLIENTS_MGR_H 1 +#include #include +#include +#include + #include +#include + #include #include @@ -67,6 +73,10 @@ private: //boost::shared_ptr* map; //MutexType* data_mutex_; }; + +// Shortcut typedef for normal use +typedef DataSrcClientsBuilderBase +DataSrcClientsBuilder; } template void DataSrcClientsBuilderBase::run() { + LOG_INFO(auth_logger, AUTH_DATASRC_CLIENT_BUILDER_STARTED); + bool keep_running = true; while (keep_running) { std::list current_commands; @@ -119,6 +131,8 @@ DataSrcClientsBuilderBase::run() { current_commands.pop_front(); } } + + LOG_INFO(auth_logger, AUTH_DATASRC_CLIENT_BUILDER_STOPPED); } template @@ -126,6 +140,9 @@ bool DataSrcClientsBuilderBase::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::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 +DataSrcClientsMgr; } // namespace auth } // namespace isc diff --git a/src/bin/auth/tests/datasrc_clients_mgr_unittest.cc b/src/bin/auth/tests/datasrc_clients_mgr_unittest.cc index 00e6926299..c58494ad70 100644 --- a/src/bin/auth/tests/datasrc_clients_mgr_unittest.cc +++ b/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