def test_async_acl(self): self.cv = threading.Condition() self.cv = threading.Condition() def aget_callback(handle, rc, acl, stat): self.cv.acquire() self.callback_flag = True self.rc = rc self.acl = acl self.stat = stat self.cv.notify() self.cv.release() def aset_callback(handle, rc): self.cv.acquire() self.callback_flag = True self.rc = rc self.cv.notify() self.cv.release() self.assertEqual(self.connected, True, "Not connected!") ret = zookeeper.create(self.handle, "/zk-python-aacltest", "nodecontents", [ZOO_OPEN_ACL_UNSAFE], zookeeper.EPHEMERAL) self.cv.acquire() zookeeper.aget_acl(self.handle, "/zk-python-aacltest", aget_callback) self.cv.wait(15) self.cv.release() self.assertEqual(self.callback_flag, True, "aget_acl timed out") self.assertEqual(self.rc, zookeeper.OK, "aget failed") self.assertEqual(self.acl, [ZOO_OPEN_ACL_UNSAFE], "Wrong ACL returned from aget") self.cv.acquire() self.callback_flag = False zookeeper.aset_acl(self.handle, "/zk-python-aacltest", -1, [ZOO_ACL_READ], aset_callback) self.cv.wait(15) self.cv.release() self.assertEqual(self.callback_flag, True, "aset_acl timed out") self.assertEqual(self.rc, zookeeper.OK, "aset failed") acls = zookeeper.get_acl(self.handle, "/zk-python-aacltest") self.assertEqual(acls[1], [ZOO_ACL_READ], "Wrong ACL returned from get when aset")
def test_dispatch_types(self): """ Test all the various dispatch mechanisms internal to the module. """ def dispatch_callback(*args, **kwargs): self.callback_flag = True self.ensureCreated("/zk-python-dispatch-test") self.callback_harness( lambda: zookeeper.adelete(self.handle, "/zk-python-dispatch-test", -1, self.create_callback(dispatch_callback)), lambda: self.assertEqual(True, self.callback_flag, "Void dispatch not fired")) self.ensureCreated("/zk-python-dispatch-test") self.callback_harness( lambda: zookeeper.aexists(self.handle, "/zk-python-dispatch-test", None, self.create_callback(dispatch_callback)), lambda: self.assertEqual(True, self.callback_flag, "Stat dispatch not fired")) self.callback_harness( lambda: zookeeper.aget(self.handle, "/zk-python-dispatch-test", None, self.create_callback(dispatch_callback)), lambda: self.assertEqual(True, self.callback_flag, "Data dispatch not fired")) self.callback_harness( lambda: zookeeper.aget_children(self.handle, "/", None, self.create_callback( dispatch_callback )), lambda: self.assertEqual(True, self.callback_flag, "Strings dispatch not fired")) self.callback_harness( lambda: zookeeper.async(self.handle, "/", self.create_callback( dispatch_callback )), lambda: self.assertEqual(True, self.callback_flag, "String dispatch not fired")) self.callback_harness( lambda: zookeeper.aget_acl(self.handle, "/", self.create_callback( dispatch_callback )), lambda: self.assertEqual(True, self.callback_flag, "ACL dispatch not fired"))