Skip to content

Commit 11356a1

Browse files
committed
finish test for sniff
1 parent 54579a4 commit 11356a1

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

src/saluki/sniff.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@ def sniff(broker: str) -> None:
2222
for p in partitions:
2323
tp = TopicPartition(k, p)
2424
low, high = c.get_watermark_offsets(tp)
25-
logger.info(f"\t\tlow:{low}, high:{high}, num_messages:{high - low}")
25+
logger.info(f"\t\t{tp.partition} - low:{low}, high:{high}, num_messages:{high - low}")

tests/test_sniff.py

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,34 @@ def test_sniff_with_two_partitions_in_a_topic():
88
with patch("saluki.sniff.AdminClient") as a, patch("saluki.sniff.Consumer") as c, patch("saluki.sniff.logger") as logger:
99
fake_cluster_md = ClusterMetadata()
1010
broker1 = BrokerMetadata()
11-
broker2 = BrokerMetadata()
12-
fake_cluster_md.brokers = {0: broker1, 1: broker2}
11+
broker1.id = "id1"
12+
broker1.host = "mybroker"
13+
broker1.port = 9093
14+
fake_cluster_md.brokers = {0: broker1}
1315

1416
topic1 = TopicMetadata()
17+
topic1.partitions = {0:{}}
1518
topic2 = TopicMetadata()
19+
topic2.partitions = {0:{}, 1:{}}
1620

1721
fake_cluster_md.topics = {
1822
"topic1": topic1,
1923
"topic2": topic2
2024
}
21-
a.list_topics.return_value = fake_cluster_md
25+
a().list_topics.return_value = fake_cluster_md
26+
c().get_watermark_offsets.return_value = 1,2
2227
sniff("whatever")
2328

24-
# TODO
29+
brokers_call = logger.info.call_args_list[2]
30+
31+
assert "mybroker:9093/id1" in brokers_call.args[0]
32+
33+
topic1_call = logger.info.call_args_list[5]
34+
assert "0 - low:1, high:2, num_messages:1" in topic1_call.args[0]
35+
36+
topic2_call1 = logger.info.call_args_list[7]
37+
assert "0 - low:1, high:2, num_messages:1" in topic2_call1.args[0]
38+
39+
topic2_call2 = logger.info.call_args_list[8]
40+
assert "1 - low:1, high:2, num_messages:1" in topic2_call2.args[0]
41+

0 commit comments

Comments
 (0)