From: JINMEI Tatuya Date: Tue, 2 Apr 2013 23:13:44 +0000 (-0700) Subject: [2834] supported CacheConfig::getLoadAction for MasterFiles. X-Git-Tag: bind10-1.1.0beta2-release~8^2~23^2~16 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=962447aa16c4f4accd42fc326d9408cdf75d2dde;p=thirdparty%2Fkea.git [2834] supported CacheConfig::getLoadAction for MasterFiles. functor was copied from client_list.cc (the latter should eventually be removed in this branch) --- diff --git a/src/lib/datasrc/cache_config.cc b/src/lib/datasrc/cache_config.cc index 9cfe3b1a7c..2bff7212c5 100644 --- a/src/lib/datasrc/cache_config.cc +++ b/src/lib/datasrc/cache_config.cc @@ -15,10 +15,18 @@ #include #include #include +#include + +#include + #include +#include + #include #include +#include + #include #include @@ -108,6 +116,33 @@ CacheConfig::CacheConfig(const std::string& datasrc_type, } } +namespace { + +// We can't use the loadZoneData function directly in boost::bind, since +// it is overloaded and the compiler can't choose the correct version +// reliably and fails. So we simply wrap it into an unique name. +memory::ZoneData* +loadZoneDataFromFile(util::MemorySegment& segment, const dns::RRClass& rrclass, + const dns::Name& name, const std::string& filename) +{ + return (memory::loadZoneData(segment, rrclass, name, filename)); +} + +} // unnamed namespace + +memory::LoadAction +CacheConfig::getLoadAction(const dns::RRClass& rrclass, + const dns::Name& zone_name) const +{ + Zones::const_iterator found = zone_config_.find(zone_name); + if (found == zone_config_.end()) { + isc_throw(Unexpected, "zone not found for getting LoadAction: " + << zone_name); + } + return (boost::bind(loadZoneDataFromFile, _1, rrclass, zone_name, + found->second)); +} + } // namespace internal } // namespace datasrc } // namespace isc diff --git a/src/lib/datasrc/cache_config.h b/src/lib/datasrc/cache_config.h index a615b8a2f5..4b0b759489 100644 --- a/src/lib/datasrc/cache_config.h +++ b/src/lib/datasrc/cache_config.h @@ -17,7 +17,7 @@ #include -#include +#include #include #include @@ -144,6 +144,9 @@ public: /// \throw None const std::string& getSegmentType() const { return (segment_type_); } + memory::LoadAction getLoadAction(const dns::RRClass& rrlcass, + const dns::Name& zone_name) const; + /// \todo the following definition is tentative, mainly for tests. /// In #2834 we'll (probably) extend it to be a custom iterator so /// the caller can iterate over the whole set of zones, loading the diff --git a/src/lib/datasrc/tests/cache_config_unittest.cc b/src/lib/datasrc/tests/cache_config_unittest.cc index 8b3e6af4e6..29d35801d0 100644 --- a/src/lib/datasrc/tests/cache_config_unittest.cc +++ b/src/lib/datasrc/tests/cache_config_unittest.cc @@ -13,10 +13,14 @@ // PERFORMANCE OF THIS SOFTWARE. #include +#include +#include #include #include +#include #include +#include #include @@ -28,6 +32,8 @@ using namespace isc::dns; using isc::datasrc::unittest::MockDataSourceClient; using isc::datasrc::internal::CacheConfig; using isc::datasrc::internal::CacheConfigError; +using isc::datasrc::memory::LoadAction; +using isc::datasrc::memory::ZoneData; namespace { @@ -50,9 +56,14 @@ protected: " \"cache-zones\": [\".\"]}")) {} + virtual void TearDown() { + EXPECT_TRUE(msgmt_.allMemoryDeallocated()); + } + MockDataSourceClient mock_client_; const ConstElementPtr master_config_; // valid config for MasterFiles const ConstElementPtr mock_config_; // valid config for MasterFiles + isc::util::MemorySegmentLocal msgmt_; }; size_t @@ -139,6 +150,29 @@ TEST_F(CacheConfigTest, badConstructMasterFiles) { isc::InvalidParameter); } +TEST_F(CacheConfigTest, getLoadActionWithMasterFiles) { + uint8_t labels_buf[LabelSequence::MAX_SERIALIZED_LENGTH]; + + const CacheConfig cache_conf("MasterFiles", 0, *master_config_, true); + + // Check getLoadAction. Since it returns a mere functor, we can only + // check the behavior by actually calling it. For the purpose of this + // test, it should suffice if we confirm the call succeeds and shows + // some reasonably valid behavior (we'll check the origin name for that). + LoadAction action = cache_conf.getLoadAction(RRClass::IN(), + Name::ROOT_NAME()); + ZoneData* zone_data = action(msgmt_); + ASSERT_TRUE(zone_data); + EXPECT_EQ(".", zone_data->getOriginNode()-> + getAbsoluteLabels(labels_buf).toText()); + ZoneData::destroy(msgmt_, zone_data, RRClass::IN()); + + // If the specified zone name is not configured to be cached, + // getLoadAction should result in exception. + EXPECT_THROW(cache_conf.getLoadAction(RRClass::IN(), Name("example.com")), + isc::Unexpected); +} + TEST_F(CacheConfigTest, constructWithMock) { // Performing equivalent set of tests as constructMasterFiles