|
|
@@ -90,50 +90,69 @@ class TestWithZooKeeper:
|
|
|
# Don't want directories laying around
|
|
|
shutil.rmtree(cls.local_directory)
|
|
|
|
|
|
+ def teardown(self):
|
|
|
+ client = ZookeeperClient(hosts=zkensemble(), read_only=False)
|
|
|
+ # Delete the root_node first just in case it wasn't cleaned up in previous run
|
|
|
+ client.zk.start()
|
|
|
+ try:
|
|
|
+ if client.zk.exists(self.namespace):
|
|
|
+ client.zk.delete(self.namespace, recursive=True)
|
|
|
+ finally:
|
|
|
+ client.zk.stop()
|
|
|
+
|
|
|
def test_get_children_data(self):
|
|
|
- client = ZookeeperClient(hosts=zkensemble())
|
|
|
- db = client.get_children_data(namespace='')
|
|
|
+ root_node = '%s/%s' % (TestWithZooKeeper.namespace, 'test_path_exists')
|
|
|
+ client = ZookeeperClient(hosts=zkensemble(), read_only=False)
|
|
|
+
|
|
|
+ client.zk.start()
|
|
|
+ try:
|
|
|
+ client.zk.create(root_node, value='test_path_exists', makepath=True)
|
|
|
+ finally:
|
|
|
+ client.zk.stop()
|
|
|
+
|
|
|
+ db = client.get_children_data(namespace=TestWithZooKeeper.namespace)
|
|
|
assert_true(len(db) > 0)
|
|
|
|
|
|
def test_path_exists(self):
|
|
|
- try:
|
|
|
- root_node = '%s/%s' % (TestWithZooKeeper.namespace, 'test_path_exists')
|
|
|
- client = ZookeeperClient(hosts=zkensemble(), read_only=False)
|
|
|
+ root_node = '%s/%s' % (TestWithZooKeeper.namespace, 'test_path_exists')
|
|
|
+ client = ZookeeperClient(hosts=zkensemble(), read_only=False)
|
|
|
|
|
|
- # Delete the root_node first just in case it wasn't cleaned up in previous run
|
|
|
- client.zk.start()
|
|
|
- client.zk.create(root_node, value='test_path_exists')
|
|
|
- client.zk.stop()
|
|
|
+ client.zk.start()
|
|
|
+ try:
|
|
|
+ client.zk.create(root_node, value='test_path_exists', makepath=True)
|
|
|
|
|
|
- assert_true(client.path_exists(namespace=root_node))
|
|
|
- assert_false(client.path_exists(namespace='bogus_path'))
|
|
|
+ try:
|
|
|
+ assert_true(client.path_exists(namespace=root_node))
|
|
|
+ assert_false(client.path_exists(namespace='bogus_path'))
|
|
|
+ finally:
|
|
|
+ client.delete_path(root_node)
|
|
|
finally:
|
|
|
- client.delete_path(root_node)
|
|
|
+ client.zk.stop()
|
|
|
|
|
|
def test_copy_and_delete_path(self):
|
|
|
root_node = '%s/%s' % (TestWithZooKeeper.namespace, 'test_copy_and_delete_path')
|
|
|
client = ZookeeperClient(hosts=zkensemble(), read_only=False)
|
|
|
|
|
|
- # Delete the root_node first just in case it wasn't cleaned up in previous run
|
|
|
- client.zk.start()
|
|
|
- client.zk.delete(root_node, recursive=True)
|
|
|
- client.zk.stop()
|
|
|
-
|
|
|
# Test copy_path
|
|
|
client.copy_path(root_node, TestWithZooKeeper.local_directory)
|
|
|
|
|
|
client.zk.start()
|
|
|
- assert_true(client.zk.exists('%s' % root_node))
|
|
|
- assert_true(client.zk.exists('%s/%s' % (root_node, TestWithZooKeeper.subdir_name)))
|
|
|
- assert_true(client.zk.exists('%s/%s/%s' % (root_node, TestWithZooKeeper.subdir_name, TestWithZooKeeper.filename)))
|
|
|
- contents, stats = client.zk.get('%s/%s/%s' % (root_node, TestWithZooKeeper.subdir_name, TestWithZooKeeper.filename))
|
|
|
- assert_equal(contents, TestWithZooKeeper.file_contents)
|
|
|
- client.zk.stop()
|
|
|
+ try:
|
|
|
+ assert_true(client.zk.exists('%s' % root_node))
|
|
|
+ assert_true(client.zk.exists('%s/%s' % (root_node, TestWithZooKeeper.subdir_name)))
|
|
|
+ assert_true(client.zk.exists('%s/%s/%s' % (root_node, TestWithZooKeeper.subdir_name, TestWithZooKeeper.filename)))
|
|
|
+ contents, stats = client.zk.get('%s/%s/%s' % (root_node, TestWithZooKeeper.subdir_name, TestWithZooKeeper.filename))
|
|
|
+ assert_equal(contents, TestWithZooKeeper.file_contents)
|
|
|
+ finally:
|
|
|
+ client.zk.stop()
|
|
|
|
|
|
# Test delete_path
|
|
|
client.delete_path(root_node)
|
|
|
|
|
|
client.zk.start()
|
|
|
- assert_equal(client.zk.exists('%s' % root_node), None)
|
|
|
- assert_equal(client.zk.exists('%s/%s' % (root_node, TestWithZooKeeper.subdir_name)), None)
|
|
|
- assert_equal(client.zk.exists('%s/%s/%s' % (root_node, TestWithZooKeeper.subdir_name, TestWithZooKeeper.filename)), None)
|
|
|
+ try:
|
|
|
+ assert_equal(client.zk.exists('%s' % root_node), None)
|
|
|
+ assert_equal(client.zk.exists('%s/%s' % (root_node, TestWithZooKeeper.subdir_name)), None)
|
|
|
+ assert_equal(client.zk.exists('%s/%s/%s' % (root_node, TestWithZooKeeper.subdir_name, TestWithZooKeeper.filename)), None)
|
|
|
+ finally:
|
|
|
+ client.zk.stop()
|