karafka-testing 1.4.2 → 2.0.0.alpha2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/.github/workflows/ci.yml +5 -3
- data/.ruby-version +1 -1
- data/2.0-Upgrade.md +60 -0
- data/CHANGELOG.md +9 -19
- data/Gemfile.lock +43 -56
- data/README.md +16 -21
- data/certs/mensfeld.pem +21 -21
- data/karafka-testing.gemspec +8 -3
- data/lib/karafka/testing/dummy_client.rb +17 -0
- data/lib/karafka/testing/rspec/helpers.rb +37 -22
- data/lib/karafka/testing/rspec/proxy.rb +25 -0
- data/lib/karafka/testing/version.rb +1 -1
- data.tar.gz.sig +0 -0
- metadata +36 -32
- metadata.gz.sig +0 -0
- data/.github/FUNDING.yml +0 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 15ad20f0c6aec1676017e4b0ae1a22275418d4c7bf455d07d27cf0696e93b483
|
4
|
+
data.tar.gz: 7316128b067662b376f001903eb993983752b9bd2fd2221ef900ba87891f047a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1dd7c25d36e028d43566249a5cc46670bdaaada4c7610da2dbc7758d3f6b09f75f06520670ed1772cc1d1197a41b95096d5d857c53d78c39ab101ff534f4e946
|
7
|
+
data.tar.gz: 3f318b4fa8690f7a44de1ac3774675044c1dfce57ace3f649a6656b03a8d97f296a25976438a208d7ff56fcc06a2d075aa142fcf94e37566e72920a61ecdede0
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/.github/workflows/ci.yml
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
name: ci
|
2
2
|
|
3
|
+
concurrency: ci-${{ github.ref }}
|
4
|
+
|
3
5
|
on:
|
4
6
|
pull_request:
|
5
7
|
push:
|
@@ -14,11 +16,11 @@ jobs:
|
|
14
16
|
fail-fast: false
|
15
17
|
matrix:
|
16
18
|
ruby:
|
19
|
+
- '3.1'
|
17
20
|
- '3.0'
|
18
21
|
- '2.7'
|
19
|
-
- '2.6'
|
20
22
|
include:
|
21
|
-
- ruby: '3.
|
23
|
+
- ruby: '3.1'
|
22
24
|
coverage: 'true'
|
23
25
|
steps:
|
24
26
|
- uses: actions/checkout@v2
|
@@ -46,7 +48,7 @@ jobs:
|
|
46
48
|
- name: Set up Ruby
|
47
49
|
uses: ruby/setup-ruby@v1
|
48
50
|
with:
|
49
|
-
ruby-version: 3.
|
51
|
+
ruby-version: 3.1
|
50
52
|
- name: Install latest bundler
|
51
53
|
run: gem install bundler --no-document
|
52
54
|
- name: Install Diffend plugin
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
3.0
|
1
|
+
3.1.0
|
data/2.0-Upgrade.md
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
# Welcome to Karafka-Testing 2.0!
|
2
|
+
|
3
|
+
Karafka-Testing 2.0 some breaking changes in the way consumer builder and message publishing is done.
|
4
|
+
|
5
|
+
## Upgrade
|
6
|
+
|
7
|
+
Please upgrade your application to `Karafka 2.0` first.
|
8
|
+
|
9
|
+
- Replace `#karafka_consumer_for` in your specs with `#karafka.consumer_for`
|
10
|
+
- Replace `#publish_for_karafka` in your specs with `#karafka.publish`
|
11
|
+
|
12
|
+
And that's all!
|
13
|
+
|
14
|
+
Below you can find same example written for Karafka `2.0` and `1.4`.
|
15
|
+
|
16
|
+
### Karafka 2.0
|
17
|
+
|
18
|
+
```ruby
|
19
|
+
RSpec.describe CountersConsumer do
|
20
|
+
subject(:consumer) { karafka.consumer_for(:counters) }
|
21
|
+
|
22
|
+
let(:nr1_value) { rand }
|
23
|
+
let(:nr2_value) { rand }
|
24
|
+
let(:sum) { nr1_value + nr2_value }
|
25
|
+
|
26
|
+
before do
|
27
|
+
karafka.publish({ 'number' => nr1_value }.to_json)
|
28
|
+
karafka.publish({ 'number' => nr2_value }.to_json, partition: 2)
|
29
|
+
allow(Karafka.logger).to receive(:info)
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'expects to log a proper message' do
|
33
|
+
expect(Karafka.logger).to receive(:info).with("Sum of 2 elements equals to: #{sum}")
|
34
|
+
consumer.consume
|
35
|
+
end
|
36
|
+
end
|
37
|
+
```
|
38
|
+
|
39
|
+
### Karafka 1.4
|
40
|
+
|
41
|
+
```ruby
|
42
|
+
RSpec.describe InlineBatchConsumer do
|
43
|
+
subject(:consumer) { karafka_consumer_for(:counters) }
|
44
|
+
|
45
|
+
let(:nr1_value) { rand }
|
46
|
+
let(:nr2_value) { rand }
|
47
|
+
let(:sum) { nr1_value + nr2_value }
|
48
|
+
|
49
|
+
before do
|
50
|
+
publish_for_karafka({ 'number' => nr1_value }.to_json)
|
51
|
+
publish_for_karafka({ 'number' => nr2_value }.to_json, partition: 2)
|
52
|
+
allow(Karafka.logger).to receive(:info)
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'expects to log a proper message' do
|
56
|
+
expect(Karafka.logger).to receive(:info).with("Sum of 2 elements equals to: #{sum}")
|
57
|
+
consumer.consume
|
58
|
+
end
|
59
|
+
end
|
60
|
+
```
|
data/CHANGELOG.md
CHANGED
@@ -1,24 +1,14 @@
|
|
1
1
|
# Karafka Test gem changelog
|
2
2
|
|
3
|
-
##
|
4
|
-
-
|
5
|
-
- Remove Ruby 2.5 support and update minimum Ruby requirement to 2.6
|
3
|
+
## 2.0.0.alpha2 (2022-02-19)
|
4
|
+
- Add `rubygems_mfa_required`
|
6
5
|
|
7
|
-
##
|
8
|
-
-
|
6
|
+
## 2.0.0.alpha1 (2022-01-30)
|
7
|
+
- Change the API to be more comprehensive
|
8
|
+
- Update to work with Karafka 2.0
|
9
|
+
- Support for Ruby 3.1
|
10
|
+
- Drop support for ruby 2.6
|
9
11
|
|
10
|
-
## 1.4
|
11
|
-
- Update to match Karafka 1.4.0 params and batch metadata setup
|
12
|
+
## 1.4.*
|
12
13
|
|
13
|
-
|
14
|
-
- change license to LGPL-3.0
|
15
|
-
- Ruby 2.6.5 support
|
16
|
-
- Ruby 2.7.1 support
|
17
|
-
- JRuby support
|
18
|
-
- Change license to LGPL-3.0
|
19
|
-
|
20
|
-
## 1.3.0 (2019-09-09)
|
21
|
-
- Dynamic `App` name (#2)
|
22
|
-
|
23
|
-
## 1.3.0.rc1 (2019-07-31)
|
24
|
-
- Support for Karafka 1.3
|
14
|
+
If you are looking for the changelog of `1.4`, please go [here](https://github.com/karafka/testing/blob/1.4/CHANGELOG.md).
|
data/Gemfile.lock
CHANGED
@@ -1,42 +1,36 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
karafka-testing (
|
5
|
-
karafka (~>
|
4
|
+
karafka-testing (2.0.0.alpha2)
|
5
|
+
karafka (~> 2.0.alpha2)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
|
-
concurrent-ruby (1.1.
|
11
|
-
|
12
|
-
king_konf (~> 1.0)
|
13
|
-
ruby-kafka (~> 1.0)
|
14
|
-
digest-crc (0.6.3)
|
15
|
-
rake (>= 12.0.0, < 14.0.0)
|
16
|
-
dry-configurable (0.12.1)
|
10
|
+
concurrent-ruby (1.1.9)
|
11
|
+
dry-configurable (0.14.0)
|
17
12
|
concurrent-ruby (~> 1.0)
|
18
|
-
dry-core (~> 0.
|
19
|
-
dry-container (0.
|
13
|
+
dry-core (~> 0.6)
|
14
|
+
dry-container (0.9.0)
|
20
15
|
concurrent-ruby (~> 1.0)
|
21
|
-
dry-configurable (~> 0.
|
22
|
-
dry-core (0.
|
16
|
+
dry-configurable (~> 0.13, >= 0.13.0)
|
17
|
+
dry-core (0.7.1)
|
23
18
|
concurrent-ruby (~> 1.0)
|
24
|
-
dry-equalizer (0.3.0)
|
25
19
|
dry-events (0.3.0)
|
26
20
|
concurrent-ruby (~> 1.0)
|
27
21
|
dry-core (~> 0.5, >= 0.5)
|
28
|
-
dry-inflector (0.2.
|
29
|
-
dry-initializer (3.
|
30
|
-
dry-logic (1.
|
22
|
+
dry-inflector (0.2.1)
|
23
|
+
dry-initializer (3.1.1)
|
24
|
+
dry-logic (1.2.0)
|
31
25
|
concurrent-ruby (~> 1.0)
|
32
26
|
dry-core (~> 0.5, >= 0.5)
|
33
|
-
dry-monitor (0.
|
34
|
-
dry-configurable (~> 0.
|
27
|
+
dry-monitor (0.5.0)
|
28
|
+
dry-configurable (~> 0.13, >= 0.13.0)
|
35
29
|
dry-core (~> 0.5, >= 0.5)
|
36
30
|
dry-events (~> 0.2)
|
37
|
-
dry-schema (1.
|
31
|
+
dry-schema (1.9.1)
|
38
32
|
concurrent-ruby (~> 1.0)
|
39
|
-
dry-configurable (~> 0.
|
33
|
+
dry-configurable (~> 0.13, >= 0.13.0)
|
40
34
|
dry-core (~> 0.5, >= 0.5)
|
41
35
|
dry-initializer (~> 3.0)
|
42
36
|
dry-logic (~> 1.0)
|
@@ -47,50 +41,43 @@ GEM
|
|
47
41
|
dry-core (~> 0.5, >= 0.5)
|
48
42
|
dry-inflector (~> 0.1, >= 0.1.2)
|
49
43
|
dry-logic (~> 1.0, >= 1.0.2)
|
50
|
-
dry-validation (1.
|
44
|
+
dry-validation (1.8.0)
|
51
45
|
concurrent-ruby (~> 1.0)
|
52
46
|
dry-container (~> 0.7, >= 0.7.1)
|
53
|
-
dry-core (~> 0.
|
54
|
-
dry-equalizer (~> 0.2)
|
47
|
+
dry-core (~> 0.5, >= 0.5)
|
55
48
|
dry-initializer (~> 3.0)
|
56
|
-
dry-schema (~> 1.
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
dry-configurable (~> 0.8)
|
64
|
-
dry-inflector (~> 0.1)
|
65
|
-
dry-monitor (~> 0.3)
|
66
|
-
dry-validation (~> 1.2)
|
67
|
-
envlogic (~> 1.1)
|
68
|
-
irb (~> 1.0)
|
69
|
-
ruby-kafka (>= 1.0.0)
|
49
|
+
dry-schema (~> 1.9, >= 1.9.1)
|
50
|
+
ffi (1.15.5)
|
51
|
+
karafka (2.0.0.alpha2)
|
52
|
+
dry-configurable (~> 0.13)
|
53
|
+
dry-monitor (~> 0.5)
|
54
|
+
dry-validation (~> 1.7)
|
55
|
+
rdkafka (>= 0.10)
|
70
56
|
thor (>= 0.20)
|
71
|
-
waterdrop (
|
72
|
-
zeitwerk (~> 2.
|
73
|
-
|
74
|
-
rake (13.0.
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
thor (1.1
|
80
|
-
waterdrop (
|
81
|
-
|
82
|
-
dry-configurable (~> 0.
|
83
|
-
dry-monitor (~> 0.
|
84
|
-
dry-validation (~> 1.
|
85
|
-
|
86
|
-
zeitwerk (~> 2.
|
87
|
-
zeitwerk (2.4
|
57
|
+
waterdrop (>= 2.2.0, < 3.0.0)
|
58
|
+
zeitwerk (~> 2.3)
|
59
|
+
mini_portile2 (2.7.1)
|
60
|
+
rake (13.0.6)
|
61
|
+
rdkafka (0.11.1)
|
62
|
+
ffi (~> 1.15)
|
63
|
+
mini_portile2 (~> 2.6)
|
64
|
+
rake (> 12)
|
65
|
+
thor (1.2.1)
|
66
|
+
waterdrop (2.2.0)
|
67
|
+
concurrent-ruby (>= 1.1)
|
68
|
+
dry-configurable (~> 0.13)
|
69
|
+
dry-monitor (~> 0.5)
|
70
|
+
dry-validation (~> 1.7)
|
71
|
+
rdkafka (>= 0.10)
|
72
|
+
zeitwerk (~> 2.3)
|
73
|
+
zeitwerk (2.5.4)
|
88
74
|
|
89
75
|
PLATFORMS
|
76
|
+
x86_64-darwin
|
90
77
|
x86_64-linux
|
91
78
|
|
92
79
|
DEPENDENCIES
|
93
80
|
karafka-testing!
|
94
81
|
|
95
82
|
BUNDLED WITH
|
96
|
-
2.
|
83
|
+
2.3.6
|
data/README.md
CHANGED
@@ -1,10 +1,14 @@
|
|
1
1
|
# Karafka Testing library
|
2
2
|
|
3
|
+
**Note**: Documentation presented below works with Karafka `2.0.0.alpha1` and higher.
|
4
|
+
|
5
|
+
Please refer to [this](https://github.com/karafka/testing/tree/1.4) branch and its documentation for details about usage with Karafka `1.4`.
|
6
|
+
|
3
7
|
[![Build Status](https://github.com/karafka/testing/workflows/ci/badge.svg)](https://github.com/karafka/testing/actions?query=workflow%3Aci)
|
4
8
|
[![Gem Version](https://badge.fury.io/rb/karafka-testing.svg)](http://badge.fury.io/rb/karafka-testing)
|
5
|
-
[![Join the chat at https://
|
9
|
+
[![Join the chat at https://slack.karafka.io](https://raw.githubusercontent.com/karafka/misc/master/slack.svg)](https://slack.karafka.io)
|
6
10
|
|
7
|
-
Karafka-Testing is a library that provides
|
11
|
+
Karafka-Testing is a library that provides RSpec helpers, to make testing of Karafka consumers much easier.
|
8
12
|
|
9
13
|
## Installation
|
10
14
|
|
@@ -28,18 +32,17 @@ end
|
|
28
32
|
|
29
33
|
## Usage
|
30
34
|
|
31
|
-
Once included into your RSpec setup, this library will provide you two methods that you can use with your specs:
|
32
|
-
|
33
|
-
- `#karafka_consumer_for` - this method will create a consumer instance for the desired topic. It **needs** to be set as the spec subject.
|
34
|
-
- `#publish_for_karafka` - this method will "send" message to the consumer instance.
|
35
|
+
Once included into your RSpec setup, this library will provide you with a special object `#karafka` that includes two methods that you can use with your specs:
|
35
36
|
|
37
|
+
- `#consumer_for` - creates a consumer instance for the desired topic. It **needs** to be set as the spec subject.
|
38
|
+
- `#publish` - "sends" message to the consumer instance.
|
36
39
|
|
37
|
-
**Note:** Messages sent using the `#
|
40
|
+
**Note:** Messages sent using the `#publish` method won't be sent to Kafka. They will be "virtually" delegated to the created consumer instance so your specs can run without Kafka setup.
|
38
41
|
|
39
42
|
```ruby
|
40
43
|
RSpec.describe InlineBatchConsumer do
|
41
44
|
# This will create a consumer instance with all the settings defined for the given topic
|
42
|
-
subject(:consumer) {
|
45
|
+
subject(:consumer) { karafka.consumer_for(:inline_batch_data) }
|
43
46
|
|
44
47
|
let(:nr1_value) { rand }
|
45
48
|
let(:nr2_value) { rand }
|
@@ -47,9 +50,9 @@ RSpec.describe InlineBatchConsumer do
|
|
47
50
|
|
48
51
|
before do
|
49
52
|
# Sends first message to Karafka consumer
|
50
|
-
|
53
|
+
karafka.publish({ 'number' => nr1_value }.to_json)
|
51
54
|
# Sends second message to Karafka consumer
|
52
|
-
|
55
|
+
karafka.publish({ 'number' => nr2_value }.to_json, partition: 2)
|
53
56
|
allow(Karafka.logger).to receive(:info)
|
54
57
|
end
|
55
58
|
|
@@ -60,18 +63,10 @@ RSpec.describe InlineBatchConsumer do
|
|
60
63
|
end
|
61
64
|
```
|
62
65
|
|
63
|
-
## References
|
64
|
-
|
65
|
-
* [Karafka framework](https://github.com/karafka/karafka)
|
66
|
-
* [Karafka Testing Actions CI](https://github.com/karafka/testing/actions?query=workflow%3Aci)
|
67
|
-
* [Karafka Testing Coditsu](https://app.coditsu.io/karafka/repositories/testing)
|
68
|
-
|
69
66
|
## Note on contributions
|
70
67
|
|
71
|
-
First, thank you for considering contributing to Karafka
|
72
|
-
|
73
|
-
Each pull request must pass all the RSpec specs and meet our quality requirements.
|
68
|
+
First, thank you for considering contributing to the Karafka ecosystem! It's people like you that make the open source community such a great community!
|
74
69
|
|
75
|
-
|
70
|
+
Each pull request must pass all the RSpec specs, integration tests and meet our quality requirements.
|
76
71
|
|
77
|
-
|
72
|
+
Fork it, update and wait for the Github Actions results.
|
data/certs/mensfeld.pem
CHANGED
@@ -1,25 +1,25 @@
|
|
1
1
|
-----BEGIN CERTIFICATE-----
|
2
2
|
MIIEODCCAqCgAwIBAgIBATANBgkqhkiG9w0BAQsFADAjMSEwHwYDVQQDDBhtYWNp
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
3
|
+
ZWovREM9bWVuc2ZlbGQvREM9cGwwHhcNMjEwODExMTQxNTEzWhcN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c7WXyrgKwJREv8rgBimLnNlgmFJLmtUCh2U/MgxvcilH
|
18
|
+
yshYcbseNvjkrtYnLRlWZR4SSB6Zei5AlyGVQLPkvdsBpNegcG6w075YEwzX/38a
|
19
|
+
8V9B/Yri2OGELBz8ykl7BsXUgNoUPA/4pHF6YRLz+VirOaUIQ4JfY7xGj6fSOWWz
|
20
|
+
/rQ/d77r6o1mfJYM/3BRVg73a3b7DmRnE5qjwmSaSQ7u802pJnLesmArch0xGCT/
|
21
|
+
fMmRli1Qb+6qOTl9mzD6UDMAyFR4t6MStLm0mIEqM0nBO5nUdUWbC7l9qXEf8XBE
|
22
|
+
2DP28p3EqSuS+lKbAWKcqv7t0iRhhmaod+Yn9mcrLN1sa3q3KSQ9BCyxezCD4Mk2
|
23
|
+
R2P11bWoCtr70BsccVrN8jEhzwXngMyI2gVt750Y+dbTu1KgRqZKp/ECe7ZzPzXj
|
24
|
+
pIy9vHxTANKYVyI4qj8OrFdEM5BQNu8oQpL0iQ==
|
25
25
|
-----END CERTIFICATE-----
|
data/karafka-testing.gemspec
CHANGED
@@ -13,18 +13,23 @@ Gem::Specification.new do |spec|
|
|
13
13
|
spec.email = %w[maciej@mensfeld.pl]
|
14
14
|
spec.summary = 'Library which provides helpers for easier Karafka consumers tests'
|
15
15
|
spec.description = 'Library which provides helpers for easier Karafka consumers tests'
|
16
|
-
spec.homepage = 'https://
|
16
|
+
spec.homepage = 'https://karafka.io'
|
17
17
|
spec.license = 'MIT'
|
18
18
|
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(spec)/}) }
|
19
19
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
20
20
|
spec.require_paths = %w[lib]
|
21
21
|
spec.cert_chain = %w[certs/mensfeld.pem]
|
22
22
|
|
23
|
-
spec.required_ruby_version = '>= 2.
|
23
|
+
spec.required_ruby_version = '>= 2.7'
|
24
24
|
|
25
25
|
if $PROGRAM_NAME.end_with?('gem')
|
26
26
|
spec.signing_key = File.expand_path('~/.ssh/gem-private_key.pem')
|
27
27
|
end
|
28
28
|
|
29
|
-
spec.add_dependency 'karafka', '~>
|
29
|
+
spec.add_dependency 'karafka', '~> 2.0.alpha2'
|
30
|
+
|
31
|
+
spec.metadata = {
|
32
|
+
'source_code_uri' => 'https://github.com/karafka/karafka',
|
33
|
+
'rubygems_mfa_required' => 'true'
|
34
|
+
}
|
30
35
|
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Karafka
|
4
|
+
module Testing
|
5
|
+
# A dummy client that takes over client delegated methods from the consumers
|
6
|
+
# For specs we do not mark anything as consumed, nor do we really send heartbeats.
|
7
|
+
# Those things are tested in the framework itself
|
8
|
+
class DummyClient
|
9
|
+
%i[
|
10
|
+
mark_as_consumed
|
11
|
+
mark_as_consumed!
|
12
|
+
].each do |caught_delegator|
|
13
|
+
define_method(caught_delegator) { |*| }
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -1,6 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'karafka/testing/errors'
|
4
|
+
require 'karafka/testing/dummy_client'
|
5
|
+
require 'karafka/testing/rspec/proxy'
|
4
6
|
|
5
7
|
module Karafka
|
6
8
|
module Testing
|
@@ -15,14 +17,15 @@ module Karafka
|
|
15
17
|
def included(base)
|
16
18
|
# This is an internal buffer for keeping "to be sent" messages before
|
17
19
|
# we run the consume
|
18
|
-
base.let(:
|
19
|
-
|
20
|
-
# in between them
|
21
|
-
base.after {
|
20
|
+
base.let(:_karafka_messages) { [] }
|
21
|
+
base.let(:karafka) { Karafka::Testing::RSpec::Proxy.new(self) }
|
22
|
+
# Clear the messages buffer after each spec, so nothing leaks in between them
|
23
|
+
base.after { _karafka_messages.clear }
|
22
24
|
end
|
23
25
|
end
|
24
26
|
|
25
|
-
# Creates a consumer instance for given topic
|
27
|
+
# Creates a consumer instance for a given topic
|
28
|
+
#
|
26
29
|
# @param requested_topic [String, Symbol] name of the topic for which we want to
|
27
30
|
# create a consumer instance
|
28
31
|
# @return [Object] described_class instance
|
@@ -31,12 +34,12 @@ module Karafka
|
|
31
34
|
#
|
32
35
|
# @example Creates a MyConsumer consumer instance with settings for `my_requested_topic`
|
33
36
|
# RSpec.describe MyConsumer do
|
34
|
-
# subject(:consumer) {
|
37
|
+
# subject(:consumer) { karafka.consumer_for(:my_requested_topic) }
|
35
38
|
# end
|
36
39
|
def karafka_consumer_for(requested_topic)
|
37
40
|
selected_topic = nil
|
38
41
|
|
39
|
-
# @note Remove in 2.
|
42
|
+
# @note Remove in 2.1. This won't work without the global state
|
40
43
|
::Karafka::App.consumer_groups.each do |consumer_group|
|
41
44
|
consumer_group.topics.each do |topic|
|
42
45
|
selected_topic = topic if topic.name == requested_topic.to_s
|
@@ -45,47 +48,59 @@ module Karafka
|
|
45
48
|
|
46
49
|
raise Karafka::Testing::Errors::TopicNotFoundError, requested_topic unless selected_topic
|
47
50
|
|
48
|
-
described_class.new
|
51
|
+
consumer = described_class.new
|
52
|
+
consumer.topic = selected_topic
|
53
|
+
consumer.client = Karafka::Testing::DummyClient.new
|
54
|
+
consumer
|
49
55
|
end
|
50
56
|
|
51
|
-
# Adds a new Karafka
|
57
|
+
# Adds a new Karafka message instance with given payload and options into an internal
|
52
58
|
# buffer that will be used to simulate messages delivery to the consumer
|
53
59
|
#
|
54
|
-
# @param
|
60
|
+
# @param payload [String] anything you want to send
|
55
61
|
# @param opts [Hash] additional options with which you want to overwrite the
|
56
62
|
# message defaults (key, offset, etc)
|
57
63
|
#
|
58
64
|
# @example Send a json message to consumer
|
59
65
|
# before do
|
60
|
-
#
|
66
|
+
# karafka.publish({ 'hello' => 'world' }.to_json)
|
61
67
|
# end
|
62
68
|
#
|
63
69
|
# @example Send a json message to consumer and simulate, that it is partition 6
|
64
70
|
# before do
|
65
|
-
#
|
71
|
+
# karafka.publish({ 'hello' => 'world' }.to_json, 'partition' => 6)
|
66
72
|
# end
|
67
|
-
def
|
68
|
-
metadata = Karafka::
|
69
|
-
**
|
73
|
+
def karafka_publish(payload, opts = {})
|
74
|
+
metadata = Karafka::Messages::Metadata.new(
|
75
|
+
**karafka_message_metadata_defaults.merge(opts)
|
70
76
|
).freeze
|
71
77
|
|
72
|
-
|
73
|
-
|
78
|
+
# Add this message to previously published messages
|
79
|
+
_karafka_messages << Karafka::Messages::Message.new(payload, metadata)
|
80
|
+
|
81
|
+
# Update batch metadata
|
82
|
+
batch_metadata = Karafka::Messages::Builders::BatchMetadata.call(
|
83
|
+
_karafka_messages,
|
84
|
+
subject.topic,
|
85
|
+
Time.now
|
86
|
+
)
|
87
|
+
|
88
|
+
# Update consumer messages batch
|
89
|
+
subject.messages = Karafka::Messages::Messages.new(_karafka_messages, batch_metadata)
|
74
90
|
end
|
75
91
|
|
76
92
|
private
|
77
93
|
|
78
94
|
# @return [Hash] message default options
|
79
|
-
def
|
95
|
+
def karafka_message_metadata_defaults
|
80
96
|
{
|
81
97
|
deserializer: subject.topic.deserializer,
|
82
|
-
|
98
|
+
timestamp: Time.now,
|
83
99
|
headers: {},
|
84
|
-
is_control_record: false,
|
85
100
|
key: nil,
|
86
|
-
offset:
|
101
|
+
offset: _karafka_messages.size,
|
87
102
|
partition: 0,
|
88
|
-
|
103
|
+
received_at: Time.now,
|
89
104
|
topic: subject.topic.name
|
90
105
|
}
|
91
106
|
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Karafka
|
4
|
+
module Testing
|
5
|
+
module RSpec
|
6
|
+
# Proxy object for a nicer `karafka.` API within RSpec
|
7
|
+
class Proxy
|
8
|
+
# @param rspec_example [RSpec::ExampleGroups] rspec context
|
9
|
+
def initialize(rspec_example)
|
10
|
+
@rspec_example = rspec_example
|
11
|
+
end
|
12
|
+
|
13
|
+
# @param args Anything that the `#karafka_consumer_for` accepts
|
14
|
+
def consumer_for(*args)
|
15
|
+
@rspec_example.karafka_consumer_for(*args)
|
16
|
+
end
|
17
|
+
|
18
|
+
# @param args Anything that the `#karafka_publish` accepts
|
19
|
+
def publish(*args)
|
20
|
+
@rspec_example.karafka_publish(*args)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data.tar.gz.sig
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: karafka-testing
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0.alpha2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Maciej Mensfeld
|
@@ -11,30 +11,30 @@ cert_chain:
|
|
11
11
|
- |
|
12
12
|
-----BEGIN CERTIFICATE-----
|
13
13
|
MIIEODCCAqCgAwIBAgIBATANBgkqhkiG9w0BAQsFADAjMSEwHwYDVQQDDBhtYWNp
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
14
|
+
ZWovREM9bWVuc2ZlbGQvREM9cGwwHhcNMjEwODExMTQxNTEzWhcNMjIwODExMTQx
|
15
|
+
NTEzWjAjMSEwHwYDVQQDDBhtYWNpZWovREM9bWVuc2ZlbGQvREM9cGwwggGiMA0G
|
16
|
+
CSqGSIb3DQEBAQUAA4IBjwAwggGKAoIBgQDV2jKH4Ti87GM6nyT6D+ESzTI0MZDj
|
17
|
+
ak2/TEwnxvijMJyCCPKT/qIkbW4/f0VHM4rhPr1nW73sb5SZBVFCLlJcOSKOBdUY
|
18
|
+
TMY+SIXN2EtUaZuhAOe8LxtxjHTgRHvHcqUQMBENXTISNzCo32LnUxweu66ia4Pd
|
19
|
+
1mNRhzOqNv9YiBZvtBf7IMQ+sYdOCjboq2dlsWmJiwiDpY9lQBTnWORnT3mQxU5x
|
20
|
+
vPSwnLB854cHd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xezCD4Mk2
|
34
|
+
R2P11bWoCtr70BsccVrN8jEhzwXngMyI2gVt750Y+dbTu1KgRqZKp/ECe7ZzPzXj
|
35
|
+
pIy9vHxTANKYVyI4qj8OrFdEM5BQNu8oQpL0iQ==
|
36
36
|
-----END CERTIFICATE-----
|
37
|
-
date:
|
37
|
+
date: 2022-02-19 00:00:00.000000000 Z
|
38
38
|
dependencies:
|
39
39
|
- !ruby/object:Gem::Dependency
|
40
40
|
name: karafka
|
@@ -42,14 +42,14 @@ dependencies:
|
|
42
42
|
requirements:
|
43
43
|
- - "~>"
|
44
44
|
- !ruby/object:Gem::Version
|
45
|
-
version:
|
45
|
+
version: 2.0.alpha2
|
46
46
|
type: :runtime
|
47
47
|
prerelease: false
|
48
48
|
version_requirements: !ruby/object:Gem::Requirement
|
49
49
|
requirements:
|
50
50
|
- - "~>"
|
51
51
|
- !ruby/object:Gem::Version
|
52
|
-
version:
|
52
|
+
version: 2.0.alpha2
|
53
53
|
description: Library which provides helpers for easier Karafka consumers tests
|
54
54
|
email:
|
55
55
|
- maciej@mensfeld.pl
|
@@ -59,12 +59,12 @@ extra_rdoc_files: []
|
|
59
59
|
files:
|
60
60
|
- ".coditsu/ci.yml"
|
61
61
|
- ".diffend.yml"
|
62
|
-
- ".github/FUNDING.yml"
|
63
62
|
- ".github/workflows/ci.yml"
|
64
63
|
- ".gitignore"
|
65
64
|
- ".rspec"
|
66
65
|
- ".ruby-gemset"
|
67
66
|
- ".ruby-version"
|
67
|
+
- 2.0-Upgrade.md
|
68
68
|
- CHANGELOG.md
|
69
69
|
- Gemfile
|
70
70
|
- Gemfile.lock
|
@@ -74,13 +74,17 @@ files:
|
|
74
74
|
- karafka-testing.gemspec
|
75
75
|
- lib/karafka-testing.rb
|
76
76
|
- lib/karafka/testing.rb
|
77
|
+
- lib/karafka/testing/dummy_client.rb
|
77
78
|
- lib/karafka/testing/errors.rb
|
78
79
|
- lib/karafka/testing/rspec/helpers.rb
|
80
|
+
- lib/karafka/testing/rspec/proxy.rb
|
79
81
|
- lib/karafka/testing/version.rb
|
80
|
-
homepage: https://
|
82
|
+
homepage: https://karafka.io
|
81
83
|
licenses:
|
82
84
|
- MIT
|
83
|
-
metadata:
|
85
|
+
metadata:
|
86
|
+
source_code_uri: https://github.com/karafka/karafka
|
87
|
+
rubygems_mfa_required: 'true'
|
84
88
|
post_install_message:
|
85
89
|
rdoc_options: []
|
86
90
|
require_paths:
|
@@ -89,14 +93,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
89
93
|
requirements:
|
90
94
|
- - ">="
|
91
95
|
- !ruby/object:Gem::Version
|
92
|
-
version: 2.
|
96
|
+
version: '2.7'
|
93
97
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
94
98
|
requirements:
|
95
|
-
- - "
|
99
|
+
- - ">"
|
96
100
|
- !ruby/object:Gem::Version
|
97
|
-
version:
|
101
|
+
version: 1.3.1
|
98
102
|
requirements: []
|
99
|
-
rubygems_version: 3.
|
103
|
+
rubygems_version: 3.3.3
|
100
104
|
signing_key:
|
101
105
|
specification_version: 4
|
102
106
|
summary: Library which provides helpers for easier Karafka consumers tests
|
metadata.gz.sig
CHANGED
Binary file
|
data/.github/FUNDING.yml
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
open_collective: karafka
|