Commit 03ce449e authored by Mukund Sivaraman's avatar Mukund Sivaraman
Browse files

[2850] Fix ZoneTableSegmentMappedTest.resetBadConfig test

parent 9784a184
...@@ -208,6 +208,12 @@ public: ...@@ -208,6 +208,12 @@ public:
/// the exception documentation below. Code that uses /// the exception documentation below. Code that uses
/// \c ZoneTableSegment would depend on such assurances. /// \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 /// In case an existing memory store is in use, and an attempt to
/// open a different memory store fails, the existing memory store /// open a different memory store fails, the existing memory store
/// must still be available and the \c ResetFailed exception must be /// must still be available and the \c ResetFailed exception must be
......
...@@ -127,43 +127,56 @@ TEST_F(ZoneTableSegmentMappedTest, isWritableUninitialized) { ...@@ -127,43 +127,56 @@ TEST_F(ZoneTableSegmentMappedTest, isWritableUninitialized) {
} }
TEST_F(ZoneTableSegmentMappedTest, resetBadConfig) { 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 // NULL is passed in config params
EXPECT_THROW({ EXPECT_THROW({
ztable_segment_->reset(ZoneTableSegment::CREATE, ztable_segment_->reset(ZoneTableSegment::CREATE,
ConstElementPtr()); ConstElementPtr());
}, isc::InvalidParameter); }, isc::InvalidParameter);
EXPECT_TRUE(verifyData(ztable_segment_->getMemorySegment()));
// Not a map // Not a map
EXPECT_THROW({ EXPECT_THROW({
ztable_segment_->reset(ZoneTableSegment::CREATE, ztable_segment_->reset(ZoneTableSegment::CREATE,
Element::fromJSON("42")); Element::fromJSON("42"));
}, isc::InvalidParameter); }, isc::InvalidParameter);
EXPECT_TRUE(verifyData(ztable_segment_->getMemorySegment()));
// Empty map // Empty map
EXPECT_THROW({ EXPECT_THROW({
ztable_segment_->reset(ZoneTableSegment::CREATE, ztable_segment_->reset(ZoneTableSegment::CREATE,
Element::fromJSON("{}")); Element::fromJSON("{}"));
}, isc::InvalidParameter); }, isc::InvalidParameter);
EXPECT_TRUE(verifyData(ztable_segment_->getMemorySegment()));
// No "mapped-file" key // No "mapped-file" key
EXPECT_THROW({ EXPECT_THROW({
ztable_segment_->reset(ZoneTableSegment::CREATE, ztable_segment_->reset(ZoneTableSegment::CREATE,
Element::fromJSON("{\"foo\": \"bar\"}")); Element::fromJSON("{\"foo\": \"bar\"}"));
}, isc::InvalidParameter); }, isc::InvalidParameter);
EXPECT_TRUE(verifyData(ztable_segment_->getMemorySegment()));
// Value of "mapped-file" key is not a string // Value of "mapped-file" key is not a string
EXPECT_THROW({ EXPECT_THROW({
ztable_segment_->reset(ZoneTableSegment::CREATE, ztable_segment_->reset(ZoneTableSegment::CREATE,
Element::fromJSON("{\"mapped-file\": 42}")); Element::fromJSON("{\"mapped-file\": 42}"));
}, isc::InvalidParameter); }, isc::InvalidParameter);
// The following should still throw, unaffected by the failed opens. EXPECT_TRUE(verifyData(ztable_segment_->getMemorySegment()));
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());
} }
TEST_F(ZoneTableSegmentMappedTest, reset) { TEST_F(ZoneTableSegmentMappedTest, reset) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment