BIND 10 trac2207, updated. 0d336b6f23ca4518b38f1e26e8b8b9998f426e5f [2207] Rename ZoneUpdater -> ZoneWriter
BIND 10 source code commits
bind10-changes at lists.isc.org
Wed Oct 17 09:15:10 UTC 2012
The branch, trac2207 has been updated
via 0d336b6f23ca4518b38f1e26e8b8b9998f426e5f (commit)
from 07e1f1ddbd299b60ee4009f53723b4271b5cea16 (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 0d336b6f23ca4518b38f1e26e8b8b9998f426e5f
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date: Wed Oct 17 11:14:30 2012 +0200
[2207] Rename ZoneUpdater -> ZoneWriter
According to the review, Updater might be misleading.
-----------------------------------------------------------------------
Summary of changes:
src/lib/datasrc/memory/Makefile.am | 2 +-
src/lib/datasrc/memory/zone_table_segment.h | 8 +-
src/lib/datasrc/memory/zone_table_segment_local.cc | 12 +--
src/lib/datasrc/memory/zone_table_segment_local.h | 8 +-
.../memory/{zone_reloader.cc => zone_writer.cc} | 18 ++---
.../memory/{zone_reloader.h => zone_writer.h} | 10 +--
src/lib/datasrc/tests/memory/Makefile.am | 2 +-
.../tests/memory/zone_table_segment_unittest.cc | 18 ++---
...eloader_unittest.cc => zone_writer_unittest.cc} | 84 ++++++++++----------
9 files changed, 81 insertions(+), 81 deletions(-)
rename src/lib/datasrc/memory/{zone_reloader.cc => zone_writer.cc} (84%)
rename src/lib/datasrc/memory/{zone_reloader.h => zone_writer.h} (95%)
rename src/lib/datasrc/tests/memory/{zone_reloader_unittest.cc => zone_writer_unittest.cc} (71%)
-----------------------------------------------------------------------
diff --git a/src/lib/datasrc/memory/Makefile.am b/src/lib/datasrc/memory/Makefile.am
index 7319602..b626068 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_reloader.h zone_reloader.cc
+libdatasrc_memory_la_SOURCES += zone_writer.h zone_writer.cc
libdatasrc_memory_la_SOURCES += load_action.h
nodist_libdatasrc_memory_la_SOURCES = memory_messages.h memory_messages.cc
diff --git a/src/lib/datasrc/memory/zone_reloader.cc b/src/lib/datasrc/memory/zone_reloader.cc
deleted file mode 100644
index 7a3bd54..0000000
--- a/src/lib/datasrc/memory/zone_reloader.cc
+++ /dev/null
@@ -1,94 +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_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 dns::Name& origin,
- const dns::RRClass& rrclass) :
- segment_(segment),
- load_action_(load_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_ = load_action_(segment_->getMemorySegment());
-
- if (zone_data_ == NULL) {
- // Bug inside load_action_.
- isc_throw(isc::Unexpected, "No data returned from load action");
- }
-
- data_ready_ = true;
-}
-
-void
-ZoneReloaderLocal::install() {
- if (!data_ready_) {
- isc_throw(isc::Unexpected, "No data to install");
- }
-
- data_ready_ = false;
-
- ZoneTable* table(segment_->getHeader().getTable());
- if (table == NULL) {
- isc_throw(isc::Unexpected, "No zone table present");
- }
- ZoneTable::AddResult result(table->addZone(segment_->getMemorySegment(),
- rrclass_, origin_, zone_data_));
-
- zone_data_ = result.zone_data;
-}
-
-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
deleted file mode 100644
index b167237..0000000
--- a/src/lib/datasrc/memory/zone_reloader.h
+++ /dev/null
@@ -1,141 +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.
-
-#ifndef ZONE_RELOADER_H
-#define ZONE_RELOADER_H
-
-#include "load_action.h"
-
-#include <dns/rrclass.h>
-#include <dns/name.h>
-
-namespace isc {
-namespace datasrc {
-namespace memory {
-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;
-};
-
-/// \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 rrclass The class of the zone.
- ZoneReloaderLocal(ZoneTableSegment* segment, const LoadAction& load_action,
- const dns::Name& name, 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_;
- 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_;
-};
-
-}
-}
-}
-
-#endif
diff --git a/src/lib/datasrc/memory/zone_table_segment.h b/src/lib/datasrc/memory/zone_table_segment.h
index f066d8e..996f446 100644
--- a/src/lib/datasrc/memory/zone_table_segment.h
+++ b/src/lib/datasrc/memory/zone_table_segment.h
@@ -32,7 +32,7 @@ class RRClass;
}
namespace datasrc {
namespace memory {
-class ZoneReloader;
+class ZoneWriter;
/// \brief Memory-management independent entry point that contains a
/// pointer to a zone table in memory.
@@ -139,9 +139,9 @@ public:
/// \param rrclass The class of the zone to reload.
/// \return New instance of a zone reloader. The ownership is passed
/// onto the caller.
- virtual ZoneReloader* getZoneReloader(const LoadAction& load_action,
- const dns::Name& origin,
- const dns::RRClass& rrclass) = 0;
+ virtual ZoneWriter* getZoneWriter(const LoadAction& load_action,
+ const dns::Name& origin,
+ const dns::RRClass& rrclass) = 0;
};
} // namespace memory
diff --git a/src/lib/datasrc/memory/zone_table_segment_local.cc b/src/lib/datasrc/memory/zone_table_segment_local.cc
index 3a19d86..218c8a2 100644
--- a/src/lib/datasrc/memory/zone_table_segment_local.cc
+++ b/src/lib/datasrc/memory/zone_table_segment_local.cc
@@ -13,7 +13,7 @@
// PERFORMANCE OF THIS SOFTWARE.
#include <datasrc/memory/zone_table_segment_local.h>
-#include "zone_reloader.h"
+#include "zone_writer.h"
using namespace isc::util;
@@ -39,12 +39,12 @@ ZoneTableSegmentLocal::getMemorySegment() {
return (mem_sgmt_);
}
-ZoneReloader*
-ZoneTableSegmentLocal::getZoneReloader(const LoadAction& load_action,
- const dns::Name& name,
- const dns::RRClass& rrclass)
+ZoneWriter*
+ZoneTableSegmentLocal::getZoneWriter(const LoadAction& load_action,
+ const dns::Name& name,
+ const dns::RRClass& rrclass)
{
- return (new ZoneReloaderLocal(this, load_action, name, rrclass));
+ return (new ZoneWriterLocal(this, load_action, name, rrclass));
}
} // namespace memory
diff --git a/src/lib/datasrc/memory/zone_table_segment_local.h b/src/lib/datasrc/memory/zone_table_segment_local.h
index 5db4a08..b83bd49 100644
--- a/src/lib/datasrc/memory/zone_table_segment_local.h
+++ b/src/lib/datasrc/memory/zone_table_segment_local.h
@@ -54,10 +54,10 @@ public:
/// implementation (a MemorySegmentLocal instance).
virtual isc::util::MemorySegment& getMemorySegment();
- /// \brief Concrete implementation of ZoneTableSegment::getZoneReloader
- virtual ZoneReloader* getZoneReloader(const LoadAction& load_action,
- const dns::Name& origin,
- const dns::RRClass& rrclass);
+ /// \brief Concrete implementation of ZoneTableSegment::getZoneWriter
+ virtual ZoneWriter* getZoneWriter(const LoadAction& load_action,
+ const dns::Name& origin,
+ const dns::RRClass& rrclass);
private:
ZoneTableHeader header_;
isc::util::MemorySegmentLocal mem_sgmt_;
diff --git a/src/lib/datasrc/memory/zone_writer.cc b/src/lib/datasrc/memory/zone_writer.cc
new file mode 100644
index 0000000..f7f90c6
--- /dev/null
+++ b/src/lib/datasrc/memory/zone_writer.cc
@@ -0,0 +1,94 @@
+// 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_writer.h"
+#include "zone_data.h"
+#include "zone_table_segment.h"
+
+#include <memory>
+
+using std::auto_ptr;
+
+namespace isc {
+namespace datasrc {
+namespace memory {
+
+ZoneWriterLocal::ZoneWriterLocal(ZoneTableSegment* segment,
+ const LoadAction& load_action,
+ const dns::Name& origin,
+ const dns::RRClass& rrclass) :
+ segment_(segment),
+ load_action_(load_action),
+ origin_(origin),
+ rrclass_(rrclass),
+ zone_data_(NULL),
+ loaded_(false),
+ data_ready_(false)
+{}
+
+ZoneWriterLocal::~ZoneWriterLocal() {
+ // Clean up everything there might be left if someone forgot, just
+ // in case. Or should we assert instead?
+ cleanup();
+}
+
+void
+ZoneWriterLocal::load() {
+ if (loaded_) {
+ isc_throw(isc::Unexpected, "Trying to load twice");
+ }
+ loaded_ = true;
+
+ zone_data_ = load_action_(segment_->getMemorySegment());
+
+ if (zone_data_ == NULL) {
+ // Bug inside load_action_.
+ isc_throw(isc::Unexpected, "No data returned from load action");
+ }
+
+ data_ready_ = true;
+}
+
+void
+ZoneWriterLocal::install() {
+ if (!data_ready_) {
+ isc_throw(isc::Unexpected, "No data to install");
+ }
+
+ data_ready_ = false;
+
+ ZoneTable* table(segment_->getHeader().getTable());
+ if (table == NULL) {
+ isc_throw(isc::Unexpected, "No zone table present");
+ }
+ ZoneTable::AddResult result(table->addZone(segment_->getMemorySegment(),
+ rrclass_, origin_, zone_data_));
+
+ zone_data_ = result.zone_data;
+}
+
+void
+ZoneWriterLocal::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_writer.h b/src/lib/datasrc/memory/zone_writer.h
new file mode 100644
index 0000000..89d417f
--- /dev/null
+++ b/src/lib/datasrc/memory/zone_writer.h
@@ -0,0 +1,141 @@
+// 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.
+
+#ifndef ZONE_RELOADER_H
+#define ZONE_RELOADER_H
+
+#include "load_action.h"
+
+#include <dns/rrclass.h>
+#include <dns/name.h>
+
+namespace isc {
+namespace datasrc {
+namespace memory {
+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 ZoneWriter {
+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;
+};
+
+/// \brief Writer 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 ZoneWriterLocal : public ZoneWriter {
+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 rrclass The class of the zone.
+ ZoneWriterLocal(ZoneTableSegment* segment, const LoadAction& load_action,
+ const dns::Name& name, const dns::RRClass& rrclass);
+ /// \brief Destructor
+ ~ZoneWriterLocal();
+ /// \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_;
+ 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_;
+};
+
+}
+}
+}
+
+#endif
diff --git a/src/lib/datasrc/tests/memory/Makefile.am b/src/lib/datasrc/tests/memory/Makefile.am
index 5b3d9b5..6a3d9a9 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_reloader_unittest.cc
+run_unittests_SOURCES += zone_writer_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
deleted file mode 100644
index a841f29..0000000
--- a/src/lib/datasrc/tests/memory/zone_reloader_unittest.cc
+++ /dev/null
@@ -1,205 +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_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),
- Name("example.org"), RRClass::IN())),
- load_called_(false),
- load_throw_(false),
- load_null_(false)
- {
- // TODO: The setTable is only a temporary interface
- segment_->getHeader().
- setTable(ZoneTable::create(segment_->getMemorySegment(),
- RRClass::IN()));
- }
- void TearDown() {
- // Release the reloader
- reloader_.reset();
- // Release the table we used
- ZoneTable::destroy(segment_->getMemorySegment(),
- segment_->getHeader().getTable(), RRClass::IN());
- // And check we freed all memory
- EXPECT_TRUE(segment_->getMemorySegment().allMemoryDeallocated());
- }
-protected:
- scoped_ptr<ZoneTableSegment> segment_;
- scoped_ptr<ZoneReloaderLocal> reloader_;
- bool load_called_;
- bool load_throw_;
- bool load_null_;
-private:
- ZoneData* loadAction(isc::util::MemorySegment& segment) {
- // Make sure it is the correct segment passed. We know the
- // exact instance, can compare pointers to them.
- EXPECT_EQ(&segment_->getMemorySegment(), &segment);
- // We got called
- load_called_ = true;
- if (load_throw_) {
- throw TestException();
- }
-
- if (load_null_) {
- // Be nasty to the caller and return NULL, which is forbidden
- return (NULL);
- }
- // Create a new zone data. It may be empty for our tests, nothing
- // goes inside.
- return (ZoneData::create(segment, Name("example.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_);
-
- // Just the load gets called now
- EXPECT_NO_THROW(reloader_->load());
- EXPECT_TRUE(load_called_);
- load_called_ = false;
-
- EXPECT_NO_THROW(reloader_->install());
- EXPECT_FALSE(load_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_);
- load_called_ = false;
-
- // The second time, it should not be possible
- EXPECT_THROW(reloader_->load(), isc::Unexpected);
- EXPECT_FALSE(load_called_);
-
- // The object should not be damaged, try installing and clearing now
- EXPECT_NO_THROW(reloader_->install());
- EXPECT_FALSE(load_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
- load_called_ = false;
-
- EXPECT_THROW(reloader_->load(), isc::Unexpected);
- EXPECT_FALSE(load_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_);
-}
-
-// 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_NO_THROW(reloader_->load());
- load_called_ = false;
- // This install is OK
- EXPECT_NO_THROW(reloader_->install());
- // But we can't call it second time now
- EXPECT_THROW(reloader_->install(), isc::Unexpected);
- EXPECT_FALSE(load_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_);
-
- // We cleaned up, no way to install now
- EXPECT_THROW(reloader_->install(), isc::Unexpected);
-}
-
-// 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_);
-
- // But we can cleanup
- EXPECT_NO_THROW(reloader_->cleanup());
-}
-
-// Check the reloader defends itsefl when load action returns NULL
-TEST_F(ZoneReloaderLocalTest, loadNull) {
- load_null_ = true;
- EXPECT_THROW(reloader_->load(), isc::Unexpected);
-
- // We can't install that
- EXPECT_THROW(reloader_->install(), isc::Unexpected);
-
- // It should be possible to clean up safely
- EXPECT_NO_THROW(reloader_->cleanup());
-}
-
-}
diff --git a/src/lib/datasrc/tests/memory/zone_table_segment_unittest.cc b/src/lib/datasrc/tests/memory/zone_table_segment_unittest.cc
index 3082644..d1d32e0 100644
--- a/src/lib/datasrc/tests/memory/zone_table_segment_unittest.cc
+++ b/src/lib/datasrc/tests/memory/zone_table_segment_unittest.cc
@@ -13,7 +13,7 @@
// PERFORMANCE OF THIS SOFTWARE.
#include <datasrc/memory/zone_table_segment.h>
-#include <datasrc/memory/zone_reloader.h>
+#include <datasrc/memory/zone_writer.h>
#include <gtest/gtest.h>
#include <boost/scoped_ptr.hpp>
@@ -92,16 +92,16 @@ load_action(MemorySegment&) {
return (NULL);
}
-// Test we can get a reloader.
-TEST_F(ZoneTableSegmentTest, getZoneReloader) {
- scoped_ptr<ZoneReloader>
- reloader(segment_->getZoneReloader(load_action, Name("example.org"),
- RRClass::IN()));
+// Test we can get a writer.
+TEST_F(ZoneTableSegmentTest, getZoneWriter) {
+ scoped_ptr<ZoneWriter>
+ writer(segment_->getZoneWriter(load_action, Name("example.org"),
+ RRClass::IN()));
// We have to get something
- EXPECT_NE(static_cast<void*>(NULL), reloader.get());
- // And for now, it should be the local reloader
+ EXPECT_NE(static_cast<void*>(NULL), writer.get());
+ // And for now, it should be the local writer
EXPECT_NE(static_cast<void*>(NULL),
- dynamic_cast<ZoneReloaderLocal*>(reloader.get()));
+ dynamic_cast<ZoneWriterLocal*>(writer.get()));
}
} // anonymous namespace
diff --git a/src/lib/datasrc/tests/memory/zone_writer_unittest.cc b/src/lib/datasrc/tests/memory/zone_writer_unittest.cc
new file mode 100644
index 0000000..e9c698f
--- /dev/null
+++ b/src/lib/datasrc/tests/memory/zone_writer_unittest.cc
@@ -0,0 +1,205 @@
+// 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_writer.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 ZoneWriterLocalTest : public ::testing::Test {
+public:
+ ZoneWriterLocalTest() :
+ // 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())),
+ writer_(new
+ ZoneWriterLocal(segment_.get(),
+ bind(&ZoneWriterLocalTest::loadAction, this,
+ _1),
+ Name("example.org"), RRClass::IN())),
+ load_called_(false),
+ load_throw_(false),
+ load_null_(false)
+ {
+ // TODO: The setTable is only a temporary interface
+ segment_->getHeader().
+ setTable(ZoneTable::create(segment_->getMemorySegment(),
+ RRClass::IN()));
+ }
+ void TearDown() {
+ // Release the writer
+ writer_.reset();
+ // Release the table we used
+ ZoneTable::destroy(segment_->getMemorySegment(),
+ segment_->getHeader().getTable(), RRClass::IN());
+ // And check we freed all memory
+ EXPECT_TRUE(segment_->getMemorySegment().allMemoryDeallocated());
+ }
+protected:
+ scoped_ptr<ZoneTableSegment> segment_;
+ scoped_ptr<ZoneWriterLocal> writer_;
+ bool load_called_;
+ bool load_throw_;
+ bool load_null_;
+private:
+ ZoneData* loadAction(isc::util::MemorySegment& segment) {
+ // Make sure it is the correct segment passed. We know the
+ // exact instance, can compare pointers to them.
+ EXPECT_EQ(&segment_->getMemorySegment(), &segment);
+ // We got called
+ load_called_ = true;
+ if (load_throw_) {
+ throw TestException();
+ }
+
+ if (load_null_) {
+ // Be nasty to the caller and return NULL, which is forbidden
+ return (NULL);
+ }
+ // Create a new zone data. It may be empty for our tests, nothing
+ // goes inside.
+ return (ZoneData::create(segment, Name("example.org")));
+ }
+};
+
+// We call it the way we are supposed to, check every callback is called in the
+// right moment.
+TEST_F(ZoneWriterLocalTest, correctCall) {
+ // Nothing called before we call it
+ EXPECT_FALSE(load_called_);
+
+ // Just the load gets called now
+ EXPECT_NO_THROW(writer_->load());
+ EXPECT_TRUE(load_called_);
+ load_called_ = false;
+
+ EXPECT_NO_THROW(writer_->install());
+ EXPECT_FALSE(load_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(writer_->cleanup());
+}
+
+TEST_F(ZoneWriterLocalTest, loadTwice) {
+ // Load it the first time
+ EXPECT_NO_THROW(writer_->load());
+ EXPECT_TRUE(load_called_);
+ load_called_ = false;
+
+ // The second time, it should not be possible
+ EXPECT_THROW(writer_->load(), isc::Unexpected);
+ EXPECT_FALSE(load_called_);
+
+ // The object should not be damaged, try installing and clearing now
+ EXPECT_NO_THROW(writer_->install());
+ EXPECT_FALSE(load_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(writer_->cleanup());
+}
+
+// Try loading after call to install and call to cleanup. Both is
+// forbidden.
+TEST_F(ZoneWriterLocalTest, loadLater) {
+ // Load first, so we can install
+ EXPECT_NO_THROW(writer_->load());
+ EXPECT_NO_THROW(writer_->install());
+ // Reset so we see nothing is called now
+ load_called_ = false;
+
+ EXPECT_THROW(writer_->load(), isc::Unexpected);
+ EXPECT_FALSE(load_called_);
+
+ // Cleanup and try loading again. Still shouldn't work.
+ EXPECT_NO_THROW(writer_->cleanup());
+
+ EXPECT_THROW(writer_->load(), isc::Unexpected);
+ EXPECT_FALSE(load_called_);
+}
+
+// Try calling install at various bad times
+TEST_F(ZoneWriterLocalTest, invalidInstall) {
+ // Nothing loaded yet
+ EXPECT_THROW(writer_->install(), isc::Unexpected);
+ EXPECT_FALSE(load_called_);
+
+ EXPECT_NO_THROW(writer_->load());
+ load_called_ = false;
+ // This install is OK
+ EXPECT_NO_THROW(writer_->install());
+ // But we can't call it second time now
+ EXPECT_THROW(writer_->install(), isc::Unexpected);
+ EXPECT_FALSE(load_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(ZoneWriterLocalTest, cleanWithoutInstall) {
+ EXPECT_NO_THROW(writer_->load());
+ EXPECT_NO_THROW(writer_->cleanup());
+
+ EXPECT_TRUE(load_called_);
+
+ // We cleaned up, no way to install now
+ EXPECT_THROW(writer_->install(), isc::Unexpected);
+}
+
+// Test the case when load callback throws
+TEST_F(ZoneWriterLocalTest, loadThrows) {
+ load_throw_ = true;
+ EXPECT_THROW(writer_->load(), TestException);
+
+ // We can't install now
+ EXPECT_THROW(writer_->install(), isc::Unexpected);
+ EXPECT_TRUE(load_called_);
+
+ // But we can cleanup
+ EXPECT_NO_THROW(writer_->cleanup());
+}
+
+// Check the writer defends itsefl when load action returns NULL
+TEST_F(ZoneWriterLocalTest, loadNull) {
+ load_null_ = true;
+ EXPECT_THROW(writer_->load(), isc::Unexpected);
+
+ // We can't install that
+ EXPECT_THROW(writer_->install(), isc::Unexpected);
+
+ // It should be possible to clean up safely
+ EXPECT_NO_THROW(writer_->cleanup());
+}
+
+}
More information about the bind10-changes
mailing list