Parcourir la source

[2435] Throw FindError in case there is a DataSourceError in ZoneFinder

Mukund Sivaraman il y a 12 ans
Parent
commit
3ea93cc724

+ 4 - 0
src/lib/datasrc/rrset_collection.cc

@@ -13,6 +13,7 @@
 // PERFORMANCE OF THIS SOFTWARE.
 
 #include <datasrc/rrset_collection.h>
+#include <datasrc/zone_loader.h>
 #include <exceptions/exceptions.h>
 
 using namespace isc;
@@ -45,6 +46,9 @@ RRsetCollection::find(const isc::dns::Name& name,
         // searched name is out of zone, we return nothing instead of
         // propagating the exception.
         return (ConstRRsetPtr());
+    } catch (const DataSourceError& e) {
+        isc_throw(FindError, "ZoneFinder threw a DataSourceError: " <<
+                  e.getMessage().c_str());
     }
 }
 

+ 1 - 0
src/lib/datasrc/rrset_collection.h

@@ -48,6 +48,7 @@ public:
     /// given \c name, \c rrclass and \c rrtype.  If no matching RRset
     /// is found, \c NULL is returned.
     ///
+    /// \throw FindError if find() results in some underlying datasrc error.
     /// \param name The name of the RRset to search for.
     /// \param rrclass The class of the RRset to search for.
     /// \param rrtype The type of the RRset to search for.

+ 24 - 0
src/lib/datasrc/tests/database_unittest.cc

@@ -4211,4 +4211,28 @@ TYPED_TEST(RRsetCollectionTest, iteratorTest) {
     EXPECT_THROW(this->collection.end(), isc::NotImplemented);
 }
 
+class MockRRsetCollectionTest : public DatabaseClientTest<MockAccessor> {
+public:
+    MockRRsetCollectionTest() :
+        DatabaseClientTest<MockAccessor>(),
+        collection(this->client_->getUpdater(this->zname_, false),
+                   this->qclass_)
+    {}
+
+    RRsetCollection collection;
+};
+
+TEST_F(MockRRsetCollectionTest, findError) {
+    // A test using the MockAccessor for checking that FindError is
+    // thrown properly if a find attempt using ZoneFinder results in a
+    // DataSourceError.
+    //
+    // The "dsexception.example.org." name is rigged by the MockAccessor
+    // to throw a DataSourceError.
+    EXPECT_THROW({
+        this->collection.find(Name("dsexception.example.org"), this->qclass_,
+                              RRType::A());
+    }, RRsetCollectionBase::FindError);
+}
+
 }

+ 14 - 0
src/lib/dns/rrset_collection_base.h

@@ -38,12 +38,26 @@ namespace dns {
 /// STL container. libdatasrc will have another implementation.
 class RRsetCollectionBase {
 public:
+    /// \brief Error during find operation
+    ///
+    /// This exception is thrown when an calling implementation of
+    /// \c find() results in an error which is not due to unmatched
+    /// data, but because of some other underlying error condition.
+    class FindError : public Exception {
+    public:
+        FindError(const char* file, size_t line, const char* what) :
+            Exception(file, line, what)
+        {}
+    };
+
     /// \brief Find a matching RRset in the collection.
     ///
     /// Returns the RRset in the collection that exactly matches the
     /// given \c name, \c rrclass and \c rrtype.  If no matching RRset
     /// is found, \c NULL is returned.
     ///
+    /// \throw FindError if find() results in some
+    /// implementation-specific error.
     /// \param name The name of the RRset to search for.
     /// \param rrtype The type of the RRset to search for.
     /// \param rrclass The class of the RRset to search for.