From: Mukund Sivaraman Date: Thu, 11 Oct 2012 13:09:13 +0000 (+0530) Subject: Merge branch 'master' into trac2268 X-Git-Tag: trac2402_base~47 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=31fdd062b59d6ac480ff48cde57e5abad2b3487c;p=thirdparty%2Fkea.git Merge branch 'master' into trac2268 Conflicts: src/lib/datasrc/memory/Makefile.am src/lib/datasrc/memory/memory_client.cc src/lib/datasrc/memory/memory_client.h src/lib/datasrc/tests/memory/memory_client_unittest.cc --- 31fdd062b59d6ac480ff48cde57e5abad2b3487c diff --cc src/lib/datasrc/memory/Makefile.am index d46a9078ee,743caa22f5..205f1374c1 --- a/src/lib/datasrc/memory/Makefile.am +++ b/src/lib/datasrc/memory/Makefile.am @@@ -19,8 -19,9 +19,11 @@@ libdatasrc_memory_la_SOURCES += segment libdatasrc_memory_la_SOURCES += logger.h logger.cc libdatasrc_memory_la_SOURCES += zone_table.h zone_table.cc libdatasrc_memory_la_SOURCES += zone_finder.h zone_finder.cc + libdatasrc_memory_la_SOURCES += zone_table_segment.h zone_table_segment.cc + libdatasrc_memory_la_SOURCES += zone_table_segment_local.h zone_table_segment_local.cc +libdatasrc_memory_la_SOURCES += zone_data_updater.h zone_data_updater.cc +libdatasrc_memory_la_SOURCES += memory_client.h memory_client.cc ++ nodist_libdatasrc_memory_la_SOURCES = memory_messages.h memory_messages.cc EXTRA_DIST = rdata_serialization_priv.cc diff --cc src/lib/datasrc/memory/memory_client.cc index 0857541ecc,f4213470fe..d6b280311f --- a/src/lib/datasrc/memory/memory_client.cc +++ b/src/lib/datasrc/memory/memory_client.cc @@@ -30,14 -31,20 +30,13 @@@ #include #include -#include #include #include - #include #include -#include -#include -#include #include -#include -#include #include -#include #include #include #include @@@ -232,8 -729,9 +229,8 @@@ InMemoryClient::load(const isc::dns::Na const std::string InMemoryClient::getFileName(const isc::dns::Name& zone_name) const { - FileNameNode* node(NULL); - FileNameTree::Result result = file_name_tree_->find(zone_name, &node); + const FileNameNode* node(NULL); - const FileNameTree::Result result = impl_->file_name_tree_->find(zone_name, - &node); ++ const FileNameTree::Result result = file_name_tree_->find(zone_name, &node); if (result == FileNameTree::EXACTMATCH) { return (*node->getData()); } else { diff --cc src/lib/datasrc/memory/memory_client.h index edd3837b6f,c37ad53c0b..9b3113e406 --- a/src/lib/datasrc/memory/memory_client.h +++ b/src/lib/datasrc/memory/memory_client.h @@@ -159,35 -139,40 +159,6 @@@ public /// zone from a file before. const std::string getFileName(const isc::dns::Name& zone_name) const; - /// \brief Inserts an rrset into the zone. - /// - /// It puts another RRset into the zone. - /// \brief RRset is NULL exception. -- /// - /// In the current implementation, this method doesn't allow an existing - /// RRset to be updated or overridden. So the caller must make sure that - /// all RRs of the same type and name must be given in the form of a - /// single RRset. The current implementation will also require that - /// when an RRSIG is added, the RRset to be covered has already been - /// added. These restrictions are probably too strict when this data - /// source accepts various forms of input, so they should be revisited - /// later. - /// This is thrown if the provided RRset parameter is NULL. - struct NullRRset : public InvalidParameter { - NullRRset(const char* file, size_t line, const char* what) : - InvalidParameter(file, line, what) - { } - }; - - /// \brief Zone is empty exception. -- /// - /// Except for NullRRset and OutOfZone, this method does not guarantee - /// strong exception safety (it is currently not needed, if it is needed - /// in future, it should be implemented). - /// This is thrown if we have an empty zone created as a result of - /// load(). - struct EmptyZone : public InvalidParameter { - EmptyZone(const char* file, size_t line, const char* what) : - InvalidParameter(file, line, what) - { } - }; - - /// \brief General failure exception for \c add(). -- /// - /// \throw NullRRset \c rrset is a NULL pointer. - /// \throw OutOfZone The owner name of \c rrset is outside of the - /// origin of the zone. - /// \throw AddError Other general errors. - /// \throw Others This method might throw standard allocation exceptions. - /// This is thrown against general error cases in adding an RRset - /// to the zone. -- /// - /// \param rrset The set to add. - /// \return SUCCESS or EXIST (if an rrset for given name and type already - /// exists). - result::Result add(const isc::dns::Name& zone_name, - const isc::dns::ConstRRsetPtr& rrset); - /// Note: this exception would cover cases for \c OutOfZone or - /// \c NullRRset. We'll need to clarify and unify the granularity - /// of exceptions eventually. For now, exceptions are added as - /// developers see the need for it. - struct AddError : public InvalidParameter { - AddError(const char* file, size_t line, const char* what) : - InvalidParameter(file, line, what) - { } - }; -- /// Returns a \c ZoneFinder result that best matches the given name. /// /// This derived version of the method never throws an exception. diff --cc src/lib/datasrc/tests/memory/memory_client_unittest.cc index 4a34badb31,c5b6c10622..295c44cb55 --- a/src/lib/datasrc/tests/memory/memory_client_unittest.cc +++ b/src/lib/datasrc/tests/memory/memory_client_unittest.cc @@@ -547,29 -542,6 +546,33 @@@ TEST_F(MemoryClientTest, loadRRSIGs) EXPECT_EQ(1, client_->getZoneCount()); } ++#if 0 // FIXME ++ +TEST_F(MemoryClientTest, loadRRSIGsRdataMixedCoveredTypes) { + client_->load(Name("example.org"), + TEST_DATA_DIR "/example.org-rrsigs.zone"); + + RRsetPtr rrset(new RRset(Name("example.org"), + RRClass::IN(), RRType::A(), RRTTL(3600))); + rrset->addRdata(in::A("192.0.2.1")); + rrset->addRdata(in::A("192.0.2.2")); + + RRsetPtr rrsig(new RRset(Name("example.org"), zclass_, + RRType::RRSIG(), RRTTL(300))); + rrsig->addRdata(generic::RRSIG("A 5 3 3600 20000101000000 20000201000000 " + "12345 example.org. FAKEFAKEFAKE")); + rrsig->addRdata(generic::RRSIG("NS 5 3 3600 20000101000000 20000201000000 " + "54321 example.org. FAKEFAKEFAKEFAKE")); + rrset->addRRsig(rrsig); + + EXPECT_THROW(client_->add(Name("example.org"), rrset), + ZoneDataUpdater::AddError); + + // Teardown checks for memory segment leaks +} + ++#endif ++ TEST_F(MemoryClientTest, getZoneCount) { EXPECT_EQ(0, client_->getZoneCount()); client_->load(Name("example.org"), TEST_DATA_DIR "/example.org-empty.zone"); @@@ -659,75 -631,6 +662,79 @@@ TEST_F(MemoryClientTest, getIteratorGet EXPECT_THROW(iterator->getSOA(), isc::NotImplemented); } ++#if 0 // FIXME ++ +TEST_F(MemoryClientTest, addRRsetToNonExistentZoneThrows) { + // The zone "example.org" doesn't exist, so we can't add an RRset to + // it. + RRsetPtr rrset_a(new RRset(Name("example.org"), RRClass::IN(), RRType::A(), + RRTTL(300))); + rrset_a->addRdata(rdata::in::A("192.0.2.1")); + EXPECT_THROW(client_->add(Name("example.org"), rrset_a), DataSourceError); +} + +TEST_F(MemoryClientTest, addOutOfZoneThrows) { + // Out of zone names should throw. + client_->load(Name("example.org"), + TEST_DATA_DIR "/example.org-empty.zone"); + + RRsetPtr rrset_a(new RRset(Name("a.example.com"), + RRClass::IN(), RRType::A(), RRTTL(300))); + rrset_a->addRdata(rdata::in::A("192.0.2.1")); + + EXPECT_THROW(client_->add(Name("example.org"), rrset_a), + OutOfZone); + // Teardown checks for memory segment leaks +} + +TEST_F(MemoryClientTest, addNullRRsetThrows) { + client_->load(Name("example.org"), + TEST_DATA_DIR "/example.org-rrsigs.zone"); + + EXPECT_THROW(client_->add(Name("example.org"), ConstRRsetPtr()), + ZoneDataUpdater::NullRRset); + + // Teardown checks for memory segment leaks +} + +TEST_F(MemoryClientTest, addEmptyRRsetThrows) { + client_->load(Name("example.org"), + TEST_DATA_DIR "/example.org-rrsigs.zone"); + + RRsetPtr rrset_a(new RRset(Name("example.org"), RRClass::IN(), RRType::A(), + RRTTL(300))); + EXPECT_THROW(client_->add(Name("example.org"), rrset_a), + ZoneDataUpdater::AddError); + + // Teardown checks for memory segment leaks +} + +TEST_F(MemoryClientTest, add) { + client_->load(Name("example.org"), TEST_DATA_DIR "/example.org-empty.zone"); + + // Add another RRset + RRsetPtr rrset_a(new RRset(Name("example.org"), RRClass::IN(), RRType::A(), + RRTTL(300))); + rrset_a->addRdata(rdata::in::A("192.0.2.1")); + client_->add(Name("example.org"), rrset_a); + + ZoneIteratorPtr iterator(client_->getIterator(Name("example.org"))); + + // First we have the SOA + ConstRRsetPtr rrset(iterator->getNextRRset()); + EXPECT_TRUE(rrset); + EXPECT_EQ(RRType::A(), rrset->getType()); + + rrset = iterator->getNextRRset(); + EXPECT_TRUE(rrset); + EXPECT_EQ(RRType::SOA(), rrset->getType()); + + // There's nothing else in this zone + EXPECT_EQ(ConstRRsetPtr(), iterator->getNextRRset()); +} + ++#endif ++ TEST_F(MemoryClientTest, findZoneData) { client_->load(Name("example.org"), TEST_DATA_DIR "/example.org-rrsigs.zone"); @@@ -778,4 -681,16 +785,5 @@@ TEST_F(MemoryClientTest, getJournalRead EXPECT_THROW(client_->getJournalReader(Name("."), 0, 0), isc::NotImplemented); } + -// TODO (upon merge of #2268): Re-add (and modify not to need -// InMemoryClient::add) the tests removed in -// 7a628baa1a158b5837d6f383e10b30542d2ac59b. Maybe some of them -// are really not needed. -// -// * MemoryClientTest::loadRRSIGsRdataMixedCoveredTypes -// * MemoryClientTest::addRRsetToNonExistentZoneThrows -// * MemoryClientTest::addOutOfZoneThrows -// * MemoryClientTest::addNullRRsetThrows -// * MemoryClientTest::addEmptyRRsetThrows -// * MemoryClientTest::add } diff --cc src/lib/datasrc/tests/memory/zone_table_unittest.cc index a8ee6144e2,401d43431b..80f2a6e5f2 --- a/src/lib/datasrc/tests/memory/zone_table_unittest.cc +++ b/src/lib/datasrc/tests/memory/zone_table_unittest.cc @@@ -32,8 -31,30 +33,9 @@@ using namespace isc::dns; using namespace isc::datasrc; using namespace isc::datasrc::memory; + using namespace isc::datasrc::memory::detail; namespace { -// Memory segment specified for tests. It normally behaves like a "local" -// memory segment. If "throw count" is set to non 0 via setThrowCount(), -// it continues the normal behavior up to the specified number of calls to -// allocate(), and throws an exception at the next call. -class TestMemorySegment : public isc::util::MemorySegmentLocal { -public: - TestMemorySegment() : throw_count_(0) {} - virtual void* allocate(size_t size) { - if (throw_count_ > 0) { - if (--throw_count_ == 0) { - throw std::bad_alloc(); - } - } - return (isc::util::MemorySegmentLocal::allocate(size)); - } - void setThrowCount(size_t count) { throw_count_ = count; } - -private: - size_t throw_count_; -}; - class ZoneTableTest : public ::testing::Test { protected: ZoneTableTest() : zclass_(RRClass::IN()),