Browse Source

[2850] Remove getZoneWriter() method

Mukund Sivaraman 12 years ago
parent
commit
e646d8af58

+ 0 - 13
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

+ 1 - 16
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

+ 6 - 1
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

+ 3 - 3
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

+ 6 - 4
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();

+ 0 - 9
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({

+ 1 - 8
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_;

+ 0 - 9
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());

+ 28 - 1
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) {

+ 3 - 2
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();

+ 3 - 3
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();