예제 #1
0
    def test_set_or_create(self):

        kv = zktx.ZKKeyValue(self.zk)

        # create

        kv.set_or_create('foo', '1')

        rst, ver = kv.get('foo')
        self.assertEqual('1', rst)
        self.assertEqual(0, ver)

        # set

        self.assertRaises(BadVersionError,
                          kv.set_or_create,
                          'foo',
                          '2',
                          version=2)

        kv.set_or_create('foo', '2', version=0)
        kv.set_or_create('foo', '2', version=1)
        rst, ver = kv.get('foo')
        self.assertEqual('2', rst)
        self.assertEqual(2, ver)
예제 #2
0
    def test_load(self):

        kv = zktx.ZKKeyValue(self.zk, load=lambda v: '(' + v + ')')

        self.zk.create('foo', '1')
        rst, ver = kv.get('foo')
        self.assertEqual('(1)', rst)
예제 #3
0
    def test_safe_delete(self):

        kv = zktx.ZKKeyValue(self.zk, get_path=lambda x: 'foo-' + x)
        kv.create('bar', '1')

        kv.delete('bar')
        self.assertRaises(NoNodeError, kv.get, 'bar')
        kv.safe_delete('bar')
예제 #4
0
    def test_set_or_create_acl(self):

        kv = zktx.ZKKeyValue(self.zkauthed)

        kv.set_or_create('tacl', '1')

        acl, _ = self.zkauthed.get_acls('tacl')

        self.assertEqual(acl, self.zkauthed._zkconf.kazoo_digest_acl())
예제 #5
0
    def test_dump(self):

        kv = zktx.ZKKeyValue(self.zk, dump=lambda v: '(' + v + ')')

        kv.create('foo', '1')
        rst, ver = self.zk.get('foo')
        self.assertEqual('(1)', rst)

        kv.set('foo', '2')
        rst, ver = self.zk.get('foo')
        self.assertEqual('(2)', rst)
예제 #6
0
    def test_version(self):

        kv = zktx.ZKKeyValue(self.zk, get_path=lambda x: 'foo-' + x)

        self.zk.create('foo-bar', '1')

        kv.set('bar', '2', version=0)
        rst, ver = kv.get('bar')
        self.assertEqual('2', rst)

        self.assertRaises(BadVersionError, kv.set, 'bar', '2', version=0)
        self.assertRaises(BadVersionError, kv.set, 'bar', '2', version=2)

        self.assertRaises(BadVersionError, kv.delete, 'bar', version=0)
        self.assertRaises(BadVersionError, kv.delete, 'bar', version=2)

        kv.delete('bar')
예제 #7
0
    def test_get_path(self):

        kv = zktx.ZKKeyValue(self.zk, get_path=lambda x: 'foo-' + x)

        kv.create('bar', '1')

        rst, ver = self.zk.get('foo-bar')
        self.assertEqual('1', rst)

        rst, ver = kv.get('bar')
        self.assertEqual('1', rst)

        kv.set('bar', '2')
        rst, ver = kv.get('bar')
        self.assertEqual('2', rst)

        kv.delete('bar')
        self.assertRaises(NoNodeError, kv.get, 'bar')
예제 #8
0
    def test_nonode_callback(self):

        kv = zktx.ZKKeyValue(self.zk, nonode_callback=lambda: ('default', 10))

        rst, ver = kv.get('foo')
        self.assertEqual(('default', 10), (rst, ver))