Skip to content

Commit ebfdeb8

Browse files
committed
Updating/adding tests for OffsetManager
1 parent 0e4115b commit ebfdeb8

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

spec/offset_manager_spec.rb

+45
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,13 @@
2121
}
2222
let(:offset_retention_time) { nil }
2323
let(:commit_interval) { 0 }
24+
let(:partition_assignments) { { 'greetings' => [0, 1, 2] } }
2425

2526
before do
2627
allow(group).to receive(:commit_offsets)
28+
allow(group).to receive(:assigned_to?) do |topic, partition|
29+
(partition_assignments[topic] || []).include?(partition)
30+
end
2731
allow(fetcher).to receive(:seek)
2832
end
2933

@@ -43,6 +47,46 @@
4347

4448
expect(group).to have_received(:commit_offsets).with(expected_offsets)
4549
end
50+
51+
context "after calling #mark_as_processed with offsets from non-assigned partitions" do
52+
it "only commits offsets from assigned partitions" do
53+
offset_manager.mark_as_processed("greetings", 0, 42)
54+
offset_manager.mark_as_processed("greetings", 1, 13)
55+
offset_manager.mark_as_processed("greetings", 5, 75)
56+
offset_manager.mark_as_processed("seasons-greetings", 3, 15)
57+
58+
offset_manager.commit_offsets
59+
60+
expected_offsets = {
61+
"greetings" => {
62+
0 => 43,
63+
1 => 14,
64+
}
65+
}
66+
67+
expect(group).to have_received(:commit_offsets).with(expected_offsets)
68+
end
69+
end
70+
71+
context "after committing offsets for the same partition out of order" do
72+
it "committs the newest offset" do
73+
offset_manager.mark_as_processed("greetings", 0, 42)
74+
offset_manager.mark_as_processed("greetings", 1, 579)
75+
offset_manager.mark_as_processed("greetings", 0, 5)
76+
offset_manager.mark_as_processed("greetings", 1, 95)
77+
78+
offset_manager.commit_offsets
79+
80+
expected_offsets = {
81+
"greetings" => {
82+
0 => 43,
83+
1 => 580
84+
}
85+
}
86+
87+
expect(group).to have_received(:commit_offsets).with(expected_offsets)
88+
end
89+
end
4690
end
4791

4892
describe "#commit_offsets_if_necessary" do
@@ -192,6 +236,7 @@ def partition_offset_info(offset)
192236
end
193237

194238
describe "#clear_offsets_excluding" do
239+
let(:partition_assignments) { { 'x' => [0, 1] } }
195240
it "clears offsets except for the partitions in the exclusion list" do
196241
offset_manager.mark_as_processed("x", 0, 42)
197242
offset_manager.mark_as_processed("x", 1, 13)

0 commit comments

Comments
 (0)