def send_offset_commit_request( self, group, payloads=None, fail_on_error=True, callback=None ): if payloads is None: payloads = [] resps = [] for req in payloads: if not self.commit_error: self.group_offsets[req.topic.decode()][req.partition] = req.offset resps.append( OffsetCommitResponse( req.topic.decode(), req.partition, 0 ) ) else: resps.append( OffsetCommitResponse( req.topic.decode(), req.partition, RequestTimedOutError.errno ) ) return [resp if not callback else callback(resp) for resp in resps]
def test_decode_offset_commit_response(self): encoded = "".join([ struct.pack(">i", 42), # Correlation ID struct.pack(">i", 1), # One topic struct.pack(">h6s", 6, "topic1"), # First topic struct.pack(">i", 2), # Two partitions struct.pack(">i", 2), # Partition 2 struct.pack(">h", 0), # No error struct.pack(">i", 4), # Partition 4 struct.pack(">h", 0), # No error ]) results = KafkaProtocol.decode_offset_commit_response(encoded) self.assertEqual( set(results), set([ OffsetCommitResponse(topic='topic1', partition=2, error=0), OffsetCommitResponse(topic='topic1', partition=4, error=0), ]))
def decode_offset_commit_response(cls, data): """ Decode bytes to an OffsetCommitResponse Arguments: data: bytes to decode """ ((correlation_id,), cur) = relative_unpack('>i', data, 0) ((num_topics,), cur) = relative_unpack('>i', data, cur) for i in xrange(num_topics): (topic, cur) = read_short_string(data, cur) ((num_partitions,), cur) = relative_unpack('>i', data, cur) for i in xrange(num_partitions): ((partition, error), cur) = relative_unpack('>ih', data, cur) yield OffsetCommitResponse(topic, partition, error)