Commit 755cd222 authored by Jelte Jansen's avatar Jelte Jansen
Browse files

[1384] update memory_datasrc to use separate_rrs as well

parent 5720f226
......@@ -729,10 +729,14 @@ private:
Domain::const_iterator dom_iterator_;
const DomainTree& tree_;
const DomainNode* node_;
// Only used when separate_rrs_ is true
RdataIteratorPtr rdata_iterator_;
bool separate_rrs_;
bool ready_;
public:
MemoryIterator(const DomainTree& tree, const Name& origin) :
MemoryIterator(const DomainTree& tree, const Name& origin, bool separate_rrs) :
tree_(tree),
separate_rrs_(separate_rrs),
ready_(true)
{
// Find the first node (origin) and preserve the node chain for future
......@@ -747,6 +751,12 @@ public:
// Initialize the iterator if there's somewhere to point to
if (node_ != NULL && node_->getData() != DomainPtr()) {
dom_iterator_ = node_->getData()->begin();
if (separate_rrs_) {
std::cout << "[XX] SET RDATA ITERATOR A" << std::endl;
if (dom_iterator_->second != NULL) {
rdata_iterator_ = dom_iterator_->second->getRdataIterator();
}
}
}
}
......@@ -766,6 +776,10 @@ public:
// if the map is empty or not
if (node_ != NULL && node_->getData() != NULL) {
dom_iterator_ = node_->getData()->begin();
// New RRset, so get a new rdata iterator
if (separate_rrs_) {
rdata_iterator_ = dom_iterator_->second->getRdataIterator();
}
}
}
if (node_ == NULL) {
......@@ -773,12 +787,35 @@ public:
ready_ = false;
return (ConstRRsetPtr());
}
// The iterator points to the next yet unused RRset now
ConstRRsetPtr result(dom_iterator_->second);
// This one is used, move it to the next time for next call
++dom_iterator_;
return (result);
if (separate_rrs_) {
// For separate rrs, reconstruct a new RRset with just the
// 'current' rdata
RRsetPtr result(new RRset(dom_iterator_->second->getName(),
dom_iterator_->second->getClass(),
dom_iterator_->second->getType(),
dom_iterator_->second->getTTL()));
result->addRdata(rdata_iterator_->getCurrent());
rdata_iterator_->next();
if (rdata_iterator_->isLast()) {
// all used up, next.
++dom_iterator_;
// New RRset, so get a new rdata iterator, but only if this
// was not the final RRset in the chain
if (dom_iterator_ != node_->getData()->end()) {
rdata_iterator_ = dom_iterator_->second->getRdataIterator();
}
}
return (result);
} else {
// The iterator points to the next yet unused RRset now
ConstRRsetPtr result(dom_iterator_->second);
// This one is used, move it to the next time for next call
++dom_iterator_;
return (result);
}
}
virtual ConstRRsetPtr getSOA() const {
......@@ -789,7 +826,7 @@ public:
} // End of anonymous namespace
ZoneIteratorPtr
InMemoryClient::getIterator(const Name& name, bool) const {
InMemoryClient::getIterator(const Name& name, bool separate_rrs) const {
// note: adjust_ttl argument is ignored, as the RRsets are already
// individually stored, and hence cannot have different TTLs anymore at
// this point
......@@ -811,7 +848,8 @@ InMemoryClient::getIterator(const Name& name, bool) const {
isc_throw(Unexpected, "The zone at " + name.toText() +
" is not InMemoryZoneFinder");
}
return (ZoneIteratorPtr(new MemoryIterator(zone->impl_->domains_, name)));
return (ZoneIteratorPtr(new MemoryIterator(zone->impl_->domains_, name,
separate_rrs)));
}
ZoneUpdaterPtr
......
......@@ -177,6 +177,54 @@ TEST_F(InMemoryClientTest, iterator) {
EXPECT_EQ(ConstRRsetPtr(), iterator->getNextRRset());
}
TEST_F(InMemoryClientTest, iterator_separate_rrs) {
// Exactly the same tests as for iterator, but now with separate_rrs = true
// For the one that returns actual data, the AAAA should now be split up
boost::shared_ptr<InMemoryZoneFinder>
zone(new InMemoryZoneFinder(RRClass::IN(), Name("a")));
RRsetPtr aRRsetA(new RRset(Name("a"), RRClass::IN(), RRType::A(),
RRTTL(300)));
aRRsetA->addRdata(rdata::in::A("192.0.2.1"));
RRsetPtr aRRsetAAAA(new RRset(Name("a"), RRClass::IN(), RRType::AAAA(),
RRTTL(300)));
aRRsetAAAA->addRdata(rdata::in::AAAA("2001:db8::1"));
aRRsetAAAA->addRdata(rdata::in::AAAA("2001:db8::2"));
RRsetPtr aRRsetAAAA_r1(new RRset(Name("a"), RRClass::IN(), RRType::AAAA(),
RRTTL(300)));
aRRsetAAAA_r1->addRdata(rdata::in::AAAA("2001:db8::1"));
RRsetPtr aRRsetAAAA_r2(new RRset(Name("a"), RRClass::IN(), RRType::AAAA(),
RRTTL(300)));
aRRsetAAAA_r2->addRdata(rdata::in::AAAA("2001:db8::2"));
RRsetPtr subRRsetA(new RRset(Name("sub.x.a"), RRClass::IN(), RRType::A(),
RRTTL(300)));
subRRsetA->addRdata(rdata::in::A("192.0.2.2"));
EXPECT_EQ(result::SUCCESS, memory_client.addZone(zone));
// First, the zone is not there, so it should throw
EXPECT_THROW(memory_client.getIterator(Name("b"), true), DataSourceError);
// This zone is not there either, even when there's a zone containing this
EXPECT_THROW(memory_client.getIterator(Name("x.a")), DataSourceError);
// Now, an empty zone
ZoneIteratorPtr iterator(memory_client.getIterator(Name("a"), true));
EXPECT_EQ(ConstRRsetPtr(), iterator->getNextRRset());
// It throws Unexpected when we are past the end
EXPECT_THROW(iterator->getNextRRset(), isc::Unexpected);
ASSERT_EQ(result::SUCCESS, zone->add(aRRsetA));
ASSERT_EQ(result::SUCCESS, zone->add(aRRsetAAAA));
ASSERT_EQ(result::SUCCESS, zone->add(subRRsetA));
// Check it with full zone, one by one.
// It should be in ascending order in case of InMemory data source
// (isn't guaranteed in general)
iterator = memory_client.getIterator(Name("a"), true);
EXPECT_EQ(aRRsetA->toText(), iterator->getNextRRset()->toText());
EXPECT_EQ(aRRsetAAAA_r1->toText(), iterator->getNextRRset()->toText());
EXPECT_EQ(aRRsetAAAA_r2->toText(), iterator->getNextRRset()->toText());
EXPECT_EQ(subRRsetA->toText(), iterator->getNextRRset()->toText());
EXPECT_EQ(ConstRRsetPtr(), iterator->getNextRRset());
}
TEST_F(InMemoryClientTest, getZoneCount) {
EXPECT_EQ(0, memory_client.getZoneCount());
memory_client.addZone(
......
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