本文整理汇总了Python中aiokafka.client.AIOKafkaClient.ensure_topic_exists方法的典型用法代码示例。如果您正苦于以下问题:Python AIOKafkaClient.ensure_topic_exists方法的具体用法?Python AIOKafkaClient.ensure_topic_exists怎么用?Python AIOKafkaClient.ensure_topic_exists使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类aiokafka.client.AIOKafkaClient
的用法示例。
在下文中一共展示了AIOKafkaClient.ensure_topic_exists方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_ensure_topic_exists
# 需要导入模块: from aiokafka.client import AIOKafkaClient [as 别名]
# 或者: from aiokafka.client.AIOKafkaClient import ensure_topic_exists [as 别名]
def test_ensure_topic_exists(self, protocol):
mocked_conns = {("broker_1", 4567): mock.MagicMock()}
fut = asyncio.Future(loop=self.loop)
fut.set_result(b"response")
mocked_conns[("broker_1", 4567)].send.return_value = fut
client = AIOKafkaClient(["broker_1:4567"], loop=self.loop)
client._conns = mocked_conns
brokers = [BrokerMetadata(0, "broker_1", 4567), BrokerMetadata(1, "broker_2", 5678)]
topics = [
TopicMetadata("topic_still_creating", NO_LEADER, []),
TopicMetadata("topic_doesnt_exist", UNKNOWN_TOPIC_OR_PARTITION, []),
TopicMetadata(
"topic_noleaders",
NO_ERROR,
[
PartitionMetadata("topic_noleaders", 0, -1, [], [], NO_LEADER),
PartitionMetadata("topic_noleaders", 1, -1, [], [], NO_LEADER),
],
),
]
protocol.decode_metadata_response.return_value = MetadataResponse(brokers, topics)
self.loop.run_until_complete(client.load_metadata_for_topics())
with self.assertRaises(UnknownTopicOrPartitionError):
self.loop.run_until_complete(client.ensure_topic_exists("topic_doesnt_exist", timeout=1))
with self.assertRaises(KafkaTimeoutError):
self.loop.run_until_complete(client.ensure_topic_exists("topic_still_creating", timeout=1))
# This should not raise
self.loop.run_until_complete(client.ensure_topic_exists("topic_noleaders", timeout=1))