本文整理汇总了Python中aiokafka.client.AIOKafkaClient._api_version方法的典型用法代码示例。如果您正苦于以下问题:Python AIOKafkaClient._api_version方法的具体用法?Python AIOKafkaClient._api_version怎么用?Python AIOKafkaClient._api_version使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类aiokafka.client.AIOKafkaClient
的用法示例。
在下文中一共展示了AIOKafkaClient._api_version方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_fetcher_offsets_for_times
# 需要导入模块: from aiokafka.client import AIOKafkaClient [as 别名]
# 或者: from aiokafka.client.AIOKafkaClient import _api_version [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])