Commit 02e0859b authored by Michal 'vorner' Vaner's avatar Michal 'vorner' Vaner
Browse files

[2862] Auxiliary function to get list of classes

parent d26eac8d
...@@ -212,6 +212,24 @@ public: ...@@ -212,6 +212,24 @@ public:
return (it->second); return (it->second);
} }
} }
/// \brief Return list of classes that are present.
///
/// Get the list of classes for which there's a client list. It is
/// returned in form of a vector, copied from the internals. As the
/// number of classes in there is expected to be small, it is not
/// a performance issue.
///
/// \return The list of classes.
/// \throw std::bad_alloc for problems allocating the result.
std::vector<dns::RRClass> getClasses() const {
std::vector<dns::RRClass> result;
for (ClientListsMap::const_iterator it =
mgr_.clients_map_->begin(); it != mgr_.clients_map_->end();
++it) {
result.push_back(it->first);
}
return (result);
}
private: private:
DataSrcClientsMgrBase& mgr_; DataSrcClientsMgrBase& mgr_;
typename MutexType::Locker locker_; typename MutexType::Locker locker_;
......
...@@ -156,6 +156,7 @@ TEST(DataSrcClientsMgrTest, holder) { ...@@ -156,6 +156,7 @@ TEST(DataSrcClientsMgrTest, holder) {
TestDataSrcClientsMgr::Holder holder(mgr); TestDataSrcClientsMgr::Holder holder(mgr);
EXPECT_FALSE(holder.findClientList(RRClass::IN())); EXPECT_FALSE(holder.findClientList(RRClass::IN()));
EXPECT_FALSE(holder.findClientList(RRClass::CH())); EXPECT_FALSE(holder.findClientList(RRClass::CH()));
EXPECT_TRUE(holder.getClasses().empty());
// map should be protected here // map should be protected here
EXPECT_EQ(1, FakeDataSrcClientsBuilder::map_mutex->lock_count); EXPECT_EQ(1, FakeDataSrcClientsBuilder::map_mutex->lock_count);
EXPECT_EQ(0, FakeDataSrcClientsBuilder::map_mutex->unlock_count); EXPECT_EQ(0, FakeDataSrcClientsBuilder::map_mutex->unlock_count);
...@@ -174,6 +175,7 @@ TEST(DataSrcClientsMgrTest, holder) { ...@@ -174,6 +175,7 @@ TEST(DataSrcClientsMgrTest, holder) {
TestDataSrcClientsMgr::Holder holder(mgr); TestDataSrcClientsMgr::Holder holder(mgr);
EXPECT_TRUE(holder.findClientList(RRClass::IN())); EXPECT_TRUE(holder.findClientList(RRClass::IN()));
EXPECT_TRUE(holder.findClientList(RRClass::CH())); EXPECT_TRUE(holder.findClientList(RRClass::CH()));
EXPECT_EQ(2, holder.getClasses().size());
} }
// We need to clear command queue by hand // We need to clear command queue by hand
FakeDataSrcClientsBuilder::command_queue->clear(); FakeDataSrcClientsBuilder::command_queue->clear();
...@@ -188,6 +190,7 @@ TEST(DataSrcClientsMgrTest, holder) { ...@@ -188,6 +190,7 @@ TEST(DataSrcClientsMgrTest, holder) {
TestDataSrcClientsMgr::Holder holder(mgr); TestDataSrcClientsMgr::Holder holder(mgr);
EXPECT_TRUE(holder.findClientList(RRClass::IN())); EXPECT_TRUE(holder.findClientList(RRClass::IN()));
EXPECT_FALSE(holder.findClientList(RRClass::CH())); EXPECT_FALSE(holder.findClientList(RRClass::CH()));
EXPECT_EQ(RRClass::IN(), holder.getClasses()[0]);
} }
// Duplicate lock acquisition is prohibited (only test mgr can detect // Duplicate lock acquisition is prohibited (only test mgr can detect
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment