From: Michal 'vorner' Vaner Date: Mon, 22 Oct 2012 14:26:25 +0000 (+0200) Subject: [2209] Make the reload tests typed X-Git-Tag: trac2487_base~23^2~27^2~8 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=f0c56bb2f6bc3a8118acd5f27e0be45d23b6be21;p=thirdparty%2Fkea.git [2209] Make the reload tests typed This'll allow us to reuse them for testing the ZoneWriter approach for the same purpose as reload(). The ZoneWriter one is not there yet, so this is an equivalent change functionality-wise. --- diff --git a/src/lib/datasrc/tests/client_list_unittest.cc b/src/lib/datasrc/tests/client_list_unittest.cc index d995d5c910..ee1ca58d97 100644 --- a/src/lib/datasrc/tests/client_list_unittest.cc +++ b/src/lib/datasrc/tests/client_list_unittest.cc @@ -844,116 +844,145 @@ TEST_F(ListTest, BadMasterFile) { true); } +// This allows us to test two versions of the reloading code +// (One by calling reload(), one by obtaining a ZoneWriter and +// plaping with that). Once we deprecate reload(), we should revert this +// change and not use typed tests any more. +template +class ReloadTest : public ListTest { +public: + ConfigurableClientList::ReloadResult doReload(const Name& origin); +}; + +// Version with calling reload() +class ReloadUpdateType {}; +template<> +ConfigurableClientList::ReloadResult +ReloadTest::doReload(const Name& origin) { + return (list_->reload(origin)); +}; + +// TODO: Version with ZoneWriter + +typedef ::testing::Types UpdateTypes; +TYPED_TEST_CASE(ReloadTest, ReloadUpdateType); + // Test we can reload a zone -TEST_F(ListTest, reloadSuccess) { - list_->configure(config_elem_zones_, true); +TYPED_TEST(ReloadTest, reloadSuccess) { + this->list_->configure(this->config_elem_zones_, true); const Name name("example.org"); - prepareCache(0, name); + this->prepareCache(0, name); // The cache currently contains a tweaked version of zone, which doesn't // have apex NS. So the lookup should result in NXRRSET. EXPECT_EQ(ZoneFinder::NXRRSET, - list_->find(name).finder_->find(name, RRType::NS())->code); + this->list_->find(name).finder_->find(name, RRType::NS())->code); // Now reload the full zone. It should be there now. - EXPECT_EQ(ConfigurableClientList::ZONE_RELOADED, list_->reload(name)); + EXPECT_EQ(ConfigurableClientList::ZONE_RELOADED, this->doReload(name)); EXPECT_EQ(ZoneFinder::SUCCESS, - list_->find(name).finder_->find(name, RRType::NS())->code); + this->list_->find(name).finder_->find(name, RRType::NS())->code); } // The cache is not enabled. The load should be rejected. -TEST_F(ListTest, reloadNotEnabled) { - list_->configure(config_elem_zones_, false); +TYPED_TEST(ReloadTest, reloadNotEnabled) { + this->list_->configure(this->config_elem_zones_, false); const Name name("example.org"); // We put the cache in even when not enabled. This won't confuse the thing. - prepareCache(0, name); + this->prepareCache(0, name); // See the reloadSuccess test. This should result in NXRRSET. EXPECT_EQ(ZoneFinder::NXRRSET, - list_->find(name).finder_->find(name, RRType::NS())->code); + this->list_->find(name).finder_->find(name, RRType::NS())->code); // Now reload. It should reject it. - EXPECT_EQ(ConfigurableClientList::CACHE_DISABLED, list_->reload(name)); + EXPECT_EQ(ConfigurableClientList::CACHE_DISABLED, this->doReload(name)); // Nothing changed here EXPECT_EQ(ZoneFinder::NXRRSET, - list_->find(name).finder_->find(name, RRType::NS())->code); + this->list_->find(name).finder_->find(name, RRType::NS())->code); } // Test several cases when the zone does not exist -TEST_F(ListTest, reloadNoSuchZone) { - list_->configure(config_elem_zones_, true); +TYPED_TEST(ReloadTest, reloadNoSuchZone) { + this->list_->configure(this->config_elem_zones_, true); const Name name("example.org"); // We put the cache in even when not enabled. This won't confuse the // reload method, as that one looks at the real state of things, not // at the configuration. - prepareCache(0, Name("example.com")); + this->prepareCache(0, Name("example.com")); // Not in the data sources EXPECT_EQ(ConfigurableClientList::ZONE_NOT_FOUND, - list_->reload(Name("example.cz"))); + this->doReload(Name("exmaple.cz"))); // Not cached - EXPECT_EQ(ConfigurableClientList::ZONE_NOT_FOUND, list_->reload(name)); + EXPECT_EQ(ConfigurableClientList::ZONE_NOT_FOUND, this->doReload(name)); // Partial match EXPECT_EQ(ConfigurableClientList::ZONE_NOT_FOUND, - list_->reload(Name("sub.example.com"))); + this->doReload(Name("sub.example.com"))); // Nothing changed here - these zones don't exist EXPECT_EQ(static_cast(NULL), - list_->find(name).dsrc_client_); + this->list_->find(name).dsrc_client_); EXPECT_EQ(static_cast(NULL), - list_->find(Name("example.cz")).dsrc_client_); + this->list_->find(Name("example.cz")).dsrc_client_); EXPECT_EQ(static_cast(NULL), - list_->find(Name("sub.example.com"), true).dsrc_client_); + this->list_->find(Name("sub.example.com"), true).dsrc_client_); // Not reloaded, so NS shouldn't be visible yet. EXPECT_EQ(ZoneFinder::NXRRSET, - list_->find(Name("example.com")).finder_-> + this->list_->find(Name("example.com")).finder_-> find(Name("example.com"), RRType::NS())->code); } // Check we gracefuly throw an exception when a zone disappeared in // the underlying data source when we want to reload it -TEST_F(ListTest, reloadZoneGone) { - list_->configure(config_elem_, true); +TYPED_TEST(ReloadTest, reloadZoneGone) { + this->list_->configure(this->config_elem_, true); const Name name("example.org"); // We put in a cache for non-existant zone. This emulates being loaded // and then the zone disappearing. We prefill the cache, so we can check // it. - prepareCache(0, name); + this->prepareCache(0, name); // The (cached) zone contains zone's SOA EXPECT_EQ(ZoneFinder::SUCCESS, - list_->find(name).finder_->find(name, RRType::SOA())->code); + this->list_->find(name).finder_->find(name, + RRType::SOA())->code); // The zone is not there, so abort the reload. - EXPECT_THROW(list_->reload(name), DataSourceError); + EXPECT_THROW(this->doReload(name), DataSourceError); // The (cached) zone is not hurt. EXPECT_EQ(ZoneFinder::SUCCESS, - list_->find(name).finder_->find(name, RRType::SOA())->code); + this->list_->find(name).finder_->find(name, + RRType::SOA())->code); } // The underlying data source throws. Check we don't modify the state. -TEST_F(ListTest, reloadZoneThrow) { - list_->configure(config_elem_zones_, true); +TYPED_TEST(ReloadTest, reloadZoneThrow) { + this->list_->configure(this->config_elem_zones_, true); const Name name("noiter.org"); - prepareCache(0, name); + this->prepareCache(0, name); // The zone contains stuff now EXPECT_EQ(ZoneFinder::SUCCESS, - list_->find(name).finder_->find(name, RRType::SOA())->code); + this->list_->find(name).finder_->find(name, + RRType::SOA())->code); // The iterator throws, so abort the reload. - EXPECT_THROW(list_->reload(name), isc::NotImplemented); + EXPECT_THROW(this->doReload(name), isc::NotImplemented); // The zone is not hurt. EXPECT_EQ(ZoneFinder::SUCCESS, - list_->find(name).finder_->find(name, RRType::SOA())->code); + this->list_->find(name).finder_->find(name, + RRType::SOA())->code); } -TEST_F(ListTest, reloadNullIterator) { - list_->configure(config_elem_zones_, true); +TYPED_TEST(ReloadTest, reloadNullIterator) { + this->list_->configure(this->config_elem_zones_, true); const Name name("null.org"); - prepareCache(0, name); + this->prepareCache(0, name); // The zone contains stuff now EXPECT_EQ(ZoneFinder::SUCCESS, - list_->find(name).finder_->find(name, RRType::SOA())->code); + this->list_->find(name).finder_->find(name, + RRType::SOA())->code); // The iterator throws, so abort the reload. - EXPECT_THROW(list_->reload(name), isc::Unexpected); + EXPECT_THROW(this->doReload(name), isc::Unexpected); // The zone is not hurt. EXPECT_EQ(ZoneFinder::SUCCESS, - list_->find(name).finder_->find(name, RRType::SOA())->code); + this->list_->find(name).finder_->find(name, + RRType::SOA())->code); } // Test we can reload the master files too (special-cased) -TEST_F(ListTest, reloadMasterFile) { +TYPED_TEST(ReloadTest, reloadMasterFile) { const char* const install_cmd = INSTALL_PROG " -c " TEST_DATA_DIR "/root.zone " TEST_DATA_BUILDDIR "/root.zone.copied"; if (system(install_cmd) != 0) { @@ -971,21 +1000,22 @@ TEST_F(ListTest, reloadMasterFile) { " \".\": \"" TEST_DATA_BUILDDIR "/root.zone.copied\"" " }" "}]")); - list_->configure(elem, true); + this->list_->configure(elem, true); // Add a record that is not in the zone EXPECT_EQ(ZoneFinder::NXDOMAIN, - list_->find(Name(".")).finder_->find(Name("nosuchdomain"), - RRType::TXT())->code); + this->list_->find(Name(".")).finder_->find(Name("nosuchdomain"), + RRType::TXT())->code); ofstream f; f.open(TEST_DATA_BUILDDIR "/root.zone.copied", ios::out | ios::app); f << "nosuchdomain.\t\t3600\tIN\tTXT\ttest" << std::endl; f.close(); // Do the reload. - EXPECT_EQ(ConfigurableClientList::ZONE_RELOADED, list_->reload(Name("."))); + EXPECT_EQ(ConfigurableClientList::ZONE_RELOADED, + this->doReload(Name("."))); // It is here now. EXPECT_EQ(ZoneFinder::SUCCESS, - list_->find(Name(".")).finder_->find(Name("nosuchdomain"), - RRType::TXT())->code); + this->list_->find(Name(".")).finder_->find(Name("nosuchdomain"), + RRType::TXT())->code); } }