From: JINMEI Tatuya Date: Wed, 3 Apr 2013 22:35:38 +0000 (-0700) Subject: [2834] avoid using InMemoryClient::load for some tests. X-Git-Tag: bind10-1.1.0beta2-release~8^2~23^2~6 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=41a8bec7700a7792e1f24883add4e542977c111e;p=thirdparty%2Fkea.git [2834] avoid using InMemoryClient::load for some tests. instead, load it into ZoneTableSegment directly. also introduced a utility function as it would be used may times --- diff --git a/src/lib/datasrc/tests/memory/Makefile.am b/src/lib/datasrc/tests/memory/Makefile.am index f77d212fc7..e0fc0f53b1 100644 --- a/src/lib/datasrc/tests/memory/Makefile.am +++ b/src/lib/datasrc/tests/memory/Makefile.am @@ -21,6 +21,7 @@ if HAVE_GTEST TESTS += run_unittests run_unittests_SOURCES = run_unittests.cc +run_unittests_SOURCES += zone_loader_util.h zone_loader_util.cc run_unittests_SOURCES += rdata_serialization_unittest.cc run_unittests_SOURCES += rdataset_unittest.cc run_unittests_SOURCES += domaintree_unittest.cc diff --git a/src/lib/datasrc/tests/memory/zone_finder_unittest.cc b/src/lib/datasrc/tests/memory/zone_finder_unittest.cc index 4d4f396bb4..0350ed9bfa 100644 --- a/src/lib/datasrc/tests/memory/zone_finder_unittest.cc +++ b/src/lib/datasrc/tests/memory/zone_finder_unittest.cc @@ -12,8 +12,9 @@ // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR // PERFORMANCE OF THIS SOFTWARE. -#include "memory_segment_test.h" -#include "zone_table_segment_test.h" +#include +#include +#include // NOTE: this faked_nsec3 inclusion (and all related code below) // was ported during #2109 for the convenience of implementing #2218 @@ -21,7 +22,7 @@ // In #2219 the original is expected to be removed, and this file should // probably be moved here (and any leftover code not handled in #2218 should // be cleaned up) -#include "../../tests/faked_nsec3.h" +#include #include #include @@ -1610,12 +1611,13 @@ TEST_F(InMemoryZoneFinderTest, findOrphanRRSIG) { // \brief testcase for #2504 (Problem in inmem NSEC denial of existence // handling) TEST_F(InMemoryZoneFinderTest, NSECNonExistentTest) { + const Name name("example.com."); shared_ptr ztable_segment( new ZoneTableSegmentTest(class_, mem_sgmt_)); + loadZoneIntoTable(*ztable_segment, name, class_, + TEST_DATA_DIR "/2504-test.zone"); InMemoryClient client(ztable_segment, class_); - Name name("example.com."); - client.load(name, TEST_DATA_DIR "/2504-test.zone"); DataSourceClient::FindResult result(client.findZone(name)); // Check for a non-existing name @@ -1771,16 +1773,17 @@ TEST_F(InMemoryZoneFinderNSEC3Test, findNSEC3MissingOrigin) { DefaultNSEC3HashCreator creator; setNSEC3HashCreator(&creator); + const Name name("example.com."); shared_ptr ztable_segment( new ZoneTableSegmentTest(class_, mem_sgmt_)); + loadZoneIntoTable(*ztable_segment, name, class_, + TEST_DATA_DIR "/2503-test.zone"); InMemoryClient client(ztable_segment, class_); - Name name("example.com."); - client.load(name, TEST_DATA_DIR "/2503-test.zone"); DataSourceClient::FindResult result(client.findZone(name)); // Check for a non-existing name - Name search_name("nonexist.example.com."); + const Name search_name("nonexist.example.com."); ZoneFinder::FindNSEC3Result find_result( result.zone_finder->findNSEC3(search_name, true)); // findNSEC3() must have completed (not throw or assert). Because diff --git a/src/lib/datasrc/tests/memory/zone_loader_util.cc b/src/lib/datasrc/tests/memory/zone_loader_util.cc new file mode 100644 index 0000000000..d9c32b4572 --- /dev/null +++ b/src/lib/datasrc/tests/memory/zone_loader_util.cc @@ -0,0 +1,58 @@ +// Copyright (C) 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 +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH +// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY +// AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, +// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM +// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE +// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +// PERFORMANCE OF THIS SOFTWARE. + +#include + +#include +#include +#include + +#include + +#include + +#include + +#include + +namespace isc { +namespace datasrc { +namespace memory { +namespace test { + +void +loadZoneIntoTable(ZoneTableSegment& zt_sgmt, const dns::Name& zname, + const dns::RRClass& zclass, const std::string& zone_file) +{ + const isc::datasrc::internal::CacheConfig cache_conf( + "MasterFiles", 0, *data::Element::fromJSON( + "{\"cache-enable\": true," + " \"params\": {\"" + zname.toText() + "\": \"" + zone_file + + "\"}}"), true); + boost::scoped_ptr writer( + zt_sgmt.getZoneWriter(cache_conf.getLoadAction(zclass, zname), + zname, zclass)); + writer->load(); + writer->install(); + writer->cleanup(); +} + +} // namespace test +} // namespace memory +} // namespace datasrc +} // namespace isc + +// Local Variables: +// mode: c++ +// End: diff --git a/src/lib/datasrc/tests/memory/zone_loader_util.h b/src/lib/datasrc/tests/memory/zone_loader_util.h new file mode 100644 index 0000000000..59de23b4d2 --- /dev/null +++ b/src/lib/datasrc/tests/memory/zone_loader_util.h @@ -0,0 +1,47 @@ +// Copyright (C) 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 +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH +// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY +// AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, +// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM +// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE +// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +// PERFORMANCE OF THIS SOFTWARE. + +#ifndef DATASRC_MEMORY_TEST_ZONE_LOADER_UTIL_H +#define DATASRC_MEMORY_TEST_ZONE_LOADER_UTIL_H 1 + +#include + +#include + +#include + +namespace isc { +namespace datasrc { +namespace memory { +namespace test { + +/// \brief A shortcut utility to load a specified zone into ZoneTableSegment. +/// +/// This function does nothing special, simply provides a shortcut for commonly +/// used pattern that would be used in tests with a ZoneTableSegment loading +/// a zone from file into it. +void +loadZoneIntoTable(ZoneTableSegment& zt_sgmt, const dns::Name& zname, + const dns::RRClass& zclass, const std::string& zone_file); + +} // namespace test +} // namespace memory +} // namespace datasrc +} // namespace isc + +#endif // DATASRC_MEMORY_TEST_ZONE_LOADER_UTIL_H + +// Local Variables: +// mode: c++ +// End: diff --git a/src/lib/datasrc/tests/zone_finder_context_unittest.cc b/src/lib/datasrc/tests/zone_finder_context_unittest.cc index 614b1be5bb..af89afe056 100644 --- a/src/lib/datasrc/tests/zone_finder_context_unittest.cc +++ b/src/lib/datasrc/tests/zone_finder_context_unittest.cc @@ -18,9 +18,13 @@ #include #include +#include + #include +#include #include #include +#include #include #include @@ -32,6 +36,7 @@ #include #include #include +#include #include #include @@ -39,11 +44,13 @@ using namespace std; using boost::shared_ptr; +using boost::scoped_ptr; using namespace isc::data; using namespace isc::util; using namespace isc::dns; using namespace isc::datasrc; +using isc::data::Element; using isc::datasrc::memory::InMemoryClient; using isc::datasrc::memory::ZoneTableSegment; using namespace isc::testutils; @@ -64,11 +71,22 @@ typedef DataSourceClientPtr (*ClientCreator)(RRClass, const Name&); // Creator for the in-memory client to be tested DataSourceClientPtr createInMemoryClient(RRClass zclass, const Name& zname) { + const internal::CacheConfig cache_conf( + "MasterFiles", 0, *Element::fromJSON( + "{\"cache-enable\": true," + " \"params\":" + " {\"" + zname.toText() + "\": \"" + + string(TEST_ZONE_FILE) + "\"}}"), true); shared_ptr ztable_segment( - ZoneTableSegment::create(zclass, "local")); + ZoneTableSegment::create(zclass, cache_conf.getSegmentType())); + scoped_ptr writer( + ztable_segment->getZoneWriter(cache_conf.getLoadAction(zclass, zname), + zname, zclass)); + writer->load(); + writer->install(); + writer->cleanup(); shared_ptr client(new InMemoryClient(ztable_segment, zclass)); - client->load(zname, TEST_ZONE_FILE); return (client); } diff --git a/src/lib/datasrc/tests/zone_loader_unittest.cc b/src/lib/datasrc/tests/zone_loader_unittest.cc index 8ed8a764be..70fa9c6a9b 100644 --- a/src/lib/datasrc/tests/zone_loader_unittest.cc +++ b/src/lib/datasrc/tests/zone_loader_unittest.cc @@ -15,9 +15,11 @@ #include #include #include +#include #include #include +#include #include #include @@ -26,6 +28,8 @@ #include #include +#include + #include #include @@ -37,6 +41,7 @@ using namespace isc::dns; using namespace isc::datasrc; +using isc::data::Element; using boost::shared_ptr; using std::string; using std::vector; @@ -301,13 +306,28 @@ protected: // (re)configure zone table, then (re)construct the in-memory client // with it. - ztable_segment_.reset(memory::ZoneTableSegment::create(rrclass_, - "local")); - source_client_.reset(new memory::InMemoryClient(ztable_segment_, - rrclass_)); + string param_data; if (filename) { - source_client_->load(zone, string(TEST_DATA_DIR) + "/" + filename); + param_data = "\"" + zone.toText() + "\": \"" + + string(TEST_DATA_DIR) + "/" + filename + "\""; } + const internal::CacheConfig cache_conf( + "MasterFiles", 0, *Element::fromJSON( + "{\"cache-enable\": true," + " \"params\": {" + param_data + "}}"), true); + ztable_segment_.reset(memory::ZoneTableSegment::create( + rrclass_, cache_conf.getSegmentType())); + if (filename) { + boost::scoped_ptr writer( + ztable_segment_->getZoneWriter(cache_conf.getLoadAction( + rrclass_, zone), + zone, rrclass_)); + writer->load(); + writer->install(); + writer->cleanup(); + } + source_client_.reset(new memory::InMemoryClient(ztable_segment_, + rrclass_)); } private: const RRClass rrclass_;