

def test_acquire_lock(self):
    flexmock(zk.ZKTransaction)
    zk.ZKTransaction.should_receive('get_lock_root_path').and_return('/lock/root/path')
    zk.ZKTransaction.should_receive('get_transaction_prefix_path').and_return(('/rootpath/' + self.appid))
    fake_zookeeper = flexmock(name='fake_zoo', get='get', connected=(lambda : True))
    fake_zookeeper.should_receive('start')
    fake_zookeeper.should_receive('retry')
    flexmock(kazoo.client)
    kazoo.client.should_receive('KazooClient').and_return(fake_zookeeper)
    zk.ZKTransaction.should_receive('is_in_transaction').and_return(False)
    zk.ZKTransaction.should_receive('acquire_additional_lock').and_return(True)
    transaction = zk.ZKTransaction(host='something', start_gc=False)
    self.assertEquals(True, transaction.acquire_lock(self.appid, 'txid', 'somekey'))
    zk.ZKTransaction.should_receive('is_in_transaction').and_return(True)
    zk.ZKTransaction.should_receive('get_transaction_lock_list_path').and_return((('/rootpath/' + self.appid) + '/tx1'))
    fake_zookeeper.should_receive('retry').with_args('get', str).and_return(['/lock/root/path'])
    transaction = zk.ZKTransaction(host='something', start_gc=False)
    self.assertEquals(True, transaction.acquire_lock(self.appid, 'txid', 'somekey'))
    zk.ZKTransaction.should_receive('is_in_transaction').and_return(True)
    zk.ZKTransaction.should_receive('get_transaction_lock_list_path').and_return((('/rootpath/' + self.appid) + '/tx1'))
    fake_zookeeper.should_receive('retry').with_args('get', str).and_return(['/lock/root/path2'])
    zk.ZKTransaction.should_receive('is_xg').and_return(False)
    transaction = zk.ZKTransaction(host='something', start_gc=False)
    self.assertRaises(zk.ZKTransactionException, transaction.acquire_lock, self.appid, 'txid', 'somekey')
    zk.ZKTransaction.should_receive('is_in_transaction').and_return(True)
    zk.ZKTransaction.should_receive('get_transaction_lock_list_path').and_return((('/rootpath/' + self.appid) + '/tx1'))
    fake_zookeeper.should_receive('retry').with_args('get', str).and_return(['/lock/root/path2'])
    zk.ZKTransaction.should_receive('is_xg').and_return(True)
    transaction = zk.ZKTransaction(host='something', start_gc=False)
    self.assertEquals(True, transaction.acquire_lock(self.appid, 'txid', 'somekey'))

dataset/ETHPy150Open AppScale/appscale/AppDB/test/unit/test_zookeeper.py TestZookeeperTransaction.test_acquire_lock/original