Browse Source

[2850] Fix ZoneTableSegmentMappedTest.resetBadConfig test

Mukund Sivaraman 12 years ago
parent
commit
03ce449ee1

+ 6 - 0
src/lib/datasrc/memory/zone_table_segment.h

@@ -208,6 +208,12 @@ public:
     /// the exception documentation below.  Code that uses
     /// \c ZoneTableSegment would depend on such assurances.
     ///
+    /// First, in case an existing memory segment is in use, and an
+    /// invalid config is passed to \c reset(), the existing memory
+    /// store must still be available and the \c isc::InvalidParameter
+    /// exception must be thrown. In this case, the segment is still
+    /// usable.
+    ///
     /// In case an existing memory store is in use, and an attempt to
     /// open a different memory store fails, the existing memory store
     /// must still be available and the \c ResetFailed exception must be

+ 20 - 7
src/lib/datasrc/tests/memory/zone_table_segment_mapped_unittest.cc

@@ -127,43 +127,56 @@ TEST_F(ZoneTableSegmentMappedTest, isWritableUninitialized) {
 }
 
 TEST_F(ZoneTableSegmentMappedTest, resetBadConfig) {
+    // Open a mapped file in create mode.
+    ztable_segment_->reset(ZoneTableSegment::CREATE, config_params_);
+
+    // Populate it with some data.
+    createData(ztable_segment_->getMemorySegment());
+    EXPECT_TRUE(verifyData(ztable_segment_->getMemorySegment()));
+
+    // All the following resets() with invalid configuration must
+    // provide a strong exception guarantee that the segment is still
+    // usable as before.
+
     // NULL is passed in config params
     EXPECT_THROW({
         ztable_segment_->reset(ZoneTableSegment::CREATE,
                                ConstElementPtr());
     }, isc::InvalidParameter);
 
+    EXPECT_TRUE(verifyData(ztable_segment_->getMemorySegment()));
+
     // Not a map
     EXPECT_THROW({
         ztable_segment_->reset(ZoneTableSegment::CREATE,
                                Element::fromJSON("42"));
     }, isc::InvalidParameter);
 
+    EXPECT_TRUE(verifyData(ztable_segment_->getMemorySegment()));
+
     // Empty map
     EXPECT_THROW({
         ztable_segment_->reset(ZoneTableSegment::CREATE,
                                Element::fromJSON("{}"));
     }, isc::InvalidParameter);
 
+    EXPECT_TRUE(verifyData(ztable_segment_->getMemorySegment()));
+
     // No "mapped-file" key
     EXPECT_THROW({
         ztable_segment_->reset(ZoneTableSegment::CREATE,
                                Element::fromJSON("{\"foo\": \"bar\"}"));
     }, isc::InvalidParameter);
 
+    EXPECT_TRUE(verifyData(ztable_segment_->getMemorySegment()));
+
     // Value of "mapped-file" key is not a string
     EXPECT_THROW({
         ztable_segment_->reset(ZoneTableSegment::CREATE,
                                Element::fromJSON("{\"mapped-file\": 42}"));
     }, isc::InvalidParameter);
 
-    // The following should still throw, unaffected by the failed opens.
-    EXPECT_THROW(ztable_segment_->getHeader(), isc::InvalidOperation);
-    EXPECT_THROW(ztable_segment_->getMemorySegment(), isc::InvalidOperation);
-
-    // isWritable() must still return false, because the segment has not
-    // been successfully reset() yet.
-    EXPECT_FALSE(ztable_segment_->isWritable());
+    EXPECT_TRUE(verifyData(ztable_segment_->getMemorySegment()));
 }
 
 TEST_F(ZoneTableSegmentMappedTest, reset) {