Esempio n. 1
0
    def test_multiple_watchers(self):
        """
        Test whether multiple watchers are correctly called
        """
        cv1, cv2 = threading.Condition(), threading.Condition()
        def watcher1(*args, **kwargs):
            cv1.acquire()
            self.watcher1 = True
            cv1.notify()
            cv1.release()

        def watcher2(*args, **kwargs):
            cv2.acquire()
            self.watcher2 = True
            cv2.notify()
            cv2.release()

        nodename = "/zk-python-multiple-watcher-test"
        self.ensureCreated(nodename, "test")
        cv1.acquire()
        cv2.acquire()
        zookeeper.get(self.handle, nodename, watcher1)
        zookeeper.get(self.handle, nodename, watcher2)
        zookeeper.set(self.handle, nodename, "test")
        cv1.wait(15)
        cv2.wait(15)
        self.assertTrue(self.watcher1 and self.watcher2, "One or more watchers failed to fire")
Esempio n. 2
0
    def test_lose_scope(self):
        """
        The idea is to test that the reference counting doesn't
        fail when we retain no references outside of the module
        """
        self.ensureDeleted("/zk-python-lose-scope-test")
        self.ensureCreated("/zk-python-lose-scope-test")
        def set_watcher():
            def fn(): self.callback_flag = True
            self.callback_flag = False
            zookeeper.exists(self.handle, "/zk-python-lose-scope-test",
                             self.create_callback( lambda handle, type, state, path: fn() )
                             )

        set_watcher()
        gc.collect()
        self.cv.acquire()
        zookeeper.set(self.handle, "/zk-python-lose-scope-test", "test")
        self.cv.wait(15)
        self.assertEqual(self.callback_flag, True)
Esempio n. 3
0
 def test_sync_getset(self):
     self.assertEqual(self.connected, True, "Not connected!")
     (data,stat) = zookeeper.get(self.handle, "/zk-python-getsettest", None)
     self.assertEqual(data, "on", "Data is not 'on' as expected: " + data)
     ret = zookeeper.set(self.handle, "/zk-python-getsettest",
                         "off", stat["version"])
     (data,stat) = zookeeper.get(self.handle, "/zk-python-getsettest", None)
     self.assertEqual(data, "off", "Data is not 'off' as expected: " + data)
     self.assertRaises(zookeeper.BadVersionException,
                       zookeeper.set,
                       self.handle,
                       "/zk-python-getsettest",
                       "test",
                       stat["version"]+1)
     stat2 = zookeeper.set2(self.handle, "/zk-python-getsettest",
                            "set2", stat["version"])
     self.assertNotEqual(stat2, None, "set2 call failed, return should not be None")
     self.assertEqual(stat2["numChildren"], 0,
                      "set2 call failed, numChildren not 0 in set2 call")
     (data,stat) = zookeeper.get(self.handle, "/zk-python-getsettest", None)
     self.assertEqual(data, "set2", "Data is not 'set2' as expected: " + data)