BIND 10 trac2207, updated. 58c41ea9cdb2df726b4b54015500acab3ae34040 [2207] Rename updater to reloader
BIND 10 source code commits
bind10-changes at lists.isc.org
Sat Oct 13 09:22:08 UTC 2012
The branch, trac2207 has been updated
via 58c41ea9cdb2df726b4b54015500acab3ae34040 (commit)
from c64356e9fdf3be868bb2d624200219d68aca45e8 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 58c41ea9cdb2df726b4b54015500acab3ae34040
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date: Sat Oct 13 11:21:44 2012 +0200
[2207] Rename updater to reloader
This might be less confusing.
-----------------------------------------------------------------------
Summary of changes:
src/lib/datasrc/memory/Makefile.am | 2 +-
.../memory/{zone_updater.cc => zone_reloader.cc} | 20 ++---
.../memory/{zone_updater.h => zone_reloader.h} | 16 ++--
src/lib/datasrc/tests/memory/Makefile.am | 2 +-
...dater_unittest.cc => zone_reloader_unittest.cc} | 91 ++++++++++----------
5 files changed, 66 insertions(+), 65 deletions(-)
rename src/lib/datasrc/memory/{zone_updater.cc => zone_reloader.cc} (80%)
rename src/lib/datasrc/memory/{zone_updater.h => zone_reloader.h} (94%)
rename src/lib/datasrc/tests/memory/{zone_updater_unittest.cc => zone_reloader_unittest.cc} (72%)
-----------------------------------------------------------------------
diff --git a/src/lib/datasrc/memory/Makefile.am b/src/lib/datasrc/memory/Makefile.am
index a4a2a6b..192bbce 100644
--- a/src/lib/datasrc/memory/Makefile.am
+++ b/src/lib/datasrc/memory/Makefile.am
@@ -22,7 +22,7 @@ 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_updater.h zone_updater.cc
+libdatasrc_memory_la_SOURCES += zone_reloader.h zone_reloader.cc
nodist_libdatasrc_memory_la_SOURCES = memory_messages.h memory_messages.cc
EXTRA_DIST = rdata_serialization_priv.cc
diff --git a/src/lib/datasrc/memory/zone_reloader.cc b/src/lib/datasrc/memory/zone_reloader.cc
new file mode 100644
index 0000000..67c6865
--- /dev/null
+++ b/src/lib/datasrc/memory/zone_reloader.cc
@@ -0,0 +1,90 @@
+// Copyright (C) 2012 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 "zone_reloader.h"
+#include "zone_data.h"
+#include "zone_table_segment.h"
+
+#include <memory>
+
+using std::auto_ptr;
+
+namespace isc {
+namespace datasrc {
+namespace memory {
+
+ZoneReloaderLocal::ZoneReloaderLocal(ZoneTableSegment* segment,
+ const LoadAction& load_action,
+ const InstallAction& install_action,
+ const dns::Name& origin,
+ const dns::RRClass& rrclass) :
+ segment_(segment),
+ load_action_(load_action),
+ install_action_(install_action),
+ origin_(origin),
+ rrclass_(rrclass),
+ zone_data_(NULL),
+ loaded_(false),
+ data_ready_(false)
+{}
+
+ZoneReloaderLocal::~ZoneReloaderLocal() {
+ // Clean up everything there might be left if someone forgot, just
+ // in case. Or should we assert instead?
+ cleanup();
+}
+
+void
+ZoneReloaderLocal::load() {
+ if (loaded_) {
+ isc_throw(isc::Unexpected, "Trying to load twice");
+ }
+ loaded_ = true;
+
+ zone_data_ = ZoneData::create(segment_->getMemorySegment(), origin_);
+
+ load_action_(zone_data_);
+
+ data_ready_ = true;
+}
+
+void
+ZoneReloaderLocal::install() {
+ if (!data_ready_) {
+ isc_throw(isc::Unexpected, "No data to install");
+ }
+
+ data_ready_ = false;
+ auto_ptr<ZoneSegment> zone_segment(new ZoneSegment(zone_data_));
+
+ zone_data_ = install_action_(ZoneSegmentID(), zone_segment.get());
+
+ // The ownership was passed to the callback, no need to clear it now.
+ zone_segment.release();
+}
+
+void
+ZoneReloaderLocal::cleanup() {
+ // We eat the data (if any) now.
+ data_ready_ = false;
+
+ if (zone_data_ != NULL) {
+ ZoneData::destroy(segment_->getMemorySegment(), zone_data_, rrclass_);
+ zone_data_ = NULL;
+ }
+}
+
+}
+}
+}
diff --git a/src/lib/datasrc/memory/zone_reloader.h b/src/lib/datasrc/memory/zone_reloader.h
new file mode 100644
index 0000000..12e84dc
--- /dev/null
+++ b/src/lib/datasrc/memory/zone_reloader.h
@@ -0,0 +1,183 @@
+// Copyright (C) 2012 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 <dns/name.h>
+#include <dns/rrclass.h>
+
+#include <boost/function.hpp>
+
+namespace isc {
+namespace datasrc {
+namespace memory {
+
+// Forward declarations
+class ZoneData;
+class ZoneTableSegment;
+
+/// \brief Does an update to a zone.
+///
+/// This abstract base class represents the work of a reload of a zone.
+/// The work is divided into three stages -- load(), install() and cleanup().
+/// They should be called in this order for the effect to take place.
+///
+/// We divide them so the update of zone data can be done asynchronously,
+/// in a different thread. The install() operation is the only one that needs
+/// to be done in a critical section.
+class ZoneReloader {
+public:
+ /// \brief Get the zone data into memory.
+ ///
+ /// This is the part that does the time-consuming loading into the memory.
+ /// This can be run in a separate thread, for example. It has no effect on
+ /// the data actually served, it only prepares them for future use.
+ ///
+ /// This is the first method you should call on the object. Never call it
+ /// multiple times.
+ ///
+ /// \note As this contains reading of files or other data sources, or with
+ /// some other source of the data to load, it may throw quite anything.
+ /// If it throws, do not call any other methods on the object and
+ /// discard it.
+ /// \note After successful load(), you have to call cleanup() some time
+ /// later.
+ /// \throw isc::Unexpected if called second time.
+ virtual void load() = 0;
+ /// \brief Put the changes to effect.
+ ///
+ /// This replaces the old version of zone with the one previously prepared
+ /// by load(). It takes ownership of the old zone data, if any.
+ ///
+ /// You may call it only after successful load() and at most once.
+ ///
+ /// The operation is expected to be fast and is meant to be used inside
+ /// a critical section.
+ ///
+ /// This may throw in rare cases, depending on the concrete implementation.
+ /// If it throws, you still need to call cleanup().
+ ///
+ /// \throw isc::Unexpected if called without previous load() or for the
+ /// second time or cleanup() was called already.
+ virtual void install() = 0;
+ /// \brief Clean up resources.
+ ///
+ /// This releases all resources held by owned zone data. That means the
+ /// one loaded by load() in case install() was not called or was not
+ /// successful, or the one replaced in install().
+ ///
+ /// Generally, this should never throw.
+ virtual void cleanup() = 0;
+};
+
+// TODO: Fully define this. It is supposed to be passed to the install_action
+// callback, but what does it actually represent? Is it the actuall zone data
+// there?
+//
+// The current interface is temporary, so the tests work. It will probably
+// change (and we may even fold this class to some other, because there
+// seem to be too many classes around holding zone already).
+//
+// FIXME: Who is responsible for releasing of the segment itself?
+class ZoneSegment {
+public:
+ explicit ZoneSegment(ZoneData* data) :
+ data_(data)
+ {}
+ ZoneData* getZoneData() {
+ return (data_);
+ }
+private:
+ ZoneData* data_;
+};
+// TODO: Somehow specify what the ID is
+class ZoneSegmentID {};
+
+/// \brief Callback to load data into the memory
+///
+/// This is called with a clean (empty) zone data. The goal of the
+/// callback is to get the data for the zone from somewhere and put
+/// them into the passed ZoneData parameter.
+typedef boost::function<void(ZoneData*)> LoadAction;
+/// \brief Install the zone somewhere.
+///
+/// The goal of the callback is to take the zone data (contained in the
+/// ZoneSegment and identified by ZoneSegmentID) and put it somewhere
+/// to use. The return value should contain the old copy of the zone, if
+/// there was any (it may be NULL). The updater will then destroy it.
+///
+/// Upon successful completion, the ownership of the new zone is passed
+/// to the callback and the old to the updater.
+typedef boost::function<ZoneData* (const ZoneSegmentID&,
+ ZoneSegment*)> InstallAction;
+
+/// \brief Reloader implementation which loads data locally.
+///
+/// This implementation prepares a clean zone data and lets one callback
+/// to fill it and another to install it somewhere. The class does mostly
+/// nothing (and delegates the work to the callbacks), just stores little bit
+/// of state between the calls.
+class ZoneReloaderLocal : public ZoneReloader {
+public:
+ /// \brief Constructor
+ ///
+ /// \param segment The zone table segment to store the zone into.
+ /// \param load_action The callback used to load data.
+ /// \param install_action The callback used to install the loaded zone.
+ /// \param origin The origin name of the zone.
+ /// \param rrclass The class of the zone.
+ ZoneReloaderLocal(ZoneTableSegment* segment, const LoadAction& load_action,
+ const InstallAction& install_action,
+ const dns::Name& origin,
+ const dns::RRClass& rrclass);
+ /// \brief Destructor
+ ~ZoneReloaderLocal();
+ /// \brief Loads the data.
+ ///
+ /// This prepares an empty ZoneData and calls load_action (passed to
+ /// constructor) to fill it with data.
+ ///
+ /// \throw std::bad_alloc If there's a problem allocating the ZoneData.
+ /// \throw isc::Unexpected if it is called the second time in lifetime
+ /// of the object.
+ /// \throw Whatever the load_action throws, it is propagated up.
+ virtual void load();
+ /// \brief Installs the zone.
+ ///
+ /// This simply calls the install_action.
+ ///
+ /// \throw isc::Unexpected if it is called the second time in lifetime
+ /// of the object or if load() was not called previously or if
+ /// cleanup() was already called.
+ /// \throw Whatever the install_action throws, it is propagated up.
+ virtual void install();
+ /// \brief Clean up memory.
+ ///
+ /// Cleans up the memory used by load()ed zone if not yet installed, or
+ /// the old zone replaced by install().
+ virtual void cleanup();
+private:
+ ZoneTableSegment* segment_;
+ LoadAction load_action_;
+ InstallAction install_action_;
+ dns::Name origin_;
+ dns::RRClass rrclass_;
+ ZoneData* zone_data_;
+ // The load was performed
+ bool loaded_;
+ // The data are ready to be installed
+ bool data_ready_;
+};
+
+}
+}
+}
diff --git a/src/lib/datasrc/memory/zone_updater.cc b/src/lib/datasrc/memory/zone_updater.cc
deleted file mode 100644
index 40d55ee..0000000
--- a/src/lib/datasrc/memory/zone_updater.cc
+++ /dev/null
@@ -1,90 +0,0 @@
-// Copyright (C) 2012 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 "zone_updater.h"
-#include "zone_data.h"
-#include "zone_table_segment.h"
-
-#include <memory>
-
-using std::auto_ptr;
-
-namespace isc {
-namespace datasrc {
-namespace memory {
-
-ZoneUpdaterLocal::ZoneUpdaterLocal(ZoneTableSegment* segment,
- const LoadAction& load_action,
- const InstallAction& install_action,
- const dns::Name& origin,
- const dns::RRClass& rrclass) :
- segment_(segment),
- load_action_(load_action),
- install_action_(install_action),
- origin_(origin),
- rrclass_(rrclass),
- zone_data_(NULL),
- loaded_(false),
- data_ready_(false)
-{}
-
-ZoneUpdaterLocal::~ZoneUpdaterLocal() {
- // Clean up everything there might be left if someone forgot, just
- // in case. Or should we assert instead?
- cleanup();
-}
-
-void
-ZoneUpdaterLocal::load() {
- if (loaded_) {
- isc_throw(isc::Unexpected, "Trying to load twice");
- }
- loaded_ = true;
-
- zone_data_ = ZoneData::create(segment_->getMemorySegment(), origin_);
-
- load_action_(zone_data_);
-
- data_ready_ = true;
-}
-
-void
-ZoneUpdaterLocal::install() {
- if (!data_ready_) {
- isc_throw(isc::Unexpected, "No data to install");
- }
-
- data_ready_ = false;
- auto_ptr<ZoneSegment> zone_segment(new ZoneSegment(zone_data_));
-
- zone_data_ = install_action_(ZoneSegmentID(), zone_segment.get());
-
- // The ownership was passed to the callback, no need to clear it now.
- zone_segment.release();
-}
-
-void
-ZoneUpdaterLocal::cleanup() {
- // We eat the data (if any) now.
- data_ready_ = false;
-
- if (zone_data_ != NULL) {
- ZoneData::destroy(segment_->getMemorySegment(), zone_data_, rrclass_);
- zone_data_ = NULL;
- }
-}
-
-}
-}
-}
diff --git a/src/lib/datasrc/memory/zone_updater.h b/src/lib/datasrc/memory/zone_updater.h
deleted file mode 100644
index 5d445dd..0000000
--- a/src/lib/datasrc/memory/zone_updater.h
+++ /dev/null
@@ -1,183 +0,0 @@
-// Copyright (C) 2012 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 <dns/name.h>
-#include <dns/rrclass.h>
-
-#include <boost/function.hpp>
-
-namespace isc {
-namespace datasrc {
-namespace memory {
-
-// Forward declarations
-class ZoneData;
-class ZoneTableSegment;
-
-/// \brief Does an update to a zone.
-///
-/// This abstract base class represents the work of a reload of a zone.
-/// The work is divided into three stages -- load(), install() and cleanup().
-/// They should be called in this order for the effect to take place.
-///
-/// We divide them so the update of zone data can be done asynchronously,
-/// in a different thread. The install() operation is the only one that needs
-/// to be done in a critical section.
-class ZoneUpdater {
-public:
- /// \brief Get the zone data into memory.
- ///
- /// This is the part that does the time-consuming loading into the memory.
- /// This can be run in a separate thread, for example. It has no effect on
- /// the data actually served, it only prepares them for future use.
- ///
- /// This is the first method you should call on the object. Never call it
- /// multiple times.
- ///
- /// \note As this contains reading of files or other data sources, or with
- /// some other source of the data to load, it may throw quite anything.
- /// If it throws, do not call any other methods on the object and
- /// discard it.
- /// \note After successful load(), you have to call cleanup() some time
- /// later.
- /// \throw isc::Unexpected if called second time.
- virtual void load() = 0;
- /// \brief Put the changes to effect.
- ///
- /// This replaces the old version of zone with the one previously prepared
- /// by load(). It takes ownership of the old zone data, if any.
- ///
- /// You may call it only after successful load() and at most once.
- ///
- /// The operation is expected to be fast and is meant to be used inside
- /// a critical section.
- ///
- /// This may throw in rare cases, depending on the concrete implementation.
- /// If it throws, you still need to call cleanup().
- ///
- /// \throw isc::Unexpected if called without previous load() or for the
- /// second time or cleanup() was called already.
- virtual void install() = 0;
- /// \brief Clean up resources.
- ///
- /// This releases all resources held by owned zone data. That means the
- /// one loaded by load() in case install() was not called or was not
- /// successful, or the one replaced in install().
- ///
- /// Generally, this should never throw.
- virtual void cleanup() = 0;
-};
-
-// TODO: Fully define this. It is supposed to be passed to the install_action
-// callback, but what does it actually represent? Is it the actuall zone data
-// there?
-//
-// The current interface is temporary, so the tests work. It will probably
-// change (and we may even fold this class to some other, because there
-// seem to be too many classes around holding zone already).
-//
-// FIXME: Who is responsible for releasing of the segment itself?
-class ZoneSegment {
-public:
- explicit ZoneSegment(ZoneData* data) :
- data_(data)
- {}
- ZoneData* getZoneData() {
- return (data_);
- }
-private:
- ZoneData* data_;
-};
-// TODO: Somehow specify what the ID is
-class ZoneSegmentID {};
-
-/// \brief Callback to load data into the memory
-///
-/// This is called with a clean (empty) zone data. The goal of the
-/// callback is to get the data for the zone from somewhere and put
-/// them into the passed ZoneData parameter.
-typedef boost::function<void(ZoneData*)> LoadAction;
-/// \brief Install the zone somewhere.
-///
-/// The goal of the callback is to take the zone data (contained in the
-/// ZoneSegment and identified by ZoneSegmentID) and put it somewhere
-/// to use. The return value should contain the old copy of the zone, if
-/// there was any (it may be NULL). The updater will then destroy it.
-///
-/// Upon successful completion, the ownership of the new zone is passed
-/// to the callback and the old to the updater.
-typedef boost::function<ZoneData* (const ZoneSegmentID&,
- ZoneSegment*)> InstallAction;
-
-/// \brief Updater implementation which loads data locally.
-///
-/// This implementation prepares a clean zone data and lets one callback
-/// to fill it and another to install it somewhere. The class does mostly
-/// nothing (and delegates the work to the callbacks), just stores little bit
-/// of state between the calls.
-class ZoneUpdaterLocal : public ZoneUpdater {
-public:
- /// \brief Constructor
- ///
- /// \param segment The zone table segment to store the zone into.
- /// \param load_action The callback used to load data.
- /// \param install_action The callback used to install the loaded zone.
- /// \param origin The origin name of the zone.
- /// \param rrclass The class of the zone.
- ZoneUpdaterLocal(ZoneTableSegment* segment, const LoadAction& load_action,
- const InstallAction& install_action,
- const dns::Name& origin,
- const dns::RRClass& rrclass);
- /// \brief Destructor
- ~ZoneUpdaterLocal();
- /// \brief Loads the data.
- ///
- /// This prepares an empty ZoneData and calls load_action (passed to
- /// constructor) to fill it with data.
- ///
- /// \throw std::bad_alloc If there's a problem allocating the ZoneData.
- /// \throw isc::Unexpected if it is called the second time in lifetime
- /// of the object.
- /// \throw Whatever the load_action throws, it is propagated up.
- virtual void load();
- /// \brief Installs the zone.
- ///
- /// This simply calls the install_action.
- ///
- /// \throw isc::Unexpected if it is called the second time in lifetime
- /// of the object or if load() was not called previously or if
- /// cleanup() was already called.
- /// \throw Whatever the install_action throws, it is propagated up.
- virtual void install();
- /// \brief Clean up memory.
- ///
- /// Cleans up the memory used by load()ed zone if not yet installed, or
- /// the old zone replaced by install().
- virtual void cleanup();
-private:
- ZoneTableSegment* segment_;
- LoadAction load_action_;
- InstallAction install_action_;
- dns::Name origin_;
- dns::RRClass rrclass_;
- ZoneData* zone_data_;
- // The load was performed
- bool loaded_;
- // The data are ready to be installed
- bool data_ready_;
-};
-
-}
-}
-}
diff --git a/src/lib/datasrc/tests/memory/Makefile.am b/src/lib/datasrc/tests/memory/Makefile.am
index ba922a6..5b3d9b5 100644
--- a/src/lib/datasrc/tests/memory/Makefile.am
+++ b/src/lib/datasrc/tests/memory/Makefile.am
@@ -33,7 +33,7 @@ run_unittests_SOURCES += memory_segment_test.h
run_unittests_SOURCES += segment_object_holder_unittest.cc
run_unittests_SOURCES += memory_client_unittest.cc
run_unittests_SOURCES += zone_table_segment_unittest.cc
-run_unittests_SOURCES += zone_updater_unittest.cc
+run_unittests_SOURCES += zone_reloader_unittest.cc
run_unittests_CPPFLAGS = $(AM_CPPFLAGS) $(GTEST_INCLUDES)
run_unittests_LDFLAGS = $(AM_LDFLAGS) $(GTEST_LDFLAGS)
diff --git a/src/lib/datasrc/tests/memory/zone_reloader_unittest.cc b/src/lib/datasrc/tests/memory/zone_reloader_unittest.cc
new file mode 100644
index 0000000..4c71abd
--- /dev/null
+++ b/src/lib/datasrc/tests/memory/zone_reloader_unittest.cc
@@ -0,0 +1,237 @@
+// Copyright (C) 2012 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 <datasrc/memory/zone_reloader.h>
+#include <datasrc/memory/zone_table_segment.h>
+#include <datasrc/memory/zone_data.h>
+
+#include <cc/data.h>
+#include <dns/rrclass.h>
+#include <dns/name.h>
+
+#include <gtest/gtest.h>
+
+#include <boost/scoped_ptr.hpp>
+#include <boost/bind.hpp>
+
+using boost::scoped_ptr;
+using boost::bind;
+using isc::dns::RRClass;
+using isc::dns::Name;
+using namespace isc::datasrc::memory;
+
+namespace {
+
+class TestException {};
+
+class ZoneReloaderLocalTest : public ::testing::Test {
+public:
+ ZoneReloaderLocalTest() :
+ // FIXME: The NullElement probably isn't the best one, but we don't
+ // know how the config will look, so it just fills the argument
+ // (which is currently ignored)
+ segment_(ZoneTableSegment::create(isc::data::NullElement())),
+ reloader_(new
+ ZoneReloaderLocal(segment_.get(),
+ bind(&ZoneReloaderLocalTest::loadAction, this,
+ _1),
+ bind(&ZoneReloaderLocalTest::installAction, this,
+ _1, _2),
+ Name("example.org"), RRClass::IN())),
+ load_called_(false),
+ install_called_(false),
+ load_throw_(false),
+ install_throw_(false)
+ {}
+ void TearDown() {
+ // Release the reloader
+ reloader_.reset();
+ // And check we freed all memory
+ EXPECT_TRUE(segment_->getMemorySegment().allMemoryDeallocated());
+ }
+protected:
+ scoped_ptr<ZoneTableSegment> segment_;
+ scoped_ptr<ZoneReloaderLocal> reloader_;
+ bool load_called_;
+ bool install_called_;
+ bool load_throw_;
+ bool install_throw_;
+private:
+ void loadAction(ZoneData* data) {
+ // Make sure we get something.
+ EXPECT_NE(static_cast<const ZoneData*>(NULL), data);
+ // We got called
+ load_called_ = true;
+ if (load_throw_) {
+ throw TestException();
+ }
+ }
+ ZoneData* installAction(const ZoneSegmentID&, ZoneSegment* segment) {
+ install_called_ = true;
+
+ // Check we got something
+ if (segment == NULL) {
+ ADD_FAILURE() << "Zone segment is NULL in install action";
+ return (NULL);
+ }
+ EXPECT_NE(static_cast<const ZoneData*>(NULL), segment->getZoneData());
+
+ if (install_throw_) {
+ // In case we throw, we do so before releasing the memory there,
+ // as in that case we don't claim the ownership of the data.
+ throw TestException();
+ }
+
+ // We received ownership of the parameters here. And we don't really need
+ // them in the tests, so we just release them.
+ ZoneData::destroy(segment_->getMemorySegment(), segment->getZoneData(),
+ RRClass::IN());
+ delete segment;
+
+ // And we are supposed to pass the old version back. So we create
+ // new zone data and pass it.
+ return (ZoneData::create(segment_->getMemorySegment(), Name("exmaple.org")));
+ }
+};
+
+// We call it the way we are supposed to, check every callback is called in the
+// right moment.
+TEST_F(ZoneReloaderLocalTest, correctCall) {
+ // Nothing called before we call it
+ EXPECT_FALSE(load_called_);
+ EXPECT_FALSE(install_called_);
+
+ // Just the load gets called now
+ EXPECT_NO_THROW(reloader_->load());
+ EXPECT_TRUE(load_called_);
+ EXPECT_FALSE(install_called_);
+ load_called_ = false;
+
+ EXPECT_NO_THROW(reloader_->install());
+ EXPECT_FALSE(load_called_);
+ EXPECT_TRUE(install_called_);
+
+ // We don't check explicitly how this works, but call it to free memory. If
+ // everything is freed should be checked inside the TearDown.
+ EXPECT_NO_THROW(reloader_->cleanup());
+}
+
+TEST_F(ZoneReloaderLocalTest, loadTwice) {
+ // Load it the first time
+ EXPECT_NO_THROW(reloader_->load());
+ EXPECT_TRUE(load_called_);
+ EXPECT_FALSE(install_called_);
+ load_called_ = false;
+
+ // The second time, it should not be possible
+ EXPECT_THROW(reloader_->load(), isc::Unexpected);
+ EXPECT_FALSE(load_called_);
+ EXPECT_FALSE(install_called_);
+
+ // The object should not be damaged, try installing and clearing now
+ EXPECT_NO_THROW(reloader_->install());
+ EXPECT_FALSE(load_called_);
+ EXPECT_TRUE(install_called_);
+
+ // We don't check explicitly how this works, but call it to free memory. If
+ // everything is freed should be checked inside the TearDown.
+ EXPECT_NO_THROW(reloader_->cleanup());
+}
+
+// Try loading after call to install and call to cleanup. Both is
+// forbidden.
+TEST_F(ZoneReloaderLocalTest, loadLater) {
+ // Load first, so we can install
+ EXPECT_NO_THROW(reloader_->load());
+ EXPECT_NO_THROW(reloader_->install());
+ // Reset so we see nothing is called now
+ install_called_ = load_called_ = false;
+
+ EXPECT_THROW(reloader_->load(), isc::Unexpected);
+ EXPECT_FALSE(load_called_);
+ EXPECT_FALSE(install_called_);
+
+ // Cleanup and try loading again. Still shouldn't work.
+ EXPECT_NO_THROW(reloader_->cleanup());
+
+ EXPECT_THROW(reloader_->load(), isc::Unexpected);
+ EXPECT_FALSE(load_called_);
+ EXPECT_FALSE(install_called_);
+}
+
+// Try calling install at various bad times
+TEST_F(ZoneReloaderLocalTest, invalidInstall) {
+ // Nothing loaded yet
+ EXPECT_THROW(reloader_->install(), isc::Unexpected);
+ EXPECT_FALSE(load_called_);
+ EXPECT_FALSE(install_called_);
+
+ EXPECT_NO_THROW(reloader_->load());
+ load_called_ = false;
+ // This install is OK
+ EXPECT_NO_THROW(reloader_->install());
+ install_called_ = false;
+ // But we can't call it second time now
+ EXPECT_THROW(reloader_->install(), isc::Unexpected);
+ EXPECT_FALSE(load_called_);
+ EXPECT_FALSE(install_called_);
+}
+
+// We check we can clean without installing first and nothing bad
+// happens. We also misuse the testcase to check we can't install
+// after cleanup.
+TEST_F(ZoneReloaderLocalTest, cleanWithoutInstall) {
+ EXPECT_NO_THROW(reloader_->load());
+ EXPECT_NO_THROW(reloader_->cleanup());
+
+ EXPECT_TRUE(load_called_);
+ EXPECT_FALSE(install_called_);
+
+ // We cleaned up, no way to install now
+ EXPECT_THROW(reloader_->install(), isc::Unexpected);
+ EXPECT_FALSE(install_called_);
+}
+
+// Test the case when load callback throws
+TEST_F(ZoneReloaderLocalTest, loadThrows) {
+ load_throw_ = true;
+ EXPECT_THROW(reloader_->load(), TestException);
+
+ // We can't install now
+ EXPECT_THROW(reloader_->install(), isc::Unexpected);
+ EXPECT_TRUE(load_called_);
+ EXPECT_FALSE(install_called_);
+
+ // But we can cleanup
+ EXPECT_NO_THROW(reloader_->cleanup());
+}
+
+// Test we free all our memory even when we throw from install
+TEST_F(ZoneReloaderLocalTest, installThrows) {
+ install_throw_ = true;
+ EXPECT_NO_THROW(reloader_->load());
+
+ EXPECT_THROW(reloader_->install(), TestException);
+ EXPECT_TRUE(load_called_);
+ EXPECT_TRUE(install_called_);
+
+ // We can't try again
+ install_throw_ = false;
+ EXPECT_THROW(reloader_->install(), isc::Unexpected);
+
+ // But it is not completely broken
+ EXPECT_NO_THROW(reloader_->cleanup());
+}
+
+}
diff --git a/src/lib/datasrc/tests/memory/zone_updater_unittest.cc b/src/lib/datasrc/tests/memory/zone_updater_unittest.cc
deleted file mode 100644
index c32fb87..0000000
--- a/src/lib/datasrc/tests/memory/zone_updater_unittest.cc
+++ /dev/null
@@ -1,236 +0,0 @@
-// Copyright (C) 2012 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 <datasrc/memory/zone_updater.h>
-#include <datasrc/memory/zone_table_segment.h>
-#include <datasrc/memory/zone_data.h>
-
-#include <cc/data.h>
-#include <dns/rrclass.h>
-#include <dns/name.h>
-
-#include <gtest/gtest.h>
-
-#include <boost/scoped_ptr.hpp>
-#include <boost/bind.hpp>
-
-using boost::scoped_ptr;
-using boost::bind;
-using isc::dns::RRClass;
-using isc::dns::Name;
-using namespace isc::datasrc::memory;
-
-namespace {
-
-class TestException {};
-
-class ZoneUpdaterLocalTest : public ::testing::Test {
-public:
- ZoneUpdaterLocalTest() :
- // FIXME: The NullElement probably isn't the best one, but we don't
- // know how the config will look, so it just fills the argument
- // (which is currently ignored)
- segment_(ZoneTableSegment::create(isc::data::NullElement())),
- updater_(new
- ZoneUpdaterLocal(segment_.get(),
- bind(&ZoneUpdaterLocalTest::loadAction, this, _1),
- bind(&ZoneUpdaterLocalTest::installAction, this,
- _1, _2),
- Name("example.org"), RRClass::IN())),
- load_called_(false),
- install_called_(false),
- load_throw_(false),
- install_throw_(false)
- {}
- void TearDown() {
- // Release the updater
- updater_.reset();
- // And check we freed all memory
- EXPECT_TRUE(segment_->getMemorySegment().allMemoryDeallocated());
- }
-protected:
- scoped_ptr<ZoneTableSegment> segment_;
- scoped_ptr<ZoneUpdaterLocal> updater_;
- bool load_called_;
- bool install_called_;
- bool load_throw_;
- bool install_throw_;
-private:
- void loadAction(ZoneData* data) {
- // Make sure we get something.
- EXPECT_NE(static_cast<const ZoneData*>(NULL), data);
- // We got called
- load_called_ = true;
- if (load_throw_) {
- throw TestException();
- }
- }
- ZoneData* installAction(const ZoneSegmentID&, ZoneSegment* segment) {
- install_called_ = true;
-
- // Check we got something
- if (segment == NULL) {
- ADD_FAILURE() << "Zone segment is NULL in install action";
- return (NULL);
- }
- EXPECT_NE(static_cast<const ZoneData*>(NULL), segment->getZoneData());
-
- if (install_throw_) {
- // In case we throw, we do so before releasing the memory there,
- // as in that case we don't claim the ownership of the data.
- throw TestException();
- }
-
- // We received ownership of the parameters here. And we don't really need
- // them in the tests, so we just release them.
- ZoneData::destroy(segment_->getMemorySegment(), segment->getZoneData(),
- RRClass::IN());
- delete segment;
-
- // And we are supposed to pass the old version back. So we create
- // new zone data and pass it.
- return (ZoneData::create(segment_->getMemorySegment(), Name("exmaple.org")));
- }
-};
-
-// We call it the way we are supposed to, check every callback is called in the
-// right moment.
-TEST_F(ZoneUpdaterLocalTest, correctCall) {
- // Nothing called before we call it
- EXPECT_FALSE(load_called_);
- EXPECT_FALSE(install_called_);
-
- // Just the load gets called now
- EXPECT_NO_THROW(updater_->load());
- EXPECT_TRUE(load_called_);
- EXPECT_FALSE(install_called_);
- load_called_ = false;
-
- EXPECT_NO_THROW(updater_->install());
- EXPECT_FALSE(load_called_);
- EXPECT_TRUE(install_called_);
-
- // We don't check explicitly how this works, but call it to free memory. If
- // everything is freed should be checked inside the TearDown.
- EXPECT_NO_THROW(updater_->cleanup());
-}
-
-TEST_F(ZoneUpdaterLocalTest, loadTwice) {
- // Load it the first time
- EXPECT_NO_THROW(updater_->load());
- EXPECT_TRUE(load_called_);
- EXPECT_FALSE(install_called_);
- load_called_ = false;
-
- // The second time, it should not be possible
- EXPECT_THROW(updater_->load(), isc::Unexpected);
- EXPECT_FALSE(load_called_);
- EXPECT_FALSE(install_called_);
-
- // The object should not be damaged, try installing and clearing now
- EXPECT_NO_THROW(updater_->install());
- EXPECT_FALSE(load_called_);
- EXPECT_TRUE(install_called_);
-
- // We don't check explicitly how this works, but call it to free memory. If
- // everything is freed should be checked inside the TearDown.
- EXPECT_NO_THROW(updater_->cleanup());
-}
-
-// Try loading after call to install and call to cleanup. Both is
-// forbidden.
-TEST_F(ZoneUpdaterLocalTest, loadLater) {
- // Load first, so we can install
- EXPECT_NO_THROW(updater_->load());
- EXPECT_NO_THROW(updater_->install());
- // Reset so we see nothing is called now
- install_called_ = load_called_ = false;
-
- EXPECT_THROW(updater_->load(), isc::Unexpected);
- EXPECT_FALSE(load_called_);
- EXPECT_FALSE(install_called_);
-
- // Cleanup and try loading again. Still shouldn't work.
- EXPECT_NO_THROW(updater_->cleanup());
-
- EXPECT_THROW(updater_->load(), isc::Unexpected);
- EXPECT_FALSE(load_called_);
- EXPECT_FALSE(install_called_);
-}
-
-// Try calling install at various bad times
-TEST_F(ZoneUpdaterLocalTest, invalidInstall) {
- // Nothing loaded yet
- EXPECT_THROW(updater_->install(), isc::Unexpected);
- EXPECT_FALSE(load_called_);
- EXPECT_FALSE(install_called_);
-
- EXPECT_NO_THROW(updater_->load());
- load_called_ = false;
- // This install is OK
- EXPECT_NO_THROW(updater_->install());
- install_called_ = false;
- // But we can't call it second time now
- EXPECT_THROW(updater_->install(), isc::Unexpected);
- EXPECT_FALSE(load_called_);
- EXPECT_FALSE(install_called_);
-}
-
-// We check we can clean without installing first and nothing bad
-// happens. We also misuse the testcase to check we can't install
-// after cleanup.
-TEST_F(ZoneUpdaterLocalTest, cleanWithoutInstall) {
- EXPECT_NO_THROW(updater_->load());
- EXPECT_NO_THROW(updater_->cleanup());
-
- EXPECT_TRUE(load_called_);
- EXPECT_FALSE(install_called_);
-
- // We cleaned up, no way to install now
- EXPECT_THROW(updater_->install(), isc::Unexpected);
- EXPECT_FALSE(install_called_);
-}
-
-// Test the case when load callback throws
-TEST_F(ZoneUpdaterLocalTest, loadThrows) {
- load_throw_ = true;
- EXPECT_THROW(updater_->load(), TestException);
-
- // We can't install now
- EXPECT_THROW(updater_->install(), isc::Unexpected);
- EXPECT_TRUE(load_called_);
- EXPECT_FALSE(install_called_);
-
- // But we can cleanup
- EXPECT_NO_THROW(updater_->cleanup());
-}
-
-// Test we free all our memory even when we throw from install
-TEST_F(ZoneUpdaterLocalTest, installThrows) {
- install_throw_ = true;
- EXPECT_NO_THROW(updater_->load());
-
- EXPECT_THROW(updater_->install(), TestException);
- EXPECT_TRUE(load_called_);
- EXPECT_TRUE(install_called_);
-
- // We can't try again
- install_throw_ = false;
- EXPECT_THROW(updater_->install(), isc::Unexpected);
-
- // But it is not completely broken
- EXPECT_NO_THROW(updater_->cleanup());
-}
-
-}
More information about the bind10-changes
mailing list