diff options
Diffstat (limited to 'src/mongo/db/range_deleter_test.cpp')
-rw-r--r-- | src/mongo/db/range_deleter_test.cpp | 255 |
1 files changed, 0 insertions, 255 deletions
diff --git a/src/mongo/db/range_deleter_test.cpp b/src/mongo/db/range_deleter_test.cpp index 71bcb5e2267..49f5fdb12c2 100644 --- a/src/mongo/db/range_deleter_test.cpp +++ b/src/mongo/db/range_deleter_test.cpp @@ -398,259 +398,4 @@ namespace { mongo::repl::setGlobalReplicationCoordinator(NULL); } - // Should not be able to delete ranges that overlaps with a black listed range. - TEST(BlackList, CantDeleteBlackListed) { - boost::scoped_ptr<mongo::repl::ReplicationCoordinatorMock> mock( - new mongo::repl::ReplicationCoordinatorMock(replSettings)); - - mongo::repl::setGlobalReplicationCoordinator(mock.get()); - - RangeDeleterMockEnv* env = new RangeDeleterMockEnv(); - RangeDeleter deleter(env); - - deleter.startWorkers(); - - const string ns("test.user"); - - string errMsg; - ASSERT_TRUE(deleter.addToBlackList(ns, BSON("x" << 100), BSON("x" << 200), &errMsg)); - ASSERT_TRUE(errMsg.empty()); - - errMsg.clear(); - ASSERT_FALSE(deleter.queueDelete(RangeDeleterOptions(KeyRange(ns, - BSON("x" << 120), - BSON("x" << 140), - BSON("x" << 1))), - NULL /* notifier not needed */, - &errMsg)); - ASSERT_FALSE(errMsg.empty()); - - errMsg.clear(); - ASSERT_FALSE(deleter.deleteNow(noTxn, - RangeDeleterOptions(KeyRange(ns, - BSON("x" << 120), - BSON("x" << 140), - BSON("x" << 1))), - &errMsg)); - ASSERT_FALSE(errMsg.empty()); - - ASSERT_FALSE(env->deleteOccured()); - - deleter.stopWorkers(); - } - - // Should not be able to black list a range that overlaps with a range that is - // already blacklisted. - TEST(BlackList, CantDoubleBlackList) { - boost::scoped_ptr<mongo::repl::ReplicationCoordinatorMock> mock( - new mongo::repl::ReplicationCoordinatorMock(replSettings)); - - mongo::repl::setGlobalReplicationCoordinator(mock.get()); - - RangeDeleterMockEnv* env = new RangeDeleterMockEnv(); - RangeDeleter deleter(env); - - const string ns("test.user"); - - string errMsg; - ASSERT_TRUE(deleter.addToBlackList(ns, BSON("x" << 100), BSON("x" << 200), &errMsg)); - ASSERT_TRUE(errMsg.empty()); - - errMsg.clear(); - ASSERT_FALSE(deleter.addToBlackList(ns, BSON("x" << 100), BSON("x" << 200), &errMsg)); - ASSERT_FALSE(errMsg.empty()); - - errMsg.clear(); - ASSERT_FALSE(deleter.addToBlackList(ns, BSON("x" << 80), BSON("x" << 120), &errMsg)); - ASSERT_FALSE(errMsg.empty()); - - deleter.stopWorkers(); - - mongo::repl::setGlobalReplicationCoordinator(NULL); - } - - // Should not be able to black list a range that overlaps with a range that is already - // queued for deletion. - TEST(BlackList, CantBlackListQueued) { - boost::scoped_ptr<mongo::repl::ReplicationCoordinatorMock> mock( - new mongo::repl::ReplicationCoordinatorMock(replSettings)); - - mongo::repl::setGlobalReplicationCoordinator(mock.get()); - - RangeDeleterMockEnv* env = new RangeDeleterMockEnv(); - RangeDeleter deleter(env); - - const string ns("test.user"); - - deleter.startWorkers(); - - // Set cursors on NS so deletes cannot be processed immediately. - env->addCursorId(ns, 58); - - Notification notifyDone; - deleter.queueDelete(RangeDeleterOptions(KeyRange(ns, - BSON("x" << 0), - BSON("x" << 10), - BSON("x" << 1))), - ¬ifyDone, - NULL /* errMsg not needed */); - - string errMsg; - ASSERT_FALSE(deleter.addToBlackList(ns, BSON("x" << 5), BSON("x" << 15), &errMsg)); - ASSERT_FALSE(errMsg.empty()); - - env->removeCursorId(ns, 58); - notifyDone.waitToBeNotified(); - - // But should be able to black list again once removed from the queue. - errMsg.clear(); - ASSERT_TRUE(deleter.addToBlackList(ns, BSON("x" << 5), BSON("x" << 15), &errMsg)); - ASSERT_TRUE(errMsg.empty()); - - deleter.stopWorkers(); - - mongo::repl::setGlobalReplicationCoordinator(NULL); - } - - // Should not be able to black list a range that overlaps the range of an - // immediate delete that is currently in progress. - TEST(BlackList, CantBlackListImmediateInProgress) { - boost::scoped_ptr<mongo::repl::ReplicationCoordinatorMock> mock( - new mongo::repl::ReplicationCoordinatorMock(replSettings)); - - mongo::repl::setGlobalReplicationCoordinator(mock.get()); - - RangeDeleterMockEnv* env = new RangeDeleterMockEnv(); - RangeDeleter deleter(env); - - const string ns("test.user"); - - env->pauseDeletes(); - - string delErrMsg; - boost::thread deleterThread = - boost::thread(mongo::stdx::bind(rangeDeleterDeleteNow, - &deleter, - noTxn, - RangeDeleterOptions(KeyRange(ns, - BSON("x" << 64), - BSON("x" << 70), - BSON("x" << 1))), - &delErrMsg)); - - env->waitForNthPausedDelete(1u); - - string blErrMsg; - ASSERT_FALSE(deleter.addToBlackList(ns, BSON("x" << 10), BSON("x" << 90), &blErrMsg)); - ASSERT_FALSE(blErrMsg.empty()); - - env->resumeOneDelete(); - deleterThread.join(); - ASSERT_TRUE(delErrMsg.empty()); - - // Can blacklist again after delete completed. - blErrMsg.clear(); - ASSERT_TRUE(deleter.addToBlackList(ns, BSON("x" << 10), BSON("x" << 90), &blErrMsg)); - ASSERT_TRUE(blErrMsg.empty()); - - deleter.stopWorkers(); - - mongo::repl::setGlobalReplicationCoordinator(NULL); - } - - // Undo black list should only work if the range given exactly match with an - // existing black listed range. - TEST(BlackList, UndoShouldBeExact) { - boost::scoped_ptr<mongo::repl::ReplicationCoordinatorMock> mock( - new mongo::repl::ReplicationCoordinatorMock(replSettings)); - - mongo::repl::setGlobalReplicationCoordinator(mock.get()); - - RangeDeleterMockEnv* env = new RangeDeleterMockEnv(); - RangeDeleter deleter(env); - - const string ns("test.user"); - - ASSERT_TRUE(deleter.addToBlackList(ns, BSON("x" << 1234), BSON("x" << 8952), - NULL /* errMsg not needed */)); - - ASSERT_FALSE(deleter.removeFromBlackList(ns, BSON("x" << 1234), BSON("x" << 9000))); - - // Range should still be blacklisted - ASSERT_FALSE(deleter.deleteNow(noTxn, - RangeDeleterOptions(KeyRange(ns, - BSON("x" << 2000), - BSON("x" << 4000), - BSON("x" << 1))), - NULL /* errMsg not needed */)); - - deleter.stopWorkers(); - } - - // Should be able to delete the range again once the black list has been undone. - TEST(BlackList, UndoBlackList) { - boost::scoped_ptr<mongo::repl::ReplicationCoordinatorMock> mock( - new mongo::repl::ReplicationCoordinatorMock(replSettings)); - - mongo::repl::setGlobalReplicationCoordinator(mock.get()); - - RangeDeleterMockEnv* env = new RangeDeleterMockEnv(); - RangeDeleter deleter(env); - - const string ns("test.user"); - - string errMsg; - ASSERT_TRUE(deleter.addToBlackList(ns, BSON("x" << 500), BSON("x" << 801), &errMsg)); - ASSERT_TRUE(errMsg.empty()); - - errMsg.clear(); - ASSERT_FALSE(deleter.deleteNow(noTxn, - RangeDeleterOptions(KeyRange(ns, - BSON("x" << 600), - BSON("x" << 700), - BSON("x" << 1))), - &errMsg)); - ASSERT_FALSE(errMsg.empty()); - - ASSERT_TRUE(deleter.removeFromBlackList(ns, BSON("x" << 500), BSON("x" << 801))); - - errMsg.clear(); - ASSERT_TRUE(deleter.deleteNow(noTxn, - RangeDeleterOptions(KeyRange(ns, - BSON("x" << 600), - BSON("x" << 700), - BSON("x" << 1))), - &errMsg)); - ASSERT_TRUE(errMsg.empty()); - - deleter.stopWorkers(); - - mongo::repl::setGlobalReplicationCoordinator(NULL); - } - - // Black listing should only affect the specified namespace. - TEST(BlackList, NSIsolation) { - boost::scoped_ptr<mongo::repl::ReplicationCoordinatorMock> mock( - new mongo::repl::ReplicationCoordinatorMock(replSettings)); - - mongo::repl::setGlobalReplicationCoordinator(mock.get()); - - RangeDeleterMockEnv* env = new RangeDeleterMockEnv(); - RangeDeleter deleter(env); - - deleter.addToBlackList("foo.bar", BSON("x" << 100), BSON("x" << 200), - NULL /* errMsg not needed */); - - ASSERT_TRUE(deleter.deleteNow(noTxn, - RangeDeleterOptions(KeyRange("test.user", - BSON("x" << 120), - BSON("x" << 140), - BSON("x" << 1))), - NULL /* errMsg not needed */)); - - deleter.stopWorkers(); - - mongo::repl::setGlobalReplicationCoordinator(NULL); - } - } // unnamed namespace |