From: Yoshitaka Aharen Date: Fri, 28 Sep 2012 10:40:55 +0000 (+0900) Subject: [2155] put statistics into isc::auth::statistics namespace X-Git-Tag: trac2487_base~52 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=a7adf4e4fe023903dd4ca362a6cfa6cafc06241d;p=thirdparty%2Fkea.git [2155] put statistics into isc::auth::statistics namespace Put statistics classes into isc::auth::statistics namespace. Rename AuthCounters to Counters. --- diff --git a/src/bin/auth/auth_srv.cc b/src/bin/auth/auth_srv.cc index 82a98a4d94..8005efe6e2 100644 --- a/src/bin/auth/auth_srv.cc +++ b/src/bin/auth/auth_srv.cc @@ -82,6 +82,7 @@ using namespace isc::xfr; using namespace isc::asiolink; using namespace isc::asiodns; using namespace isc::server_common::portconfig; +using isc::auth::statistics::Counters; namespace { // A helper class for cleaning up message renderer. @@ -257,7 +258,7 @@ public: AbstractSession* xfrin_session_; /// Query counters for statistics - AuthCounters counters_; + Counters counters_; /// Addresses we listen on AddressList listen_addresses_; @@ -812,9 +813,9 @@ void AuthSrvImpl::incCounter(const int protocol) { // Increment query counter. if (protocol == IPPROTO_UDP) { - counters_.inc(AuthCounters::SERVER_UDP_QUERY); + counters_.inc(Counters::SERVER_UDP_QUERY); } else if (protocol == IPPROTO_TCP) { - counters_.inc(AuthCounters::SERVER_TCP_QUERY); + counters_.inc(Counters::SERVER_TCP_QUERY); } else { // unknown protocol isc_throw(Unexpected, "Unknown protocol: " << protocol); @@ -865,7 +866,7 @@ ConstElementPtr AuthSrv::getStatistics() const { } uint64_t -AuthSrv::getCounter(const AuthCounters::ServerCounterType type) const { +AuthSrv::getCounter(const Counters::ServerCounterType type) const { return (impl_->counters_.getCounter(type)); } diff --git a/src/bin/auth/auth_srv.h b/src/bin/auth/auth_srv.h index e2ffd71526..1f996a7f13 100644 --- a/src/bin/auth/auth_srv.h +++ b/src/bin/auth/auth_srv.h @@ -205,18 +205,18 @@ public: /// \brief Returns statistics data /// /// This function can throw an exception from - /// AuthCounters::getStatistics(). + /// Counters::getStatistics(). /// /// \return JSON format statistics data. isc::data::ConstElementPtr getStatistics() const; - /// \brief Get the value of counter in the AuthCounters. + /// \brief Get the value of counter in the Counters. /// - /// This function calls AuthCounters::getStatistics() and + /// This function calls Counters::getStatistics() and /// returns its return value. /// /// This function never throws an exception as far as - /// AuthCounters::getStatistics() doesn't throw. + /// Counters::getStatistics() doesn't throw. /// /// Note: Currently this function is for testing purpose only. /// @@ -224,11 +224,13 @@ public: /// /// \return the value of the counter. - uint64_t getCounter(const AuthCounters::ServerCounterType type) const; + uint64_t getCounter( + const isc::auth::statistics::Counters::ServerCounterType type) + const; /// \brief Get the value of per Opcode counter in the Auth Counters. /// - /// This function calls AuthCounters::getCounter(isc::dns::Opcode) and + /// This function calls Counters::getCounter(isc::dns::Opcode) and /// returns its return value. /// /// \note This is a tentative interface as an attempt of experimentally @@ -242,7 +244,7 @@ public: /// \brief Get the value of per Rcode counter in the Auth Counters. /// - /// This function calls AuthCounters::getCounter(isc::dns::Rcode) and + /// This function calls Counters::getCounter(isc::dns::Rcode) and /// returns its return value. /// /// \note This is a tentative interface as an attempt of experimentally diff --git a/src/bin/auth/statistics.cc b/src/bin/auth/statistics.cc index 2d5f336195..6b68ab093a 100644 --- a/src/bin/auth/statistics.cc +++ b/src/bin/auth/statistics.cc @@ -36,30 +36,29 @@ using namespace isc::dns; using namespace isc::auth; using namespace isc::statistics; -// TODO: We need a namespace ("auth_server"?) to hold -// AuthSrv and AuthCounters. +namespace isc { +namespace auth { +namespace statistics { // TODO: Make use of wrappers like isc::dns::Opcode // for counter item type. -class AuthCountersImpl : boost::noncopyable { +class CountersImpl : boost::noncopyable { public: - AuthCountersImpl(); - ~AuthCountersImpl(); - void inc(const AuthCounters::ServerCounterType type); + CountersImpl(); + ~CountersImpl(); + void inc(const Counters::ServerCounterType type); void inc(const Opcode opcode) { opcode_counter_.inc(opcode.getCode()); } void inc(const Rcode rcode) { rcode_counter_.inc(rcode.getCode()); } - void inc(const std::string& zone, - const AuthCounters::PerZoneCounterType type); + void inc(const std::string& zone, const Counters::PerZoneCounterType type); isc::data::ConstElementPtr getStatistics() const; - void registerStatisticsValidator - (AuthCounters::validator_type validator); + void registerStatisticsValidator (Counters::validator_type validator); // Currently for testing purpose only - uint64_t getCounter(const AuthCounters::ServerCounterType type) const; + uint64_t getCounter(const Counters::ServerCounterType type) const; uint64_t getCounter(const Opcode opcode) const { return (opcode_counter_.get(opcode.getCode())); } @@ -73,42 +72,42 @@ private: Counter rcode_counter_; static const size_t NUM_RCODES = 17; CounterDictionary per_zone_counter_; - AuthCounters::validator_type validator_; + Counters::validator_type validator_; }; -AuthCountersImpl::AuthCountersImpl() : +CountersImpl::CountersImpl() : // initialize counter - // size of server_counter_: AuthCounters::SERVER_COUNTER_TYPES - // size of per_zone_counter_: AuthCounters::PER_ZONE_COUNTER_TYPES - server_counter_(AuthCounters::SERVER_COUNTER_TYPES), + // size of server_counter_: Counters::SERVER_COUNTER_TYPES + // size of per_zone_counter_: Counters::PER_ZONE_COUNTER_TYPES + server_counter_(Counters::SERVER_COUNTER_TYPES), opcode_counter_(NUM_OPCODES), rcode_counter_(NUM_RCODES), - per_zone_counter_(AuthCounters::PER_ZONE_COUNTER_TYPES) + per_zone_counter_(Counters::PER_ZONE_COUNTER_TYPES) { per_zone_counter_.addElement("_SERVER_"); } -AuthCountersImpl::~AuthCountersImpl() +CountersImpl::~CountersImpl() {} void -AuthCountersImpl::inc(const AuthCounters::ServerCounterType type) { +CountersImpl::inc(const Counters::ServerCounterType type) { server_counter_.inc(type); } void -AuthCountersImpl::inc(const std::string& zone, - const AuthCounters::PerZoneCounterType type) +CountersImpl::inc(const std::string& zone, + const Counters::PerZoneCounterType type) { per_zone_counter_[zone].inc(type); } isc::data::ConstElementPtr -AuthCountersImpl::getStatistics() const { +CountersImpl::getStatistics() const { std::stringstream statistics_string; statistics_string << "{ \"queries.udp\": " - << server_counter_.get(AuthCounters::SERVER_UDP_QUERY) + << server_counter_.get(Counters::SERVER_UDP_QUERY) << ", \"queries.tcp\": " - << server_counter_.get(AuthCounters::SERVER_TCP_QUERY); + << server_counter_.get(Counters::SERVER_TCP_QUERY); // Insert non 0 Opcode counters. for (int i = 0; i < NUM_OPCODES; ++i) { const Counter::Type counter = opcode_counter_.get(i); @@ -150,61 +149,65 @@ AuthCountersImpl::getStatistics() const { } void -AuthCountersImpl::registerStatisticsValidator - (AuthCounters::validator_type validator) +CountersImpl::registerStatisticsValidator + (Counters::validator_type validator) { validator_ = validator; } // Currently for testing purpose only uint64_t -AuthCountersImpl::getCounter(const AuthCounters::ServerCounterType type) const { +CountersImpl::getCounter(const Counters::ServerCounterType type) const { return (server_counter_.get(type)); } -AuthCounters::AuthCounters() : impl_(new AuthCountersImpl()) +Counters::Counters() : impl_(new CountersImpl()) {} -AuthCounters::~AuthCounters() {} +Counters::~Counters() {} void -AuthCounters::inc(const AuthCounters::ServerCounterType type) { +Counters::inc(const Counters::ServerCounterType type) { impl_->inc(type); } void -AuthCounters::inc(const Opcode opcode) { +Counters::inc(const Opcode opcode) { impl_->inc(opcode); } void -AuthCounters::inc(const Rcode rcode) { +Counters::inc(const Rcode rcode) { impl_->inc(rcode); } isc::data::ConstElementPtr -AuthCounters::getStatistics() const { +Counters::getStatistics() const { return (impl_->getStatistics()); } uint64_t -AuthCounters::getCounter(const AuthCounters::ServerCounterType type) const { +Counters::getCounter(const Counters::ServerCounterType type) const { return (impl_->getCounter(type)); } uint64_t -AuthCounters::getCounter(const Opcode opcode) const { +Counters::getCounter(const Opcode opcode) const { return (impl_->getCounter(opcode)); } uint64_t -AuthCounters::getCounter(const Rcode rcode) const { +Counters::getCounter(const Rcode rcode) const { return (impl_->getCounter(rcode)); } void -AuthCounters::registerStatisticsValidator - (AuthCounters::validator_type validator) const +Counters::registerStatisticsValidator + (Counters::validator_type validator) const { return (impl_->registerStatisticsValidator(validator)); } + +} // namespace statistics +} // namespace auth +} // namespace isc diff --git a/src/bin/auth/statistics.h b/src/bin/auth/statistics.h index 5906885990..d0ddd5f4e2 100644 --- a/src/bin/auth/statistics.h +++ b/src/bin/auth/statistics.h @@ -23,12 +23,12 @@ #include #include -class AuthCountersImpl; - namespace isc { namespace auth { namespace statistics { +class CountersImpl; + class QRAttributes { /// \brief Query/Response attributes for statistics. /// @@ -36,8 +36,8 @@ class QRAttributes { /// for statistics data collection. /// /// This class does not have getter methods since it exposes private members -/// to \c AuthCountersImpl directly. -friend class AuthCountersImpl; +/// to \c CountersImpl directly. +friend class CountersImpl; private: // request attributes int req_ip_version_; // IP version @@ -174,13 +174,9 @@ QRAttributes::reset() { res_is_truncated_ = false; } -} // namespace statistics -} // namespace auth -} // namespace isc - /// \brief Set of query counters. /// -/// \c AuthCounters is set of query counters class. It holds query counters +/// \c Counters is set of query counters class. It holds query counters /// and provides an interface to increment the counter of specified type /// (e.g. UDP query, TCP query). /// @@ -203,10 +199,10 @@ QRAttributes::reset() { /// construction overhead of this approach should be acceptable. /// /// \todo Hold counters for each query types (Notify, Axfr, Ixfr, Normal) -/// \todo Consider overhead of \c AuthCounters::inc() -class AuthCounters { +/// \todo Consider overhead of \c Counters::inc() +class Counters { private: - boost::scoped_ptr impl_; + boost::scoped_ptr impl_; public: // Enum for the type of counter enum ServerCounterType { @@ -224,12 +220,12 @@ public: /// This constructor is mostly exception free. But it may still throw /// a standard exception if memory allocation fails inside the method. /// - AuthCounters(); + Counters(); /// The destructor. /// /// This method never throws an exception. /// - ~AuthCounters(); + ~Counters(); /// \brief Increment the counter specified by the parameter. /// @@ -237,7 +233,7 @@ public: /// /// \throw std::out_of_range \a type is unknown. /// - /// usage: counter.inc(AuthCounters::SERVER_UDP_QUERY); + /// usage: counter.inc(Counters::SERVER_UDP_QUERY); /// void inc(const ServerCounterType type); @@ -269,7 +265,7 @@ public: /// isc::data::ConstElementPtr getStatistics() const; - /// \brief Get the value of a counter in the AuthCounters. + /// \brief Get the value of a counter in the Counters. /// /// This function returns a value of the counter specified by \a type. /// This method never throws an exception. @@ -279,7 +275,7 @@ public: /// \param type Type of a counter to get the value of /// /// \return the value of the counter specified by \a type. - uint64_t getCounter(const AuthCounters::ServerCounterType type) const; + uint64_t getCounter(const Counters::ServerCounterType type) const; /// \brief Get the value of a per opcode counter. /// @@ -321,16 +317,20 @@ public: validator_type; /// \brief Register a function type of the statistics validation - /// function for AuthCounters. + /// function for Counters. /// /// This method never throws an exception. /// /// \param validator A function type of the validation of /// statistics specification. /// - void registerStatisticsValidator(AuthCounters::validator_type validator) const; + void registerStatisticsValidator(Counters::validator_type validator) const; }; +} // namespace statistics +} // namespace auth +} // namespace isc + #endif // __STATISTICS_H // Local Variables: diff --git a/src/bin/auth/tests/auth_srv_unittest.cc b/src/bin/auth/tests/auth_srv_unittest.cc index e7b4ca7dea..65d0e58de5 100644 --- a/src/bin/auth/tests/auth_srv_unittest.cc +++ b/src/bin/auth/tests/auth_srv_unittest.cc @@ -74,6 +74,7 @@ using namespace isc::testutils; using namespace isc::server_common::portconfig; using isc::UnitTestUtil; using boost::scoped_ptr; +using isc::auth::statistics::Counters; namespace { const char* const CONFIG_TESTDB = @@ -1029,7 +1030,7 @@ TEST_F(AuthSrvTest, // Submit UDP normal query and check query counter TEST_F(AuthSrvTest, queryCounterUDPNormal) { // The counter should be initialized to 0. - EXPECT_EQ(0, server.getCounter(AuthCounters::SERVER_UDP_QUERY)); + EXPECT_EQ(0, server.getCounter(Counters::SERVER_UDP_QUERY)); // Create UDP message and process. UnitTestUtil::createRequestMessage(request_message, Opcode::QUERY(), default_qid, Name("example.com"), @@ -1038,7 +1039,7 @@ TEST_F(AuthSrvTest, queryCounterUDPNormal) { server.processMessage(*io_message, *parse_message, *response_obuffer, &dnsserv); // After processing UDP query, the counter should be 1. - EXPECT_EQ(1, server.getCounter(AuthCounters::SERVER_UDP_QUERY)); + EXPECT_EQ(1, server.getCounter(Counters::SERVER_UDP_QUERY)); // The counter for opcode Query should also be one EXPECT_EQ(1, server.getCounter(Opcode::QUERY())); // The counter for REFUSED responses should also be one, the rest zero @@ -1048,7 +1049,7 @@ TEST_F(AuthSrvTest, queryCounterUDPNormal) { // Submit TCP normal query and check query counter TEST_F(AuthSrvTest, queryCounterTCPNormal) { // The counter should be initialized to 0. - EXPECT_EQ(0, server.getCounter(AuthCounters::SERVER_TCP_QUERY)); + EXPECT_EQ(0, server.getCounter(Counters::SERVER_TCP_QUERY)); // Create TCP message and process. UnitTestUtil::createRequestMessage(request_message, Opcode::QUERY(), default_qid, Name("example.com"), @@ -1057,7 +1058,7 @@ TEST_F(AuthSrvTest, queryCounterTCPNormal) { server.processMessage(*io_message, *parse_message, *response_obuffer, &dnsserv); // After processing TCP query, the counter should be 1. - EXPECT_EQ(1, server.getCounter(AuthCounters::SERVER_TCP_QUERY)); + EXPECT_EQ(1, server.getCounter(Counters::SERVER_TCP_QUERY)); // The counter for SUCCESS responses should also be one EXPECT_EQ(1, server.getCounter(Opcode::QUERY())); // The counter for REFUSED responses should also be one, the rest zero @@ -1067,7 +1068,7 @@ TEST_F(AuthSrvTest, queryCounterTCPNormal) { // Submit TCP AXFR query and check query counter TEST_F(AuthSrvTest, queryCounterTCPAXFR) { // The counter should be initialized to 0. - EXPECT_EQ(0, server.getCounter(AuthCounters::SERVER_TCP_QUERY)); + EXPECT_EQ(0, server.getCounter(Counters::SERVER_TCP_QUERY)); UnitTestUtil::createRequestMessage(request_message, opcode, default_qid, Name("example.com"), RRClass::IN(), RRType::AXFR()); createRequestPacket(request_message, IPPROTO_TCP); @@ -1077,7 +1078,7 @@ TEST_F(AuthSrvTest, queryCounterTCPAXFR) { &dnsserv); EXPECT_FALSE(dnsserv.hasAnswer()); // After processing TCP AXFR query, the counter should be 1. - EXPECT_EQ(1, server.getCounter(AuthCounters::SERVER_TCP_QUERY)); + EXPECT_EQ(1, server.getCounter(Counters::SERVER_TCP_QUERY)); // No rcodes should be incremented checkAllRcodeCountersZero(); } @@ -1085,7 +1086,7 @@ TEST_F(AuthSrvTest, queryCounterTCPAXFR) { // Submit TCP IXFR query and check query counter TEST_F(AuthSrvTest, queryCounterTCPIXFR) { // The counter should be initialized to 0. - EXPECT_EQ(0, server.getCounter(AuthCounters::SERVER_TCP_QUERY)); + EXPECT_EQ(0, server.getCounter(Counters::SERVER_TCP_QUERY)); UnitTestUtil::createRequestMessage(request_message, opcode, default_qid, Name("example.com"), RRClass::IN(), RRType::IXFR()); createRequestPacket(request_message, IPPROTO_TCP); @@ -1095,7 +1096,7 @@ TEST_F(AuthSrvTest, queryCounterTCPIXFR) { &dnsserv); EXPECT_FALSE(dnsserv.hasAnswer()); // After processing TCP IXFR query, the counter should be 1. - EXPECT_EQ(1, server.getCounter(AuthCounters::SERVER_TCP_QUERY)); + EXPECT_EQ(1, server.getCounter(Counters::SERVER_TCP_QUERY)); } TEST_F(AuthSrvTest, queryCounterOpcodes) { diff --git a/src/bin/auth/tests/statistics_unittest.cc b/src/bin/auth/tests/statistics_unittest.cc index dc4b91f70e..43c217501e 100644 --- a/src/bin/auth/tests/statistics_unittest.cc +++ b/src/bin/auth/tests/statistics_unittest.cc @@ -35,10 +35,11 @@ using namespace std; using namespace isc::cc; using namespace isc::dns; using namespace isc::data; +using isc::auth::statistics::Counters; namespace { -class AuthCountersTest : public ::testing::Test { +class CountersTest : public ::testing::Test { private: class MockSession : public AbstractSession { public: @@ -76,11 +77,11 @@ private: }; protected: - AuthCountersTest() : counters() { + CountersTest() : counters() { } - ~AuthCountersTest() { + ~CountersTest() { } - AuthCounters counters; + Counters counters; // no need to be inherited from the original class here. class MockModuleSpec { public: @@ -91,35 +92,35 @@ protected: }; void -AuthCountersTest::MockSession::establish(const char*) {} +CountersTest::MockSession::establish(const char*) {} void -AuthCountersTest::MockSession::disconnect() {} +CountersTest::MockSession::disconnect() {} void -AuthCountersTest::MockSession::subscribe(string, string) +CountersTest::MockSession::subscribe(string, string) {} void -AuthCountersTest::MockSession::unsubscribe(string, string) +CountersTest::MockSession::unsubscribe(string, string) {} void -AuthCountersTest::MockSession::startRead(boost::function) +CountersTest::MockSession::startRead(boost::function) {} int -AuthCountersTest::MockSession::reply(ConstElementPtr, ConstElementPtr) { +CountersTest::MockSession::reply(ConstElementPtr, ConstElementPtr) { return (-1); } bool -AuthCountersTest::MockSession::hasQueuedMsgs() const { +CountersTest::MockSession::hasQueuedMsgs() const { return (false); } int -AuthCountersTest::MockSession::group_sendmsg(ConstElementPtr msg, +CountersTest::MockSession::group_sendmsg(ConstElementPtr msg, string group, string, string) { if (throw_session_error_) { @@ -131,7 +132,7 @@ AuthCountersTest::MockSession::group_sendmsg(ConstElementPtr msg, } bool -AuthCountersTest::MockSession::group_recvmsg(ConstElementPtr&, +CountersTest::MockSession::group_recvmsg(ConstElementPtr&, ConstElementPtr& msg, bool, int) { if (throw_session_timeout_) { @@ -142,38 +143,38 @@ AuthCountersTest::MockSession::group_recvmsg(ConstElementPtr&, } void -AuthCountersTest::MockSession::setThrowSessionError(bool flag) { +CountersTest::MockSession::setThrowSessionError(bool flag) { throw_session_error_ = flag; } void -AuthCountersTest::MockSession::setThrowSessionTimeout(bool flag) { +CountersTest::MockSession::setThrowSessionTimeout(bool flag) { throw_session_timeout_ = flag; } -TEST_F(AuthCountersTest, incrementUDPCounter) { +TEST_F(CountersTest, incrementUDPCounter) { // The counter should be initialized to 0. - EXPECT_EQ(0, counters.getCounter(AuthCounters::SERVER_UDP_QUERY)); - EXPECT_NO_THROW(counters.inc(AuthCounters::SERVER_UDP_QUERY)); + EXPECT_EQ(0, counters.getCounter(Counters::SERVER_UDP_QUERY)); + EXPECT_NO_THROW(counters.inc(Counters::SERVER_UDP_QUERY)); // After increment, the counter should be 1. - EXPECT_EQ(1, counters.getCounter(AuthCounters::SERVER_UDP_QUERY)); + EXPECT_EQ(1, counters.getCounter(Counters::SERVER_UDP_QUERY)); } -TEST_F(AuthCountersTest, incrementTCPCounter) { +TEST_F(CountersTest, incrementTCPCounter) { // The counter should be initialized to 0. - EXPECT_EQ(0, counters.getCounter(AuthCounters::SERVER_TCP_QUERY)); - EXPECT_NO_THROW(counters.inc(AuthCounters::SERVER_TCP_QUERY)); + EXPECT_EQ(0, counters.getCounter(Counters::SERVER_TCP_QUERY)); + EXPECT_NO_THROW(counters.inc(Counters::SERVER_TCP_QUERY)); // After increment, the counter should be 1. - EXPECT_EQ(1, counters.getCounter(AuthCounters::SERVER_TCP_QUERY)); + EXPECT_EQ(1, counters.getCounter(Counters::SERVER_TCP_QUERY)); } -TEST_F(AuthCountersTest, incrementInvalidCounter) { +TEST_F(CountersTest, incrementInvalidCounter) { // Expect to throw an isc::OutOfRange - EXPECT_THROW(counters.inc(AuthCounters::SERVER_COUNTER_TYPES), + EXPECT_THROW(counters.inc(Counters::SERVER_COUNTER_TYPES), isc::OutOfRange); } -TEST_F(AuthCountersTest, incrementOpcodeCounter) { +TEST_F(CountersTest, incrementOpcodeCounter) { // The counter should be initialized to 0. If we increment it by 1 // the counter should be 1. for (int i = 0; i < 16; ++i) { @@ -183,7 +184,7 @@ TEST_F(AuthCountersTest, incrementOpcodeCounter) { } } -TEST_F(AuthCountersTest, incrementRcodeCounter) { +TEST_F(CountersTest, incrementRcodeCounter) { // The counter should be initialized to 0. If we increment it by 1 // the counter should be 1. for (int i = 0; i < 17; ++i) { @@ -237,19 +238,19 @@ rcodeDataCheck(ConstElementPtr data, const int expected[17]) { ASSERT_EQ(static_cast(NULL), item_names[i]); } -TEST_F(AuthCountersTest, getStatisticsWithoutValidator) { +TEST_F(CountersTest, getStatisticsWithoutValidator) { // Get statistics data. // Validate if it answers correct data. // Counters should be initialized to 0. - EXPECT_EQ(0, counters.getCounter(AuthCounters::SERVER_UDP_QUERY)); - EXPECT_EQ(0, counters.getCounter(AuthCounters::SERVER_TCP_QUERY)); + EXPECT_EQ(0, counters.getCounter(Counters::SERVER_UDP_QUERY)); + EXPECT_EQ(0, counters.getCounter(Counters::SERVER_TCP_QUERY)); // UDP query counter is set to 2. - counters.inc(AuthCounters::SERVER_UDP_QUERY); - counters.inc(AuthCounters::SERVER_UDP_QUERY); + counters.inc(Counters::SERVER_UDP_QUERY); + counters.inc(Counters::SERVER_UDP_QUERY); // TCP query counter is set to 1. - counters.inc(AuthCounters::SERVER_TCP_QUERY); + counters.inc(Counters::SERVER_TCP_QUERY); ConstElementPtr statistics_data = counters.getStatistics(); // UDP query counter is 2 and TCP query counter is 1. @@ -267,7 +268,7 @@ TEST_F(AuthCountersTest, getStatisticsWithoutValidator) { } void -updateOpcodeCounters(AuthCounters &counters, const int expected[16]) { +updateOpcodeCounters(Counters &counters, const int expected[16]) { for (int i = 0; i < 16; ++i) { for (int j = 0; j < expected[i]; ++j) { counters.inc(Opcode(i)); @@ -276,7 +277,7 @@ updateOpcodeCounters(AuthCounters &counters, const int expected[16]) { } void -updateRcodeCounters(AuthCounters &counters, const int expected[17]) { +updateRcodeCounters(Counters &counters, const int expected[17]) { for (int i = 0; i < 17; ++i) { for (int j = 0; j < expected[i]; ++j) { counters.inc(Rcode(i)); @@ -284,7 +285,7 @@ updateRcodeCounters(AuthCounters &counters, const int expected[17]) { } } -TEST_F(AuthCountersTest, getStatisticsWithOpcodeCounters) { +TEST_F(CountersTest, getStatisticsWithOpcodeCounters) { // Increment some of the opcode counters. Then they should appear in the // submitted data; others shouldn't const int opcode_results[16] = { 1, 2, 3, 0, 4, 5, 0, 0, @@ -294,7 +295,7 @@ TEST_F(AuthCountersTest, getStatisticsWithOpcodeCounters) { opcodeDataCheck(statistics_data, opcode_results); } -TEST_F(AuthCountersTest, getStatisticsWithAllOpcodeCounters) { +TEST_F(CountersTest, getStatisticsWithAllOpcodeCounters) { // Increment all opcode counters. Then they should appear in the // submitted data. const int opcode_results[16] = { 1, 1, 1, 1, 1, 1, 1, 1, @@ -304,7 +305,7 @@ TEST_F(AuthCountersTest, getStatisticsWithAllOpcodeCounters) { opcodeDataCheck(statistics_data, opcode_results); } -TEST_F(AuthCountersTest, getStatisticsWithRcodeCounters) { +TEST_F(CountersTest, getStatisticsWithRcodeCounters) { // Increment some of the rcode counters. Then they should appear in the // submitted data; others shouldn't const int rcode_results[17] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, @@ -314,7 +315,7 @@ TEST_F(AuthCountersTest, getStatisticsWithRcodeCounters) { rcodeDataCheck(statistics_data, rcode_results); } -TEST_F(AuthCountersTest, getStatisticsWithAllRcodeCounters) { +TEST_F(CountersTest, getStatisticsWithAllRcodeCounters) { // Increment all rcode counters. Then they should appear in the // submitted data. const int rcode_results[17] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, @@ -324,31 +325,31 @@ TEST_F(AuthCountersTest, getStatisticsWithAllRcodeCounters) { opcodeDataCheck(statistics_data, rcode_results); } -TEST_F(AuthCountersTest, getStatisticsWithValidator) { +TEST_F(CountersTest, getStatisticsWithValidator) { //a validator for the unittest - AuthCounters::validator_type validator; + Counters::validator_type validator; ConstElementPtr el; // Get statistics data with correct statistics validator. validator = boost::bind( - &AuthCountersTest::MockModuleSpec::validateStatistics, + &CountersTest::MockModuleSpec::validateStatistics, &module_spec_, _1, true); EXPECT_TRUE(validator(el)); - // register validator to AuthCounters + // register validator to Counters counters.registerStatisticsValidator(validator); // Counters should be initialized to 0. - EXPECT_EQ(0, counters.getCounter(AuthCounters::SERVER_UDP_QUERY)); - EXPECT_EQ(0, counters.getCounter(AuthCounters::SERVER_TCP_QUERY)); + EXPECT_EQ(0, counters.getCounter(Counters::SERVER_UDP_QUERY)); + EXPECT_EQ(0, counters.getCounter(Counters::SERVER_TCP_QUERY)); // UDP query counter is set to 2. - counters.inc(AuthCounters::SERVER_UDP_QUERY); - counters.inc(AuthCounters::SERVER_UDP_QUERY); + counters.inc(Counters::SERVER_UDP_QUERY); + counters.inc(Counters::SERVER_UDP_QUERY); // TCP query counter is set to 1. - counters.inc(AuthCounters::SERVER_TCP_QUERY); + counters.inc(Counters::SERVER_TCP_QUERY); // checks the value returned by getStatistics ConstElementPtr statistics_data = counters.getStatistics(); @@ -359,7 +360,7 @@ TEST_F(AuthCountersTest, getStatisticsWithValidator) { // Get statistics data with incorrect statistics validator. validator = boost::bind( - &AuthCountersTest::MockModuleSpec::validateStatistics, + &CountersTest::MockModuleSpec::validateStatistics, &module_spec_, _1, false); EXPECT_FALSE(validator(el));