def test_bad_version_error(self): """ The node captures the node version on any read operations, which it utilizes for write operations. On a concurrent modification error the node return a bad version error, this also clears the cached state so subsequent modifications will be against the latest version, unless the cache is seeded again by a read operation. """ node = ZNode("/zoo/lion", self.client) self.client2 = ZookeeperClient("127.0.0.1:2181") yield self.client2.connect() yield self.client.create("/zoo/lion", "mouse") yield node.get_data() yield self.client2.set("/zoo/lion", "den2") data = yield self.client.exists("/zoo/lion") self.assertEqual(data['version'], 1) d = node.set_data("zebra") self.failUnlessFailure(d, zookeeper.BadVersionException) yield d # after failure the cache is deleted, and a set proceeds yield node.set_data("zebra") data = yield node.get_data() self.assertEqual(data, "zebra")
def test_node_set_data_on_nonexistant(self): """ Setting data on a non existant node raises a no node exception. """ node = ZNode("/zoo/rabbit", self.client) d = node.set_data("big furry ears") self.failUnlessFailure(d, zookeeper.NoNodeException) yield d
def test_node_set_data_update_with_exists(self): """ Data can be set on an existing node, updating it in place. """ node = ZNode("/zoo/monkey", self.client) yield self.client.create("/zoo/monkey", "stripes") yield node.set_data("banana") data, stat = yield self.client.get("/zoo/monkey") self.assertEqual(data, "banana")
def test_node_set_data_update_with_invalid_cached_exists(self): """ If a node is deleted, attempting to set data on it raises a no node exception. """ node = ZNode("/zoo/monkey", self.client) yield self.client.create("/zoo/monkey", "stripes") exists = yield node.exists() self.assertTrue(exists) yield self.client.delete("/zoo/monkey") d = node.set_data("banana") self.failUnlessFailure(d, zookeeper.NoNodeException) yield d
def test_node_create_set_data(self): """ A node can be created and have its data set. """ node = ZNode("/zoo/rabbit", self.client) data = "big furry ears" yield node.create(data) exists = yield self.client.exists("/zoo/rabbit") self.assertTrue(exists) node_data = yield node.get_data() self.assertEqual(data, node_data) data = data*2 yield node.set_data(data) node_data = yield node.get_data() self.assertEqual(data, node_data)