karafka-testing 2.2.0 → 2.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 84ae796af17d02ace2ed5130aab0d964ea724bcd5b8379f954b3b93d265afbf2
4
- data.tar.gz: 938a1f00fa6b1670d6cf8c6a045426c17ad9964398e6f3e16785ee927f21be93
3
+ metadata.gz: 073f7b386365e017596e6ad5d8c1f5753d72dab2eaf90c46504a4676f2690066
4
+ data.tar.gz: c64a949126353354af0218ed81fc2ee0229fea1edbc3dacf08d129f495053929
5
5
  SHA512:
6
- metadata.gz: 7229353c31414e28d97b0d498ec0a92d628432d8544b3a34811d518681607573ab2734c75ea936cb25666e1f12dbcce7c6de8fda2e39e2ce7f5f1c394759ec2a
7
- data.tar.gz: 0a5b5db670109114c6fbb77e6da81fde0215dbe2c2b38dc95cc063654cc349d836fde8dd09a18fa76a52a50c0560529c4ddd0971b5e4da1ae37a50845e103c08
6
+ metadata.gz: eedf2b5d5ac5c5507f0e5ddf7c3a1f24efb729966c7de9e5f1ecc785f27a08a8fa16d38b8cd12aa5446ed3e5f94d2a3db3e71b675ce1ca250cad7b28635937b3
7
+ data.tar.gz: 709de9d3f9f6d4351c5abd33c4c0a1888d680fb8159ca07f643bfe4153860e6ed290272cd7545a697b7eeaef4b754f446c945f40cef872413831aefa444c33ec
checksums.yaml.gz.sig CHANGED
Binary file
@@ -16,6 +16,7 @@ jobs:
16
16
  fail-fast: false
17
17
  matrix:
18
18
  ruby:
19
+ - '3.3.0-preview2'
19
20
  - '3.2'
20
21
  - '3.1'
21
22
  - '3.0'
@@ -24,7 +25,7 @@ jobs:
24
25
  - ruby: '3.2'
25
26
  coverage: 'true'
26
27
  steps:
27
- - uses: actions/checkout@v3
28
+ - uses: actions/checkout@v4
28
29
  - name: Install package dependencies
29
30
  run: "[ -e $APT_DEPS ] || sudo apt-get install -y --no-install-recommends $APT_DEPS"
30
31
  - name: Set up Ruby
@@ -43,7 +44,7 @@ jobs:
43
44
  strategy:
44
45
  fail-fast: false
45
46
  steps:
46
- - uses: actions/checkout@v3
47
+ - uses: actions/checkout@v4
47
48
  with:
48
49
  fetch-depth: 0
49
50
  - name: Set up Ruby
@@ -62,7 +63,7 @@ jobs:
62
63
  strategy:
63
64
  fail-fast: false
64
65
  steps:
65
- - uses: actions/checkout@v3
66
+ - uses: actions/checkout@v4
66
67
  with:
67
68
  fetch-depth: 0
68
69
  - name: Run Coditsu
data/CHANGELOG.md CHANGED
@@ -1,6 +1,9 @@
1
1
  # Karafka Test gem changelog
2
2
 
3
- ## 2.2.0 (2023-09-91)
3
+ ## 2.2.1 (2023-10-26)
4
+ - [Enhancement] Support patterns in `#consumer_for` consumer builder.
5
+
6
+ ## 2.2.0 (2023-09-01)
4
7
  - [Maintenance] Ensure that `2.2.0` works with consumers for patterns.
5
8
  - [Maintenance] Replace signing key with a new one (old expired).
6
9
 
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- karafka-testing (2.2.0)
4
+ karafka-testing (2.2.1)
5
5
  karafka (>= 2.2.0, < 3.0.0)
6
6
  waterdrop (>= 2.6.6)
7
7
 
@@ -30,7 +30,7 @@ Gem::Specification.new do |spec|
30
30
  spec.metadata = {
31
31
  'funding_uri' => 'https://karafka.io/#become-pro',
32
32
  'homepage_uri' => 'https://karafka.io',
33
- 'changelog_uri' => 'https://github.com/karafka/karafka-testing/blob/master/CHANGELOG.md',
33
+ 'changelog_uri' => 'https://karafka.io/docs/Changelog-Karafka-Testing',
34
34
  'bug_tracker_uri' => 'https://github.com/karafka/karafka-testing/issues',
35
35
  'source_code_uri' => 'https://github.com/karafka/karafka-testing',
36
36
  'documentation_uri' => 'https://karafka.io/docs',
@@ -13,6 +13,9 @@ module Karafka
13
13
 
14
14
  # Raised when topic is in many consumer groups and not limited by consumer group expectation
15
15
  TopicInManyConsumerGroupsError = Class.new(BaseError)
16
+
17
+ # Raised when you requested a topic from a consumer group that does not exist
18
+ ConsumerGroupNotFound = Class.new(BaseError)
16
19
  end
17
20
  end
18
21
  end
@@ -57,17 +57,10 @@ module Karafka
57
57
  # subject(:consumer) { karafka.consumer_for(:my_requested_topic) }
58
58
  # end
59
59
  def _karafka_consumer_for(requested_topic, requested_consumer_group = nil)
60
- all_topics = ::Karafka::App.consumer_groups.map(&:topics).flat_map(&:to_a)
61
-
62
- # First select topics that match what we are looking for
63
- selected_topics = all_topics.select do |topic|
64
- topic.name == requested_topic.to_s
65
- end
66
-
67
- # And then narrow it down based on the consumer group criteria (if present)
68
- selected_topics.delete_if do |topic|
69
- requested_consumer_group && topic.consumer_group.name != requested_consumer_group.to_s
70
- end
60
+ selected_topics = _karafka_consumer_find_candidate_topics(
61
+ requested_topic.to_s,
62
+ requested_consumer_group.to_s
63
+ )
71
64
 
72
65
  raise Errors::TopicInManyConsumerGroupsError, requested_topic if selected_topics.size > 1
73
66
  raise Errors::TopicNotFoundError, requested_topic if selected_topics.empty?
@@ -183,6 +176,47 @@ module Karafka
183
176
  consumer.instance_variable_set('@used', true)
184
177
  consumer
185
178
  end
179
+
180
+ # Finds all the routing topics matching requested topic within all topics or within
181
+ # provided consumer group based on name
182
+ #
183
+ # @param requested_topic [String] requested topic name
184
+ # @param requested_consumer_group [String] requested consumer group or nil to look in all
185
+ # @return [Array<Karafka::Routing::Topic>] all matching topics
186
+ #
187
+ # @note Since we run the lookup on subscription groups, the search will automatically
188
+ # expand with matching patterns
189
+ def _karafka_consumer_find_candidate_topics(requested_topic, requested_consumer_group)
190
+ _karafka_consumer_find_subscription_groups(requested_consumer_group)
191
+ .map(&:topics)
192
+ .filter_map do |topics|
193
+ topics.find(requested_topic.to_s)
194
+ rescue Karafka::Errors::TopicNotFoundError
195
+ nil
196
+ end
197
+ end
198
+
199
+ # Finds subscription groups from the requested consumer group or selects all if no
200
+ # consumer group specified
201
+ # @param requested_consumer_group [String] requested consumer group or nil to look in all
202
+ # @return [Array<Karafka::Routing::SubscriptionGroup>] requested subscription groups
203
+ def _karafka_consumer_find_subscription_groups(requested_consumer_group)
204
+ if requested_consumer_group && !requested_consumer_group.empty?
205
+ ::Karafka::App
206
+ .subscription_groups
207
+ # Find matching consumer group
208
+ .find { |cg, _sgs| cg.name == requested_consumer_group.to_s }
209
+ # Raise error if not found
210
+ .tap { |cg| cg || raise(Errors::ConsumerGroupNotFound, requested_consumer_group) }
211
+ # Since lookup was on a hash, get the value, that is subscription groups
212
+ .last
213
+ else
214
+ ::Karafka::App
215
+ .subscription_groups
216
+ .values
217
+ .flatten
218
+ end
219
+ end
186
220
  end
187
221
  end
188
222
  end
@@ -4,6 +4,6 @@
4
4
  module Karafka
5
5
  module Testing
6
6
  # Current version of gem. It should match Karafka framework version
7
- VERSION = '2.2.0'
7
+ VERSION = '2.2.1'
8
8
  end
9
9
  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.2.0
4
+ version: 2.2.1
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: 2023-09-01 00:00:00.000000000 Z
38
+ date: 2023-10-26 00:00:00.000000000 Z
39
39
  dependencies:
40
40
  - !ruby/object:Gem::Dependency
41
41
  name: karafka
@@ -109,7 +109,7 @@ licenses:
109
109
  metadata:
110
110
  funding_uri: https://karafka.io/#become-pro
111
111
  homepage_uri: https://karafka.io
112
- changelog_uri: https://github.com/karafka/karafka-testing/blob/master/CHANGELOG.md
112
+ changelog_uri: https://karafka.io/docs/Changelog-Karafka-Testing
113
113
  bug_tracker_uri: https://github.com/karafka/karafka-testing/issues
114
114
  source_code_uri: https://github.com/karafka/karafka-testing
115
115
  documentation_uri: https://karafka.io/docs
metadata.gz.sig CHANGED
Binary file