BIND 10 trac2435, updated. 3ea93cc724f87d47c024f895650853f284daf9a1 [2435] Throw FindError in case there is a DataSourceError in ZoneFinder
BIND 10 source code commits
bind10-changes at lists.isc.org
Wed Jan 9 06:26:10 UTC 2013
The branch, trac2435 has been updated
via 3ea93cc724f87d47c024f895650853f284daf9a1 (commit)
via 5e3bc4cf78dddd89f3a9e4670336b7d46bbb124e (commit)
from c16bfe0dc892c2bd34e88daa12120202bcf9e3eb (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 3ea93cc724f87d47c024f895650853f284daf9a1
Author: Mukund Sivaraman <muks at isc.org>
Date: Wed Jan 9 11:52:51 2013 +0530
[2435] Throw FindError in case there is a DataSourceError in ZoneFinder
commit 5e3bc4cf78dddd89f3a9e4670336b7d46bbb124e
Author: Mukund Sivaraman <muks at isc.org>
Date: Wed Jan 9 11:23:47 2013 +0530
[2435] Don't throw in case of out of zone queries
-----------------------------------------------------------------------
Summary of changes:
src/lib/datasrc/rrset_collection.cc | 20 ++++++++++++++-----
src/lib/datasrc/rrset_collection.h | 1 +
src/lib/datasrc/tests/database_unittest.cc | 29 ++++++++++++++++++++++++++++
src/lib/dns/rrset_collection_base.h | 14 ++++++++++++++
4 files changed, 59 insertions(+), 5 deletions(-)
-----------------------------------------------------------------------
diff --git a/src/lib/datasrc/rrset_collection.cc b/src/lib/datasrc/rrset_collection.cc
index e4cfd88..771ce7d 100644
--- a/src/lib/datasrc/rrset_collection.cc
+++ b/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;
@@ -35,11 +36,20 @@ RRsetCollection::find(const isc::dns::Name& name,
}
ZoneFinder& finder = updater_->getFinder();
- ZoneFinderContextPtr result =
- finder.find(name, rrtype,
- ZoneFinder::NO_WILDCARD | ZoneFinder::FIND_GLUE_OK);
-
- return (result->rrset);
+ try {
+ ZoneFinderContextPtr result =
+ finder.find(name, rrtype,
+ ZoneFinder::NO_WILDCARD | ZoneFinder::FIND_GLUE_OK);
+ return (result->rrset);
+ } catch (const OutOfZone&) {
+ // As RRsetCollection is an arbitrary set of RRsets, in case the
+ // 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());
+ }
}
RRsetCollectionBase::IterPtr
diff --git a/src/lib/datasrc/rrset_collection.h b/src/lib/datasrc/rrset_collection.h
index afe1199..ec3dcf0 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 39729f8..3aff9ca 100644
--- a/src/lib/datasrc/tests/database_unittest.cc
+++ b/src/lib/datasrc/tests/database_unittest.cc
@@ -4198,6 +4198,11 @@ TYPED_TEST(RRsetCollectionTest, find) {
rrset = this->collection.find(Name("www.example.org"), RRClass::CH(),
RRType::AAAA());
EXPECT_FALSE(rrset);
+
+ // Out of zone find()s must not throw.
+ rrset = this->collection.find(Name("www.example.com"), this->qclass_,
+ RRType::A());
+ EXPECT_FALSE(rrset);
}
TYPED_TEST(RRsetCollectionTest, iteratorTest) {
@@ -4206,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);
+}
+
}
diff --git a/src/lib/dns/rrset_collection_base.h b/src/lib/dns/rrset_collection_base.h
index 27e46d1..ff2617f 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.
More information about the bind10-changes
mailing list