karafka-testing 2.0.3 → 2.0.4

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: c7a7e11e7f5ba273fc7875d3c20bd2b1457d46f315f168e933f1f48f82f6bbf6
4
- data.tar.gz: 0ac2a1804d0b7e94cfd409763edd8ced61dd64fdde2219d9d42a375f9a21542a
3
+ metadata.gz: 560aa633f1c2710d530871e4194d0cb631540c2844a97207b05bfe7297dba13a
4
+ data.tar.gz: 6fb1dbb71bbb69f427356ee78b9ddc9fdeee83a9105564d7d9798ba6da3c6a70
5
5
  SHA512:
6
- metadata.gz: 38d9372fcf299860d91efe18061ed219583a95fb1955a4817536a9fe4ae5ac6e9f86fc4e92c35c02a256cf9b9a1162f0a2cd54c17d6dd48b503f9a36c1d2be6c
7
- data.tar.gz: fa0f0e8395e9fc00b155074a5e0059ad8dc4aecf0f9e93b0edaf6806574a873e17e183ad8bbede526237e3dcd321b378664252755d05d82204329c3351361861
6
+ metadata.gz: 0d0f3c2504f22eb9d3d36ba620b5e4f439c97d19b5607931a32a8bbbdf014a1cc772e0436d889e7536006c46b53239b248c44bfc230a0b69ae6d5c91b2e623ce
7
+ data.tar.gz: 67f249bfd323f1c5f27bc97f78e33701a5cf6d42715c11e0b146857bf90ef7f00f307e4d1cb9e186947390c9fdff2bf98453fcc9483192a4a491a026d420e2f2
checksums.yaml.gz.sig CHANGED
Binary file
data/CHANGELOG.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # Karafka Test gem changelog
2
2
 
3
+ ## 2.0.4 (2022-10-14)
4
+ - Align changes with Karafka `2.0.13` changes.
5
+
3
6
  ## 2.0.3 (2022-09-30)
4
7
  - Fix direct name reference `consumer` instead of `subject` (#97).
5
8
 
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- karafka-testing (2.0.3)
4
+ karafka-testing (2.0.4)
5
5
  karafka (>= 2.0, < 3.0.0)
6
6
 
7
7
  GEM
@@ -9,13 +9,13 @@ GEM
9
9
  specs:
10
10
  concurrent-ruby (1.1.10)
11
11
  ffi (1.15.5)
12
- karafka (2.0.11)
12
+ karafka (2.0.13)
13
13
  karafka-core (>= 2.0.2, < 3.0.0)
14
14
  rdkafka (>= 0.12)
15
15
  thor (>= 0.20)
16
16
  waterdrop (>= 2.4.1, < 3.0.0)
17
17
  zeitwerk (~> 2.3)
18
- karafka-core (2.0.2)
18
+ karafka-core (2.0.3)
19
19
  concurrent-ruby (>= 1.1)
20
20
  mini_portile2 (2.8.0)
21
21
  rake (13.0.6)
@@ -28,7 +28,7 @@ GEM
28
28
  karafka-core (>= 2.0.2, < 3.0.0)
29
29
  rdkafka (>= 0.10)
30
30
  zeitwerk (~> 2.3)
31
- zeitwerk (2.6.0)
31
+ zeitwerk (2.6.1)
32
32
 
33
33
  PLATFORMS
34
34
  x86_64-linux
data/README.md CHANGED
@@ -6,114 +6,9 @@
6
6
 
7
7
  Karafka-Testing is a library that provides RSpec helpers, to make testing of Karafka consumers and producer much easier.
8
8
 
9
- ## Installation
9
+ ## Installation and usage
10
10
 
11
- Add this gem to your Gemfile in the `test` group:
12
- ```ruby
13
- group :test do
14
- gem 'karafka-testing'
15
- gem 'rspec'
16
- end
17
- ```
18
-
19
- and then in your `spec_helper.rb` file:
20
-
21
- ```ruby
22
- require 'karafka/testing/rspec/helpers'
23
-
24
- RSpec.configure do |config|
25
- config.include Karafka::Testing::RSpec::Helpers
26
- end
27
- ```
28
-
29
- ## Usage
30
-
31
- Once included in your RSpec setup, this library will provide you with a special `#karafka` object that contains three methods that you can use within your specs:
32
-
33
- - `#consumer_for` - creates a consumer instance for the desired topic. It **needs** to be set as the spec subject.
34
- - `#produce` - "sends" message to the consumer instance.
35
- - `#produced_messages` - contains all the messages "sent" to Kafka during spec execution.
36
-
37
- **Note:** Messages sent using the `#produce` method and directly from `Karafka.producer` won't be sent to Kafka. They will be buffered and accessible in a per-spec buffer in case you want to test messages production.
38
-
39
- Messages that target the topic built using the `karafka#consumer_for` method will additionally be delivered to the consumer you want to test.
40
-
41
- ### Testing messages consumption (consumers)
42
-
43
- ```ruby
44
- RSpec.describe InlineBatchConsumer do
45
- # This will create a consumer instance with all the settings defined for the given topic
46
- subject(:consumer) { karafka.consumer_for('inline_batch_data') }
47
-
48
- let(:nr1_value) { rand }
49
- let(:nr2_value) { rand }
50
- let(:sum) { nr1_value + nr2_value }
51
-
52
- before do
53
- # Sends first message to Karafka consumer
54
- karafka.produce({ 'number' => nr1_value }.to_json)
55
-
56
- # Sends second message to Karafka consumer
57
- karafka.produce({ 'number' => nr2_value }.to_json, partition: 2)
58
-
59
- allow(Karafka.logger).to receive(:info)
60
- end
61
-
62
- it 'expects to log a proper message' do
63
- expect(Karafka.logger).to receive(:info).with("Sum of 2 elements equals to: #{sum}")
64
- consumer.consume
65
- end
66
- end
67
- ```
68
-
69
- If your consumers use `producer` to dispatch messages, you can check its operations as well:
70
-
71
- ```ruby
72
- RSpec.describe InlineBatchConsumer do
73
- subject(:consumer) { karafka.consumer_for(:inline_batch_data) }
74
-
75
- before { karafka.produce({ 'number' => 1 }.to_json) }
76
-
77
- it 'expects to dispatch async message to messages topic with value bigger by 1' do
78
- consumer.consume
79
-
80
- expect(karafka.produced_messages.last.payload).to eq({ number: 2 }.to_json)
81
- end
82
- end
83
- ```
84
-
85
- ### Testing messages production (producer)
86
-
87
- When running RSpec, Karafka will not dispatch messages to Kafka using `Karafka.producer` but will buffer them internally.
88
-
89
- This means you can check your application flow, making sure your logic acts as expected:
90
-
91
- ```ruby
92
- # Example class in which there is a message production
93
- class UsersBuilder
94
- def create(user_details)
95
- user = ::User.create!(user_details)
96
-
97
- Karafka.producer.produce_sync(
98
- topic: 'users_changes',
99
- payload: { user_id: user.id, type: 'user.created' },
100
- key: user.id.to_s
101
- )
102
-
103
- user
104
- end
105
- end
106
-
107
- RSpec.describe InlineBatchConsumer do
108
- let(:created_user) { UsersBuilder.new.create(user_details) }
109
-
110
- before { created_user }
111
-
112
- it { expect(karafka.produced_messages.size).to eq(1) }
113
- it { expect(karafka.produced_messages.first[:topic]).to eq('user.created') }
114
- it { expect(karafka.produced_messages.first[:key]).to eq(created_user.id.to_s) }
115
- end
116
- ```
11
+ `karafka-testing` docs are part of Karafka framework docs. You can find the testing section [here](https://karafka.io/docs/Testing/).
117
12
 
118
13
  ## Note on contributions
119
14
 
@@ -163,6 +163,7 @@ module Karafka
163
163
  consumer.producer = Karafka::App.producer
164
164
  consumer.client = _karafka_consumer_client
165
165
  consumer.coordinator = coordinators.find_or_create(topic.name, 0)
166
+ consumer.coordinator.seek_offset = 0
166
167
  consumer
167
168
  end
168
169
  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.0.3'
7
+ VERSION = '2.0.4'
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.0.3
4
+ version: 2.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Maciej Mensfeld
@@ -35,7 +35,7 @@ cert_chain:
35
35
  Qf04B9ceLUaC4fPVEz10FyobjaFoY4i32xRto3XnrzeAgfEe4swLq8bQsR3w/EF3
36
36
  MGU0FeSV2Yj7Xc2x/7BzLK8xQn5l7Yy75iPF+KP3vVmDHnNl
37
37
  -----END CERTIFICATE-----
38
- date: 2022-09-30 00:00:00.000000000 Z
38
+ date: 2022-10-14 00:00:00.000000000 Z
39
39
  dependencies:
40
40
  - !ruby/object:Gem::Dependency
41
41
  name: karafka
metadata.gz.sig CHANGED
Binary file