BIND 10 trac2207, updated. 21170f738cf943a5750c26eb8b418972a673a27f [2207] Extend the strong-exception guarantee test

BIND 10 source code commits bind10-changes at lists.isc.org
Fri Oct 19 17:56:17 UTC 2012


The branch, trac2207 has been updated
       via  21170f738cf943a5750c26eb8b418972a673a27f (commit)
       via  396d1867ce3420d759bd5eaaed64ce3f83b0b874 (commit)
      from  c1e16071d91f9db0b3f78f7a09551c66278ace5e (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 21170f738cf943a5750c26eb8b418972a673a27f
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date:   Fri Oct 19 19:55:53 2012 +0200

    [2207] Extend the strong-exception guarantee test
    
    We try to put some data there and see it survived.

commit 396d1867ce3420d759bd5eaaed64ce3f83b0b874
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date:   Fri Oct 19 19:10:39 2012 +0200

    [2207] Exceptions & asserts
    
    Changed an exception for unexpected problem and removed a comment about
    assert.

-----------------------------------------------------------------------

Summary of changes:
 src/lib/datasrc/memory/zone_writer_local.cc        |    4 +--
 .../datasrc/tests/memory/zone_writer_unittest.cc   |   34 ++++++++++++++++----
 2 files changed, 30 insertions(+), 8 deletions(-)

-----------------------------------------------------------------------
diff --git a/src/lib/datasrc/memory/zone_writer_local.cc b/src/lib/datasrc/memory/zone_writer_local.cc
index a14cbff..0cd9587 100644
--- a/src/lib/datasrc/memory/zone_writer_local.cc
+++ b/src/lib/datasrc/memory/zone_writer_local.cc
@@ -38,7 +38,7 @@ ZoneWriterLocal::ZoneWriterLocal(ZoneTableSegmentLocal* segment,
 
 ZoneWriterLocal::~ZoneWriterLocal() {
     // Clean up everything there might be left if someone forgot, just
-    // in case. Or should we assert instead?
+    // in case.
     cleanup();
 }
 
@@ -67,7 +67,7 @@ ZoneWriterLocal::install() {
 
     ZoneTable* table(segment_->getHeader().getTable());
     if (table == NULL) {
-        isc_throw(isc::InvalidOperation, "No zone table present");
+        isc_throw(isc::Unexpected, "No zone table present");
     }
     const ZoneTable::AddResult result(table->addZone(
                                           segment_->getMemorySegment(),
diff --git a/src/lib/datasrc/tests/memory/zone_writer_unittest.cc b/src/lib/datasrc/tests/memory/zone_writer_unittest.cc
index 73e45a1..e5ff498 100644
--- a/src/lib/datasrc/tests/memory/zone_writer_unittest.cc
+++ b/src/lib/datasrc/tests/memory/zone_writer_unittest.cc
@@ -49,7 +49,8 @@ public:
                             Name("example.org"), RRClass::IN())),
         load_called_(false),
         load_throw_(false),
-        load_null_(false)
+        load_null_(false),
+        load_data_(false)
     {
         // TODO: The setTable is only a temporary interface
         segment_->getHeader().
@@ -71,6 +72,7 @@ protected:
     bool load_called_;
     bool load_throw_;
     bool load_null_;
+    bool load_data_;
 private:
     ZoneData* loadAction(isc::util::MemorySegment& segment) {
         // Make sure it is the correct segment passed. We know the
@@ -86,9 +88,15 @@ private:
             // 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")));
+        ZoneData* data = ZoneData::create(segment, Name("example.org"));
+        if (load_data_) {
+            // Put something inside. The node itself should be enough for
+            // the tests.
+            ZoneNode* node(NULL);
+            data->insertName(segment, Name("subdomain.example.org"), &node);
+            EXPECT_NE(static_cast<ZoneNode*>(NULL), node);
+        }
+        return (data);
     }
 };
 
@@ -193,15 +201,29 @@ TEST_F(ZoneWriterLocalTest, loadThrows) {
 // Check the strong exception guarantee - if it throws, nothing happened
 // to the content.
 TEST_F(ZoneWriterLocalTest, retry) {
+    // First attempt fails due to some exception.
     load_throw_ = true;
     EXPECT_THROW(writer_->load(), TestException);
-
+    // This one shall succeed.
     load_called_ = load_throw_ = false;
+    // We want some data inside.
+    load_data_ = true;
     EXPECT_NO_THROW(writer_->load());
-    EXPECT_TRUE(load_called_);
+    // And this one will fail again. But the old data will survive.
+    load_data_ = false;
+    EXPECT_THROW(writer_->load(), isc::InvalidOperation);
 
     // The rest still works correctly
     EXPECT_NO_THROW(writer_->install());
+    ZoneTable* const table(segment_->getHeader().getTable());
+    const ZoneTable::FindResult found(table->findZone(Name("example.org")));
+    ASSERT_EQ(isc::datasrc::result::SUCCESS, found.code);
+    // For some reason it doesn't seem to work by the ZoneNode typedef, using the
+    // full definition instead.
+    const isc::datasrc::memory::DomainTreeNode<RdataSet>* node;
+    EXPECT_EQ(isc::datasrc::memory::DomainTree<RdataSet>::EXACTMATCH,
+              found.zone_data->getZoneTree().
+              find(Name("subdomain.example.org"), &node));
     EXPECT_NO_THROW(writer_->cleanup());
 }
 



More information about the bind10-changes mailing list