karafka-core 2.5.11 → 2.5.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +3 -3
- data/.github/workflows/push.yml +1 -1
- data/CHANGELOG.md +3 -0
- data/Gemfile.lock +1 -1
- data/karafka-core.gemspec +1 -1
- data/lib/karafka/core/version.rb +1 -1
- metadata +1 -25
- data/test/lib/karafka/core/configurable/leaf_test.rb +0 -3
- data/test/lib/karafka/core/configurable/node_test.rb +0 -3
- data/test/lib/karafka/core/configurable_test.rb +0 -504
- data/test/lib/karafka/core/contractable/contract_test.rb +0 -241
- data/test/lib/karafka/core/contractable/result_test.rb +0 -106
- data/test/lib/karafka/core/contractable/rule_test.rb +0 -5
- data/test/lib/karafka/core/contractable_test.rb +0 -3
- data/test/lib/karafka/core/helpers/time_test.rb +0 -29
- data/test/lib/karafka/core/instrumentation/callbacks_manager_test.rb +0 -81
- data/test/lib/karafka/core/instrumentation_test.rb +0 -35
- data/test/lib/karafka/core/monitoring/event_test.rb +0 -62
- data/test/lib/karafka/core/monitoring/monitor_test.rb +0 -237
- data/test/lib/karafka/core/monitoring/notifications_test.rb +0 -275
- data/test/lib/karafka/core/monitoring/statistics_decorator_test.rb +0 -503
- data/test/lib/karafka/core/monitoring_test.rb +0 -3
- data/test/lib/karafka/core/patches/rdkafka/bindings_test.rb +0 -25
- data/test/lib/karafka/core/taggable/tags_test.rb +0 -66
- data/test/lib/karafka/core/taggable_test.rb +0 -36
- data/test/lib/karafka/core/version_test.rb +0 -5
- data/test/lib/karafka/core_test.rb +0 -13
- data/test/lib/karafka-core_test.rb +0 -3
- data/test/support/class_builder.rb +0 -24
- data/test/support/describe_current_helper.rb +0 -41
- data/test/test_helper.rb +0 -55
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: a1ca213972a7e05632f164e423383f6a9172926291140ad6005c822b347855b2
|
|
4
|
+
data.tar.gz: acb97b8887fed4e6534bed1c8c764a19a38462b6a6581893ed80b3bb1efd7a82
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 0d3ead51c6a1fe7697cb5c13d914acd148c65d0be5b04be88b898d8cb5e220f65095bab181083a993a6085483c2f5815cb69c5cbd31cf92bcd246ea72c2f343a
|
|
7
|
+
data.tar.gz: 1210463f030fe15c691b0d136498327ae9a83128b5f871a256401bd498ebfd4117391d250ee49a1ab53c1f5f4fd427db292755bc792ea73a99435535bb79d115
|
data/.github/workflows/ci.yml
CHANGED
|
@@ -37,7 +37,7 @@ jobs:
|
|
|
37
37
|
run: "[ -e $APT_DEPS ] || sudo apt-get install -y --no-install-recommends $APT_DEPS"
|
|
38
38
|
|
|
39
39
|
- name: Set up Ruby
|
|
40
|
-
uses: ruby/setup-ruby@
|
|
40
|
+
uses: ruby/setup-ruby@c515ec17f69368147deb311832da000dd229d338 # v1.297.0
|
|
41
41
|
with:
|
|
42
42
|
ruby-version: ${{matrix.ruby}}
|
|
43
43
|
bundler: 'latest'
|
|
@@ -69,7 +69,7 @@ jobs:
|
|
|
69
69
|
with:
|
|
70
70
|
fetch-depth: 0
|
|
71
71
|
- name: Set up Ruby
|
|
72
|
-
uses: ruby/setup-ruby@
|
|
72
|
+
uses: ruby/setup-ruby@c515ec17f69368147deb311832da000dd229d338 # v1.297.0
|
|
73
73
|
with:
|
|
74
74
|
ruby-version: '4.0.2'
|
|
75
75
|
bundler-cache: true
|
|
@@ -86,7 +86,7 @@ jobs:
|
|
|
86
86
|
with:
|
|
87
87
|
fetch-depth: 0
|
|
88
88
|
- name: Set up Ruby
|
|
89
|
-
uses: ruby/setup-ruby@
|
|
89
|
+
uses: ruby/setup-ruby@c515ec17f69368147deb311832da000dd229d338 # v1.297.0
|
|
90
90
|
with:
|
|
91
91
|
ruby-version: '4.0.2'
|
|
92
92
|
bundler-cache: true
|
data/.github/workflows/push.yml
CHANGED
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
# Karafka Core Changelog
|
|
2
2
|
|
|
3
|
+
## 2.5.12 (2026-04-02)
|
|
4
|
+
- [Fix] Exclude `test/` directory from gem releases to reduce package size.
|
|
5
|
+
|
|
3
6
|
## 2.5.11 (2026-04-02)
|
|
4
7
|
- [Enhancement] Specialize `Contract#dig` for common 1-key and 2-key paths to avoid iterator overhead, yielding ~1.5x faster single-key lookups and ~1.45x faster two-key nested lookups.
|
|
5
8
|
- [Enhancement] Replace `Node#build_accessors` `@local_defs` Array with Hash for O(1) membership checks instead of O(n) `Array#include?`, yielding up to ~5x faster accessor lookups at 50 settings.
|
data/Gemfile.lock
CHANGED
data/karafka-core.gemspec
CHANGED
|
@@ -21,7 +21,7 @@ Gem::Specification.new do |spec|
|
|
|
21
21
|
|
|
22
22
|
spec.required_ruby_version = ">= 3.2.0"
|
|
23
23
|
|
|
24
|
-
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(
|
|
24
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test)/}) }
|
|
25
25
|
spec.require_paths = %w[lib]
|
|
26
26
|
|
|
27
27
|
spec.metadata = {
|
data/lib/karafka/core/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: karafka-core
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.5.
|
|
4
|
+
version: 2.5.12
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Maciej Mensfeld
|
|
@@ -96,30 +96,6 @@ files:
|
|
|
96
96
|
- package-lock.json
|
|
97
97
|
- package.json
|
|
98
98
|
- renovate.json
|
|
99
|
-
- test/lib/karafka-core_test.rb
|
|
100
|
-
- test/lib/karafka/core/configurable/leaf_test.rb
|
|
101
|
-
- test/lib/karafka/core/configurable/node_test.rb
|
|
102
|
-
- test/lib/karafka/core/configurable_test.rb
|
|
103
|
-
- test/lib/karafka/core/contractable/contract_test.rb
|
|
104
|
-
- test/lib/karafka/core/contractable/result_test.rb
|
|
105
|
-
- test/lib/karafka/core/contractable/rule_test.rb
|
|
106
|
-
- test/lib/karafka/core/contractable_test.rb
|
|
107
|
-
- test/lib/karafka/core/helpers/time_test.rb
|
|
108
|
-
- test/lib/karafka/core/instrumentation/callbacks_manager_test.rb
|
|
109
|
-
- test/lib/karafka/core/instrumentation_test.rb
|
|
110
|
-
- test/lib/karafka/core/monitoring/event_test.rb
|
|
111
|
-
- test/lib/karafka/core/monitoring/monitor_test.rb
|
|
112
|
-
- test/lib/karafka/core/monitoring/notifications_test.rb
|
|
113
|
-
- test/lib/karafka/core/monitoring/statistics_decorator_test.rb
|
|
114
|
-
- test/lib/karafka/core/monitoring_test.rb
|
|
115
|
-
- test/lib/karafka/core/patches/rdkafka/bindings_test.rb
|
|
116
|
-
- test/lib/karafka/core/taggable/tags_test.rb
|
|
117
|
-
- test/lib/karafka/core/taggable_test.rb
|
|
118
|
-
- test/lib/karafka/core/version_test.rb
|
|
119
|
-
- test/lib/karafka/core_test.rb
|
|
120
|
-
- test/support/class_builder.rb
|
|
121
|
-
- test/support/describe_current_helper.rb
|
|
122
|
-
- test/test_helper.rb
|
|
123
99
|
homepage: https://karafka.io
|
|
124
100
|
licenses:
|
|
125
101
|
- MIT
|
|
@@ -1,504 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
describe_current do
|
|
4
|
-
context "when we define settings on a class level" do
|
|
5
|
-
subject(:configurable_class) do
|
|
6
|
-
Class.new do
|
|
7
|
-
extend Karafka::Core::Configurable
|
|
8
|
-
|
|
9
|
-
setting(:with_default, default: 123)
|
|
10
|
-
|
|
11
|
-
setting(:nested1) do
|
|
12
|
-
setting(:nested2) do
|
|
13
|
-
setting(:leaf, default: 6)
|
|
14
|
-
setting(:with_constructor, default: false, constructor: ->(default) { default || 5 })
|
|
15
|
-
setting(:ov_constructor, default: true, constructor: ->(default) { default || 5 })
|
|
16
|
-
setting(:with_zero_constructor, constructor: -> { 7 })
|
|
17
|
-
setting(:name, default: "name")
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
setting(:nested1, default: 1)
|
|
21
|
-
end
|
|
22
|
-
end
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
let(:config) { configurable_class.config }
|
|
26
|
-
|
|
27
|
-
context "when we want to inject more settings into it" do
|
|
28
|
-
before { configurable_class.config.setting(:testme, default: 7) }
|
|
29
|
-
|
|
30
|
-
it { assert_equal 7, configurable_class.config.testme }
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
context "when we do not override any settings" do
|
|
34
|
-
before { configurable_class.configure }
|
|
35
|
-
|
|
36
|
-
it { assert_equal 123, config.with_default }
|
|
37
|
-
it { assert_equal "name", config.nested1.nested2.name }
|
|
38
|
-
it { assert_equal 6, config.nested1.nested2.leaf }
|
|
39
|
-
it { assert_equal 1, config.nested1.nested1 }
|
|
40
|
-
it { assert_equal 5, config.nested1.nested2.with_constructor }
|
|
41
|
-
it { assert config.nested1.nested2.ov_constructor }
|
|
42
|
-
it { assert_equal 7, config.nested1.nested2.with_zero_constructor }
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
context "when we do override some settings" do
|
|
46
|
-
before do
|
|
47
|
-
configurable_class.configure do |config|
|
|
48
|
-
config.with_default = 7
|
|
49
|
-
config.nested1.nested2.leaf = 8
|
|
50
|
-
end
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
it { assert_equal 7, config.with_default }
|
|
54
|
-
it { assert_equal 8, config.nested1.nested2.leaf }
|
|
55
|
-
it { assert_equal 1, config.nested1.nested1 }
|
|
56
|
-
it { assert_equal 5, config.nested1.nested2.with_constructor }
|
|
57
|
-
it { assert config.nested1.nested2.ov_constructor }
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
context "when we inherit and alter settings" do
|
|
61
|
-
let(:config_sub) { configurable_sub.config }
|
|
62
|
-
|
|
63
|
-
let(:configurable_sub) do
|
|
64
|
-
Class.new(configurable_class) do
|
|
65
|
-
setting(:extra, default: 0)
|
|
66
|
-
end
|
|
67
|
-
end
|
|
68
|
-
|
|
69
|
-
before do
|
|
70
|
-
configurable_class.configure
|
|
71
|
-
configurable_sub.configure
|
|
72
|
-
end
|
|
73
|
-
|
|
74
|
-
it { assert_raises(NoMethodError) { config.extra } }
|
|
75
|
-
it { assert_equal 0, config_sub.extra }
|
|
76
|
-
it { assert_equal 123, config.with_default }
|
|
77
|
-
it { assert_equal 6, config.nested1.nested2.leaf }
|
|
78
|
-
it { assert_equal 1, config.nested1.nested1 }
|
|
79
|
-
it { assert_equal 5, config.nested1.nested2.with_constructor }
|
|
80
|
-
it { assert config.nested1.nested2.ov_constructor }
|
|
81
|
-
it { assert_equal 123, config_sub.with_default }
|
|
82
|
-
it { assert_equal 6, config_sub.nested1.nested2.leaf }
|
|
83
|
-
it { assert_equal 1, config_sub.nested1.nested1 }
|
|
84
|
-
it { assert_equal 5, config_sub.nested1.nested2.with_constructor }
|
|
85
|
-
it { assert config_sub.nested1.nested2.ov_constructor }
|
|
86
|
-
end
|
|
87
|
-
|
|
88
|
-
context "when we inherit and change values" do
|
|
89
|
-
let(:config_sub) { configurable_sub.config }
|
|
90
|
-
|
|
91
|
-
let(:configurable_sub) do
|
|
92
|
-
Class.new(configurable_class) do
|
|
93
|
-
setting(:extra, default: 0)
|
|
94
|
-
end
|
|
95
|
-
end
|
|
96
|
-
|
|
97
|
-
before do
|
|
98
|
-
configurable_class.configure
|
|
99
|
-
|
|
100
|
-
configurable_sub.configure do |config|
|
|
101
|
-
config.with_default = 0
|
|
102
|
-
end
|
|
103
|
-
end
|
|
104
|
-
|
|
105
|
-
it { assert_equal 123, config.with_default }
|
|
106
|
-
it { assert_equal 0, config_sub.with_default }
|
|
107
|
-
end
|
|
108
|
-
|
|
109
|
-
context "when we run configuration once again" do
|
|
110
|
-
before do
|
|
111
|
-
config.configure { |node| node.with_default = 555 }
|
|
112
|
-
config.configure { |node| node.nested1.nested1 = 123 }
|
|
113
|
-
end
|
|
114
|
-
|
|
115
|
-
it "expect not to update values that are set" do
|
|
116
|
-
assert_equal 555, config.with_default
|
|
117
|
-
end
|
|
118
|
-
end
|
|
119
|
-
|
|
120
|
-
describe "#to_h" do
|
|
121
|
-
let(:expected_hash) do
|
|
122
|
-
{
|
|
123
|
-
with_default: 123,
|
|
124
|
-
nested1: {
|
|
125
|
-
nested1: 1,
|
|
126
|
-
nested2: {
|
|
127
|
-
name: "name",
|
|
128
|
-
leaf: 6,
|
|
129
|
-
ov_constructor: true,
|
|
130
|
-
with_constructor: 5,
|
|
131
|
-
with_zero_constructor: 7
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
end
|
|
136
|
-
|
|
137
|
-
before { config.configure }
|
|
138
|
-
|
|
139
|
-
it "expect to map with correct values" do
|
|
140
|
-
assert_equal expected_hash, config.to_h
|
|
141
|
-
end
|
|
142
|
-
|
|
143
|
-
context "when casting with a dynamic attribute" do
|
|
144
|
-
let(:configurable_class) do
|
|
145
|
-
Class.new do
|
|
146
|
-
include Karafka::Core::Configurable
|
|
147
|
-
|
|
148
|
-
setting(:producer1, constructor: -> { 2 }, lazy: true)
|
|
149
|
-
setting(:producer2, default: 1, lazy: true)
|
|
150
|
-
setting(:producer3, lazy: true)
|
|
151
|
-
setting(:producer4, default: 2)
|
|
152
|
-
end
|
|
153
|
-
end
|
|
154
|
-
|
|
155
|
-
let(:expected_hash) do
|
|
156
|
-
{
|
|
157
|
-
producer1: 2,
|
|
158
|
-
producer2: 1,
|
|
159
|
-
producer3: nil,
|
|
160
|
-
producer4: 2
|
|
161
|
-
}
|
|
162
|
-
end
|
|
163
|
-
|
|
164
|
-
let(:configurable) { configurable_class.new }
|
|
165
|
-
let(:config) { configurable.config }
|
|
166
|
-
|
|
167
|
-
it { assert_equal expected_hash, config.to_h }
|
|
168
|
-
end
|
|
169
|
-
end
|
|
170
|
-
|
|
171
|
-
context "when we want to merge extra config as a nested setting" do
|
|
172
|
-
let(:extra) do
|
|
173
|
-
Class.new do
|
|
174
|
-
extend Karafka::Core::Configurable
|
|
175
|
-
|
|
176
|
-
setting(:additional, default: 7)
|
|
177
|
-
end
|
|
178
|
-
end
|
|
179
|
-
|
|
180
|
-
before do
|
|
181
|
-
extra_config = extra
|
|
182
|
-
|
|
183
|
-
configurable_class.instance_eval do
|
|
184
|
-
setting(:superscope, default: extra_config.config)
|
|
185
|
-
end
|
|
186
|
-
end
|
|
187
|
-
|
|
188
|
-
it { assert_equal 7, configurable_class.config.superscope.additional }
|
|
189
|
-
|
|
190
|
-
it "expect to build correct hash when casted" do
|
|
191
|
-
assert_equal 7, configurable_class.config.to_h[:superscope][:additional]
|
|
192
|
-
end
|
|
193
|
-
end
|
|
194
|
-
|
|
195
|
-
context "when we define a lazy evaluated root setting" do
|
|
196
|
-
let(:configurable_class) do
|
|
197
|
-
default1 = default
|
|
198
|
-
constructor1 = constructor
|
|
199
|
-
|
|
200
|
-
Class.new do
|
|
201
|
-
extend Karafka::Core::Configurable
|
|
202
|
-
|
|
203
|
-
setting(
|
|
204
|
-
:lazy_setting,
|
|
205
|
-
default: default1,
|
|
206
|
-
constructor: constructor1,
|
|
207
|
-
lazy: true
|
|
208
|
-
)
|
|
209
|
-
end
|
|
210
|
-
end
|
|
211
|
-
|
|
212
|
-
let(:config) { configurable_class.config }
|
|
213
|
-
let(:constructor) { ->(default) { default || 1 } }
|
|
214
|
-
|
|
215
|
-
context "when default is not false nor nil" do
|
|
216
|
-
let(:default) { 100 }
|
|
217
|
-
|
|
218
|
-
it { assert_equal 100, config.lazy_setting }
|
|
219
|
-
end
|
|
220
|
-
|
|
221
|
-
context "when default is false" do
|
|
222
|
-
let(:default) { false }
|
|
223
|
-
|
|
224
|
-
it { assert_equal 1, config.lazy_setting }
|
|
225
|
-
end
|
|
226
|
-
|
|
227
|
-
context "when default is false and value is false for some time" do
|
|
228
|
-
let(:attempts) { [1, 10, false, false, false] }
|
|
229
|
-
let(:default) { false }
|
|
230
|
-
let(:constructor) { ->(default) { default || attempts.pop } }
|
|
231
|
-
|
|
232
|
-
it "expect to retry until non-false is present and then cache it" do
|
|
233
|
-
3.times { refute config.lazy_setting }
|
|
234
|
-
assert_equal 10, config.lazy_setting
|
|
235
|
-
assert_equal 10, config.lazy_setting
|
|
236
|
-
end
|
|
237
|
-
end
|
|
238
|
-
|
|
239
|
-
context "when constructor changes and its zero arity" do
|
|
240
|
-
let(:configurable_class) do
|
|
241
|
-
constructor1 = constructor
|
|
242
|
-
|
|
243
|
-
Class.new do
|
|
244
|
-
extend Karafka::Core::Configurable
|
|
245
|
-
|
|
246
|
-
setting(
|
|
247
|
-
:lazy_setting,
|
|
248
|
-
constructor: constructor1,
|
|
249
|
-
lazy: true
|
|
250
|
-
)
|
|
251
|
-
end
|
|
252
|
-
end
|
|
253
|
-
|
|
254
|
-
let(:attempts) { [1, 10, false, false, false] }
|
|
255
|
-
let(:constructor) { -> { attempts.pop } }
|
|
256
|
-
|
|
257
|
-
it "expect to retry until non-false is present and then cache it" do
|
|
258
|
-
3.times { refute config.lazy_setting }
|
|
259
|
-
assert_equal 10, config.lazy_setting
|
|
260
|
-
assert_equal 10, config.lazy_setting
|
|
261
|
-
end
|
|
262
|
-
end
|
|
263
|
-
|
|
264
|
-
context "when we want to overwrite constructed state with a different one during config" do
|
|
265
|
-
let(:default) { false }
|
|
266
|
-
let(:constructor) { ->(_) { false } }
|
|
267
|
-
|
|
268
|
-
before do
|
|
269
|
-
configurable_class.configure do |config|
|
|
270
|
-
config.lazy_setting = 20
|
|
271
|
-
end
|
|
272
|
-
end
|
|
273
|
-
|
|
274
|
-
it { assert_equal 20, config.lazy_setting }
|
|
275
|
-
end
|
|
276
|
-
end
|
|
277
|
-
end
|
|
278
|
-
|
|
279
|
-
context "when we define settings on an instance level" do
|
|
280
|
-
let(:configurable_class) do
|
|
281
|
-
Class.new do
|
|
282
|
-
include Karafka::Core::Configurable
|
|
283
|
-
|
|
284
|
-
setting(:with_default, default: 123)
|
|
285
|
-
|
|
286
|
-
setting(:nested1) do
|
|
287
|
-
setting(:nested2) do
|
|
288
|
-
setting(:leaf, default: 6)
|
|
289
|
-
setting(:with_constructor, default: false, constructor: ->(default) { default || 5 })
|
|
290
|
-
setting(:ov_constructor, default: true, constructor: ->(default) { default || 5 })
|
|
291
|
-
end
|
|
292
|
-
|
|
293
|
-
setting(:nested1, default: 1)
|
|
294
|
-
end
|
|
295
|
-
end
|
|
296
|
-
end
|
|
297
|
-
|
|
298
|
-
let(:configurable) { configurable_class.new }
|
|
299
|
-
let(:config) { configurable.config }
|
|
300
|
-
|
|
301
|
-
context "when we do not override any settings" do
|
|
302
|
-
before { configurable.configure }
|
|
303
|
-
|
|
304
|
-
it { assert_equal 123, config.with_default }
|
|
305
|
-
it { assert_equal 6, config.nested1.nested2.leaf }
|
|
306
|
-
it { assert_equal 1, config.nested1.nested1 }
|
|
307
|
-
it { assert_equal 5, config.nested1.nested2.with_constructor }
|
|
308
|
-
it { assert config.nested1.nested2.ov_constructor }
|
|
309
|
-
end
|
|
310
|
-
|
|
311
|
-
context "when we have two instances" do
|
|
312
|
-
let(:configurable2) { configurable_class.new }
|
|
313
|
-
let(:config2) { configurable2.config }
|
|
314
|
-
|
|
315
|
-
before do
|
|
316
|
-
configurable.configure
|
|
317
|
-
|
|
318
|
-
configurable2.configure do |config|
|
|
319
|
-
config.nested1.nested2.leaf = 100
|
|
320
|
-
end
|
|
321
|
-
end
|
|
322
|
-
|
|
323
|
-
it { assert_equal 6, config.nested1.nested2.leaf }
|
|
324
|
-
it { assert_equal 100, config2.nested1.nested2.leaf }
|
|
325
|
-
end
|
|
326
|
-
|
|
327
|
-
context "when we do override some settings" do
|
|
328
|
-
before do
|
|
329
|
-
configurable.configure do |config|
|
|
330
|
-
config.with_default = 7
|
|
331
|
-
config.nested1.nested2.leaf = 8
|
|
332
|
-
end
|
|
333
|
-
end
|
|
334
|
-
|
|
335
|
-
it { assert_equal 7, config.with_default }
|
|
336
|
-
it { assert_equal 8, config.nested1.nested2.leaf }
|
|
337
|
-
it { assert_equal 1, config.nested1.nested1 }
|
|
338
|
-
it { assert_equal 5, config.nested1.nested2.with_constructor }
|
|
339
|
-
it { assert config.nested1.nested2.ov_constructor }
|
|
340
|
-
end
|
|
341
|
-
|
|
342
|
-
context "when we inherit and alter settings" do
|
|
343
|
-
let(:config_sub) { configurable_sub.config }
|
|
344
|
-
|
|
345
|
-
let(:configurable_sub) do
|
|
346
|
-
Class.new(configurable_class) do
|
|
347
|
-
setting(:extra, default: 0)
|
|
348
|
-
end.new
|
|
349
|
-
end
|
|
350
|
-
|
|
351
|
-
before do
|
|
352
|
-
configurable.configure
|
|
353
|
-
configurable_sub.configure
|
|
354
|
-
end
|
|
355
|
-
|
|
356
|
-
it { assert_raises(NoMethodError) { config.extra } }
|
|
357
|
-
it { assert_equal 0, config_sub.extra }
|
|
358
|
-
it { assert_equal 123, config.with_default }
|
|
359
|
-
it { assert_equal 6, config.nested1.nested2.leaf }
|
|
360
|
-
it { assert_equal 1, config.nested1.nested1 }
|
|
361
|
-
it { assert_equal 5, config.nested1.nested2.with_constructor }
|
|
362
|
-
it { assert config.nested1.nested2.ov_constructor }
|
|
363
|
-
it { assert_equal 123, config_sub.with_default }
|
|
364
|
-
it { assert_equal 6, config_sub.nested1.nested2.leaf }
|
|
365
|
-
it { assert_equal 1, config_sub.nested1.nested1 }
|
|
366
|
-
it { assert_equal 5, config_sub.nested1.nested2.with_constructor }
|
|
367
|
-
it { assert config_sub.nested1.nested2.ov_constructor }
|
|
368
|
-
end
|
|
369
|
-
|
|
370
|
-
context "when we inherit and change values" do
|
|
371
|
-
let(:config_sub) { configurable_sub.config }
|
|
372
|
-
|
|
373
|
-
let(:configurable_sub) do
|
|
374
|
-
Class.new(configurable_class) do
|
|
375
|
-
setting(:extra, default: 0)
|
|
376
|
-
end
|
|
377
|
-
end
|
|
378
|
-
|
|
379
|
-
before do
|
|
380
|
-
configurable.configure
|
|
381
|
-
|
|
382
|
-
configurable_sub.configure do |config|
|
|
383
|
-
config.with_default = 0
|
|
384
|
-
end
|
|
385
|
-
end
|
|
386
|
-
|
|
387
|
-
it { assert_equal 123, config.with_default }
|
|
388
|
-
it { assert_equal 0, config_sub.with_default }
|
|
389
|
-
end
|
|
390
|
-
|
|
391
|
-
# https://github.com/karafka/karafka-core/issues/1
|
|
392
|
-
context "when configurable class has a method already defined in the object class" do
|
|
393
|
-
# We add method to the node to simulate this. We do not want to patch the Object class
|
|
394
|
-
before do
|
|
395
|
-
mod = Module.new do
|
|
396
|
-
def testable
|
|
397
|
-
raise
|
|
398
|
-
end
|
|
399
|
-
end
|
|
400
|
-
|
|
401
|
-
Karafka::Core::Configurable::Node.include mod
|
|
402
|
-
end
|
|
403
|
-
|
|
404
|
-
let(:configurable_class) do
|
|
405
|
-
Class.new do
|
|
406
|
-
include Karafka::Core::Configurable
|
|
407
|
-
|
|
408
|
-
setting(:testable, default: 123)
|
|
409
|
-
end
|
|
410
|
-
end
|
|
411
|
-
|
|
412
|
-
it "expect to redefine it with the accessors" do
|
|
413
|
-
instance = configurable_class.new
|
|
414
|
-
|
|
415
|
-
instance.configure do |config|
|
|
416
|
-
config.testable = 1
|
|
417
|
-
end
|
|
418
|
-
end
|
|
419
|
-
end
|
|
420
|
-
|
|
421
|
-
context "when we define a lazy evaluated root setting" do
|
|
422
|
-
let(:configurable_class) do
|
|
423
|
-
default1 = default
|
|
424
|
-
constructor1 = constructor
|
|
425
|
-
|
|
426
|
-
Class.new do
|
|
427
|
-
include Karafka::Core::Configurable
|
|
428
|
-
|
|
429
|
-
setting(
|
|
430
|
-
:lazy_setting,
|
|
431
|
-
default: default1,
|
|
432
|
-
constructor: constructor1,
|
|
433
|
-
lazy: true
|
|
434
|
-
)
|
|
435
|
-
end
|
|
436
|
-
end
|
|
437
|
-
|
|
438
|
-
let(:config) { configurable_class.new.tap(&:configure).config }
|
|
439
|
-
let(:constructor) { ->(default) { default || 1 } }
|
|
440
|
-
|
|
441
|
-
context "when default is not false nor nil" do
|
|
442
|
-
let(:default) { 100 }
|
|
443
|
-
|
|
444
|
-
it { assert_equal 100, config.lazy_setting }
|
|
445
|
-
end
|
|
446
|
-
|
|
447
|
-
context "when default is false" do
|
|
448
|
-
let(:default) { false }
|
|
449
|
-
|
|
450
|
-
it { assert_equal 1, config.lazy_setting }
|
|
451
|
-
end
|
|
452
|
-
|
|
453
|
-
context "when default is false and value is false for some time" do
|
|
454
|
-
let(:attempts) { [1, 10, false, false, false] }
|
|
455
|
-
let(:default) { false }
|
|
456
|
-
let(:constructor) { ->(default) { default || attempts.pop } }
|
|
457
|
-
|
|
458
|
-
it "expect to retry until non-false is present and then cache it" do
|
|
459
|
-
3.times { refute config.lazy_setting }
|
|
460
|
-
assert_equal 10, config.lazy_setting
|
|
461
|
-
assert_equal 10, config.lazy_setting
|
|
462
|
-
end
|
|
463
|
-
end
|
|
464
|
-
end
|
|
465
|
-
end
|
|
466
|
-
|
|
467
|
-
# @see https://github.com/karafka/karafka-core/issues/1
|
|
468
|
-
context "when methods defined on Object" do
|
|
469
|
-
before do
|
|
470
|
-
Object.class_eval do
|
|
471
|
-
def self.logger
|
|
472
|
-
raise
|
|
473
|
-
end
|
|
474
|
-
|
|
475
|
-
def logger
|
|
476
|
-
raise
|
|
477
|
-
end
|
|
478
|
-
end
|
|
479
|
-
|
|
480
|
-
configurable_class.configure
|
|
481
|
-
config.configure
|
|
482
|
-
end
|
|
483
|
-
|
|
484
|
-
after do
|
|
485
|
-
Object.remove_method(:logger)
|
|
486
|
-
Object.singleton_class.remove_method(:logger)
|
|
487
|
-
end
|
|
488
|
-
|
|
489
|
-
let(:configurable_class) do
|
|
490
|
-
Class.new do
|
|
491
|
-
include Karafka::Core::Configurable
|
|
492
|
-
|
|
493
|
-
setting(:logger, default: 123)
|
|
494
|
-
end
|
|
495
|
-
end
|
|
496
|
-
|
|
497
|
-
let(:configurable) { configurable_class.new }
|
|
498
|
-
let(:config) { configurable.config }
|
|
499
|
-
|
|
500
|
-
it "expect not to raise because it should redefine" do
|
|
501
|
-
assert_equal 123, config.logger
|
|
502
|
-
end
|
|
503
|
-
end
|
|
504
|
-
end
|