BIND 10 trac2108_3, updated. dd5485e6973a8ebc6fc99727ac3bc8903c8fce3b [2108] Add unittest for load() which accepts an iterator

BIND 10 source code commits bind10-changes at lists.isc.org
Mon Sep 10 07:23:56 UTC 2012


The branch, trac2108_3 has been updated
       via  dd5485e6973a8ebc6fc99727ac3bc8903c8fce3b (commit)
       via  4171ba94fead572dbc4de66f9a35380680d55fa7 (commit)
       via  8716a098a9205bf1aeae4dd61d7c2e4fb4956c47 (commit)
      from  eb66b3c19f083d918a536b422376217851896d0f (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit dd5485e6973a8ebc6fc99727ac3bc8903c8fce3b
Author: Mukund Sivaraman <muks at isc.org>
Date:   Mon Sep 10 12:53:39 2012 +0530

    [2108] Add unittest for load() which accepts an iterator

commit 4171ba94fead572dbc4de66f9a35380680d55fa7
Author: Mukund Sivaraman <muks at isc.org>
Date:   Mon Sep 10 12:43:10 2012 +0530

    [2108] Wrap lines

commit 8716a098a9205bf1aeae4dd61d7c2e4fb4956c47
Author: Mukund Sivaraman <muks at isc.org>
Date:   Mon Sep 10 12:08:06 2012 +0530

    [2108] Add unique prefix to datasrc::memory message IDs

-----------------------------------------------------------------------

Summary of changes:
 src/lib/datasrc/memory/memory_client.cc            |   34 +++++-----
 src/lib/datasrc/memory/memory_messages.mes         |   30 ++++-----
 .../datasrc/memory/tests/memory_client_unittest.cc |   69 ++++++++++++++++++++
 3 files changed, 103 insertions(+), 30 deletions(-)

-----------------------------------------------------------------------
diff --git a/src/lib/datasrc/memory/memory_client.cc b/src/lib/datasrc/memory/memory_client.cc
index e21fd48..7758e3c 100644
--- a/src/lib/datasrc/memory/memory_client.cc
+++ b/src/lib/datasrc/memory/memory_client.cc
@@ -147,8 +147,8 @@ public:
              l > origin_labels;
              --l, wname = wname.split(1)) {
             if (wname.isWildcard()) {
-                LOG_DEBUG(logger, DBG_TRACE_DATA, DATASRC_MEM_ADD_WILDCARD).
-                    arg(name);
+                LOG_DEBUG(logger, DBG_TRACE_DATA,
+                          DATASRC_MEMORY_MEM_ADD_WILDCARD).arg(name);
 
                 // Ensure a separate level exists for the "wildcarding" name,
                 // and mark the node as "wild".
@@ -180,7 +180,7 @@ public:
         if (rrset.getType() == RRType::CNAME()) {
             for (const RdataSet* sp = set; sp != NULL; sp = sp->getNext()) {
                 if (sp->type != RRType::NSEC()) {
-                    LOG_ERROR(logger, DATASRC_MEM_CNAME_TO_NONEMPTY).
+                    LOG_ERROR(logger, DATASRC_MEMORY_MEM_CNAME_TO_NONEMPTY).
                         arg(rrset.getName());
                     isc_throw(AddError, "CNAME can't be added with "
                               << sp->type << " RRType for "
@@ -189,7 +189,8 @@ public:
             }
         } else if ((rrset.getType() != RRType::NSEC()) &&
                    (RdataSet::find(set, RRType::CNAME()) != NULL)) {
-            LOG_ERROR(logger, DATASRC_MEM_CNAME_COEXIST).arg(rrset.getName());
+            LOG_ERROR(logger,
+                      DATASRC_MEMORY_MEM_CNAME_COEXIST).arg(rrset.getName());
             isc_throw(AddError, "CNAME and " << rrset.getType() <<
                       " can't coexist for " << rrset.getName());
         }
@@ -207,7 +208,7 @@ public:
             (rrset.getType() == RRType::NS() &&
              RdataSet::find(set, RRType::DNAME()) != NULL)))
         {
-            LOG_ERROR(logger, DATASRC_MEM_DNAME_NS).arg(rrset.getName());
+            LOG_ERROR(logger, DATASRC_MEMORY_MEM_DNAME_NS).arg(rrset.getName());
             isc_throw(AddError, "DNAME can't coexist with NS in non-apex "
                 "domain " << rrset.getName());
         }
@@ -233,7 +234,8 @@ public:
             // XXX: this is not only for CNAME or DNAME. We should generalize
             // this code for all other "singleton RR types" (such as SOA) in a
             // separate task.
-            LOG_ERROR(logger, DATASRC_MEM_SINGLETON).arg(rrset->getName()).
+            LOG_ERROR(logger,
+                      DATASRC_MEMORY_MEM_SINGLETON).arg(rrset->getName()).
                 arg(rrset->getType());
             isc_throw(AddError, "multiple RRs of singleton type for "
                       << rrset->getName());
@@ -251,7 +253,8 @@ public:
         if (compare.getRelation() != NameComparisonResult::SUPERDOMAIN &&
             compare.getRelation() != NameComparisonResult::EQUAL)
         {
-            LOG_ERROR(logger, DATASRC_MEM_OUT_OF_ZONE).arg(rrset->getName()).
+            LOG_ERROR(logger,
+                      DATASRC_MEMORY_MEM_OUT_OF_ZONE).arg(rrset->getName()).
                 arg(zone_name);
             isc_throw(OutOfZone, "The name " << rrset->getName() <<
                 " is not contained in zone " << zone_name);
@@ -267,13 +270,13 @@ public:
         // behavior.
         if (rrset->getName().isWildcard()) {
             if (rrset->getType() == RRType::NS()) {
-                LOG_ERROR(logger, DATASRC_MEM_WILDCARD_NS).
+                LOG_ERROR(logger, DATASRC_MEMORY_MEM_WILDCARD_NS).
                     arg(rrset->getName());
                 isc_throw(AddError, "Invalid NS owner name (wildcard): " <<
                           rrset->getName());
             }
             if (rrset->getType() == RRType::DNAME()) {
-                LOG_ERROR(logger, DATASRC_MEM_WILDCARD_DNAME).
+                LOG_ERROR(logger, DATASRC_MEMORY_MEM_WILDCARD_DNAME).
                     arg(rrset->getName());
                 isc_throw(AddError, "Invalid DNAME owner name (wildcard): " <<
                           rrset->getName());
@@ -289,7 +292,7 @@ public:
             (rrset->getName().isWildcard() ||
              rrset->getName().getLabelCount() !=
              zone_name.getLabelCount() + 1)) {
-            LOG_ERROR(logger, DATASRC_BAD_NSEC3_NAME).
+            LOG_ERROR(logger, DATASRC_MEMORY_BAD_NSEC3_NAME).
                 arg(rrset->getName());
             isc_throw(AddError, "Invalid NSEC3 owner name: " <<
                       rrset->getName());
@@ -498,7 +501,7 @@ public:
         addValidation(zone_name, rrset);
 
         // OK, can add the RRset.
-        LOG_DEBUG(logger, DBG_TRACE_DATA, DATASRC_MEM_ADD_RRSET).
+        LOG_DEBUG(logger, DBG_TRACE_DATA, DATASRC_MEMORY_MEM_ADD_RRSET).
             arg(rrset->getName()).arg(rrset->getType()).arg(zone_name);
 
         if (rrset->getType() == RRType::NSEC3()) {
@@ -572,7 +575,7 @@ InMemoryClient::InMemoryClientImpl::load(
         // process only adds new nodes (and their data), so this assertion
         // should hold.
         if (RdataSet::find(set, RRType::NSEC3PARAM()) == NULL) {
-            LOG_WARN(logger, DATASRC_MEM_NO_NSEC3PARAM).
+            LOG_WARN(logger, DATASRC_MEMORY_MEM_NO_NSEC3PARAM).
                 arg(zone_name).arg(rrclass_);
         }
     }
@@ -585,7 +588,7 @@ InMemoryClient::InMemoryClientImpl::load(
                   "Won't create an empty zone for: " << zone_name);
     }
 
-    LOG_DEBUG(logger, DBG_TRACE_BASIC, DATASRC_MEM_ADD_ZONE).
+    LOG_DEBUG(logger, DBG_TRACE_BASIC, DATASRC_MEMORY_MEM_ADD_ZONE).
         arg(zone_name).arg(rrclass_.toText());
 
     // Set the filename in file_name_tree_ now, so that getFileName()
@@ -688,7 +691,8 @@ InMemoryClient::getZoneCount() const {
 
 isc::datasrc::memory::ZoneTable::FindResult
 InMemoryClient::findZone2(const isc::dns::Name& zone_name) const {
-    LOG_DEBUG(logger, DBG_TRACE_DATA, DATASRC_MEM_FIND_ZONE).arg(zone_name);
+    LOG_DEBUG(logger, DBG_TRACE_DATA,
+              DATASRC_MEMORY_MEM_FIND_ZONE).arg(zone_name);
     ZoneTable::FindResult result(impl_->zone_table_->findZone(zone_name));
     return (result);
 }
@@ -705,7 +709,7 @@ InMemoryClient::findZone(const isc::dns::Name&) const {
 result::Result
 InMemoryClient::load(const isc::dns::Name& zone_name,
                      const std::string& filename) {
-    LOG_DEBUG(logger, DBG_TRACE_BASIC, DATASRC_MEM_LOAD).arg(zone_name).
+    LOG_DEBUG(logger, DBG_TRACE_BASIC, DATASRC_MEMORY_MEM_LOAD).arg(zone_name).
         arg(filename);
 
     return (impl_->load(zone_name, filename,
diff --git a/src/lib/datasrc/memory/memory_messages.mes b/src/lib/datasrc/memory/memory_messages.mes
index 6fe63c7..a66297c 100644
--- a/src/lib/datasrc/memory/memory_messages.mes
+++ b/src/lib/datasrc/memory/memory_messages.mes
@@ -16,62 +16,62 @@ $NAMESPACE isc::datasrc::memory
 
 # \brief Messages for the data source memory library
 
-% DATASRC_MEM_ADD_WILDCARD adding wildcards for '%1'
+% DATASRC_MEMORY_MEM_ADD_WILDCARD adding wildcards for '%1'
 This is a debug message issued during the processing of a wildcard
 name. The internal domain name tree is scanned and some nodes are
 specially marked to allow the wildcard lookup to succeed.
 
-% DATASRC_MEM_CNAME_TO_NONEMPTY can't add CNAME to domain with other data in '%1'
+% DATASRC_MEMORY_MEM_CNAME_TO_NONEMPTY can't add CNAME to domain with other data in '%1'
 Someone or something tried to add a CNAME into a domain that already contains
 some other data. But the protocol forbids coexistence of CNAME with anything
 (RFC 1034, section 3.6.2). This indicates a problem with provided data.
 
-% DATASRC_MEM_CNAME_COEXIST can't add data to CNAME in domain '%1'
+% DATASRC_MEMORY_MEM_CNAME_COEXIST can't add data to CNAME in domain '%1'
 This is the same problem as in MEM_CNAME_TO_NONEMPTY, but it happened the
 other way around -- adding some other data to CNAME.
 
-% DATASRC_MEM_DNAME_NS DNAME and NS can't coexist in non-apex domain '%1'
+% DATASRC_MEMORY_MEM_DNAME_NS DNAME and NS can't coexist in non-apex domain '%1'
 A request was made for DNAME and NS records to be put into the same
 domain which is not the apex (the top of the zone). This is forbidden
 by RFC 2672 (section 3) and indicates a problem with provided data.
 
-% DATASRC_MEM_SINGLETON trying to add multiple RRs for domain '%1' and type '%2'
+% DATASRC_MEMORY_MEM_SINGLETON trying to add multiple RRs for domain '%1' and type '%2'
 Some resource types are singletons -- only one is allowed in a domain
 (for example CNAME or SOA). This indicates a problem with provided data.
 
-% DATASRC_MEM_OUT_OF_ZONE domain '%1' doesn't belong to zone '%2'
+% DATASRC_MEMORY_MEM_OUT_OF_ZONE domain '%1' doesn't belong to zone '%2'
 It was attempted to add the domain into a zone that shouldn't have it
 (eg. the domain is not subdomain of the zone origin). This indicates a
 problem with provided data.
 
-% DATASRC_MEM_WILDCARD_NS NS record in wildcard domain '%1'
+% DATASRC_MEMORY_MEM_WILDCARD_NS NS record in wildcard domain '%1'
 The software refuses to load NS records into a wildcard domain.  It isn't
 explicitly forbidden, but the protocol is ambiguous about how this should
 behave and BIND 9 refuses that as well. Please describe your intention using
 different tools.
 
-% DATASRC_MEM_WILDCARD_DNAME DNAME record in wildcard domain '%1'
+% DATASRC_MEMORY_MEM_WILDCARD_DNAME DNAME record in wildcard domain '%1'
 The software refuses to load DNAME records into a wildcard domain.  It isn't
 explicitly forbidden, but the protocol is ambiguous about how this should
 behave and BIND 9 refuses that as well. Please describe your intention using
 different tools.
 
-% DATASRC_BAD_NSEC3_NAME NSEC3 record has a bad owner name '%1'
+% DATASRC_MEMORY_BAD_NSEC3_NAME NSEC3 record has a bad owner name '%1'
 The software refuses to load NSEC3 records into a wildcard domain or
 the owner name has two or more labels below the zone origin.
 It isn't explicitly forbidden, but no sane zone wouldn have such names
 for NSEC3.  BIND 9 also refuses NSEC3 at wildcard, so this behavior is
 compatible with BIND 9.
 
-% DATASRC_MEM_ADD_RRSET adding RRset '%1/%2' into zone '%3'
+% DATASRC_MEMORY_MEM_ADD_RRSET adding RRset '%1/%2' into zone '%3'
 Debug information. An RRset is being added to the in-memory data source.
 
-% DATASRC_MEM_DUP_RRSET duplicate RRset '%1/%2'
+% DATASRC_MEMORY_MEM_DUP_RRSET duplicate RRset '%1/%2'
 An RRset is being inserted into in-memory data source for a second time.  The
 original version must be removed first. Note that loading master files where an
 RRset is split into multiple locations is not supported yet.
 
-% DATASRC_MEM_NO_NSEC3PARAM NSEC3PARAM is missing for NSEC3-signed zone %1/%2
+% DATASRC_MEMORY_MEM_NO_NSEC3PARAM NSEC3PARAM is missing for NSEC3-signed zone %1/%2
 The in-memory data source has loaded a zone signed with NSEC3 RRs,
 but it doesn't have a NSEC3PARAM RR at the zone origin.  It's likely that
 the zone is somehow broken, but this RR is not necessarily needed for
@@ -79,12 +79,12 @@ handling lookups with NSEC3 in this data source, so it accepts the given
 content of the zone.  Nevertheless the administrator should look into
 the integrity of the zone data.
 
-% DATASRC_MEM_ADD_ZONE adding zone '%1/%2'
+% DATASRC_MEMORY_MEM_ADD_ZONE adding zone '%1/%2'
 Debug information. A zone is being added into the in-memory data source.
 
-% DATASRC_MEM_FIND_ZONE looking for zone '%1'
+% DATASRC_MEMORY_MEM_FIND_ZONE looking for zone '%1'
 Debug information. A zone object for this zone is being searched for in the
 in-memory data source.
 
-% DATASRC_MEM_LOAD loading zone '%1' from file '%2'
+% DATASRC_MEMORY_MEM_LOAD loading zone '%1' from file '%2'
 Debug information. The content of master file is being loaded into the memory.
diff --git a/src/lib/datasrc/memory/tests/memory_client_unittest.cc b/src/lib/datasrc/memory/tests/memory_client_unittest.cc
index ee747a3..b86a3bd 100644
--- a/src/lib/datasrc/memory/tests/memory_client_unittest.cc
+++ b/src/lib/datasrc/memory/tests/memory_client_unittest.cc
@@ -32,6 +32,8 @@
 #include <datasrc/memory/zone_table.h>
 #include <datasrc/memory/memory_client.h>
 
+#include <testutils/dnsmessage_test.h>
+
 #include <gtest/gtest.h>
 
 #include <new>                  // for bad_alloc
@@ -40,6 +42,7 @@ using namespace isc::dns;
 using namespace isc::dns::rdata;
 using namespace isc::datasrc;
 using namespace isc::datasrc::memory;
+using namespace isc::testutils;
 
 namespace {
 // Memory segment specified for tests.  It normally behaves like a "local"
@@ -63,6 +66,44 @@ private:
     size_t throw_count_;
 };
 
+static const char* rrset_data[] = {
+    "example.org. 3600 IN SOA   ns1.example.org. bugs.x.w.example.org. 68 3600 300 3600000 3600",
+    "a.example.org.		   	 3600 IN A	192.168.0.1",
+    "a.example.org.		   	 3600 IN MX	10 mail.example.org.",
+    NULL
+};
+
+class MockIterator : public ZoneIterator {
+private:
+    MockIterator() :
+        rrset_data_ptr_(rrset_data)
+    {
+    }
+
+    const char** rrset_data_ptr_;
+
+public:
+    virtual ConstRRsetPtr getNextRRset() {
+        if (*rrset_data_ptr_ == NULL) {
+             return (ConstRRsetPtr());
+        }
+
+        RRsetPtr result(textToRRset(*rrset_data_ptr_,
+                                    RRClass::IN(), Name("example.org")));
+        rrset_data_ptr_++;
+
+        return (result);
+    }
+
+    virtual ConstRRsetPtr getSOA() const {
+        isc_throw(isc::NotImplemented, "Not implemented");
+    }
+
+    static ZoneIteratorPtr makeIterator(void) {
+        return (ZoneIteratorPtr(new MockIterator()));
+    }
+};
+
 class MemoryClientTest : public ::testing::Test {
 protected:
     MemoryClientTest() : zclass_(RRClass::IN()),
@@ -142,6 +183,34 @@ TEST_F(MemoryClientTest, load) {
                   TEST_DATA_DIR "/example.org.zone");
 }
 
+TEST_F(MemoryClientTest, loadFromIterator) {
+    client_->load(Name("example.org"),
+                  *MockIterator::makeIterator());
+
+    ZoneIteratorPtr iterator(client_->getIterator(Name("example.org")));
+
+    // First we have the SOA
+    ConstRRsetPtr rrset(iterator->getNextRRset());
+    EXPECT_TRUE(rrset);
+    EXPECT_EQ(RRType::SOA(), rrset->getType());
+
+    // RRType::MX() RRset
+    rrset = iterator->getNextRRset();
+    EXPECT_TRUE(rrset);
+    EXPECT_EQ(RRType::MX(), rrset->getType());
+
+    // RRType::A() RRset
+    rrset = iterator->getNextRRset();
+    EXPECT_TRUE(rrset);
+    EXPECT_EQ(RRType::A(), rrset->getType());
+
+    // There's nothing else in this iterator
+    EXPECT_EQ(ConstRRsetPtr(), iterator->getNextRRset());
+
+    // Iterating past the end should result in an exception
+    EXPECT_THROW(iterator->getNextRRset(), isc::Unexpected);
+}
+
 TEST_F(MemoryClientTest, loadNSEC3Signed) {
     client_->load(Name("example.org"),
                   TEST_DATA_DIR "/example.org-nsec3-signed.zone");



More information about the bind10-changes mailing list