Beispiel #1
0
    def test_stat_deleted_node(self):
        """
        Test for a bug that surfaced when trying to build a
        stat object from a non-existant node.

        """
        self.ensureDeleted("/zk-python-test-deleteme")
        self.assertRaises(zookeeper.NoNodeException,
                          zookeeper.get,
                          self.handle,
                          "/zk-python-test-deleteme")
        self.cv = threading.Condition()
        def callback(handle, rc, value, stat):
            self.cv.acquire()
            self.stat = stat
            self.rc = rc
            self.value = value
            self.callback_flag = True
            self.cv.notify()
            self.cv.release()
        self.cv.acquire()
        zookeeper.aget(self.handle, "/zk-python-test-deleteme", None, callback)
        self.cv.wait(15)
        self.assertEqual(self.callback_flag, True, "aget timed out!")
        self.assertEqual(self.stat, None, "Stat should be none!")
        self.assertEqual(self.value, None, "Value should be none!")
Beispiel #2
0
  def deadlock():
    cv = threading.Condition()

    def callback(*args):
        cv.acquire()
        cv.notifyAll()
        cv.release()
        time.sleep(1)

    cv.acquire()
    zookeeper.aget(handle, "/", None, callback)
    cv.wait()
    zookeeper.close(handle)
Beispiel #3
0
    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"))
Beispiel #4
0
    def test_async_getset(self):
        self.cv = threading.Condition()
        def get_callback(handle, rc, value, stat):
            self.cv.acquire()
            self.callback_flag = True
            self.rc = rc
            self.value = (value,stat)
            self.cv.notify()
            self.cv.release()

        def set_callback(handle, rc, stat):
            self.cv.acquire()
            self.callback_flag = True
            self.rc = rc
            self.value = stat
            self.cv.notify()
            self.cv.release()

        self.assertEqual(self.connected, True, "Not connected!")

        self.cv.acquire()
        self.callback_flag = False
        ret = zookeeper.aset(self.handle, "/zk-python-agetsettest", "off", -1, set_callback)
        self.assertEqual(ret, zookeeper.OK, "aset failed")
        while not self.callback_flag:
            self.cv.wait(15)
        self.cv.release()
        self.assertEqual(self.callback_flag, True, "aset timed out")

        self.cv.acquire()
        self.callback_flag = False
        ret = zookeeper.aget(self.handle, "/zk-python-agetsettest", None, get_callback)
        self.assertEqual(ret, zookeeper.OK, "aget failed")
        self.cv.wait(15)
        self.cv.release()
        self.assertEqual(self.callback_flag, True, "aget timed out")
        self.assertEqual(self.value[0], "off", "Data is not 'off' as expected: " + self.value[0])