karafka-testing 2.4.3 → 2.4.4
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 +1 -0
- data/.ruby-version +1 -1
- data/CHANGELOG.md +3 -0
- data/Gemfile.lock +15 -11
- data/lib/karafka/testing/minitest/helpers.rb +26 -10
- data/lib/karafka/testing/rspec/helpers.rb +26 -10
- data/lib/karafka/testing/version.rb +1 -1
- data.tar.gz.sig +0 -0
- metadata +3 -3
- metadata.gz.sig +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7dbd023d8dfb5cb1f11dce4a3ddf893c005228b9f8bc9f0bf199d37eaad6a5be
|
4
|
+
data.tar.gz: 17754c2c15f2b975241294fd6eff2e0ff40f64188b0bffcf110f019e52fc3e84
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2ee758d81cc2ddf98fedafeac9105cf3c50aa0ad6845bca729aa3dde5c461f82328c91a6dd449faa460ee28c8e27e5b26ea87f1bbdc541f4be8c11aae6388020
|
7
|
+
data.tar.gz: 80d66738edd43d2e8a373f29b3658f12fce556505c5185af5929bc4e721c80eec54af6479661129cb1b57f67c7bc506fca0ddd410aea5418f85be8b71e6b6608
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/.github/workflows/ci.yml
CHANGED
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
3.3.
|
1
|
+
3.3.3
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
# Karafka Test gem changelog
|
2
2
|
|
3
|
+
## 2.4.4 (2024-07-02)
|
4
|
+
- [Enhancement] Memoize `consumer_for` so consumers can be set up for multiple topics and `let(:consumer)` is no longer a requirement. (dorner)
|
5
|
+
|
3
6
|
## 2.4.3 (2024-05-06)
|
4
7
|
- [Fix] Fix: raw_key is not being assigned for rspec (CaioPenhalver)
|
5
8
|
- [Fix] Fix: raw_key is not being assigned for minitest
|
data/Gemfile.lock
CHANGED
@@ -1,30 +1,34 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
karafka-testing (2.4.
|
4
|
+
karafka-testing (2.4.4)
|
5
5
|
karafka (>= 2.4.0, < 2.5.0)
|
6
6
|
waterdrop (>= 2.7.0)
|
7
7
|
|
8
8
|
GEM
|
9
9
|
remote: https://rubygems.org/
|
10
10
|
specs:
|
11
|
-
|
12
|
-
|
11
|
+
base64 (0.2.0)
|
12
|
+
ffi (1.17.0)
|
13
|
+
ffi (1.17.0-x86_64-linux-gnu)
|
14
|
+
karafka (2.4.3)
|
15
|
+
base64 (~> 0.2)
|
13
16
|
karafka-core (>= 2.4.0, < 2.5.0)
|
14
|
-
waterdrop (>= 2.7.
|
17
|
+
waterdrop (>= 2.7.3, < 3.0.0)
|
15
18
|
zeitwerk (~> 2.3)
|
16
|
-
karafka-core (2.4.
|
17
|
-
karafka-rdkafka (>= 0.15.0, < 0.
|
18
|
-
karafka-rdkafka (0.
|
19
|
+
karafka-core (2.4.3)
|
20
|
+
karafka-rdkafka (>= 0.15.0, < 0.17.0)
|
21
|
+
karafka-rdkafka (0.16.0)
|
19
22
|
ffi (~> 1.15)
|
20
23
|
mini_portile2 (~> 2.6)
|
21
24
|
rake (> 12)
|
22
|
-
mini_portile2 (2.8.
|
25
|
+
mini_portile2 (2.8.7)
|
23
26
|
rake (13.2.1)
|
24
|
-
waterdrop (2.7.
|
27
|
+
waterdrop (2.7.3)
|
25
28
|
karafka-core (>= 2.4.0, < 3.0.0)
|
29
|
+
karafka-rdkafka (>= 0.15.1)
|
26
30
|
zeitwerk (~> 2.3)
|
27
|
-
zeitwerk (2.6.
|
31
|
+
zeitwerk (2.6.16)
|
28
32
|
|
29
33
|
PLATFORMS
|
30
34
|
ruby
|
@@ -34,4 +38,4 @@ DEPENDENCIES
|
|
34
38
|
karafka-testing!
|
35
39
|
|
36
40
|
BUNDLED WITH
|
37
|
-
2.5.
|
41
|
+
2.5.14
|
@@ -37,6 +37,8 @@ module Karafka
|
|
37
37
|
@_karafka_consumer_messages.clear
|
38
38
|
@_karafka_producer_client.reset
|
39
39
|
|
40
|
+
@_karafka_consumer_mappings = {}
|
41
|
+
|
40
42
|
Karafka.producer.stubs(:client).returns(@_karafka_producer_client)
|
41
43
|
end
|
42
44
|
|
@@ -87,18 +89,23 @@ module Karafka
|
|
87
89
|
# @example Send a json message to consumer and simulate, that it is partition 6
|
88
90
|
# @karafka.produce({ 'hello' => 'world' }.to_json, 'partition' => 6)
|
89
91
|
def _karafka_add_message_to_consumer_if_needed(message)
|
92
|
+
consumer_obj = if defined?(@consumer)
|
93
|
+
@consumer
|
94
|
+
else
|
95
|
+
@_karafka_consumer_mappings&.dig(message[:topic])
|
96
|
+
end
|
90
97
|
# Consumer needs to be defined in order to pass messages to it
|
91
|
-
return unless defined?(
|
98
|
+
return unless defined?(consumer_obj)
|
92
99
|
# We're interested in adding message to consumer only when it is a Karafka consumer
|
93
100
|
# Users may want to test other things (models producing messages for example) and in
|
94
101
|
# their case consumer will not be a consumer
|
95
|
-
return unless
|
102
|
+
return unless consumer_obj.is_a?(Karafka::BaseConsumer)
|
96
103
|
# We target to the consumer only messages that were produced to it, since specs may also
|
97
104
|
# produce other messages targeting other topics
|
98
|
-
return unless message[:topic] ==
|
105
|
+
return unless message[:topic] == consumer_obj.topic.name
|
99
106
|
|
100
107
|
# Build message metadata and copy any metadata that would come from the message
|
101
|
-
metadata = _karafka_message_metadata_defaults
|
108
|
+
metadata = _karafka_message_metadata_defaults(consumer_obj)
|
102
109
|
|
103
110
|
metadata.keys.each do |key|
|
104
111
|
message_key = METADATA_DISPATCH_MAPPINGS.fetch(key, key)
|
@@ -116,13 +123,13 @@ module Karafka
|
|
116
123
|
# Update batch metadata
|
117
124
|
batch_metadata = Karafka::Messages::Builders::BatchMetadata.call(
|
118
125
|
@_karafka_consumer_messages,
|
119
|
-
|
126
|
+
consumer_obj.topic,
|
120
127
|
0,
|
121
128
|
Time.now
|
122
129
|
)
|
123
130
|
|
124
131
|
# Update consumer messages batch
|
125
|
-
|
132
|
+
consumer_obj.messages = Karafka::Messages::Messages.new(
|
126
133
|
@_karafka_consumer_messages,
|
127
134
|
batch_metadata
|
128
135
|
)
|
@@ -132,9 +139,16 @@ module Karafka
|
|
132
139
|
# @param payload [String] payload we want to dispatch
|
133
140
|
# @param metadata [Hash] any metadata we want to dispatch alongside the payload
|
134
141
|
def _karafka_produce(payload, metadata = {})
|
142
|
+
topic = if metadata[:topic]
|
143
|
+
metadata[:topic]
|
144
|
+
elsif defined?(@consumer)
|
145
|
+
@consumer.topic.name
|
146
|
+
else
|
147
|
+
@_karafka_consumer_mappings&.keys&.last
|
148
|
+
end
|
135
149
|
Karafka.producer.produce_sync(
|
136
150
|
{
|
137
|
-
topic:
|
151
|
+
topic: topic,
|
138
152
|
payload: payload
|
139
153
|
}.merge(metadata)
|
140
154
|
)
|
@@ -147,17 +161,18 @@ module Karafka
|
|
147
161
|
|
148
162
|
private
|
149
163
|
|
164
|
+
# @param consumer_obj [Karafka::BaseConsumer] consumer reference
|
150
165
|
# @return [Hash] message default options
|
151
|
-
def _karafka_message_metadata_defaults
|
166
|
+
def _karafka_message_metadata_defaults(consumer_obj)
|
152
167
|
{
|
153
|
-
deserializers:
|
168
|
+
deserializers: consumer_obj.topic.deserializers,
|
154
169
|
timestamp: Time.now,
|
155
170
|
raw_headers: {},
|
156
171
|
raw_key: nil,
|
157
172
|
offset: @_karafka_consumer_messages.size,
|
158
173
|
partition: 0,
|
159
174
|
received_at: Time.now,
|
160
|
-
topic:
|
175
|
+
topic: consumer_obj.topic.name
|
161
176
|
}
|
162
177
|
end
|
163
178
|
|
@@ -179,6 +194,7 @@ module Karafka
|
|
179
194
|
@consumer.coordinator.seek_offset = 0
|
180
195
|
# Indicate usage as for tests no direct enqueuing happens
|
181
196
|
@consumer.instance_variable_set('@used', true)
|
197
|
+
@_karafka_consumer_mappings[topic.name] = @consumer
|
182
198
|
@consumer
|
183
199
|
end
|
184
200
|
end
|
@@ -44,6 +44,7 @@ module Karafka
|
|
44
44
|
|
45
45
|
_karafka_consumer_messages.clear
|
46
46
|
_karafka_producer_client.reset
|
47
|
+
@_karafka_consumer_mappings = {}
|
47
48
|
|
48
49
|
if Object.const_defined?('Mocha', false)
|
49
50
|
Karafka.producer.stubs(:client).returns(_karafka_producer_client)
|
@@ -94,18 +95,23 @@ module Karafka
|
|
94
95
|
# karafka.produce({ 'hello' => 'world' }.to_json, 'partition' => 6)
|
95
96
|
# end
|
96
97
|
def _karafka_add_message_to_consumer_if_needed(message)
|
98
|
+
consumer_obj = if defined?(consumer)
|
99
|
+
consumer
|
100
|
+
else
|
101
|
+
@_karafka_consumer_mappings&.dig(message[:topic])
|
102
|
+
end
|
97
103
|
# Consumer needs to be defined in order to pass messages to it
|
98
|
-
return unless
|
104
|
+
return unless consumer_obj
|
99
105
|
# We're interested in adding message to consumer only when it is a Karafka consumer
|
100
106
|
# Users may want to test other things (models producing messages for example) and in
|
101
107
|
# their case consumer will not be a consumer
|
102
|
-
return unless
|
108
|
+
return unless consumer_obj.is_a?(Karafka::BaseConsumer)
|
103
109
|
# We target to the consumer only messages that were produced to it, since specs may also
|
104
110
|
# produce other messages targeting other topics
|
105
|
-
return unless message[:topic] ==
|
111
|
+
return unless message[:topic] == consumer_obj.topic.name
|
106
112
|
|
107
113
|
# Build message metadata and copy any metadata that would come from the message
|
108
|
-
metadata = _karafka_message_metadata_defaults
|
114
|
+
metadata = _karafka_message_metadata_defaults(consumer_obj)
|
109
115
|
|
110
116
|
metadata.keys.each do |key|
|
111
117
|
message_key = METADATA_DISPATCH_MAPPINGS.fetch(key, key)
|
@@ -124,13 +130,13 @@ module Karafka
|
|
124
130
|
# Update batch metadata
|
125
131
|
batch_metadata = Karafka::Messages::Builders::BatchMetadata.call(
|
126
132
|
_karafka_consumer_messages,
|
127
|
-
|
133
|
+
consumer_obj.topic,
|
128
134
|
0,
|
129
135
|
Time.now
|
130
136
|
)
|
131
137
|
|
132
138
|
# Update consumer messages batch
|
133
|
-
|
139
|
+
consumer_obj.messages = Karafka::Messages::Messages.new(
|
134
140
|
_karafka_consumer_messages,
|
135
141
|
batch_metadata
|
136
142
|
)
|
@@ -140,9 +146,16 @@ module Karafka
|
|
140
146
|
# @param payload [String] payload we want to dispatch
|
141
147
|
# @param metadata [Hash] any metadata we want to dispatch alongside the payload
|
142
148
|
def _karafka_produce(payload, metadata = {})
|
149
|
+
topic = if metadata[:topic]
|
150
|
+
metadata[:topic]
|
151
|
+
elsif defined?(consumer)
|
152
|
+
consumer.topic.name
|
153
|
+
else
|
154
|
+
@_karafka_consumer_mappings&.keys&.last
|
155
|
+
end
|
143
156
|
Karafka.producer.produce_sync(
|
144
157
|
{
|
145
|
-
topic:
|
158
|
+
topic: topic,
|
146
159
|
payload: payload
|
147
160
|
}.merge(metadata)
|
148
161
|
)
|
@@ -155,17 +168,18 @@ module Karafka
|
|
155
168
|
|
156
169
|
private
|
157
170
|
|
171
|
+
# @param consumer_obj [Karafka::BaseConsumer] consumer reference
|
158
172
|
# @return [Hash] message default options
|
159
|
-
def _karafka_message_metadata_defaults
|
173
|
+
def _karafka_message_metadata_defaults(consumer_obj)
|
160
174
|
{
|
161
|
-
deserializers:
|
175
|
+
deserializers: consumer_obj.topic.deserializers,
|
162
176
|
timestamp: Time.now,
|
163
177
|
raw_headers: {},
|
164
178
|
raw_key: nil,
|
165
179
|
offset: _karafka_consumer_messages.size,
|
166
180
|
partition: 0,
|
167
181
|
received_at: Time.now,
|
168
|
-
topic:
|
182
|
+
topic: consumer_obj.topic.name
|
169
183
|
}
|
170
184
|
end
|
171
185
|
|
@@ -188,6 +202,8 @@ module Karafka
|
|
188
202
|
consumer.coordinator.seek_offset = 0
|
189
203
|
# Indicate usage as for tests no direct enqueuing happens
|
190
204
|
consumer.instance_variable_set('@used', true)
|
205
|
+
|
206
|
+
@_karafka_consumer_mappings[topic.name] = consumer
|
191
207
|
consumer
|
192
208
|
end
|
193
209
|
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: 2.4.
|
4
|
+
version: 2.4.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Maciej Mensfeld
|
@@ -35,7 +35,7 @@ cert_chain:
|
|
35
35
|
AnG1dJU+yL2BK7vaVytLTstJME5mepSZ46qqIJXMuWob/YPDmVaBF39TDSG9e34s
|
36
36
|
msG3BiCqgOgHAnL23+CN3Rt8MsuRfEtoTKpJVcCfoEoNHOkc
|
37
37
|
-----END CERTIFICATE-----
|
38
|
-
date: 2024-
|
38
|
+
date: 2024-07-02 00:00:00.000000000 Z
|
39
39
|
dependencies:
|
40
40
|
- !ruby/object:Gem::Dependency
|
41
41
|
name: karafka
|
@@ -132,7 +132,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
132
132
|
- !ruby/object:Gem::Version
|
133
133
|
version: '0'
|
134
134
|
requirements: []
|
135
|
-
rubygems_version: 3.5.
|
135
|
+
rubygems_version: 3.5.11
|
136
136
|
signing_key:
|
137
137
|
specification_version: 4
|
138
138
|
summary: Library which provides helpers for easier Karafka consumers tests
|
metadata.gz.sig
CHANGED
@@ -1 +1,2 @@
|
|
1
|
-
|
1
|
+
H�ó�ֳ�2�Yu�j������8+���q�4���~����間j� ���-�O��zM(>(�.;^�&� U{B�#x��셎�������;��ɨ��+5/Nt/��ٲ��آV��3���-Qmx^��E]QB�#���?ks�r���H���}��rԤǘ��o[�E������F��\�9��?.ܪ���D���/c��te�T�
|
2
|
+
l�
|