Skip to content
This repository has been archived by the owner on Jan 27, 2021. It is now read-only.

Commit

Permalink
add a test checking zc.zk.testing handles sequence nodes like a real …
Browse files Browse the repository at this point in the history
…zookeeper,

and that the API returns the path to the created node as expected
  • Loading branch information
freddrake committed Jul 10, 2014
1 parent 37b62af commit f0a053a
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/zc/zk/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -474,8 +474,9 @@ def create(self, handle, path, data, acl, ephemeral=False, sequence=False):
self._check_handle(handle)
node = self._traverse(base or u'/')
if sequence:
node.child_seqno += 1
name = "%s%010d" % (name, node.child_seqno)
node.child_seqno += 1
path = u'%s/%s' % (base, name)
if name in node.children:
raise kazoo.exceptions.NodeExistsError()
node.children[name] = newnode = Node(data)
Expand Down
45 changes: 45 additions & 0 deletions src/zc/zk/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1095,6 +1095,51 @@ def no_error_calling_close_more_than_once():
>>> zk.close()
"""

def create_handles_sequence_nodes():
"""
This ensures we handle sequence nodes the same way as the real
zookeeper in the zc.zk.testing support. This has to pass both with
the test support and a real zookeeper backend.
>>> zk = zc.zk.ZooKeeper('zookeeper.example.com:2181')
>>> _ = zk.create('/a', '', zc.zk.OPEN_ACL_UNSAFE)
>>> _ = zk.create('/b', '', zc.zk.OPEN_ACL_UNSAFE)
>>> zk.delete_recursive('/fooservice')
>>> zk.create(
... '/a/fubar', '{"a": 1}', zc.zk.OPEN_ACL_UNSAFE, sequence=True)
u'/a/fubar0000000000'
>>> zk.print_tree()
/a
/fubar0000000000
a = 1
/b
>>> zk.create(
... '/a/fubar', '{"a": 2}', zc.zk.OPEN_ACL_UNSAFE, sequence=True)
u'/a/fubar0000000001'
>>> zk.print_tree()
/a
/fubar0000000000
a = 1
/fubar0000000001
a = 2
/b
>>> zk.create(
... '/b/fubar', '{"a": 42}', zc.zk.OPEN_ACL_UNSAFE, sequence=True)
u'/b/fubar0000000000'
>>> zk.print_tree()
/a
/fubar0000000000
a = 1
/fubar0000000001
a = 2
/b
/fubar0000000000
a = 42
"""

def backward_compatible_create_recursive():
"""
>>> zk = zc.zk.ZooKeeper('zookeeper.example.com:2181')
Expand Down

0 comments on commit f0a053a

Please sign in to comment.