2
0
mirror of https://gitlab.isc.org/isc-projects/kea synced 2025-08-29 13:07:50 +00:00

[2205] added a test case using a real thread

This commit is contained in:
JINMEI Tatuya 2012-10-15 16:04:46 -07:00
parent b4ec1b3e23
commit ae89f6e491
3 changed files with 41 additions and 6 deletions

View File

@ -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

View File

@ -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

View File

@ -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