

def test_try_garbage_collection(self):
    flexmock(zk.ZKTransaction)
    zk.ZKTransaction.should_receive('update_node')
    fake_zookeeper = flexmock(name='fake_zoo', exists='exists', get='get', get_children='get_children', create='create', delete='delete')
    fake_zookeeper.should_receive('start')
    fake_zookeeper.should_receive('retry').with_args('exists', str).and_return(True)
    fake_zookeeper.should_receive('retry').with_args('get', str).and_return([str((time.time() + 10000))])
    fake_zookeeper.should_receive('retry').with_args('get_children', str).and_return(['1', '2', '3'])
    fake_zookeeper.should_receive('retry').with_args('create', str, value=str, acl=None, ephemeral=bool)
    fake_zookeeper.should_receive('retry').with_args('delete', str)
    flexmock(kazoo.client)
    kazoo.client.should_receive('KazooClient').and_return(fake_zookeeper)
    transaction = zk.ZKTransaction(host='something', start_gc=False)
    self.assertEquals(False, transaction.try_garbage_collection(self.appid, '/some/path'))
    fake_zookeeper.should_receive('retry').with_args('get', str).and_return([str(time.time())])
    self.assertEquals(False, transaction.try_garbage_collection(self.appid, '/some/path'))
    fake_zookeeper.should_receive('retry').with_args('get', str).and_return([str((time.time() - 1000))])
    self.assertEquals(True, transaction.try_garbage_collection(self.appid, '/some/path'))
    fake_zookeeper.should_receive('retry').with_args('get', str).and_raise(kazoo.exceptions.NoNodeError)
    self.assertEquals(True, transaction.try_garbage_collection(self.appid, '/some/path'))

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