コード例 #1
0
  def test_lock_context_manager_raises_exeception_when_key_is_locked(self):
    # Acquire lock on a key.
    key = 'KEY'
    lock_key_name = locking.get_lock_key_name(key)
    locking.acquire_lock(lock_key_name)
    stats = memcache.get_stats()
    self.assertEqual(1, stats['items'])

    # Ensure a RuntimeError is raised.
    with self.assertRaises(RuntimeError):
      with locking.lock(lock_key_name, tries=1):
        pass
コード例 #2
0
 def test_release_lock(self):
   # Ensure that a lock's memcache entry is deleted upon release.
   key = 'KEY'
   self.assertTrue(locking.acquire_lock(key))
   lock_key_name = locking.get_lock_key_name(key)
   self.assertTrue(memcache.get(lock_key_name))
   stats = memcache.get_stats()
   self.assertEqual(1, stats['items'])
   locking.release_lock(key)
   self.assertIsNone(memcache.get(lock_key_name))
コード例 #3
0
 def test_acquire_lock_creates_memcache_entry(self):
   key = 'KEY'
   self.assertTrue(locking.acquire_lock(key))
   lock_key_name = locking.get_lock_key_name(key)
   self.assertTrue(memcache.get(lock_key_name))