private:
// counter for query/response
Counter server_qr_counter_;
- // counter for socket
- Counter socket_counter_;
// set of counters for zones
CounterDictionary zone_qr_counters_;
// validator
CountersImpl::CountersImpl() :
// size of server_qr_counter_, zone_qr_counters_: QR_COUNTER_TYPES
- // size of server_socket_counter_: SOCKET_COUNTER_TYPES
server_qr_counter_(QR_COUNTER_TYPES),
- socket_counter_(SOCKET_COUNTER_TYPES),
zone_qr_counters_(QR_COUNTER_TYPES),
validator_()
{}
for (int i = QR_OPCODE_QUERY; i <= QR_OPCODE_OTHER; ++i) {
const Counter::Type counter = server_qr_counter_.get(i);
if (counter != 0) {
- statistics_string << ", \"" << QRCounterItemName[i] << "\": "
- << counter;
+ statistics_string << ", \"" << "opcode." <<
+ QRCounterOpcode[i - QR_OPCODE_QUERY].name <<
+ "\": " << counter;
}
}
// Insert non 0 Rcode counters.
for (int i = QR_RCODE_NOERROR; i <= QR_RCODE_OTHER; ++i) {
const Counter::Type counter = server_qr_counter_.get(i);
if (counter != 0) {
- statistics_string << ", \"" << QRCounterItemName[i] << "\": "
- << counter;
+ statistics_string << ", \"" << "rcode." <<
+ QRCounterRcode[i - QR_RCODE_NOERROR].name <<
+ "\": " << counter;
}
}
statistics_string << "}";
for (int i = 0; i < 6; ++i) {
// The counter should be initialized to 0.
expectCounterItem(server.getStatistics(),
- QRCounterItemName[QROpCodeToQRCounterType[i]], 0);
+ std::string("opcode.") +
+ QRCounterOpcode[QROpCodeToQRCounterType[i] -
+ QR_OPCODE_QUERY].name,
+ 0);
// For each possible opcode, create a request message and send it
UnitTestUtil::createRequestMessage(request_message, Opcode(i),
// Confirm the counter.
expectCounterItem(server.getStatistics(),
- QRCounterItemName[QROpCodeToQRCounterType[i]],
+ std::string("opcode.") +
+ QRCounterOpcode[QROpCodeToQRCounterType[i] -
+ QR_OPCODE_QUERY].name,
i + 1);
}
// Check for 6..15
for (int i = 6; i < 16; ++i) {
// The counter should be initialized to 0.
expectCounterItem(server.getStatistics(),
- QRCounterItemName[QROpCodeToQRCounterType[i]],
+ std::string("opcode.") +
+ QRCounterOpcode[QROpCodeToQRCounterType[i] -
+ QR_OPCODE_QUERY].name,
expected);
// For each possible opcode, create a request message and send it
// Confirm the counter.
expectCounterItem(server.getStatistics(),
- QRCounterItemName[QROpCodeToQRCounterType[i]],
+ std::string("opcode.") +
+ QRCounterOpcode[QROpCodeToQRCounterType[i] -
+ QR_OPCODE_QUERY].name,
expected);
}
}
checkCountersAllZeroExcept(counters.getStatistics(), expect_nonzero);
}
-TEST_F(CountersTest, getStatistics) {
- std::map<std::string, ConstElementPtr> stats_map =
- counters.getStatistics()->mapValue();
- for (std::map<std::string, ConstElementPtr>::const_iterator
- i = stats_map.begin(), e = stats_map.end();
- i != e;
- ++i)
- {
- // item type check
- EXPECT_NO_THROW(i->second->intValue())
- << "Item " << i->first << " is not IntElement";
- }
-}
-
-TEST_F(AuthCountersTest, 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,
- 0, 0, 0, 0, 0, 0, 0, 0 };
- updateOpcodeCounters(counters, opcode_results);
- ConstElementPtr statistics_data = counters.getStatistics();
- opcodeDataCheck(statistics_data, opcode_results);
-}
-
-TEST_F(AuthCountersTest, 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,
- 1, 1, 1, 1, 1, 1, 1, 1 };
- updateOpcodeCounters(counters, opcode_results);
- ConstElementPtr statistics_data = counters.getStatistics();
- opcodeDataCheck(statistics_data, opcode_results);
-}
-
-TEST_F(AuthCountersTest, 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,
- 10, 0, 0, 0, 0, 0, 0, 11 };
- updateRcodeCounters(counters, rcode_results);
- ConstElementPtr statistics_data = counters.getStatistics();
- rcodeDataCheck(statistics_data, rcode_results);
-}
-
-TEST_F(AuthCountersTest, 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,
- 1, 1, 1, 1, 1, 1, 1, 1 };
- updateOpcodeCounters(counters, rcode_results);
- ConstElementPtr statistics_data = counters.getStatistics();
- opcodeDataCheck(statistics_data, rcode_results);
-}
-
-TEST_F(AuthCountersTest, getStatisticsWithValidator) {
-
- //a validator for the unittest
- AuthCounters::validator_type validator;
- ConstElementPtr el;
-
- // Get statistics data with correct statistics validator.
- validator = boost::bind(
- &AuthCountersTest::MockModuleSpec::validateStatistics,
- &module_spec_, _1, true);
-
- EXPECT_TRUE(validator(el));
-
- // register validator to AuthCounters
- 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));
-
- // UDP query counter is set to 2.
- counters.inc(AuthCounters::SERVER_UDP_QUERY);
- counters.inc(AuthCounters::SERVER_UDP_QUERY);
- // TCP query counter is set to 1.
- counters.inc(AuthCounters::SERVER_TCP_QUERY);
-
- // checks the value returned by getStatistics
- ConstElementPtr statistics_data = counters.getStatistics();
-
- // UDP query counter is 2 and TCP query counter is 1.
- EXPECT_EQ(2, statistics_data->get("queries.udp")->intValue());
- EXPECT_EQ(1, statistics_data->get("queries.tcp")->intValue());
-
- // Get statistics data with incorrect statistics validator.
- validator = boost::bind(
- &AuthCountersTest::MockModuleSpec::validateStatistics,
- &module_spec_, _1, false);
-
- EXPECT_FALSE(validator(el));
-
- counters.registerStatisticsValidator(validator);
-
- // checks the value returned by getStatistics
- EXPECT_FALSE(counters.getStatistics());
-}
-
int
countTreeElements(const struct CounterTypeTree* tree) {
int count = 0;