コード例 #1
0
 def test_lock_context_manager(self):
   # Ensure that lock creates an entry in memcache.
   key = 'KEY'
   lock_key_name = locking.get_lock_key_name(key)
   with locking.lock(key):
     self.assertTrue(memcache.get(lock_key_name))
     stats = memcache.get_stats()
     self.assertEqual(1, stats['items'])
   self.assertIsNone(memcache.get(lock_key_name))
コード例 #2
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