Commit 8c3f8ac2 authored by Marcin Siodelski's avatar Marcin Siodelski

[#716,!412] StampedElement stores server tags in a set rather that vector.

parent e3395f1f
......@@ -683,7 +683,7 @@ TEST_F(MySqlConfigBackendDHCPv6Test, createUpdateDeleteGlobalParameter6) {
EXPECT_TRUE(returned_global_parameter->getModificationTime() ==
global_parameter->getModificationTime());
ASSERT_EQ(1, returned_global_parameter->getServerTags().size());
EXPECT_EQ("all", returned_global_parameter->getServerTags()[0].get());
EXPECT_EQ("all", returned_global_parameter->getServerTags().begin()->get());
// Because we have added the global parameter for all servers, it
// should be also returned for the explicitly specified server.
......@@ -695,7 +695,7 @@ TEST_F(MySqlConfigBackendDHCPv6Test, createUpdateDeleteGlobalParameter6) {
EXPECT_TRUE(returned_global_parameter->getModificationTime() ==
global_parameter->getModificationTime());
ASSERT_EQ(1, returned_global_parameter->getServerTags().size());
EXPECT_EQ("all", returned_global_parameter->getServerTags()[0].get());
EXPECT_EQ("all", returned_global_parameter->getServerTags().begin()->get());
// Check that the parameter is updated when selector is specified correctly.
global_parameter = StampedValue::create("global", "fish");
......@@ -815,7 +815,7 @@ TEST_F(MySqlConfigBackendDHCPv6Test, globalParameters6WithServerTags) {
ASSERT_TRUE(returned_global);
EXPECT_EQ(global_parameter3->getValue(), returned_global->getValue());
ASSERT_EQ(1, returned_global->getServerTags().size());
EXPECT_EQ("all", returned_global->getServerTags()[0].get());
EXPECT_EQ("all", returned_global->getServerTags().begin()->get());
// Try to fetch the value specified for the server1. This should override the
// value specified for all servers.
......@@ -827,7 +827,7 @@ TEST_F(MySqlConfigBackendDHCPv6Test, globalParameters6WithServerTags) {
EXPECT_EQ(global_parameter1->getValue(), returned_global->getValue());
ASSERT_EQ(1, returned_global->getServerTags().size());
EXPECT_EQ("server1", returned_global->getServerTags()[0].get());
EXPECT_EQ("server1", returned_global->getServerTags().begin()->get());
// The same in case of the server2.
EXPECT_NO_THROW(
......@@ -837,7 +837,7 @@ TEST_F(MySqlConfigBackendDHCPv6Test, globalParameters6WithServerTags) {
ASSERT_TRUE(returned_global);
EXPECT_EQ(global_parameter2->getValue(), returned_global->getValue());
ASSERT_EQ(1, returned_global->getServerTags().size());
EXPECT_EQ("server2", returned_global->getServerTags()[0].get());
EXPECT_EQ("server2", returned_global->getServerTags().begin()->get());
StampedValueCollection returned_globals;
......@@ -856,7 +856,7 @@ TEST_F(MySqlConfigBackendDHCPv6Test, globalParameters6WithServerTags) {
std::map<std::string, std::string> values;
for (auto g = returned_globals.begin(); g != returned_globals.end(); ++g) {
ASSERT_EQ(1, (*g)->getServerTags().size());
values[(*g)->getServerTags()[0].get()] = ((*g)->getValue());
values[(*g)->getServerTags().begin()->get()] = ((*g)->getValue());
}
ASSERT_EQ(3, values.size());
......@@ -874,7 +874,7 @@ TEST_F(MySqlConfigBackendDHCPv6Test, globalParameters6WithServerTags) {
returned_global = *returned_globals.begin();
EXPECT_EQ(global_parameter3->getValue(), returned_global->getValue());
ASSERT_EQ(1, returned_global->getServerTags().size());
EXPECT_EQ("all", returned_global->getServerTags()[0].get());
EXPECT_EQ("all", returned_global->getServerTags().begin()->get());
// Delete the server1. It should remove associations of this server with the
// global parameter and the global parameter itself.
......@@ -889,7 +889,7 @@ TEST_F(MySqlConfigBackendDHCPv6Test, globalParameters6WithServerTags) {
// the server1 specific value with the server1 should be gone.
EXPECT_EQ(global_parameter3->getValue(), returned_global->getValue());
ASSERT_EQ(1, returned_global->getServerTags().size());
EXPECT_EQ("all", returned_global->getServerTags()[0].get());
EXPECT_EQ("all", returned_global->getServerTags().begin()->get());
{
SCOPED_TRACE("DELETE audit entry for the global parameter after server deletion");
......@@ -931,7 +931,7 @@ TEST_F(MySqlConfigBackendDHCPv6Test, globalParameters6WithServerTags) {
// logical server should not be deleted.
EXPECT_EQ(global_parameter3->getValue(), returned_global->getValue());
ASSERT_EQ(1, returned_global->getServerTags().size());
EXPECT_EQ("all", returned_global->getServerTags()[0].get());
EXPECT_EQ("all", returned_global->getServerTags().begin()->get());
{
SCOPED_TRACE("DELETE audit entry for the global parameter after deletion of"
......@@ -969,7 +969,7 @@ TEST_F(MySqlConfigBackendDHCPv6Test, getAllGlobalParameters6) {
for (auto param = parameters_index.begin(); param != parameters_index.end();
++param) {
ASSERT_EQ(1, (*param)->getServerTags().size());
EXPECT_EQ("all", (*param)->getServerTags()[0].get());
EXPECT_EQ("all", (*param)->getServerTags().begin()->get());
}
// Verify their values.
......@@ -1046,7 +1046,7 @@ TEST_F(MySqlConfigBackendDHCPv6Test, getSubnet6) {
test_subnets_[0]->getID());
ASSERT_TRUE(returned_subnet);
ASSERT_EQ(1, returned_subnet->getServerTags().size());
EXPECT_EQ("all", returned_subnet->getServerTags()[0].get());
EXPECT_EQ("all", returned_subnet->getServerTags().begin()->get());
// The easiest way to verify whether the returned subnet matches the inserted
// subnet is to convert both to text.
......@@ -1190,7 +1190,7 @@ TEST_F(MySqlConfigBackendDHCPv6Test, getSubnet6SharedNetwork) {
test_subnets_[0]->getID());
ASSERT_TRUE(returned_subnet);
ASSERT_EQ(1, returned_subnet->getServerTags().size());
EXPECT_EQ("all", returned_subnet->getServerTags()[0].get());
EXPECT_EQ("all", returned_subnet->getServerTags().begin()->get());
// The easiest way to verify whether the returned subnet matches the inserted
// subnet is to convert both to text.
......@@ -1212,7 +1212,7 @@ TEST_F(MySqlConfigBackendDHCPv6Test, getSubnet6ByPrefix) {
"2001:db8::/64");
ASSERT_TRUE(returned_subnet);
ASSERT_EQ(1, returned_subnet->getServerTags().size());
EXPECT_EQ("all", returned_subnet->getServerTags()[0].get());
EXPECT_EQ("all", returned_subnet->getServerTags().begin()->get());
// Verify subnet contents.
EXPECT_EQ(subnet->toElement()->str(), returned_subnet->toElement()->str());
......@@ -1260,7 +1260,7 @@ TEST_F(MySqlConfigBackendDHCPv6Test, getAllSubnets6) {
EXPECT_EQ(test_subnets_[i + 1]->toElement()->str(),
subnets[i]->toElement()->str());
ASSERT_EQ(1, subnets[i]->getServerTags().size());
EXPECT_EQ("all", subnets[i]->getServerTags()[0].get());
EXPECT_EQ("all", subnets[i]->getServerTags().begin()->get());
}
// Attempt to remove the non existing subnet should return 0.
......@@ -1488,7 +1488,7 @@ TEST_F(MySqlConfigBackendDHCPv6Test, getSharedNetwork6) {
EXPECT_GT(network->getId(), 0);
ASSERT_EQ(1, network->getServerTags().size());
EXPECT_EQ(expected_tag, network->getServerTags()[0].get());
EXPECT_EQ(expected_tag, network->getServerTags().begin()->get());
// The easiest way to verify whether the returned shared network matches the
// inserted shared network is to convert both to text.
......@@ -1727,7 +1727,7 @@ TEST_F(MySqlConfigBackendDHCPv6Test, getAllSharedNetworks6) {
EXPECT_EQ(test_networks_[i + 1]->toElement()->str(),
networks[i]->toElement()->str());
ASSERT_EQ(1, networks[i]->getServerTags().size());
EXPECT_EQ("all", networks[i]->getServerTags()[0].get());
EXPECT_EQ("all", networks[i]->getServerTags().begin()->get());
}
// Add some subnets.
......@@ -2219,7 +2219,7 @@ TEST_F(MySqlConfigBackendDHCPv6Test, getOptionDef6) {
ASSERT_TRUE(returned_option_def);
EXPECT_GT(returned_option_def->getId(), 0);
ASSERT_EQ(1, returned_option_def->getServerTags().size());
EXPECT_EQ("all", returned_option_def->getServerTags()[0].get());
EXPECT_EQ("all", returned_option_def->getServerTags().begin()->get());
EXPECT_TRUE(returned_option_def->equals(*option_def));
......@@ -2485,7 +2485,7 @@ TEST_F(MySqlConfigBackendDHCPv6Test, getAllOptionDefs6) {
// See if option definitions are returned ok.
for (auto def = option_defs.begin(); def != option_defs.end(); ++def) {
ASSERT_EQ(1, (*def)->getServerTags().size());
EXPECT_EQ("all", (*def)->getServerTags()[0].get());
EXPECT_EQ("all", (*def)->getServerTags().begin()->get());
bool success = false;
for (auto i = 1; i < test_option_defs_.size(); ++i) {
if ((*def)->equals(*test_option_defs_[i])) {
......@@ -2868,7 +2868,7 @@ TEST_F(MySqlConfigBackendDHCPv6Test, getAllOptions6) {
testOptionsEquivalent(*test_options_[0], *option0);
EXPECT_GT(option0->getId(), 0);
ASSERT_EQ(1, option0->getServerTags().size());
EXPECT_EQ("all", option0->getServerTags()[0].get());
EXPECT_EQ("all", option0->getServerTags().begin()->get());
}
{
......@@ -2878,7 +2878,7 @@ TEST_F(MySqlConfigBackendDHCPv6Test, getAllOptions6) {
testOptionsEquivalent(*test_options_[1], *option1);
EXPECT_GT(option1->getId(), 0);
ASSERT_EQ(1, option1->getServerTags().size());
EXPECT_EQ("all", option1->getServerTags()[0].get());
EXPECT_EQ("all", option1->getServerTags().begin()->get());
}
{
......@@ -2888,7 +2888,7 @@ TEST_F(MySqlConfigBackendDHCPv6Test, getAllOptions6) {
testOptionsEquivalent(*test_options_[5], *option5);
EXPECT_GT(option5->getId(), 0);
ASSERT_EQ(1, option5->getServerTags().size());
EXPECT_EQ("all", option5->getServerTags()[0].get());
EXPECT_EQ("all", option5->getServerTags().begin()->get());
}
}
......
......@@ -15,23 +15,14 @@ StampedElement::StampedElement()
bool
StampedElement::hasServerTag(const ServerTag& server_tag) const {
for (auto tag : server_tags_) {
if (tag.get() == server_tag.get()) {
return (true);
}
}
return (false);
return (server_tags_.count(server_tag) > 0);
}
void
StampedElement::delServerTag(const std::string& server_tag) {
for (auto it = server_tags_.begin(); it < server_tags_.end(); ++it) {
if (it->get() == server_tag) {
server_tags_.erase(it);
return;
}
if (!server_tags_.erase(ServerTag(server_tag))) {
isc_throw(NotFound, "can't find server tag '" << server_tag << "' to delete");
}
isc_throw(NotFound, "can't find server tag '" << server_tag << "' to delete");
}
bool
......
......@@ -9,7 +9,7 @@
#include <cc/base_stamped_element.h>
#include <cc/server_tag.h>
#include <vector>
#include <set>
namespace isc {
namespace data {
......@@ -44,7 +44,7 @@ public:
/// @param server_tag new server tag.
/// @throw BadValue if the server tag length exceeds 256 characters.
void setServerTag(const std::string& server_tag) {
server_tags_.push_back(ServerTag(server_tag));
server_tags_.insert(ServerTag(server_tag));
}
/// @brief Deletes server tag.
......@@ -57,8 +57,8 @@ public:
/// @brief Returns server tags.
///
/// @return Server tag as string.
std::vector<ServerTag> getServerTags() const {
/// @return Server tags.
std::set<ServerTag> getServerTags() const {
return (server_tags_);
}
......@@ -82,7 +82,7 @@ public:
private:
/// @brief Holds server tags.
std::vector<ServerTag> server_tags_;
std::set<ServerTag> server_tags_;
};
} // end of namespace isc::data
......
......@@ -75,12 +75,10 @@ TEST(StampedElementTest, setServerTag) {
StampedElement element;
element.setServerTag("foo");
EXPECT_EQ(1, element.getServerTags().size());
EXPECT_EQ("foo", element.getServerTags()[0].get());
EXPECT_EQ("foo", element.getServerTags().begin()->get());
element.setServerTag("bar");
EXPECT_EQ(2, element.getServerTags().size());
EXPECT_EQ("foo", element.getServerTags()[0].get());
EXPECT_EQ("bar", element.getServerTags()[1].get());
EXPECT_TRUE(element.hasServerTag(ServerTag("foo")));
EXPECT_TRUE(element.hasServerTag(ServerTag("bar")));
......@@ -96,18 +94,19 @@ TEST(StampedElementTest, delServerTag) {
StampedElement element;
EXPECT_THROW(element.delServerTag("foo"), isc::NotFound);
element.setServerTag("foo");
element.setServerTag("foo");
element.setServerTag("bar");
ASSERT_EQ(2, element.getServerTags().size());
EXPECT_EQ("foo", element.getServerTags()[0].get());
EXPECT_EQ("foo", element.getServerTags()[1].get());
EXPECT_TRUE(element.hasServerTag(ServerTag("foo")));
EXPECT_TRUE(element.hasServerTag(ServerTag("bar")));
EXPECT_NO_THROW(element.delServerTag("foo"));
ASSERT_EQ(1, element.getServerTags().size());
EXPECT_EQ("foo", element.getServerTags()[0].get());
EXPECT_TRUE(element.hasServerTag(ServerTag("bar")));
EXPECT_NO_THROW(element.delServerTag("foo"));
EXPECT_NO_THROW(element.delServerTag("bar"));
EXPECT_EQ(0, element.getServerTags().size());
EXPECT_THROW(element.delServerTag("foo"), isc::NotFound);
EXPECT_THROW(element.delServerTag("bar"), isc::NotFound);
}
......
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