Skip to content

Don't fail on retry when the cluster is secured #545

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

Merged
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions lib/kafka/broker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,17 @@ def address_match?(host, port)

# @return [String]
def to_s
"#{connection} (node_id=#{@node_id.inspect})"
"#{@host}:#{@port} (node_id=#{@node_id.inspect})"
end

# @return [nil]
def disconnect
connection.close
connection.close if connected?
end

# @return [Boolean]
def connected?
[email protected]?
end

# Fetches cluster metadata from the broker.
Expand Down
20 changes: 20 additions & 0 deletions spec/broker_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ def mock_response(response)
def send_request(request)
@mocked_response
end

def close
end
end

describe "#address_match?" do
Expand Down Expand Up @@ -112,4 +115,21 @@ def send_request(request)
expect(actual_response.topics).to eq []
end
end

describe "#disconnect" do
it "doesn't close a connection if it's not connected yet " do
expect(connection).not_to receive(:close)
broker.disconnect
end

it "closes a connection if the connection is present" do
expect(connection).to receive(:close)

broker.fetch_messages(
max_wait_time: 0, min_bytes: 0, max_bytes: 10 * 1024, topics: {}
)

broker.disconnect
end
end
end