summaryrefslogtreecommitdiff
path: root/tooz/tests
diff options
context:
space:
mode:
authorzhangsong <zhangsong@cmss.chinamobile.com>2017-03-15 12:51:27 +0800
committerzhangsong <zhangsong@cmss.chinamobile.com>2017-03-21 11:27:24 +0800
commite6dc88b2a56cdb687c1c65bdc1d2ebc03ba28101 (patch)
treef70e20cd8479ae0d1091195806ce92fe0ffaf3e9 /tooz/tests
parentf624e16f6236e1a925fac3d720a8d7ceed2bf705 (diff)
downloadtooz-e6dc88b2a56cdb687c1c65bdc1d2ebc03ba28101.tar.gz
Add shared filelock
Currently each driver in tooz only support exclusive lock, it is inefficient in some scenarios which only need shared lock. This patch adds shared lock in file driver. Change-Id: I55a528977e74b27da736f421d2eee28c7aae8aa3 Implements: blueprint support-shared-lock Co-Authored-By: Julien Danjou <julien@danjou.info>
Diffstat (limited to 'tooz/tests')
-rw-r--r--tooz/tests/test_coordination.py56
1 files changed, 56 insertions, 0 deletions
diff --git a/tooz/tests/test_coordination.py b/tooz/tests/test_coordination.py
index 74a74b1..c177100 100644
--- a/tooz/tests/test_coordination.py
+++ b/tooz/tests/test_coordination.py
@@ -712,6 +712,62 @@ class TestAPI(tests.TestWithCoordinator):
with lock:
pass
+ def test_get_shared_lock(self):
+ lock = self._coord.get_lock(tests.get_random_uuid())
+ self.assertTrue(lock.acquire(shared=True))
+ self.assertTrue(lock.release())
+ with lock(shared=True):
+ pass
+
+ def test_get_shared_lock_locking_same_lock_twice(self):
+ lock = self._coord.get_lock(tests.get_random_uuid())
+ self.assertTrue(lock.acquire(shared=True))
+ self.assertTrue(lock.acquire(shared=True))
+ self.assertTrue(lock.release())
+ self.assertTrue(lock.release())
+ self.assertFalse(lock.release())
+ with lock(shared=True):
+ pass
+
+ def test_get_shared_lock_locking_two_lock(self):
+ name = tests.get_random_uuid()
+ lock1 = self._coord.get_lock(name)
+ coord = tooz.coordination.get_coordinator(
+ self.url, tests.get_random_uuid())
+ coord.start()
+ lock2 = coord.get_lock(name)
+
+ self.assertTrue(lock1.acquire(shared=True))
+ self.assertTrue(lock2.acquire(shared=True))
+ self.assertTrue(lock1.release())
+ self.assertTrue(lock2.release())
+
+ def test_get_lock_locking_shared_and_exclusive(self):
+ name = tests.get_random_uuid()
+ lock1 = self._coord.get_lock(name)
+ coord = tooz.coordination.get_coordinator(
+ self.url, tests.get_random_uuid())
+ coord.start()
+ lock2 = coord.get_lock(name)
+
+ self.assertTrue(lock1.acquire(shared=True))
+ self.assertFalse(lock2.acquire(blocking=False))
+ self.assertTrue(lock1.release())
+ self.assertFalse(lock2.release())
+
+ def test_get_lock_locking_exclusive_and_shared(self):
+ name = tests.get_random_uuid()
+ lock1 = self._coord.get_lock(name)
+ coord = tooz.coordination.get_coordinator(
+ self.url, tests.get_random_uuid())
+ coord.start()
+ lock2 = coord.get_lock(name)
+
+ self.assertTrue(lock1.acquire())
+ self.assertFalse(lock2.acquire(shared=True, blocking=False))
+ self.assertTrue(lock1.release())
+ self.assertFalse(lock2.release())
+
def test_get_lock_concurrency_locking_same_lock(self):
lock = self._coord.get_lock(tests.get_random_uuid())