Beispiel #1
0
 def test_locked(self):
     lock = sherlock.EtcdLock(self.lock_name)
     lock._acquire()
     self.assertTrue(lock._locked)
     lock._release()
     self.assertFalse(lock._locked)
Beispiel #2
0
 def test_acquire(self):
     lock = sherlock.EtcdLock(self.lock_name)
     self.assertTrue(lock._acquire())
     self.assertEqual(self.client.get(self.lock_name).value,
                      str(lock._owner))
Beispiel #3
0
 def test_release_with_namespace(self):
     lock = sherlock.EtcdLock(self.lock_name, namespace='ns')
     lock._acquire()
     lock._release()
     self.assertRaises(etcd.EtcdKeyNotFound, self.client.get, '/ns/%s' % self.lock_name)
Beispiel #4
0
 def test_release_own_only(self):
     lock1 = sherlock.EtcdLock(self.lock_name)
     lock2 = sherlock.EtcdLock(self.lock_name)
     lock1._acquire()
     self.assertRaises(sherlock.LockException, lock2._release)
     lock1._release()
Beispiel #5
0
 def test_release(self):
     lock = sherlock.EtcdLock(self.lock_name)
     lock._acquire()
     lock._release()
     self.assertRaises(etcd.EtcdKeyNotFound, self.client.get, self.lock_name)
Beispiel #6
0
 def test_acquire_check_expire_is_not_set(self):
     lock = sherlock.EtcdLock(self.lock_name, expire=None)
     lock.acquire()
     time.sleep(2)
     self.assertEquals(self.client.get(self.lock_name).ttl, None)
Beispiel #7
0
 def test_acquire_check_expiry(self):
     lock = sherlock.EtcdLock(self.lock_name, expire=1)
     lock.acquire()
     time.sleep(2)
     self.assertFalse(lock.locked())
Beispiel #8
0
 def test_acquire_once_only(self):
     lock1 = sherlock.EtcdLock(self.lock_name)
     lock2 = sherlock.EtcdLock(self.lock_name)
     self.assertTrue(lock1._acquire())
     self.assertFalse(lock2._acquire())
Beispiel #9
0
 def test_acquire_with_namespace(self):
     lock = sherlock.EtcdLock(self.lock_name, namespace='ns')
     self.assertTrue(lock._acquire())
     self.assertEqual(self.client.get('/ns/%s' % self.lock_name).value,
                      str(lock._owner))