Skip to content

Commit 602f58b

Browse files
committed
Add Kafka module with KRaft configuration
1 parent ad12ab6 commit 602f58b

File tree

15 files changed

+446
-1
lines changed

15 files changed

+446
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ TestContainers is composed of modules for common databases and services. This ch
88

99
- [ElasticsearchContainer](https://github.com/testcontainers/testcontainers-ruby/tree/main/elasticsearch/CHANGELOG.md)
1010
- [OpensearchContainer](https://github.com/testcontainers/testcontainers-ruby/tree/main/opensearch/CHANGELOG.md)
11+
- [KafkaContainer](https://github.com/testcontainers/testcontainers-ruby/tree/main/kafka/CHANGELOG.md)
1112

1213
- [MariadbContainer](https://github.com/testcontainers/testcontainers-ruby/tree/main/mariadb/CHANGELOG.md)
1314

Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ gem "testcontainers-redis", path: "./redis"
1111
gem "testcontainers-postgres", path: "./postgres"
1212
gem "testcontainers-nginx", path: "./nginx"
1313
gem "testcontainers-elasticsearch", path: "./elasticsearch"
14+
gem "testcontainers-kafka", path: "./kafka"
1415
gem "testcontainers-opensearch", path: "./opensearch"
1516
gem "testcontainers-mariadb", path: "./mariadb"
1617
gem "testcontainers-mongo", path: "./mongo"

Gemfile.lock

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ PATH
2424
testcontainers-elasticsearch (0.2.0)
2525
testcontainers-core (~> 0.1)
2626

27+
PATH
28+
remote: kafka
29+
specs:
30+
testcontainers-kafka (0.1.0)
31+
testcontainers-core (~> 0.1)
32+
2733
PATH
2834
remote: mariadb
2935
specs:
@@ -216,6 +222,7 @@ DEPENDENCIES
216222
testcontainers-compose!
217223
testcontainers-core!
218224
testcontainers-elasticsearch!
225+
testcontainers-kafka!
219226
testcontainers-mariadb!
220227
testcontainers-mongo!
221228
testcontainers-mysql!

Rakefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ require "rake/testtask"
66
require "yard"
77
require "standard/rake"
88

9-
MODULES = %w[core mysql redis postgres nginx elasticsearch opensearch mariadb mongo redpanda]
9+
MODULES = %w[core mysql redis postgres nginx elasticsearch opensearch kafka mariadb mongo redpanda]
1010

1111
%w[test standard].each do |task_name|
1212
desc "Run #{task_name} task for all projects"

kafka/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
## [Unreleased]
2+
3+
### Added
4+
5+
- Initial release of `testcontainers-kafka` providing a single-broker KRaft
6+
Kafka container and convenience helpers.

kafka/Gemfile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# frozen_string_literal: true
2+
3+
source "https://rubygems.org"
4+
5+
# Specify your gem's dependencies in testcontainers-kafka.gemspec
6+
gemspec
7+
8+
# Use the latest version of testcontainers-core from the local path
9+
gem "testcontainers-core", path: "../core"

kafka/Gemfile.lock

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
PATH
2+
remote: ../core
3+
specs:
4+
testcontainers-core (0.2.0)
5+
base64 (~> 0.3)
6+
docker-api (~> 2.4)
7+
java-properties (~> 0.3.0)
8+
9+
PATH
10+
remote: .
11+
specs:
12+
testcontainers-kafka (0.1.0)
13+
testcontainers-core (~> 0.1)
14+
15+
GEM
16+
remote: https://rubygems.org/
17+
specs:
18+
ast (2.4.3)
19+
base64 (0.3.0)
20+
docker-api (2.4.0)
21+
excon (>= 0.64.0)
22+
multi_json
23+
excon (1.3.0)
24+
logger
25+
ffi (1.17.2-arm64-darwin)
26+
java-properties (0.3.0)
27+
json (2.15.1)
28+
language_server-protocol (3.17.0.5)
29+
lint_roller (1.1.0)
30+
logger (1.7.0)
31+
mini_portile2 (2.8.9)
32+
minitest (5.26.0)
33+
minitest-hooks (1.5.2)
34+
minitest (> 5.3)
35+
multi_json (1.17.0)
36+
parallel (1.27.0)
37+
parser (3.3.9.0)
38+
ast (~> 2.4.1)
39+
racc
40+
prism (1.6.0)
41+
racc (1.8.1)
42+
rainbow (3.1.1)
43+
rake (13.3.0)
44+
rdkafka (0.24.1-arm64-darwin)
45+
ffi (~> 1.15)
46+
json (> 2.0)
47+
logger
48+
mini_portile2 (~> 2.6)
49+
rake (> 12)
50+
regexp_parser (2.11.3)
51+
rubocop (1.80.2)
52+
json (~> 2.3)
53+
language_server-protocol (~> 3.17.0.2)
54+
lint_roller (~> 1.1.0)
55+
parallel (~> 1.10)
56+
parser (>= 3.3.0.2)
57+
rainbow (>= 2.2.2, < 4.0)
58+
regexp_parser (>= 2.9.3, < 3.0)
59+
rubocop-ast (>= 1.46.0, < 2.0)
60+
ruby-progressbar (~> 1.7)
61+
unicode-display_width (>= 2.4.0, < 4.0)
62+
rubocop-ast (1.47.1)
63+
parser (>= 3.3.7.2)
64+
prism (~> 1.4)
65+
rubocop-performance (1.25.0)
66+
lint_roller (~> 1.1)
67+
rubocop (>= 1.75.0, < 2.0)
68+
rubocop-ast (>= 1.38.0, < 2.0)
69+
ruby-progressbar (1.13.0)
70+
standard (1.51.1)
71+
language_server-protocol (~> 3.17.0.2)
72+
lint_roller (~> 1.0)
73+
rubocop (~> 1.80.2)
74+
standard-custom (~> 1.0.0)
75+
standard-performance (~> 1.8)
76+
standard-custom (1.0.2)
77+
lint_roller (~> 1.0)
78+
rubocop (~> 1.50)
79+
standard-performance (1.8.0)
80+
lint_roller (~> 1.1)
81+
rubocop-performance (~> 1.25.0)
82+
unicode-display_width (3.2.0)
83+
unicode-emoji (~> 4.1)
84+
unicode-emoji (4.1.0)
85+
86+
PLATFORMS
87+
arm64-darwin-23
88+
89+
DEPENDENCIES
90+
minitest (~> 5.0)
91+
minitest-hooks (~> 1.5)
92+
rake (~> 13.0)
93+
rdkafka (~> 0.12)
94+
standard (~> 1.3)
95+
testcontainers-core!
96+
testcontainers-kafka!
97+
98+
BUNDLED WITH
99+
2.6.9

kafka/LICENSE.txt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2023 Guillermo Iguaran
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
THE SOFTWARE.

kafka/README.md

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# Testcontainers module for Kafka
2+
3+
## Installation
4+
5+
Add the library to the test section in your application's Gemfile:
6+
7+
```ruby
8+
group :test do
9+
gem 'testcontainers-kafka'
10+
end
11+
```
12+
13+
And then execute:
14+
15+
```bash
16+
$ bundle install
17+
```
18+
19+
Or install it yourself as:
20+
21+
```bash
22+
$ gem install testcontainers-kafka
23+
```
24+
25+
## Usage
26+
27+
```ruby
28+
require "testcontainers/kafka"
29+
require "rdkafka"
30+
31+
container = Testcontainers::KafkaContainer.new.start
32+
33+
begin
34+
container.wait_for_tcp_port(9092)
35+
config = {
36+
"bootstrap.servers": container.connection_url,
37+
"group.id": "ruby-example",
38+
"auto.offset.reset": "earliest"
39+
}
40+
41+
producer = Rdkafka::Config.new(config).producer
42+
producer.produce(payload: "hello", topic: "example").wait
43+
44+
consumer = Rdkafka::Config.new(config).consumer
45+
consumer.subscribe("example")
46+
puts consumer.each { |msg| break msg.payload }
47+
ensure
48+
container.stop if container.running?
49+
container.remove if container.exists?
50+
end
51+
```
52+
53+
## Contributing
54+
55+
Bug reports and pull requests are welcome on GitHub at https://github.com/testcontainers/testcontainers-ruby. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/testcontainers/testcontainers-ruby/blob/main/CODE_OF_CONDUCT.md).
56+
57+
## License
58+
59+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
60+
61+
## Code of Conduct
62+
63+
Everyone interacting in the Testcontainers project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/testcontainers/testcontainers-ruby/blob/main/CODE_OF_CONDUCT.md).

kafka/Rakefile

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# frozen_string_literal: true
2+
3+
require "bundler/gem_tasks"
4+
require "rake/testtask"
5+
6+
Rake::TestTask.new(:test) do |t|
7+
t.libs << "test"
8+
t.libs << "lib"
9+
t.test_files = FileList["test/**/*_test.rb"]
10+
end
11+
12+
require "standard/rake"
13+
14+
task default: %i[test standard]

0 commit comments

Comments
 (0)