From: Mukund Sivaraman Date: Wed, 9 Jan 2013 06:22:51 +0000 (+0530) Subject: [2435] Throw FindError in case there is a DataSourceError in ZoneFinder X-Git-Tag: bind10-1.0.0-rc-release~76^2~21^2~3^2^2~11^2~5 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=ae4e532f39b85f619ff99d8feb91898d8ee741a9;p=thirdparty%2Fkea.git [2435] Throw FindError in case there is a DataSourceError in ZoneFinder --- diff --git a/src/lib/datasrc/rrset_collection.cc b/src/lib/datasrc/rrset_collection.cc index ffe102e11b..771ce7dba4 100644 --- a/src/lib/datasrc/rrset_collection.cc +++ b/src/lib/datasrc/rrset_collection.cc @@ -13,6 +13,7 @@ // PERFORMANCE OF THIS SOFTWARE. #include +#include #include 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()); } } diff --git a/src/lib/datasrc/rrset_collection.h b/src/lib/datasrc/rrset_collection.h index afe11992db..ec3dcf0d0a 100644 --- a/src/lib/datasrc/rrset_collection.h +++ b/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. diff --git a/src/lib/datasrc/tests/database_unittest.cc b/src/lib/datasrc/tests/database_unittest.cc index 5b19ace943..3aff9ca50a 100644 --- a/src/lib/datasrc/tests/database_unittest.cc +++ b/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 { +public: + MockRRsetCollectionTest() : + DatabaseClientTest(), + 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); +} + } diff --git a/src/lib/dns/rrset_collection_base.h b/src/lib/dns/rrset_collection_base.h index 27e46d1266..ff2617fc9e 100644 --- a/src/lib/dns/rrset_collection_base.h +++ b/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.