当前位置: 首页>>代码示例>>Python>>正文


Python ZkFarmJoiner.loop方法代码示例

本文整理汇总了Python中zkfarmer.watcher.ZkFarmJoiner.loop方法的典型用法代码示例。如果您正苦于以下问题:Python ZkFarmJoiner.loop方法的具体用法?Python ZkFarmJoiner.loop怎么用?Python ZkFarmJoiner.loop使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在zkfarmer.watcher.ZkFarmJoiner的用法示例。


在下文中一共展示了ZkFarmJoiner.loop方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_disconnect_while_remote_modification

# 需要导入模块: from zkfarmer.watcher import ZkFarmJoiner [as 别名]
# 或者: from zkfarmer.watcher.ZkFarmJoiner import loop [as 别名]
 def test_disconnect_while_remote_modification(self):
     """Test we can disconnect and have a remote 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.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)
     try:
         self.assertEqual(json.loads(self.client.get("/services/db/%s" % self.IP)[0]),
                          {"enabled": "22",
                           "hostname": self.NAME})
     except AssertionError:
         # This test could be fixed but we won't because we
         # consider that the local filesystem is authoritative. If
         # this test succeeds, we can make it fail by stopping
         # zkfarmer before reconnection to ZooKeeper. In this case,
         # on next start, ZooKeeper modifications would be
         # lost. Moreover, the znode is ephemeral, so no "remote"
         # modifications can happend while the node is down.
         raise SkipTest("Fuzzy test")
开发者ID:vincentbernat,项目名称:zkfarmer,代码行数:27,代码来源:test_joiner.py

示例2: test_initialize_observer

# 需要导入模块: from zkfarmer.watcher import ZkFarmJoiner [as 别名]
# 或者: from zkfarmer.watcher.ZkFarmJoiner import loop [as 别名]
 def test_initialize_observer(self):
     """Test if observer is correctly initialized"""
     self.conf.read.return_value = {}
     z = ZkFarmJoiner(self.client, "/services/db", self.conf)
     z.loop(3, timeout=self.TIMEOUT)
     self.mock_observer.schedule.assert_called_once_with(z, path="/fake", recursive=True)
     self.mock_observer.start.assert_called_once_with()
开发者ID:iskandar,项目名称:zkfarmer,代码行数:9,代码来源:test_joiner.py

示例3: test_set_hostname

# 需要导入模块: from zkfarmer.watcher import ZkFarmJoiner [as 别名]
# 或者: from zkfarmer.watcher.ZkFarmJoiner import loop [as 别名]
 def test_set_hostname(self):
     """Check if hostname is correctly set into configuration file"""
     self.conf.read.return_value = {"enabled": "1"}
     z = ZkFarmJoiner(self.client, "/services/db", self.conf)
     z.loop(1, timeout=self.TIMEOUT)
     self.conf.write.assert_called_with({"enabled": "1",
                                         "hostname": self.NAME})
开发者ID:iskandar,项目名称:zkfarmer,代码行数:9,代码来源:test_joiner.py

示例4: test_initial_set_ephemereal

# 需要导入模块: from zkfarmer.watcher import ZkFarmJoiner [as 别名]
# 或者: from zkfarmer.watcher.ZkFarmJoiner import loop [as 别名]
 def test_initial_set_ephemereal(self):
     """Check if created znode is ephemereal"""
     self.conf.read.return_value = {"enabled": "1",
                                    "hostname": self.NAME}
     z = ZkFarmJoiner(self.client, "/services/db", self.conf)
     z.loop(2, timeout=self.TIMEOUT)
     self.assertEqual(self.client.get("/services/db/%s" % self.IP)[1].ephemeralOwner,
                      self.client.client_id[0])
开发者ID:iskandar,项目名称:zkfarmer,代码行数:10,代码来源:test_joiner.py

示例5: test_initial_set

# 需要导入模块: from zkfarmer.watcher import ZkFarmJoiner [as 别名]
# 或者: from zkfarmer.watcher.ZkFarmJoiner import loop [as 别名]
 def test_initial_set(self):
     """Check if znode is correctly created into ZooKeeper"""
     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.assertEqual(json.loads(self.client.get("/services/db/%s" % self.IP)[0]),
                      {"enabled": "1",
                       "hostname": self.NAME})
开发者ID:iskandar,项目名称:zkfarmer,代码行数:11,代码来源:test_joiner.py

示例6: test_common_node_disconnect_and_local_modifications

# 需要导入模块: from zkfarmer.watcher import ZkFarmJoiner [as 别名]
# 或者: from zkfarmer.watcher.ZkFarmJoiner import loop [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"})
开发者ID:iskandar,项目名称:zkfarmer,代码行数:13,代码来源:test_joiner.py

示例7: test_common_node_join_when_local_modifications

# 需要导入模块: from zkfarmer.watcher import ZkFarmJoiner [as 别名]
# 或者: from zkfarmer.watcher.ZkFarmJoiner import loop [as 别名]
 def test_common_node_join_when_local_modifications(self):
     """Check that we get remote modification when using a common node"""
     self.conf.read.return_value = { "enabled": "1" }
     self.client.ensure_path("/services/db/common")
     self.client.set("/services/db/common", json.dumps({ "enabled": "42" }))
     z = ZkFarmJoiner(self.client, "/services/db", self.conf, True)
     z.loop(3, timeout=self.TIMEOUT)
     self.conf.write.assert_called_with({ "enabled": "42" })
     n = self.client.get("/services/db/common")
     self.assertEqual(n[0],
                      json.dumps({"enabled": "42"}))
开发者ID:iskandar,项目名称:zkfarmer,代码行数:13,代码来源:test_joiner.py

示例8: test_disconnect

# 需要导入模块: from zkfarmer.watcher import ZkFarmJoiner [as 别名]
# 或者: from zkfarmer.watcher.ZkFarmJoiner import loop [as 别名]
 def test_disconnect(self):
     """Test we handle a disconnect correctly"""
     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.loop(8, timeout=self.TIMEOUT)
     self.assertEqual(json.loads(self.client.get("/services/db/%s" % self.IP)[0]),
                      {"enabled": "1",
                       "hostname": self.NAME})
     return z
开发者ID:iskandar,项目名称:zkfarmer,代码行数:14,代码来源:test_joiner.py

示例9: test_zookeeper_modification

# 需要导入模块: from zkfarmer.watcher import ZkFarmJoiner [as 别名]
# 或者: from zkfarmer.watcher.ZkFarmJoiner import loop [as 别名]
 def test_zookeeper_modification(self):
     """Check if local configuration is updated after remote 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.client.set("/services/db/%s" % self.IP,
                     json.dumps({"enabled": "0",
                                 "hostname": self.NAME}))
     z.loop(2, timeout=self.TIMEOUT)
     self.conf.write.assert_called_once_with({"enabled": "0",
                                              "hostname": self.NAME})
开发者ID:vincentbernat,项目名称:zkfarmer,代码行数:15,代码来源:test_joiner.py

示例10: test_updated_handler_called

# 需要导入模块: from zkfarmer.watcher import ZkFarmJoiner [as 别名]
# 或者: from zkfarmer.watcher.ZkFarmJoiner import loop [as 别名]
 def test_updated_handler_called(self):
     """Test the appropriate handler is called on modification"""
     self.conf.read.return_value = {"enabled": "1",
                                    "hostname": self.NAME}
     handler = Mock()
     z = ZkFarmJoiner(self.client, "/services/db", self.conf,
                      updated_handler=handler)
     z.loop(3, timeout=self.TIMEOUT)
     handler.reset_mock()
     self.client.set("/services/db/%s" % self.IP,
                     json.dumps({"enabled": "0",
                                 "hostname": self.NAME}))
     z.loop(2, timeout=self.TIMEOUT)
     handler.assert_called_once_with()
开发者ID:ienliven,项目名称:zkfarmer,代码行数:16,代码来源:test_joiner.py

示例11: test_no_write_when_no_modification

# 需要导入模块: from zkfarmer.watcher import ZkFarmJoiner [as 别名]
# 或者: from zkfarmer.watcher.ZkFarmJoiner import loop [as 别名]
 def test_no_write_when_no_modification(self):
     """Check we don't write modification if not needed"""
     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}
     self.client.set("/services/db/%s" % self.IP,
                     json.dumps({"enabled": "0",
                                 "hostname": self.NAME}))
     z.loop(2, timeout=self.TIMEOUT)
     self.assertFalse(self.conf.write.called)
开发者ID:vincentbernat,项目名称:zkfarmer,代码行数:16,代码来源:test_joiner.py

示例12: test_disconnect_while_local_modification

# 需要导入模块: from zkfarmer.watcher import ZkFarmJoiner [as 别名]
# 或者: from zkfarmer.watcher.ZkFarmJoiner import loop [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})
开发者ID:iskandar,项目名称:zkfarmer,代码行数:16,代码来源:test_joiner.py

示例13: test_common_node

# 需要导入模块: from zkfarmer.watcher import ZkFarmJoiner [as 别名]
# 或者: from zkfarmer.watcher.ZkFarmJoiner import loop [as 别名]
 def test_common_node(self):
     """Check we can request a common node"""
     self.conf.read.return_value = {"enabled": "1",
                                    "maintainance": "2"}
     z = ZkFarmJoiner(self.client, "/services/db", self.conf, True)
     z.loop(3, timeout=self.TIMEOUT)
     # Check we don't get the hostname
     self.conf.write.assert_called_with({"enabled": "1",
                                         "maintainance": "2"})
     # Check the node exists
     n = self.client.get("/services/db/common")
     self.assertEqual(n[0],
                      json.dumps({"enabled": "1",
                                  "maintainance": "2"}))
     self.assertEqual(n[1].ephemeralOwner, 0)
开发者ID:iskandar,项目名称:zkfarmer,代码行数:17,代码来源:test_joiner.py

示例14: test_local_modification

# 需要导入模块: from zkfarmer.watcher import ZkFarmJoiner [as 别名]
# 或者: from zkfarmer.watcher.ZkFarmJoiner import loop [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})
开发者ID:iskandar,项目名称:zkfarmer,代码行数:17,代码来源:test_joiner.py

示例15: test_no_update_handler_when_no_modification

# 需要导入模块: from zkfarmer.watcher import ZkFarmJoiner [as 别名]
# 或者: from zkfarmer.watcher.ZkFarmJoiner import loop [as 别名]
 def test_no_update_handler_when_no_modification(self):
     """Check we don't call handler if not needed"""
     self.conf.read.return_value = {"enabled": "1",
                                    "hostname": self.NAME}
     handler = Mock()
     z = ZkFarmJoiner(self.client, "/services/db", self.conf,
                      updated_handler=handler)
     z.loop(3, timeout=self.TIMEOUT)
     handler.reset_mock()
     self.conf.read.return_value = {"enabled": "0",
                                    "hostname": self.NAME}
     self.client.set("/services/db/%s" % self.IP,
                     json.dumps({"enabled": "0",
                                 "hostname": self.NAME}))
     z.loop(2, timeout=self.TIMEOUT)
     self.assertFalse(handler.called)
开发者ID:ienliven,项目名称:zkfarmer,代码行数:18,代码来源:test_joiner.py


注:本文中的zkfarmer.watcher.ZkFarmJoiner.loop方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。