本文整理匯總了Python中aiokafka.client.AIOKafkaClient._maybe_wait_metadata方法的典型用法代碼示例。如果您正苦於以下問題:Python AIOKafkaClient._maybe_wait_metadata方法的具體用法?Python AIOKafkaClient._maybe_wait_metadata怎麽用?Python AIOKafkaClient._maybe_wait_metadata使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類aiokafka.client.AIOKafkaClient
的用法示例。
在下文中一共展示了AIOKafkaClient._maybe_wait_metadata方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_fetcher_offsets_for_times
# 需要導入模塊: from aiokafka.client import AIOKafkaClient [as 別名]
# 或者: from aiokafka.client.AIOKafkaClient import _maybe_wait_metadata [as 別名]
def test_fetcher_offsets_for_times(self):
client = AIOKafkaClient(
loop=self.loop,
bootstrap_servers=[])
client.ready = mock.MagicMock()
client.ready.side_effect = asyncio.coroutine(lambda a: True)
client._maybe_wait_metadata = mock.MagicMock()
client._maybe_wait_metadata.side_effect = asyncio.coroutine(
lambda: False)
client.cluster.leader_for_partition = mock.MagicMock()
client.cluster.leader_for_partition.return_value = 0
client._api_version = (0, 10, 1)
subscriptions = SubscriptionState(loop=self.loop)
fetcher = Fetcher(client, subscriptions, loop=self.loop)
tp0 = TopicPartition("topic", 0)
tp1 = TopicPartition("topic", 1)
# Timeouting will result in KafkaTimeoutError
with mock.patch.object(fetcher, "_proc_offset_requests") as mocked:
mocked.side_effect = asyncio.TimeoutError
with self.assertRaises(KafkaTimeoutError):
yield from fetcher.get_offsets_by_times({tp0: 0}, 1000)
# Broker returns UnsupportedForMessageFormatError
with mock.patch.object(client, "send") as mocked:
@asyncio.coroutine
def mock_send(node_id, request):
return OffsetResponse[1]([
("topic", [(0, 43, -1, -1)]),
("topic", [(1, 0, 1000, 9999)])
])
mocked.side_effect = mock_send
offsets = yield from fetcher.get_offsets_by_times(
{tp0: 0, tp1: 0}, 1000)
self.assertEqual(offsets, {
tp0: None,
tp1: OffsetAndTimestamp(9999, 1000),
})
# Brokers returns NotLeaderForPartitionError
with mock.patch.object(client, "send") as mocked:
@asyncio.coroutine
def mock_send(node_id, request):
return OffsetResponse[1]([
("topic", [(0, 6, -1, -1)]),
])
mocked.side_effect = mock_send
with self.assertRaises(NotLeaderForPartitionError):
yield from fetcher._proc_offset_request(
0, {"topic": (0, 1000)})
# Broker returns UnknownTopicOrPartitionError
with mock.patch.object(client, "send") as mocked:
@asyncio.coroutine
def mock_send(node_id, request):
return OffsetResponse[1]([
("topic", [(0, 3, -1, -1)]),
])
mocked.side_effect = mock_send
with self.assertLogs("aiokafka.consumer.fetcher", "WARN") as cm:
with self.assertRaises(UnknownTopicOrPartitionError):
yield from fetcher._proc_offset_request(
0, {"topic": (0, 1000)})
if cm is not None:
self.assertIn(
"Received unknown topic or partition error", cm.output[0])