Beispiel #1
0
    def test_ex(self):
        try:
            zkutil.CachedReader(self.zk, 'bar')
            self.assertFalse(True, 'should raise a NoNodeError')
        except NoNodeError:
            pass

        c = zkutil.CachedReader(self.zk, 'foo')
        self.assertRaises(zkutil.ZKWaitTimeout, c.watch, 1)
Beispiel #2
0
    def test_update(self):
        c = zkutil.CachedReader(self.zk, 'foo')
        self.assertDictEqual(self.val, c)

        cases = (
            {
                'a': 2
            },
            {
                'a': 'a_v',
                'b': 'b_v'
            },
            {
                'a': 3,
                'b': {
                    'c': 4
                },
                'd': {
                    'e': {
                        'e': 'val'
                    }
                }
            },
        )

        for case in cases:
            self.zk.set('foo', utfjson.dump(case))
            time.sleep(0.5)
            self.assertDictEqual(case, c)
Beispiel #3
0
    def test_cb(self):
        latest = ['foo']

        def cb(path, old, new):
            latest[0] = new

        zkutil.CachedReader(self.zk, 'foo', callback=cb)

        for i in range(100):
            self.val['a'] += 1
            self.zk.set('foo', utfjson.dump(self.val))

        time.sleep(1)
        self.assertEqual(self.val, latest[0])
Beispiel #4
0
    def test_watch(self):
        val = {'a': 2}
        c = zkutil.CachedReader(self.zk, 'foo')

        def _change_node():
            self.zk.set('foo', utfjson.dump(val))

        threadutil.start_daemon(_change_node, after=1)
        self.assertEqual([self.val, val], c.watch())

        def _close():
            c.close()

        threadutil.start_daemon(_close, after=1)
        self.assertEqual(None, c.watch())
Beispiel #5
0
 def test_cache(self):
     c = zkutil.CachedReader(self.zk, 'foo')
     self.assertDictEqual(self.val, c)