Skip to content

Commit 5bab3f2

Browse files
committed
test_producer_batch_maybe_expire
1 parent 0d981ee commit 5bab3f2

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

test/test_record_accumulator.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import pytest
55
import io
66

7+
from kafka.errors import KafkaTimeoutError
78
from kafka.producer.future import FutureRecordMetadata, RecordMetadata
89
from kafka.producer.record_accumulator import RecordAccumulator, ProducerBatch
910
from kafka.record.memory_records import MemoryRecordsBuilder
@@ -58,4 +59,17 @@ def test_producer_batch_retry():
5859
assert batch.in_retry()
5960

6061
def test_producer_batch_maybe_expire():
61-
pass
62+
tp = TopicPartition('foo', 0)
63+
records = MemoryRecordsBuilder(
64+
magic=2, compression_type=0, batch_size=100000)
65+
batch = ProducerBatch(tp, records, io.BytesIO(), now=1)
66+
future = batch.try_append(0, b'key', b'value', [], now=2)
67+
request_timeout_ms = 5000
68+
retry_backoff_ms = 200
69+
linger_ms = 1000
70+
is_full = True
71+
batch.maybe_expire(request_timeout_ms, retry_backoff_ms, linger_ms, is_full, now=20)
72+
assert batch.is_done
73+
assert future.is_done
74+
assert future.failed()
75+
assert isinstance(future.exception, KafkaTimeoutError)

0 commit comments

Comments
 (0)