summaryrefslogtreecommitdiff
path: root/src/mongo/db/concurrency/d_concurrency_test.cpp
diff options
context:
space:
mode:
authorKaloian Manassiev <kaloian.manassiev@mongodb.com>2014-08-13 14:53:12 -0400
committerKaloian Manassiev <kaloian.manassiev@mongodb.com>2014-08-25 16:58:58 -0400
commit052175eb9e0b793de19575fea37a7fdd95126a50 (patch)
treee9b3d5ad0b30e8825448c6e8dffe19dc5297af05 /src/mongo/db/concurrency/d_concurrency_test.cpp
parenteacc825ccae11f81a3d06513ceced054b9562ef6 (diff)
downloadmongo-052175eb9e0b793de19575fea37a7fdd95126a50.tar.gz
SERVER-14668 Move DB-level locks to be on the LockManager
Diffstat (limited to 'src/mongo/db/concurrency/d_concurrency_test.cpp')
-rw-r--r--src/mongo/db/concurrency/d_concurrency_test.cpp82
1 files changed, 82 insertions, 0 deletions
diff --git a/src/mongo/db/concurrency/d_concurrency_test.cpp b/src/mongo/db/concurrency/d_concurrency_test.cpp
new file mode 100644
index 00000000000..19a2bbead66
--- /dev/null
+++ b/src/mongo/db/concurrency/d_concurrency_test.cpp
@@ -0,0 +1,82 @@
+/**
+ * Copyright (C) 2014 MongoDB Inc.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * As a special exception, the copyright holders give permission to link the
+ * code of portions of this program with the OpenSSL library under certain
+ * conditions as described in each individual source file and distribute
+ * linked combinations including the program with the OpenSSL library. You
+ * must comply with the GNU Affero General Public License in all respects for
+ * all of the code used other than as permitted herein. If you modify file(s)
+ * with this exception, you may extend this exception to your version of the
+ * file(s), but you are not obligated to do so. If you do not wish to do so,
+ * delete this exception statement from your version. If you delete this
+ * exception statement from all source files in the program, then also delete
+ * it in the license file.
+ */
+
+#include "mongo/platform/basic.h"
+
+#include <boost/scoped_ptr.hpp>
+#include <boost/thread/thread.hpp>
+
+#include "mongo/db/concurrency/d_concurrency.h"
+#include "mongo/db/concurrency/lock_state.h"
+#include "mongo/unittest/unittest.h"
+
+
+// Most of the tests here will be removed once we move everything over to using LockManager
+//
+
+namespace mongo {
+
+ // These two tests ensure that we have preserved the behaviour of TempRelease
+ TEST(DConcurrency, TempReleaseOneDB) {
+ LockState ls;
+
+ Lock::DBRead r1(&ls, "db1");
+
+ {
+ Lock::TempRelease tempRelease(&ls);
+ }
+
+ ls.assertAtLeastReadLocked("db1");
+ }
+
+ TEST(DConcurrency, TempReleaseRecursive) {
+ LockState ls;
+
+ Lock::DBRead r1(&ls, "db1");
+ Lock::DBRead r2(&ls, "db2");
+
+ {
+ Lock::TempRelease tempRelease(&ls);
+
+ ls.assertAtLeastReadLocked("db1");
+ ls.assertAtLeastReadLocked("db2");
+ }
+
+ ls.assertAtLeastReadLocked("db1");
+ ls.assertAtLeastReadLocked("db2");
+ }
+
+ TEST(DConcurrency, MultipleDBLocks) {
+ LockState ls;
+
+ Lock::DBWrite r1(&ls, "db1");
+ Lock::DBRead r2(&ls, "db1");
+
+ ls.assertWriteLocked("db1");
+ }
+} // namespace mongo