Exemplo n.º 1
0
 def setUp(self):
     self.client = etcd.Client()
     self.key = "lock-%d" % random.uniform(1, 100000)
     self.locks = [
         Lock(etcd.Client(), self.key, ttl=2, renewSecondsPrior=1),
         Lock(etcd.Client(), self.key, ttl=5, renewSecondsPrior=1),
         Lock(etcd.Client(),
              self.key,
              ttl=2,
              renewSecondsPrior=None,
              timeout=2)
     ]
Exemplo n.º 2
0
 def test_it_should_be_able_to_be_acquired_and_released(self):
     self.lock = Lock(self.client,
                      "locks/foo/bar/%d" % random.uniform(1, 100000))
     self.lock.acquire()
     node = self.client.get(self.lock.key)
     expect(node.value).to.eq(self.lock.token)
     expect(node.ttl).to.eq(60)
     self.lock.release()
     expect(self.client.get(self.lock.key).value).to.eq("0")
Exemplo n.º 3
0
 def test_it_should_require_an_etcd_key(self):
     expect(lambda: Lock(self.client, key=None)).to.raise_error(ValueError)
Exemplo n.º 4
0
 def test_it_should_require_renew_prior_to_be_less_than_the_ttl(self):
     expect(
         lambda: Lock(self.client, 'lock/foo', ttl=20, renewSecondsPrior=20
                      )).to.raise_error(ValueError)
Exemplo n.º 5
0
 def test_it_should_require_a_valid_renew_prior_time(self):
     expect(lambda: Lock(self.client, 'lock/foo', renewSecondsPrior=-5)
            ).to.raise_error(ValueError)
Exemplo n.º 6
0
 def test_it_should_require_a_valid_ttl(self):
     expect(lambda: Lock(self.client, 'lock/foo', ttl=0)).to.raise_error(
         ValueError)
Exemplo n.º 7
0
 def test_it_should_require_an_etcd_client(self):
     expect(lambda: Lock(None, 'lock/foo')).to.raise_error(ValueError)
Exemplo n.º 8
0
 def setUp(self):
     self.client = etcd.Client()
     self.lock = Lock(self.client,
                      "lock-%d" % random.uniform(1, 100000),
                      ttl=2,
                      renewSecondsPrior=1)