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"))
def test_async_exists(self): self.cv = threading.Condition() def callback(handle, rc, stat): self.cv.acquire() self.callback_flag = True self.cv.notify() self.cv.release() self.rc = rc self.assertEqual(self.connected, True) self.cv.acquire() ret = zookeeper.aexists(self.handle, "/zk-python-aexiststest", None, callback ) self.assertEqual(ret, zookeeper.OK) while not self.callback_flag: self.cv.wait(15) self.cv.release() self.assertEqual(self.callback_flag, True, "aexists timed out") self.assertEqual(self.rc, zookeeper.OK, "Return code not ok:" + zookeeper.zerror(self.rc))