]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[2435] Throw FindError in case there is a DataSourceError in ZoneFinder
authorMukund Sivaraman <muks@isc.org>
Wed, 9 Jan 2013 06:22:51 +0000 (11:52 +0530)
committerJINMEI Tatuya <jinmei@isc.org>
Wed, 9 Jan 2013 22:31:20 +0000 (14:31 -0800)
src/lib/datasrc/rrset_collection.cc
src/lib/datasrc/rrset_collection.h
src/lib/datasrc/tests/database_unittest.cc
src/lib/dns/rrset_collection_base.h

index ffe102e11bd441f5be39ac4169686233d053a3ae..771ce7dba4f04b65f0983203d627b74ec5face4c 100644 (file)
@@ -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());
     }
 }
 
index afe11992db313cde0b31d1ca77248825c0fad380..ec3dcf0d0ae953f9db9250265fe30c99bbb86be7 100644 (file)
@@ -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.
index 5b19ace9438ce79dc42577b4c3e4b814f95129e9..3aff9ca50a18aafcea1463b54edf96e8725cf1bc 100644 (file)
@@ -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);
+}
+
 }
index 27e46d1266ca7dabb3e17ca931fef55c5e83d565..ff2617fc9e0adeb5a7a2c016c36327ec7cd790bf 100644 (file)
@@ -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.