當前位置: 首頁>>代碼示例>>Python>>正文


Python AIOKafkaClient._send_broker_unaware_request方法代碼示例

本文整理匯總了Python中aiokafka.client.AIOKafkaClient._send_broker_unaware_request方法的典型用法代碼示例。如果您正苦於以下問題:Python AIOKafkaClient._send_broker_unaware_request方法的具體用法?Python AIOKafkaClient._send_broker_unaware_request怎麽用?Python AIOKafkaClient._send_broker_unaware_request使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在aiokafka.client.AIOKafkaClient的用法示例。


在下文中一共展示了AIOKafkaClient._send_broker_unaware_request方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_send_broker_unaware_request

# 需要導入模塊: from aiokafka.client import AIOKafkaClient [as 別名]
# 或者: from aiokafka.client.AIOKafkaClient import _send_broker_unaware_request [as 別名]
    def test_send_broker_unaware_request(self):
        "Tests that call works when at least one of the host is available"

        mocked_conns = {
            ("kafka01", 9092): mock.MagicMock(),
            ("kafka02", 9092): mock.MagicMock(),
            ("kafka03", 9092): mock.MagicMock(),
        }
        # inject KafkaConnection side effects
        fut = asyncio.Future(loop=self.loop)
        fut.set_exception(RuntimeError("kafka01 went away (unittest)"))
        mocked_conns[("kafka01", 9092)].send.return_value = fut

        fut2 = asyncio.Future(loop=self.loop)
        fut2.set_result(b"valid response")
        mocked_conns[("kafka02", 9092)].send.return_value = fut2

        fut3 = asyncio.Future(loop=self.loop)
        fut3.set_exception(RuntimeError("kafka03 went away (unittest)"))
        mocked_conns[("kafka03", 9092)].send.return_value = fut3

        client = AIOKafkaClient("kafka01:9092,kafka02:9092", loop=self.loop)
        client._conns = mocked_conns

        resp = self.loop.run_until_complete(
            client._send_broker_unaware_request(
                payloads=[b"fake request"], encoder_fn=mock.MagicMock(), decoder_fn=lambda x: x
            )
        )

        self.assertEqual(b"valid response", resp)
開發者ID:thedrow,項目名稱:aiokafka,代碼行數:33,代碼來源:test_client.py


注:本文中的aiokafka.client.AIOKafkaClient._send_broker_unaware_request方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。