From: Paul Selkirk Date: Wed, 29 May 2013 18:04:40 +0000 (-0400) Subject: [2907] add abstract method clientList::getZoneTableAccessor X-Git-Tag: bind10-1.2.0beta1-release~411^2~7^2~2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=807607ead100bba4afa0c5af2697ebe6dd2f4ec7;p=thirdparty%2Fkea.git [2907] add abstract method clientList::getZoneTableAccessor Also add type ConstZoneTableAccessorPtr for convenience, pass smart pointer by reference in unit test. --- diff --git a/src/lib/datasrc/client_list.cc b/src/lib/datasrc/client_list.cc index fcafb2930f..e283b0c2c0 100644 --- a/src/lib/datasrc/client_list.cc +++ b/src/lib/datasrc/client_list.cc @@ -24,9 +24,9 @@ #include #include #include +#include #include #include -#include #include #include @@ -400,7 +400,7 @@ ConfigurableClientList::getStatus() const { return (result); } -boost::shared_ptr +ConstZoneTableAccessorPtr ConfigurableClientList::getZoneTableAccessor(const std::string& datasrc_name, bool use_cache) const { @@ -418,11 +418,11 @@ ConfigurableClientList::getZoneTableAccessor(const std::string& datasrc_name, const internal::CacheConfig* config(info.getCacheConfig()); // If caching is disabled for the named data source, this will // return an accessor to an effectivley empty table. - return (boost::shared_ptr + return (ConstZoneTableAccessorPtr (new internal::ZoneTableAccessorCache(*config))); } - return (boost::shared_ptr()); + return (ConstZoneTableAccessorPtr()); } } diff --git a/src/lib/datasrc/client_list.h b/src/lib/datasrc/client_list.h index e226ed2276..85b96d9d63 100644 --- a/src/lib/datasrc/client_list.h +++ b/src/lib/datasrc/client_list.h @@ -121,6 +121,8 @@ private: MemorySegmentState state_; }; +typedef boost::shared_ptr ConstZoneTableAccessorPtr; + /// \brief The list of data source clients. /// /// The purpose of this class is to hold several data source clients and search @@ -273,6 +275,19 @@ public: virtual FindResult find(const dns::Name& zone, bool want_exact_match = false, bool want_finder = true) const = 0; + + /// \brief Creates a ZoneTableAccessor object for the specified data + /// source. + /// + /// \param datasrc_name If not empty, the name of the data source. + /// \param use_cache If true, create a zone table for in-memory cache. + /// \throw NotImplemented if this method is not implemented. + /// \return A pointer to the accessor, or NULL if the requested data + /// source is not found. + virtual ConstZoneTableAccessorPtr + getZoneTableAccessor(const std::string& datasrc_name, + bool use_cache) const = 0; + }; /// \brief Shared pointer to the list. @@ -494,7 +509,7 @@ public: /// \throw NotImplemented if \c use_cache is false. /// \return A pointer to the accessor, or NULL if the requested data /// source is not found. - boost::shared_ptr + ConstZoneTableAccessorPtr getZoneTableAccessor(const std::string& datasrc_name, bool use_cache) const; diff --git a/src/lib/datasrc/tests/client_list_unittest.cc b/src/lib/datasrc/tests/client_list_unittest.cc index 42652e9489..4ca4c9b61b 100644 --- a/src/lib/datasrc/tests/client_list_unittest.cc +++ b/src/lib/datasrc/tests/client_list_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (C) 2012 Internet Systems Consortium, Inc. ("ISC") +// Copyright (C) 2012-2013 Internet Systems Consortium, Inc. ("ISC") // // Permission to use, copy, modify, and/or distribute this software for any // purpose with or without fee is hereby granted, provided that the above @@ -254,7 +254,7 @@ public: } ConfigurableClientList::CacheStatus doReload( const Name& origin, const string& datasrc_name = ""); - void accessorIterate(boost::shared_ptr accessor, + void accessorIterate(ConstZoneTableAccessorPtr& accessor, int numZones, const string& zoneName); const RRClass rrclass_; @@ -1134,31 +1134,25 @@ TEST_F(ListTest, reloadByDataSourceName) { // through the table, and verifies that the expected number of zones are // present, as well as the named zone. void -ListTest::accessorIterate(boost::shared_ptr accessor, +ListTest::accessorIterate(ConstZoneTableAccessorPtr& accessor, int numZones, const string& zoneName="") { // Confirm basic iterator behavior. ASSERT_TRUE(accessor); ZoneTableAccessor::IteratorPtr it = accessor->getIterator(); ASSERT_TRUE(it); + // Iterator does not guarantee ordering, so we look for the target + // name anywhere in the table. + bool found = false; + int i; + for (i = 0; !it->isLast(); ++i, it->next()) { + if (Name(zoneName) == it->getCurrent().origin) { + found = true; + } + } + EXPECT_EQ(i, numZones); if (numZones > 0) { - EXPECT_FALSE(it->isLast()); - EXPECT_EQ(0, it->getCurrent().index); - // Iterator does not guarantee ordering, so we look for the target - // name anywhere in the table. - bool found = false; - int i = 0; - while (!it->isLast()) { - ++i; - if (Name(zoneName) == it->getCurrent().origin) { - found = true; - } - it->next(); - } EXPECT_TRUE(found); - EXPECT_EQ(i, numZones); - } else { - EXPECT_TRUE(it->isLast()); } } @@ -1171,8 +1165,7 @@ TEST_F(ListTest, zoneTableAccessor) { // empty list; expect it to return an empty list list_->configure(config_elem_, true); - boost::shared_ptr - z(list_->getZoneTableAccessor("", true)); + ConstZoneTableAccessorPtr z(list_->getZoneTableAccessor("", true)); accessorIterate(z, 0); const ConstElementPtr elem2(Element::fromJSON("["