當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。