本文整理汇总了Python中afkak.kafkacodec.KafkaCodec.encode_offset_commit_request方法的典型用法代码示例。如果您正苦于以下问题:Python KafkaCodec.encode_offset_commit_request方法的具体用法?Python KafkaCodec.encode_offset_commit_request怎么用?Python KafkaCodec.encode_offset_commit_request使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类afkak.kafkacodec.KafkaCodec
的用法示例。
在下文中一共展示了KafkaCodec.encode_offset_commit_request方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_encode_offset_commit_request
# 需要导入模块: from afkak.kafkacodec import KafkaCodec [as 别名]
# 或者: from afkak.kafkacodec.KafkaCodec import encode_offset_commit_request [as 别名]
def test_encode_offset_commit_request(self):
header = b"".join([
struct.pack('>h', 8), # Message type = offset commit
struct.pack('>h', 1), # API version
struct.pack('>i', 42), # Correlation ID
struct.pack('>h9s', 9, b"client_id"), # The client ID
struct.pack('>h8s', 8, b"group_id"), # The group to commit for
struct.pack('>i', 996), # Group generation ID
struct.pack('>h11s', 11, b'consumer_id'), # Consumer ID
struct.pack('>i', 2), # Num topics
])
topic1 = b"".join([
struct.pack(">h6s", 6, b"topic1"), # Topic for the request
struct.pack(">i", 2), # Two partitions
struct.pack(">i", 0), # Partition 0
struct.pack(">q", 123), # Offset 123
struct.pack(">q", 1437585816816), # Timestamp in ms > epoch
struct.pack(">h", -1), # Null metadata
struct.pack(">i", 1), # Partition 1
struct.pack(">q", 234), # Offset 234
struct.pack(">q", 1436981054199), # Timestamp in ms > epoch
struct.pack(">h11s", 11, b'My_Metadata'), # Null metadata
])
topic2 = b"".join([
struct.pack(">h6s", 6, b"topic2"), # Topic for the request
struct.pack(">i", 1), # One partition
struct.pack(">i", 2), # Partition 2
struct.pack(">q", 345), # Offset 345
struct.pack(">q", -1), # Timestamp 'invalid-time'
struct.pack(">h", -1), # Null metadata
])
# A dict is used, so we can't predict the order of the topics...
expected1 = b"".join([header, topic1, topic2])
expected2 = b"".join([header, topic2, topic1])
encoded = KafkaCodec.encode_offset_commit_request(
b"client_id", 42, u"group_id", 996, u'consumer_id', [
OffsetCommitRequest("topic1", 0, 123, 1437585816816, None),
OffsetCommitRequest(u"topic1", 1, 234, 1436981054199,
b'My_Metadata'),
OffsetCommitRequest(u"topic2", 2, 345, -1, None),
])
self.assertIn(encoded, [expected1, expected2])