deimos-ruby 1.10.1 → 1.11.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +16 -0
- data/Gemfile.lock +1 -1
- data/README.md +54 -16
- data/lib/deimos/active_record_consume/batch_consumption.rb +8 -6
- data/lib/deimos/test_helpers.rb +27 -10
- data/lib/deimos/utils/db_producer.rb +2 -1
- data/lib/deimos/version.rb +1 -1
- data/spec/utils/db_producer_spec.rb +2 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a5424d471910dffc66acead04734420173b69b41dae286fac03edb60825936fe
|
4
|
+
data.tar.gz: fe424e2929984d971cb1f48cd88e6a1d78c83783c0b81fd8b8376571ebcf5634
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9a5f53681cc8fdc79c39c2b42ae11c40f44246ffdf7bcfaeff6dac7b5b1e0cd21de4bc4a931615c1c4c944c0516dcc663a4638ad90d8e8ddf2a4ae9669b4fadc
|
7
|
+
data.tar.gz: fc21c854ebebce35ab5ecf7a113ca24d7ba4c1a0a880dc225d53b3fdf99823f9a1b06a039159a1a0fe0b7acedd45eec29f3b84af09a847efb329b03eef9f46bd
|
data/CHANGELOG.md
CHANGED
@@ -7,6 +7,22 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
7
7
|
|
8
8
|
## UNRELEASED
|
9
9
|
|
10
|
+
## 1.11.2 - 2021-08-27
|
11
|
+
|
12
|
+
- ### Fixes :wrench:
|
13
|
+
- Fixed ActiveRecord batch consumption on MySQL.
|
14
|
+
|
15
|
+
- ### Roadmap :car:
|
16
|
+
- TestHelper does not automatically reset Deimos config before each test. [#120](https://github.com/flipp-oss/deimos/pull/120).
|
17
|
+
**Please note that this is a breaking change**
|
18
|
+
|
19
|
+
|
20
|
+
## 1.10.2 - 2021-07-20
|
21
|
+
|
22
|
+
- ### Fixes :wrench:
|
23
|
+
|
24
|
+
- Fixed issue where producers would stay in an error state after e.g. authorization failures for one topic that wouldn't apply to other topics.
|
25
|
+
|
10
26
|
## 1.10.1 - 2021-06-21
|
11
27
|
|
12
28
|
- ### Fixes :wrench:
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -29,6 +29,7 @@ Built on Phobos and hence Ruby-Kafka.
|
|
29
29
|
* [Running Consumers](#running-consumers)
|
30
30
|
* [Metrics](#metrics)
|
31
31
|
* [Testing](#testing)
|
32
|
+
* [Test Helpers](#test-helpers)
|
32
33
|
* [Integration Test Helpers](#integration-test-helpers)
|
33
34
|
* [Utilities](#utilities)
|
34
35
|
* [Contributing](#contributing)
|
@@ -879,8 +880,7 @@ Also see [deimos.rb](lib/deimos.rb) under `Configure tracing` to see how the tra
|
|
879
880
|
|
880
881
|
# Testing
|
881
882
|
|
882
|
-
Deimos comes with a test helper class which
|
883
|
-
to mock versions, and provides useful methods for testing consumers.
|
883
|
+
Deimos comes with a test helper class which provides useful methods for testing consumers.
|
884
884
|
|
885
885
|
In `spec_helper.rb`:
|
886
886
|
```ruby
|
@@ -889,7 +889,56 @@ RSpec.configure do |config|
|
|
889
889
|
end
|
890
890
|
```
|
891
891
|
|
892
|
-
|
892
|
+
## Test Configuration
|
893
|
+
|
894
|
+
```ruby
|
895
|
+
# The following can be added to a rpsec file so that each unit
|
896
|
+
# test can have the same settings every time it is run
|
897
|
+
around(:each) do |example|
|
898
|
+
Deimos::TestHelpers.unit_test!
|
899
|
+
example.run
|
900
|
+
Deimos.config.reset!
|
901
|
+
end
|
902
|
+
|
903
|
+
# Similarly you can use the Kafka test helper
|
904
|
+
around(:each) do |example|
|
905
|
+
Deimos::TestHelpers.kafka_test!
|
906
|
+
example.run
|
907
|
+
Deimos.config.reset!
|
908
|
+
end
|
909
|
+
|
910
|
+
# Kakfa test helper using schema registry
|
911
|
+
around(:each) do |example|
|
912
|
+
Deimos::TestHelpers.full_integration_test!
|
913
|
+
example.run
|
914
|
+
Deimos.config.reset!
|
915
|
+
end
|
916
|
+
```
|
917
|
+
|
918
|
+
With the help of these helper methods, rspec examples can be written without having to tinker with Deimos settings.
|
919
|
+
This also prevents Deimos setting changes from leaking in to other examples.
|
920
|
+
|
921
|
+
This does not take away the ability to configure Deimos manually in individual examples. Deimos can still be configured like so:
|
922
|
+
```ruby
|
923
|
+
it 'should not fail this random test' do
|
924
|
+
|
925
|
+
Deimos.configure do |config|
|
926
|
+
config.consumers.fatal_error = proc { true }
|
927
|
+
config.consumers.reraise_errors = false
|
928
|
+
end
|
929
|
+
...
|
930
|
+
expect(some_object).to be_truthy
|
931
|
+
...
|
932
|
+
Deimos.config.reset!
|
933
|
+
end
|
934
|
+
```
|
935
|
+
If you are using one of the test helpers in an `around(:each)` block and want to override few settings for one example,
|
936
|
+
you can do it like in the example shown above. These settings would only apply to that specific example and the Deimos config should
|
937
|
+
reset once the example has finished running.
|
938
|
+
|
939
|
+
## Test Usage
|
940
|
+
|
941
|
+
In your tests, you now have the following methods available:
|
893
942
|
```ruby
|
894
943
|
# Pass a consumer class (not instance) to validate a payload against it.
|
895
944
|
# This will fail if the payload does not match the schema the consumer
|
@@ -937,6 +986,8 @@ expect(message).to eq({
|
|
937
986
|
})
|
938
987
|
```
|
939
988
|
|
989
|
+
### Test Utilities
|
990
|
+
|
940
991
|
There is also a helper method that will let you test if an existing schema
|
941
992
|
would be compatible with a new version of it. You can use this in your
|
942
993
|
Ruby console but it would likely not be part of your RSpec test:
|
@@ -947,19 +998,6 @@ require 'deimos/test_helpers'
|
|
947
998
|
Deimos::TestHelpers.schemas_compatible?(schema1, schema2)
|
948
999
|
```
|
949
1000
|
|
950
|
-
### Integration Test Helpers
|
951
|
-
|
952
|
-
When running integration tests, you'll want to override the default test helper settings:
|
953
|
-
|
954
|
-
```ruby
|
955
|
-
config.before(:each, :my_integration_metadata) do
|
956
|
-
Deimos.configure do
|
957
|
-
producers.backend :kafka
|
958
|
-
schema.backend :avro_schema_registry
|
959
|
-
end
|
960
|
-
end
|
961
|
-
```
|
962
|
-
|
963
1001
|
You can use the `InlineConsumer` class to help with integration testing,
|
964
1002
|
with a full external Kafka running.
|
965
1003
|
|
@@ -44,14 +44,12 @@ module Deimos
|
|
44
44
|
# @param key [String] The encoded key.
|
45
45
|
# @return [Hash] The key attributes.
|
46
46
|
def record_key(key)
|
47
|
-
|
48
|
-
|
49
|
-
if decoded_key.nil?
|
47
|
+
if key.nil?
|
50
48
|
{}
|
51
|
-
elsif
|
52
|
-
@key_converter.convert(
|
49
|
+
elsif key.is_a?(Hash)
|
50
|
+
@key_converter.convert(key)
|
53
51
|
else
|
54
|
-
{ @klass.primary_key =>
|
52
|
+
{ @klass.primary_key => key }
|
55
53
|
end
|
56
54
|
end
|
57
55
|
|
@@ -102,6 +100,10 @@ module Deimos
|
|
102
100
|
|
103
101
|
options = if key_cols.empty?
|
104
102
|
{} # Can't upsert with no key, just do regular insert
|
103
|
+
elsif ActiveRecord::Base.connection.adapter_name =~ /mysql/i
|
104
|
+
{
|
105
|
+
on_duplicate_key_update: :all
|
106
|
+
}
|
105
107
|
else
|
106
108
|
{
|
107
109
|
on_duplicate_key_update: {
|
data/lib/deimos/test_helpers.rb
CHANGED
@@ -18,22 +18,39 @@ module Deimos
|
|
18
18
|
def sent_messages
|
19
19
|
Deimos::Backends::Test.sent_messages
|
20
20
|
end
|
21
|
+
|
22
|
+
# Set the config to the right settings for a unit test
|
23
|
+
def unit_test!
|
24
|
+
Deimos.configure do |deimos_config|
|
25
|
+
deimos_config.logger = Logger.new(STDOUT)
|
26
|
+
deimos_config.consumers.reraise_errors = true
|
27
|
+
deimos_config.kafka.seed_brokers ||= ['test_broker']
|
28
|
+
deimos_config.schema.backend = Deimos.schema_backend_class.mock_backend
|
29
|
+
deimos_config.producers.backend = :test
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
# Kafka test config with avro schema registry
|
34
|
+
def full_integration_test!
|
35
|
+
Deimos.configure do |deimos_config|
|
36
|
+
deimos_config.producers.backend = :kafka
|
37
|
+
deimos_config.schema.backend = :avro_schema_registry
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
# Set the config to the right settings for a kafka test
|
42
|
+
def kafka_test!
|
43
|
+
Deimos.configure do |deimos_config|
|
44
|
+
deimos_config.producers.backend = :kafka
|
45
|
+
deimos_config.schema.backend = :avro_validation
|
46
|
+
end
|
47
|
+
end
|
21
48
|
end
|
22
49
|
|
23
50
|
included do
|
24
51
|
|
25
52
|
RSpec.configure do |config|
|
26
53
|
|
27
|
-
config.before(:suite) do
|
28
|
-
Deimos.configure do |d_config|
|
29
|
-
d_config.logger = Logger.new(STDOUT)
|
30
|
-
d_config.consumers.reraise_errors = true
|
31
|
-
d_config.kafka.seed_brokers ||= ['test_broker']
|
32
|
-
d_config.schema.backend = Deimos.schema_backend_class.mock_backend
|
33
|
-
d_config.producers.backend = :test
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
54
|
config.prepend_before(:each) do
|
38
55
|
client = double('client').as_null_object
|
39
56
|
allow(client).to receive(:time) do |*_args, &block|
|
@@ -60,7 +60,7 @@ module Deimos
|
|
60
60
|
end
|
61
61
|
|
62
62
|
# @param topic [String]
|
63
|
-
# @return [String] the topic that was locked, or nil if none were.
|
63
|
+
# @return [String, nil] the topic that was locked, or nil if none were.
|
64
64
|
def process_topic(topic)
|
65
65
|
# If the topic is already locked, another producer is currently
|
66
66
|
# working on it. Move on to the next one.
|
@@ -76,6 +76,7 @@ module Deimos
|
|
76
76
|
rescue StandardError => e
|
77
77
|
@logger.error("Error processing messages for topic #{@current_topic}: #{e.class.name}: #{e.message} #{e.backtrace.join("\n")}")
|
78
78
|
KafkaTopicInfo.register_error(@current_topic, @id)
|
79
|
+
shutdown_producer
|
79
80
|
end
|
80
81
|
|
81
82
|
# Process a single batch in a topic.
|
data/lib/deimos/version.rb
CHANGED
@@ -262,11 +262,13 @@ each_db_config(Deimos::Utils::DbProducer) do
|
|
262
262
|
end
|
263
263
|
|
264
264
|
it 'should register an error if it gets an error' do
|
265
|
+
allow(producer).to receive(:shutdown_producer)
|
265
266
|
expect(producer).to receive(:retrieve_messages).and_raise('OH NOES')
|
266
267
|
expect(Deimos::KafkaTopicInfo).to receive(:register_error).
|
267
268
|
with('my-topic', 'abc')
|
268
269
|
expect(producer).not_to receive(:produce_messages)
|
269
270
|
producer.process_topic('my-topic')
|
271
|
+
expect(producer).to have_received(:shutdown_producer)
|
270
272
|
end
|
271
273
|
|
272
274
|
it 'should move on if it gets a partial batch' do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: deimos-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.11.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Orner
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-08-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: avro_turf
|