BIND 10 trac2850_2, updated. e646d8af58ff6b9863a89ae65b6244275405bce0 [2850] Remove getZoneWriter() method
BIND 10 source code commits
bind10-changes at lists.isc.org
Thu May 2 08:18:13 UTC 2013
The branch, trac2850_2 has been updated
via e646d8af58ff6b9863a89ae65b6244275405bce0 (commit)
from 68343c845a46a9be3f38c38388ec02a8bb4ef884 (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 e646d8af58ff6b9863a89ae65b6244275405bce0
Author: Mukund Sivaraman <muks at isc.org>
Date: Thu May 2 13:25:00 2013 +0530
[2850] Remove getZoneWriter() method
-----------------------------------------------------------------------
Summary of changes:
src/lib/datasrc/memory/zone_table_segment.cc | 13 ---------
src/lib/datasrc/memory/zone_table_segment.h | 17 +-----------
src/lib/datasrc/memory/zone_writer.cc | 7 ++++-
src/lib/datasrc/tests/client_list_unittest.cc | 6 ++--
src/lib/datasrc/tests/memory/zone_loader_util.cc | 10 ++++---
.../memory/zone_table_segment_mapped_unittest.cc | 9 ------
.../datasrc/tests/memory/zone_table_segment_test.h | 9 +-----
.../tests/memory/zone_table_segment_unittest.cc | 9 ------
.../datasrc/tests/memory/zone_writer_unittest.cc | 29 +++++++++++++++++++-
.../datasrc/tests/zone_finder_context_unittest.cc | 5 ++--
src/lib/datasrc/tests/zone_loader_unittest.cc | 6 ++--
11 files changed, 51 insertions(+), 69 deletions(-)
-----------------------------------------------------------------------
diff --git a/src/lib/datasrc/memory/zone_table_segment.cc b/src/lib/datasrc/memory/zone_table_segment.cc
index 6e705a4..54d915b 100644
--- a/src/lib/datasrc/memory/zone_table_segment.cc
+++ b/src/lib/datasrc/memory/zone_table_segment.cc
@@ -44,19 +44,6 @@ ZoneTableSegment::destroy(ZoneTableSegment *segment) {
delete segment;
}
-ZoneWriter*
-ZoneTableSegment::getZoneWriter(const LoadAction& load_action,
- const dns::Name& name,
- const dns::RRClass& rrclass)
-{
- if (!isWritable()) {
- isc_throw(isc::Unexpected,
- "getZoneWriter() called on a read-only segment");
- }
-
- return (new ZoneWriter(this, load_action, name, rrclass));
-}
-
} // namespace memory
} // namespace datasrc
} // namespace isc
diff --git a/src/lib/datasrc/memory/zone_table_segment.h b/src/lib/datasrc/memory/zone_table_segment.h
index 7b1c0e3..8c55c1d 100644
--- a/src/lib/datasrc/memory/zone_table_segment.h
+++ b/src/lib/datasrc/memory/zone_table_segment.h
@@ -89,7 +89,7 @@ protected:
/// An instance implementing this interface is expected to be
/// created by the factory method (\c create()), so this constructor
/// is protected.
- ZoneTableSegment(isc::dns::RRClass)
+ ZoneTableSegment(const isc::dns::RRClass&)
{}
public:
/// \brief Destructor
@@ -135,21 +135,6 @@ public:
///
/// \param segment The segment to destroy.
static void destroy(ZoneTableSegment* segment);
-
- /// \brief Create a zone writer
- ///
- /// This creates a new writer that can be used to update a zone
- /// inside this zone table segment.
- ///
- /// \param loadAction Callback to provide the actual data.
- /// \param origin The origin of the zone to update.
- /// \param rrclass The class of the zone to update.
- /// \return New instance of a zone writer. The ownership is passed
- /// onto the caller and the caller needs to \c delete it when
- /// it's done with the writer.
- ZoneWriter* getZoneWriter(const LoadAction& load_action,
- const dns::Name& origin,
- const dns::RRClass& rrclass);
};
} // namespace memory
diff --git a/src/lib/datasrc/memory/zone_writer.cc b/src/lib/datasrc/memory/zone_writer.cc
index b4d7232..c174b1b 100644
--- a/src/lib/datasrc/memory/zone_writer.cc
+++ b/src/lib/datasrc/memory/zone_writer.cc
@@ -33,7 +33,12 @@ ZoneWriter::ZoneWriter(ZoneTableSegment* segment,
rrclass_(rrclass),
zone_data_(NULL),
state_(ZW_UNUSED)
-{}
+{
+ if (!segment->isWritable()) {
+ isc_throw(isc::Unexpected,
+ "Attempt to construct ZoneWriter for a read-only segment");
+ }
+}
ZoneWriter::~ZoneWriter() {
// Clean up everything there might be left if someone forgot, just
diff --git a/src/lib/datasrc/tests/client_list_unittest.cc b/src/lib/datasrc/tests/client_list_unittest.cc
index 8013f01..0bd58ff 100644
--- a/src/lib/datasrc/tests/client_list_unittest.cc
+++ b/src/lib/datasrc/tests/client_list_unittest.cc
@@ -166,9 +166,9 @@ public:
// Load the data into the zone table.
if (enabled) {
boost::scoped_ptr<memory::ZoneWriter> writer(
- dsrc_info.ztable_segment_->getZoneWriter(
- cache_conf->getLoadAction(rrclass_, zone),
- zone, rrclass_));
+ new memory::ZoneWriter(&(*dsrc_info.ztable_segment_),
+ cache_conf->getLoadAction(rrclass_, zone),
+ zone, rrclass_));
writer->load();
writer->install();
writer->cleanup(); // not absolutely necessary, but just in case
diff --git a/src/lib/datasrc/tests/memory/zone_loader_util.cc b/src/lib/datasrc/tests/memory/zone_loader_util.cc
index 1bf9cfa..77f23fd 100644
--- a/src/lib/datasrc/tests/memory/zone_loader_util.cc
+++ b/src/lib/datasrc/tests/memory/zone_loader_util.cc
@@ -44,8 +44,9 @@ loadZoneIntoTable(ZoneTableSegment& zt_sgmt, const dns::Name& zname,
" \"params\": {\"" + zname.toText() + "\": \"" + zone_file +
"\"}}"), true);
boost::scoped_ptr<memory::ZoneWriter> writer(
- zt_sgmt.getZoneWriter(cache_conf.getLoadAction(zclass, zname),
- zname, zclass));
+ new memory::ZoneWriter(&zt_sgmt,
+ cache_conf.getLoadAction(zclass, zname),
+ zname, zclass));
writer->load();
writer->install();
writer->cleanup();
@@ -76,8 +77,9 @@ loadZoneIntoTable(ZoneTableSegment& zt_sgmt, const dns::Name& zname,
const dns::RRClass& zclass, ZoneIterator& iterator)
{
boost::scoped_ptr<memory::ZoneWriter> writer(
- zt_sgmt.getZoneWriter(IteratorLoader(zclass, zname, iterator),
- zname, zclass));
+ new memory::ZoneWriter(&zt_sgmt,
+ IteratorLoader(zclass, zname, iterator),
+ zname, zclass));
writer->load();
writer->install();
writer->cleanup();
diff --git a/src/lib/datasrc/tests/memory/zone_table_segment_mapped_unittest.cc b/src/lib/datasrc/tests/memory/zone_table_segment_mapped_unittest.cc
index a8b706e..a5942a6 100644
--- a/src/lib/datasrc/tests/memory/zone_table_segment_mapped_unittest.cc
+++ b/src/lib/datasrc/tests/memory/zone_table_segment_mapped_unittest.cc
@@ -76,15 +76,6 @@ loadAction(MemorySegment&) {
return (NULL);
}
-// Test we can get a writer.
-TEST_F(ZoneTableSegmentMappedTest, getZoneWriterUninitialized) {
- // This should throw as we haven't called reset() yet.
- EXPECT_THROW({
- ztable_segment_->getZoneWriter(loadAction, Name("example.org"),
- RRClass::IN());
- }, isc::Unexpected);
-}
-
TEST_F(ZoneTableSegmentMappedTest, resetBadConfig) {
// Not a map
EXPECT_THROW({
diff --git a/src/lib/datasrc/tests/memory/zone_table_segment_test.h b/src/lib/datasrc/tests/memory/zone_table_segment_test.h
index 2a65f43..f1cfbee 100644
--- a/src/lib/datasrc/tests/memory/zone_table_segment_test.h
+++ b/src/lib/datasrc/tests/memory/zone_table_segment_test.h
@@ -30,7 +30,7 @@ namespace test {
// was de-allocated on it.
class ZoneTableSegmentTest : public ZoneTableSegment {
public:
- ZoneTableSegmentTest(isc::dns::RRClass rrclass,
+ ZoneTableSegmentTest(const isc::dns::RRClass& rrclass,
isc::util::MemorySegment& mem_sgmt) :
ZoneTableSegment(rrclass),
mem_sgmt_(mem_sgmt),
@@ -57,13 +57,6 @@ public:
return (true);
}
- virtual ZoneWriter* getZoneWriter(const LoadAction& load_action,
- const dns::Name& name,
- const dns::RRClass& rrclass)
- {
- return (new ZoneWriter(this, load_action, name, rrclass));
- }
-
private:
isc::util::MemorySegment& mem_sgmt_;
ZoneTableHeader header_;
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 f36de06..1ef997c 100644
--- a/src/lib/datasrc/tests/memory/zone_table_segment_unittest.cc
+++ b/src/lib/datasrc/tests/memory/zone_table_segment_unittest.cc
@@ -84,15 +84,6 @@ loadAction(MemorySegment&) {
return (NULL);
}
-// Test we can get a writer.
-TEST_F(ZoneTableSegmentTest, getZoneWriter) {
- scoped_ptr<ZoneWriter>
- writer(ztable_segment_->getZoneWriter(loadAction, Name("example.org"),
- RRClass::IN()));
- // We have to get something
- EXPECT_NE(static_cast<void*>(NULL), writer.get());
-}
-
TEST_F(ZoneTableSegmentTest, isWritable) {
// Local segments are always writable.
EXPECT_TRUE(ztable_segment_->isWritable());
diff --git a/src/lib/datasrc/tests/memory/zone_writer_unittest.cc b/src/lib/datasrc/tests/memory/zone_writer_unittest.cc
index 38e4be1..0c337ea 100644
--- a/src/lib/datasrc/tests/memory/zone_writer_unittest.cc
+++ b/src/lib/datasrc/tests/memory/zone_writer_unittest.cc
@@ -19,6 +19,9 @@
#include <dns/rrclass.h>
#include <dns/name.h>
+#include <datasrc/tests/memory/memory_segment_test.h>
+#include <datasrc/tests/memory/zone_table_segment_test.h>
+
#include <gtest/gtest.h>
#include <boost/scoped_ptr.hpp>
@@ -29,6 +32,7 @@ using boost::bind;
using isc::dns::RRClass;
using isc::dns::Name;
using namespace isc::datasrc::memory;
+using namespace isc::datasrc::memory::test;
namespace {
@@ -58,7 +62,7 @@ protected:
bool load_throw_;
bool load_null_;
bool load_data_;
-private:
+public:
ZoneData* loadAction(isc::util::MemorySegment& segment) {
// Make sure it is the correct segment passed. We know the
// exact instance, can compare pointers to them.
@@ -85,6 +89,29 @@ private:
}
};
+class ReadOnlySegment : public ZoneTableSegmentTest {
+public:
+ ReadOnlySegment(const isc::dns::RRClass& rrclass,
+ isc::util::MemorySegment& mem_sgmt) :
+ ZoneTableSegmentTest(rrclass, mem_sgmt)
+ {}
+
+ // Returns false indicating it is a read-only segment. It is used in
+ // the ZoneWriter tests.
+ virtual bool isWritable() const {
+ return (false);
+ }
+};
+
+TEST_F(ZoneWriterTest, constructForReadOnlySegment) {
+ MemorySegmentTest mem_sgmt;
+ ReadOnlySegment ztable_segment(RRClass::IN(), mem_sgmt);
+ EXPECT_THROW(ZoneWriter(&ztable_segment,
+ bind(&ZoneWriterTest::loadAction, this, _1),
+ Name("example.org"), RRClass::IN()),
+ isc::Unexpected);
+}
+
// We call it the way we are supposed to, check every callback is called in the
// right moment.
TEST_F(ZoneWriterTest, correctCall) {
diff --git a/src/lib/datasrc/tests/zone_finder_context_unittest.cc b/src/lib/datasrc/tests/zone_finder_context_unittest.cc
index f541fd8..ef81896 100644
--- a/src/lib/datasrc/tests/zone_finder_context_unittest.cc
+++ b/src/lib/datasrc/tests/zone_finder_context_unittest.cc
@@ -80,8 +80,9 @@ createInMemoryClient(RRClass zclass, const Name& zname) {
shared_ptr<ZoneTableSegment> ztable_segment(
ZoneTableSegment::create(zclass, cache_conf.getSegmentType()));
scoped_ptr<memory::ZoneWriter> writer(
- ztable_segment->getZoneWriter(cache_conf.getLoadAction(zclass, zname),
- zname, zclass));
+ new memory::ZoneWriter(&(*ztable_segment),
+ cache_conf.getLoadAction(zclass, zname),
+ zname, zclass));
writer->load();
writer->install();
writer->cleanup();
diff --git a/src/lib/datasrc/tests/zone_loader_unittest.cc b/src/lib/datasrc/tests/zone_loader_unittest.cc
index 4cf9e9a..5fd190b 100644
--- a/src/lib/datasrc/tests/zone_loader_unittest.cc
+++ b/src/lib/datasrc/tests/zone_loader_unittest.cc
@@ -319,9 +319,9 @@ protected:
rrclass_, cache_conf.getSegmentType()));
if (filename) {
boost::scoped_ptr<memory::ZoneWriter> writer(
- ztable_segment_->getZoneWriter(cache_conf.getLoadAction(
- rrclass_, zone),
- zone, rrclass_));
+ new memory::ZoneWriter(&(*ztable_segment_),
+ cache_conf.getLoadAction(rrclass_, zone),
+ zone, rrclass_));
writer->load();
writer->install();
writer->cleanup();
More information about the bind10-changes
mailing list