def test_try_garbage_collection(self):
    # mock out getTransactionRootPath
    flexmock(zk.ZKTransaction)
    zk.ZKTransaction.should_receive('update_node')

    # mock out initializing a ZK connection
    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)

    # Put the last time we ran GC way into the future.
    transaction = zk.ZKTransaction(host="something", start_gc=False)
    self.assertEquals(False, transaction.try_garbage_collection(self.appid, 
      "/some/path"))

    # Make it so we recently ran the GC
    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"))

    # Make it so we ran the GC a long time ago.
    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"))

    # No node means we have not run the GC before, so run it.
    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