From 925f60d39dbd065429e0383204220ac51b5c3884 Mon Sep 17 00:00:00 2001 From: heyongqiang Date: Mon, 29 Oct 2012 15:25:01 -0700 Subject: [PATCH] add a test case to make sure chaning num_levels will fail Summary: Summary: as subject Test Plan: db_test Reviewers: dhruba, MarkCallaghan Reviewed By: MarkCallaghan Differential Revision: https://reviews.facebook.net/D6303 --- db/db_test.cc | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/db/db_test.cc b/db/db_test.cc index e5a8f8711..6c8bba868 100644 --- a/db/db_test.cc +++ b/db/db_test.cc @@ -1682,6 +1682,28 @@ TEST(DBTest, DBOpen_Options) { db = NULL; } +TEST(DBTest, DBOpen_Change_NumLevels) { + std::string dbname = test::TmpDir() + "/db_change_num_levels"; + DestroyDB(dbname, Options()); + Options opts; + Status s; + opts.create_if_missing = true; + s = DB::Open(opts, dbname, &db_); + ASSERT_OK(s); + ASSERT_TRUE(db_ != NULL); + db_->Put(WriteOptions(), "a", "123"); + db_->Put(WriteOptions(), "b", "234"); + db_->CompactRange(NULL, NULL); + delete db_; + db_ = NULL; + + opts.create_if_missing = false; + opts.num_levels = 2; + s = DB::Open(opts, dbname, &db_); + ASSERT_TRUE(strstr(s.ToString().c_str(), "Corruption") != NULL); + ASSERT_TRUE(db_ == NULL); +} + // Check that number of files does not grow when we are out of space TEST(DBTest, NoSpace) { Options options = CurrentOptions();