Browse Source

[2435] Handle find() with RRClass that may not be found

Mukund Sivaraman 12 years ago
parent
commit
c16bfe0dc8

+ 8 - 3
src/lib/datasrc/rrset_collection.cc

@@ -23,11 +23,16 @@ namespace datasrc {
 
 ConstRRsetPtr
 RRsetCollection::find(const isc::dns::Name& name,
-                      const isc::dns::RRClass&,
+                      const isc::dns::RRClass& rrclass,
                       const isc::dns::RRType& rrtype) const
 {
-    // TODO: RRClass needs to be checked here to see if it is as
-    // expected.
+    if (rrclass != rrclass_) {
+        // We could throw an exception here, but RRsetCollection is
+        // expected to support an arbitrary collection of RRsets, and it
+        // can be queried just as arbitrarily. So we just return nothing
+        // here.
+        return (ConstRRsetPtr());
+    }
 
     ZoneFinder& finder = updater_->getFinder();
     ZoneFinderContextPtr result =

+ 5 - 2
src/lib/datasrc/rrset_collection.h

@@ -33,8 +33,10 @@ public:
     /// destroyed by the client.
     ///
     /// \param updater The ZoneUpdater to wrap around.
-    RRsetCollection(ZoneUpdaterPtr updater) :
-        updater_(updater)
+    /// \param rrclass The RRClass of the records in the zone.
+    RRsetCollection(ZoneUpdaterPtr updater, const isc::dns::RRClass& rrclass) :
+        updater_(updater),
+        rrclass_(rrclass)
     {}
 
     /// \brief Destructor
@@ -56,6 +58,7 @@ public:
 
 private:
     ZoneUpdaterPtr updater_;
+    isc::dns::RRClass rrclass_;
 
 protected:
     // TODO: RRsetCollectionBase::Iter is not implemented and the

+ 7 - 1
src/lib/datasrc/tests/database_unittest.cc

@@ -4162,7 +4162,8 @@ class RRsetCollectionTest : public DatabaseClientTest<ACCESSOR_TYPE> {
 public:
     RRsetCollectionTest() :
         DatabaseClientTest<ACCESSOR_TYPE>(),
-        collection(this->client_->getUpdater(this->zname_, false))
+        collection(this->client_->getUpdater(this->zname_, false),
+                   this->qclass_)
     {}
 
     RRsetCollection collection;
@@ -4192,6 +4193,11 @@ TYPED_TEST(RRsetCollectionTest, find) {
     rrset = this->collection.find(Name("www.example.org"), this->qclass_,
                                   RRType::AAAA());
     EXPECT_TRUE(rrset);
+
+    // www.example.org with AAAA does not exist in RRClass::CH()
+    rrset = this->collection.find(Name("www.example.org"), RRClass::CH(),
+                                  RRType::AAAA());
+    EXPECT_FALSE(rrset);
 }
 
 TYPED_TEST(RRsetCollectionTest, iteratorTest) {