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


Python watcher.ZkFarmJoiner类代码示例

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


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

示例1: test_initialize_observer

 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,代码行数:7,代码来源:test_joiner.py

示例2: test_disconnect_while_remote_modification

 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,代码行数:25,代码来源:test_joiner.py

示例3: test_set_hostname

 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,代码行数:7,代码来源:test_joiner.py

示例4: test_initial_set_ephemereal

 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,代码行数:8,代码来源:test_joiner.py

示例5: test_initial_set

 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,代码行数:9,代码来源:test_joiner.py

示例6: test_remote_modification_should_not_cancel_local_one

    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)
开发者ID:vincentbernat,项目名称:zkfarmer,代码行数:27,代码来源:test_joiner.py

示例7: test_common_node_join_when_local_modifications

 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,代码行数:11,代码来源:test_joiner.py

示例8: test_disconnect

 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,代码行数:12,代码来源:test_joiner.py

示例9: test_zookeeper_modification

 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,代码行数:13,代码来源:test_joiner.py

示例10: test_no_write_when_no_modification

 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,代码行数:14,代码来源:test_joiner.py

示例11: test_updated_handler_called

 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,代码行数:14,代码来源:test_joiner.py

示例12: test_common_node

 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,代码行数:15,代码来源:test_joiner.py

示例13: test_no_update_handler_when_no_modification

 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,代码行数:16,代码来源:test_joiner.py

示例14: test_common_node_disconnect_and_local_modifications

 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,代码行数:11,代码来源:test_joiner.py

示例15: test_disconnect_while_local_modification

 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,代码行数:14,代码来源:test_joiner.py


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