Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix kayrock auto commit behavior on empty results #387

Merged
merged 1 commit into from Nov 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/kafka_ex/new/client_compatibility.ex
Expand Up @@ -104,7 +104,7 @@ defmodule KafkaEx.New.ClientCompatibility do
{adapted_resp, last_offset} = Adapter.fetch_response(resp)

state_out =
if fetch_request.auto_commit do
if last_offset && fetch_request.auto_commit do
consumer_group = state.consumer_group_for_auto_commit

commit_request = %OffsetCommitRequest{
Expand Down
23 changes: 23 additions & 0 deletions test/integration/kayrock/compatibility_consumer_group_test.exs
Expand Up @@ -28,6 +28,29 @@ defmodule KafkaEx.KayrockCompatibilityConsumerGroupTest do
KafkaEx.consumer_group(client)
end

test "fetch with auto_commit doesn't blow up on no messages", %{
client: client
} do
topic = TestHelper.generate_random_string()
consumer_group = "auto_commit_consumer_group"

KafkaExAPI.set_consumer_group_for_auto_commit(client, consumer_group)

{:ok, offset_before} = KafkaExAPI.latest_offset(client, topic, 0)
assert offset_before == 0

[logs] =
KafkaEx.fetch(
topic,
0,
offset: offset_before,
worker_name: client
)

[partition] = logs.partitions
assert partition.message_set == []
end

test "fetch auto_commits offset by default", %{client: client} do
topic = "kafka_ex_consumer_group_test"
consumer_group = "auto_commit_consumer_group"
Expand Down