Commit 9cb41a2f authored by Mukund Sivaraman's avatar Mukund Sivaraman
Browse files

[2432] Throw during addRRset() if an rrset with the given class, type and name already exists

parent 73834570
......@@ -16,8 +16,12 @@
#include <dns/master_loader_callbacks.h>
#include <dns/master_loader.h>
#include <exceptions/exceptions.h>
#include <boost/bind.hpp>
using namespace isc;
namespace isc {
namespace dns {
......@@ -41,6 +45,13 @@ void
RRsetCollection::addRRset(RRsetPtr rrset) {
const CollectionKey key(rrset->getClass(), rrset->getType(),
rrset->getName());
CollectionMap::const_iterator it = rrsets_.find(key);
if (it != rrsets_.end()) {
isc_throw(InvalidParameter,
"RRset for " << rrset->getName() << "/" << rrset->getClass()
<< " with type " << rrset->getType() << " already exists");
}
rrsets_.insert(std::pair<CollectionKey, RRsetPtr>(key, rrset));
}
......
......@@ -50,7 +50,9 @@ public:
/// \brief Add an RRset to the collection.
///
/// Does not do any validation whether \c rrset belongs to a
/// particular zone or not.
/// particular zone or not. It throws an \c isc::InvalidParameter
/// exception if an rrset with the same class, type and name already
/// exists.
void addRRset(isc::dns::RRsetPtr rrset);
/// \brief Remove an RRset from the collection.
......
......@@ -129,6 +129,11 @@ doAddAndRemove(RRsetCollection& collection, const RRClass& rrclass) {
// The collection must not be empty.
EXPECT_NE(collection.end(), collection.begin());
// Adding a duplicate RRset must throw.
EXPECT_THROW({
collection.addRRset(rrset);
}, isc::InvalidParameter);
// Remove foo.example.org/A
collection.removeRRset(Name("foo.example.org"), rrclass, RRType::A());
......
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