本文整理汇总了Python中zkfarmer.watcher.ZkFarmJoiner.dispatch方法的典型用法代码示例。如果您正苦于以下问题:Python ZkFarmJoiner.dispatch方法的具体用法?Python ZkFarmJoiner.dispatch怎么用?Python ZkFarmJoiner.dispatch使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类zkfarmer.watcher.ZkFarmJoiner
的用法示例。
在下文中一共展示了ZkFarmJoiner.dispatch方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_remote_modification_should_not_cancel_local_one
# 需要导入模块: from zkfarmer.watcher import ZkFarmJoiner [as 别名]
# 或者: from zkfarmer.watcher.ZkFarmJoiner import dispatch [as 别名]
def test_remote_modification_should_not_cancel_local_one(self):
"""Test if a received remote modification does not cancel a local one.
This may happen if we have a local modification while
processing the echo of a previous modification. For example,
we set a value to 1021, we receive back a remote change about
this value being set to 1021 but we have a local modification
at the same time putting the value to 1022.
"""
self.conf.read.return_value = {"enabled": "1",
"hostname": self.NAME,
"counter": 1000}
z = ZkFarmJoiner(self.client, "/services/db", self.conf)
z.loop(3, timeout=self.TIMEOUT)
self.conf.reset_mock()
self.conf.read.return_value = {"enabled": "1",
"hostname": self.NAME,
"counter": 1001}
z.dispatch(FakeFileEvent())
z.loop(1, timeout=self.TIMEOUT)
# Here comes the local modification that won't be noticed now
self.conf.reset_mock()
self.conf.read.return_value = {"enabled": "1",
"hostname": self.NAME,
"counter": 1002}
z.loop(3, timeout=self.TIMEOUT)
self.assertFalse(self.conf.write.called)
示例2: test_common_node_disconnect_and_local_modifications
# 需要导入模块: from zkfarmer.watcher import ZkFarmJoiner [as 别名]
# 或者: from zkfarmer.watcher.ZkFarmJoiner import dispatch [as 别名]
def test_common_node_disconnect_and_local_modifications(self):
"""Check that remote modifications take over local modifications for a common node"""
self.conf.read.return_value = {"enabled": "1"}
z = ZkFarmJoiner(self.client, "/services/db", self.conf, True)
z.loop(3, timeout=self.TIMEOUT)
self.expire_session()
self.conf.read.return_value = {"enabled": "22"}
z.dispatch(FakeFileEvent())
z.loop(10, timeout=self.TIMEOUT)
self.assertEqual(json.loads(self.client.get("/services/db/common")[0]),
{"enabled": "1"})
示例3: test_disconnect_while_local_modification
# 需要导入模块: from zkfarmer.watcher import ZkFarmJoiner [as 别名]
# 或者: from zkfarmer.watcher.ZkFarmJoiner import dispatch [as 别名]
def test_disconnect_while_local_modification(self):
"""Test we can disconnect and have a local modification while disconnected"""
self.conf.read.return_value = {"enabled": "1",
"hostname": self.NAME}
z = ZkFarmJoiner(self.client, "/services/db", self.conf)
z.loop(3, timeout=self.TIMEOUT)
self.expire_session()
self.conf.read.return_value = {"enabled": "22",
"hostname": self.NAME}
z.dispatch(FakeFileEvent())
z.loop(10, timeout=self.TIMEOUT)
self.assertEqual(json.loads(self.client.get("/services/db/%s" % self.IP)[0]),
{"enabled": "22",
"hostname": self.NAME})
示例4: test_local_modification
# 需要导入模块: from zkfarmer.watcher import ZkFarmJoiner [as 别名]
# 或者: from zkfarmer.watcher.ZkFarmJoiner import dispatch [as 别名]
def test_local_modification(self):
"""Check if ZooKeeper is updated after a local modification"""
self.conf.read.return_value = {"enabled": "1",
"hostname": self.NAME}
z = ZkFarmJoiner(self.client, "/services/db", self.conf)
z.loop(3, timeout=self.TIMEOUT)
self.conf.reset_mock()
self.conf.read.return_value = {"enabled": "0",
"hostname": self.NAME}
z.dispatch(FakeFileEvent())
z.loop(4, timeout=self.TIMEOUT)
self.assertFalse(self.conf.write.called)
self.assertEqual(json.loads(self.client.get("/services/db/%s" % self.IP)[0]),
{"enabled": "0",
"hostname": self.NAME})
示例5: test_disconnect_while_both_remote_and_local_modification
# 需要导入模块: from zkfarmer.watcher import ZkFarmJoiner [as 别名]
# 或者: from zkfarmer.watcher.ZkFarmJoiner import dispatch [as 别名]
def test_disconnect_while_both_remote_and_local_modification(self):
self.conf.read.return_value = {"enabled": "1",
"hostname": self.NAME}
z = ZkFarmJoiner(self.client, "/services/db", self.conf)
z.loop(3, timeout=self.TIMEOUT)
self.expire_session()
z.dispatch(FakeFileEvent())
self.conf.read.return_value = {"enabled": "56",
"hostname": self.NAME}
self.client.ensure_path("/services/db/%s" % self.IP) # Disconnected, the path does not exist
self.client.set("/services/db/%s" % self.IP,
json.dumps({"enabled": "22",
"hostname": self.NAME}))
z.loop(10, timeout=self.TIMEOUT)
self.assertEqual(json.loads(self.client.get("/services/db/%s" % self.IP)[0]),
{"enabled": "56",
"hostname": self.NAME})
示例6: test_detect_file_moved
# 需要导入模块: from zkfarmer.watcher import ZkFarmJoiner [as 别名]
# 或者: from zkfarmer.watcher.ZkFarmJoiner import dispatch [as 别名]
def test_detect_file_moved(self):
"""Test if we can detect a file moved into our location."""
self.conf.read.return_value = {"enabled": "56",
"hostname": self.NAME}
z = ZkFarmJoiner(self.client, "/services/db", self.conf)
z.loop(3, timeout=self.TIMEOUT)
self.conf.reset_mock()
self.conf.read.return_value = {"enabled": "57",
"hostname": self.NAME}
f = FakeFileEvent()
f.src_path="/unrelated/path"
f.dst_path="/fake/root"
z.dispatch(f)
z.loop(4, timeout=self.TIMEOUT)
self.assertFalse(self.conf.write.called)
self.assertEqual(json.loads(self.client.get("/services/db/%s" % self.IP)[0]),
{"enabled": "57",
"hostname": self.NAME})