-
Notifications
You must be signed in to change notification settings - Fork 162
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #369 from kafkaex/api_versions_streaming
Allow specifying kafka API versions for streaming
- Loading branch information
Showing
3 changed files
with
102 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
defmodule KafkaEx.KayrockCompatibilityStreamingTest do | ||
@moduledoc """ | ||
Tests for streaming using Kayrock for client implementation | ||
""" | ||
|
||
use ExUnit.Case | ||
|
||
alias KafkaEx.New.Client | ||
alias KafkaEx.Protocol.OffsetFetch.Request, as: OffsetFetchRequest | ||
alias KafkaEx.Protocol.OffsetFetch.Response, as: OffsetFetchResponse | ||
|
||
@moduletag :new_client | ||
|
||
setup do | ||
{:ok, pid} = | ||
KafkaEx.start_link_worker(:no_name, server_impl: KafkaEx.New.Client) | ||
|
||
{:ok, %{client: pid}} | ||
end | ||
|
||
test "stream with kafka offset storage and timestamps", %{client: client} do | ||
topic = "kayrock_stream_test" | ||
partition = 0 | ||
consumer_group = "streamers" | ||
|
||
{:ok, topic} = TestHelper.ensure_append_timestamp_topic(client, topic) | ||
|
||
KafkaEx.produce(topic, partition, "foo 1", api_version: 3) | ||
KafkaEx.produce(topic, partition, "foo 2", api_version: 3) | ||
KafkaEx.produce(topic, partition, "foo 3", api_version: 3) | ||
|
||
stream = | ||
KafkaEx.stream(topic, partition, | ||
worker_name: client, | ||
auto_commit: true, | ||
no_wait_at_logend: true, | ||
consumer_group: consumer_group, | ||
api_versions: %{ | ||
fetch: 3, | ||
offset_fetch: 3, | ||
offset_commit: 3 | ||
} | ||
) | ||
|
||
TestHelper.wait_for(fn -> | ||
length(Enum.take(stream, 3)) == 3 | ||
end) | ||
|
||
[msg1, msg2, msg3] = Enum.take(stream, 3) | ||
|
||
assert msg1.value == "foo 1" | ||
assert msg2.value == "foo 2" | ||
assert msg3.value == "foo 3" | ||
assert is_integer(msg1.timestamp) | ||
assert msg1.timestamp > 0 | ||
assert is_integer(msg2.timestamp) | ||
assert msg2.timestamp > 0 | ||
assert is_integer(msg3.timestamp) | ||
assert msg3.timestamp > 0 | ||
|
||
[ | ||
%OffsetFetchResponse{ | ||
partitions: [ | ||
%{error_code: :no_error, offset: offset} | ||
] | ||
} | ||
] = | ||
KafkaEx.offset_fetch(client, %OffsetFetchRequest{ | ||
topic: topic, | ||
partition: partition, | ||
consumer_group: consumer_group, | ||
api_version: 3 | ||
}) | ||
|
||
assert is_integer(offset) | ||
assert offset > 0 | ||
end | ||
end |