-
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.
[Kayrock] Add response parser & send describe groups request
With single group now only
- Loading branch information
Showing
6 changed files
with
185 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
defmodule KafkaEx.New.Client.ResponseParser do | ||
@moduledoc """ | ||
This module is used to parse response from KafkaEx.New.Client. | ||
It's main decision point which protocol to use for parsing response | ||
""" | ||
alias KafkaEx.New.Structs.ConsumerGroup | ||
|
||
@protocol Application.get_env( | ||
:kafka_ex, | ||
:protocol, | ||
KafkaEx.New.Protocols.KayrockProtocol | ||
) | ||
|
||
@doc """ | ||
Parses response for Describe Groups API | ||
""" | ||
@spec describe_groups_response(term) :: | ||
{:ok, [ConsumerGroup.t()]} | {:error, term} | ||
def describe_groups_response(response) do | ||
@protocol.parse_response(:describe_groups, response) | ||
end | ||
end |
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,17 @@ | ||
defmodule KafkaEx.New.Client.Protocol do | ||
@moduledoc """ | ||
This module is responsible for defining the behaviour of a protocol. | ||
""" | ||
# ------------------------------------------------------------------------------ | ||
@type api_version :: non_neg_integer | ||
@type params :: Keyword.t() | ||
|
||
# ------------------------------------------------------------------------------ | ||
@callback build_request(:describe_groups, integer, params) :: term | ||
|
||
# ------------------------------------------------------------------------------ | ||
@type consumer_group :: KafkaEx.New.Structs.ConsumerGroup | ||
|
||
@callback parse_response(:describe_groups, term) :: | ||
{:ok, [consumer_group]} | {:error, term} | ||
end |
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 |
---|---|---|
@@ -1,17 +1,21 @@ | ||
defmodule KafkaEx.New.Client.RequestBuilderTest do | ||
use ExUnit.Case, async: true | ||
|
||
alias KafkaEx.New.Client.RequestBuilder | ||
|
||
describe "describe_groups_request/2" do | ||
test "returns request for DescribeGroups API" do | ||
state = %KafkaEx.New.Client.State{api_versions: %{describe_groups: 1}} | ||
group_names = ["group1", "group2"] | ||
|
||
assert RequestBuilder.describe_groups_request(group_names, state) == | ||
{:ok, | ||
%KafkaEx.New.Protocols.DescribeGroups.Request{ | ||
group_names: group_names | ||
}} | ||
expected_request = %Kayrock.DescribeGroups.V1.Request{ | ||
group_ids: group_ids | ||
} | ||
|
||
{:ok, request} = | ||
RequestBuilder.describe_groups_request(group_names, state) | ||
|
||
assert expected_request == request | ||
end | ||
end | ||
end |