Exemplo n.º 1
0
    def set(self, path, data, version=-1):
        """Set the data for the node of the given path.

        Set the data for the node of the given path if such a node exists and
        the given version matches the version of the node (if the given version
        is -1 (default), node version is ignored).

        This operation, if successful, will trigger all the watches on the node
        of the given path left by `get()` calls.

        The maximum allowable size of the data array is 1 MB (1,048,576 bytes).
        Arrays larger than this will cause a `ZooKeeperExecption` to be thrown.

        :Parameters:
            - `path`: path of the node
            - `data`: data to set
            - `version`: expected version (-1 (default) ignored)

        :Returns:
            Stat object for the node

        :Exceptions:
            - `NoNodeException`: thrown if no node with the given path exists
            - `BadVersionException`: thrown if the version does not match
        """
        stat_dict = _zookeeper.set2(self.zk_handle, path, data, version)
        return Stat(**stat_dict)
Exemplo n.º 2
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)