コード例 #1
0
    def test_acquired_no_timeout(self):
        self.locker._sequence = 4
        returns = [('/_locks/test_lock/4', None),
                   ('/_locks/test_lock/1',
                    etcd.EtcdResult(node={
                        "key": '/_locks/test_lock/4',
                        "modifiedIndex": 1
                    }))]

        def side_effect():
            return returns.pop()

        d = {
            u'action': u'get',
            u'node': {
                u'modifiedIndex': 190,
                u'key': u'/_locks/test_lock/4',
                u'value': self.locker.uuid
            }
        }
        self._mock_api(200, d)

        self.locker._get_locker = mock.create_autospec(self.locker._get_locker,
                                                       side_effect=side_effect)
        self.assertTrue(self.locker._acquired())
コード例 #2
0
 async def _result_from_response(self, response):
     """ Creates an EtcdResult from json dictionary """
     raw_response = await response.read()
     try:
         res = await response.json()
     except (TypeError, ValueError, UnicodeError) as e:
         raise etcd.EtcdException('Server response was not valid JSON: %r',
                                  raw_response)
     _log.debug("result: %s", res)
     try:
         r = etcd.EtcdResult(**res)
         if response.status == 201:
             r.newKey = True
         r.parse_headers(response)
         return r
     except Exception as e:
         raise etcd.EtcdException('Unable to decode server response') from e
コード例 #3
0
 def test_get_locker(self):
     self.recursive_read()
     self.assertEquals((u'/_locks/test_lock/1',
                        etcd.EtcdResult(
                            node={
                                'newKey': False,
                                '_children': [],
                                'createdIndex': 33,
                                'modifiedIndex': 33,
                                'value': u'2qwwwq',
                                'expiration': None,
                                'key': u'/_locks/test_lock/1',
                                'ttl': None,
                                'action': None,
                                'dir': False
                            })), self.locker._get_locker())
     with self.assertRaises(etcd.EtcdLockExpired):
         self.locker._sequence = '35'
         self.locker._get_locker()