mirror of
https://gitlab.isc.org/isc-projects/kea
synced 2025-08-30 05:27:55 +00:00
[2207] Rename ZoneUpdater -> ZoneWriter
According to the review, Updater might be misleading.
This commit is contained in:
parent
07e1f1ddbd
commit
0d336b6f23
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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_;
|
||||
|
@ -12,7 +12,7 @@
|
||||
// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||
// PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
#include "zone_reloader.h"
|
||||
#include "zone_writer.h"
|
||||
#include "zone_data.h"
|
||||
#include "zone_table_segment.h"
|
||||
|
||||
@ -24,10 +24,10 @@ namespace isc {
|
||||
namespace datasrc {
|
||||
namespace memory {
|
||||
|
||||
ZoneReloaderLocal::ZoneReloaderLocal(ZoneTableSegment* segment,
|
||||
const LoadAction& load_action,
|
||||
const dns::Name& origin,
|
||||
const dns::RRClass& rrclass) :
|
||||
ZoneWriterLocal::ZoneWriterLocal(ZoneTableSegment* segment,
|
||||
const LoadAction& load_action,
|
||||
const dns::Name& origin,
|
||||
const dns::RRClass& rrclass) :
|
||||
segment_(segment),
|
||||
load_action_(load_action),
|
||||
origin_(origin),
|
||||
@ -37,14 +37,14 @@ ZoneReloaderLocal::ZoneReloaderLocal(ZoneTableSegment* segment,
|
||||
data_ready_(false)
|
||||
{}
|
||||
|
||||
ZoneReloaderLocal::~ZoneReloaderLocal() {
|
||||
ZoneWriterLocal::~ZoneWriterLocal() {
|
||||
// Clean up everything there might be left if someone forgot, just
|
||||
// in case. Or should we assert instead?
|
||||
cleanup();
|
||||
}
|
||||
|
||||
void
|
||||
ZoneReloaderLocal::load() {
|
||||
ZoneWriterLocal::load() {
|
||||
if (loaded_) {
|
||||
isc_throw(isc::Unexpected, "Trying to load twice");
|
||||
}
|
||||
@ -61,7 +61,7 @@ ZoneReloaderLocal::load() {
|
||||
}
|
||||
|
||||
void
|
||||
ZoneReloaderLocal::install() {
|
||||
ZoneWriterLocal::install() {
|
||||
if (!data_ready_) {
|
||||
isc_throw(isc::Unexpected, "No data to install");
|
||||
}
|
||||
@ -79,7 +79,7 @@ ZoneReloaderLocal::install() {
|
||||
}
|
||||
|
||||
void
|
||||
ZoneReloaderLocal::cleanup() {
|
||||
ZoneWriterLocal::cleanup() {
|
||||
// We eat the data (if any) now.
|
||||
data_ready_ = false;
|
||||
|
@ -35,7 +35,7 @@ class ZoneTableSegment;
|
||||
/// 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 {
|
||||
class ZoneWriter {
|
||||
public:
|
||||
/// \brief Get the zone data into memory.
|
||||
///
|
||||
@ -80,13 +80,13 @@ public:
|
||||
virtual void cleanup() = 0;
|
||||
};
|
||||
|
||||
/// \brief Reloader implementation which loads data locally.
|
||||
/// \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 ZoneReloaderLocal : public ZoneReloader {
|
||||
class ZoneWriterLocal : public ZoneWriter {
|
||||
public:
|
||||
/// \brief Constructor
|
||||
///
|
||||
@ -94,10 +94,10 @@ public:
|
||||
/// \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,
|
||||
ZoneWriterLocal(ZoneTableSegment* segment, const LoadAction& load_action,
|
||||
const dns::Name& name, const dns::RRClass& rrclass);
|
||||
/// \brief Destructor
|
||||
~ZoneReloaderLocal();
|
||||
~ZoneWriterLocal();
|
||||
/// \brief Loads the data.
|
||||
///
|
||||
/// This prepares an empty ZoneData and calls load_action (passed to
|
@ -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)
|
||||
|
@ -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
|
||||
|
@ -12,7 +12,7 @@
|
||||
// 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_writer.h>
|
||||
#include <datasrc/memory/zone_table_segment.h>
|
||||
#include <datasrc/memory/zone_data.h>
|
||||
|
||||
@ -35,16 +35,16 @@ namespace {
|
||||
|
||||
class TestException {};
|
||||
|
||||
class ZoneReloaderLocalTest : public ::testing::Test {
|
||||
class ZoneWriterLocalTest : public ::testing::Test {
|
||||
public:
|
||||
ZoneReloaderLocalTest() :
|
||||
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())),
|
||||
reloader_(new
|
||||
ZoneReloaderLocal(segment_.get(),
|
||||
bind(&ZoneReloaderLocalTest::loadAction, this,
|
||||
writer_(new
|
||||
ZoneWriterLocal(segment_.get(),
|
||||
bind(&ZoneWriterLocalTest::loadAction, this,
|
||||
_1),
|
||||
Name("example.org"), RRClass::IN())),
|
||||
load_called_(false),
|
||||
@ -57,8 +57,8 @@ public:
|
||||
RRClass::IN()));
|
||||
}
|
||||
void TearDown() {
|
||||
// Release the reloader
|
||||
reloader_.reset();
|
||||
// Release the writer
|
||||
writer_.reset();
|
||||
// Release the table we used
|
||||
ZoneTable::destroy(segment_->getMemorySegment(),
|
||||
segment_->getHeader().getTable(), RRClass::IN());
|
||||
@ -67,7 +67,7 @@ public:
|
||||
}
|
||||
protected:
|
||||
scoped_ptr<ZoneTableSegment> segment_;
|
||||
scoped_ptr<ZoneReloaderLocal> reloader_;
|
||||
scoped_ptr<ZoneWriterLocal> writer_;
|
||||
bool load_called_;
|
||||
bool load_throw_;
|
||||
bool load_null_;
|
||||
@ -94,112 +94,112 @@ private:
|
||||
|
||||
// We call it the way we are supposed to, check every callback is called in the
|
||||
// right moment.
|
||||
TEST_F(ZoneReloaderLocalTest, correctCall) {
|
||||
TEST_F(ZoneWriterLocalTest, correctCall) {
|
||||
// Nothing called before we call it
|
||||
EXPECT_FALSE(load_called_);
|
||||
|
||||
// Just the load gets called now
|
||||
EXPECT_NO_THROW(reloader_->load());
|
||||
EXPECT_NO_THROW(writer_->load());
|
||||
EXPECT_TRUE(load_called_);
|
||||
load_called_ = false;
|
||||
|
||||
EXPECT_NO_THROW(reloader_->install());
|
||||
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(reloader_->cleanup());
|
||||
EXPECT_NO_THROW(writer_->cleanup());
|
||||
}
|
||||
|
||||
TEST_F(ZoneReloaderLocalTest, loadTwice) {
|
||||
TEST_F(ZoneWriterLocalTest, loadTwice) {
|
||||
// Load it the first time
|
||||
EXPECT_NO_THROW(reloader_->load());
|
||||
EXPECT_NO_THROW(writer_->load());
|
||||
EXPECT_TRUE(load_called_);
|
||||
load_called_ = false;
|
||||
|
||||
// The second time, it should not be possible
|
||||
EXPECT_THROW(reloader_->load(), isc::Unexpected);
|
||||
EXPECT_THROW(writer_->load(), isc::Unexpected);
|
||||
EXPECT_FALSE(load_called_);
|
||||
|
||||
// The object should not be damaged, try installing and clearing now
|
||||
EXPECT_NO_THROW(reloader_->install());
|
||||
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(reloader_->cleanup());
|
||||
EXPECT_NO_THROW(writer_->cleanup());
|
||||
}
|
||||
|
||||
// Try loading after call to install and call to cleanup. Both is
|
||||
// forbidden.
|
||||
TEST_F(ZoneReloaderLocalTest, loadLater) {
|
||||
TEST_F(ZoneWriterLocalTest, loadLater) {
|
||||
// Load first, so we can install
|
||||
EXPECT_NO_THROW(reloader_->load());
|
||||
EXPECT_NO_THROW(reloader_->install());
|
||||
EXPECT_NO_THROW(writer_->load());
|
||||
EXPECT_NO_THROW(writer_->install());
|
||||
// Reset so we see nothing is called now
|
||||
load_called_ = false;
|
||||
|
||||
EXPECT_THROW(reloader_->load(), isc::Unexpected);
|
||||
EXPECT_THROW(writer_->load(), isc::Unexpected);
|
||||
EXPECT_FALSE(load_called_);
|
||||
|
||||
// Cleanup and try loading again. Still shouldn't work.
|
||||
EXPECT_NO_THROW(reloader_->cleanup());
|
||||
EXPECT_NO_THROW(writer_->cleanup());
|
||||
|
||||
EXPECT_THROW(reloader_->load(), isc::Unexpected);
|
||||
EXPECT_THROW(writer_->load(), isc::Unexpected);
|
||||
EXPECT_FALSE(load_called_);
|
||||
}
|
||||
|
||||
// Try calling install at various bad times
|
||||
TEST_F(ZoneReloaderLocalTest, invalidInstall) {
|
||||
TEST_F(ZoneWriterLocalTest, invalidInstall) {
|
||||
// Nothing loaded yet
|
||||
EXPECT_THROW(reloader_->install(), isc::Unexpected);
|
||||
EXPECT_THROW(writer_->install(), isc::Unexpected);
|
||||
EXPECT_FALSE(load_called_);
|
||||
|
||||
EXPECT_NO_THROW(reloader_->load());
|
||||
EXPECT_NO_THROW(writer_->load());
|
||||
load_called_ = false;
|
||||
// This install is OK
|
||||
EXPECT_NO_THROW(reloader_->install());
|
||||
EXPECT_NO_THROW(writer_->install());
|
||||
// But we can't call it second time now
|
||||
EXPECT_THROW(reloader_->install(), isc::Unexpected);
|
||||
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(ZoneReloaderLocalTest, cleanWithoutInstall) {
|
||||
EXPECT_NO_THROW(reloader_->load());
|
||||
EXPECT_NO_THROW(reloader_->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(reloader_->install(), isc::Unexpected);
|
||||
EXPECT_THROW(writer_->install(), isc::Unexpected);
|
||||
}
|
||||
|
||||
// Test the case when load callback throws
|
||||
TEST_F(ZoneReloaderLocalTest, loadThrows) {
|
||||
TEST_F(ZoneWriterLocalTest, loadThrows) {
|
||||
load_throw_ = true;
|
||||
EXPECT_THROW(reloader_->load(), TestException);
|
||||
EXPECT_THROW(writer_->load(), TestException);
|
||||
|
||||
// We can't install now
|
||||
EXPECT_THROW(reloader_->install(), isc::Unexpected);
|
||||
EXPECT_THROW(writer_->install(), isc::Unexpected);
|
||||
EXPECT_TRUE(load_called_);
|
||||
|
||||
// But we can cleanup
|
||||
EXPECT_NO_THROW(reloader_->cleanup());
|
||||
EXPECT_NO_THROW(writer_->cleanup());
|
||||
}
|
||||
|
||||
// Check the reloader defends itsefl when load action returns NULL
|
||||
TEST_F(ZoneReloaderLocalTest, loadNull) {
|
||||
// Check the writer defends itsefl when load action returns NULL
|
||||
TEST_F(ZoneWriterLocalTest, loadNull) {
|
||||
load_null_ = true;
|
||||
EXPECT_THROW(reloader_->load(), isc::Unexpected);
|
||||
EXPECT_THROW(writer_->load(), isc::Unexpected);
|
||||
|
||||
// We can't install that
|
||||
EXPECT_THROW(reloader_->install(), isc::Unexpected);
|
||||
EXPECT_THROW(writer_->install(), isc::Unexpected);
|
||||
|
||||
// It should be possible to clean up safely
|
||||
EXPECT_NO_THROW(reloader_->cleanup());
|
||||
EXPECT_NO_THROW(writer_->cleanup());
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user