deimos-ruby 1.11.0 → 1.11.1
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/CHANGELOG.md +2 -2
- data/Gemfile.lock +1 -1
- data/README.md +53 -66
- data/lib/deimos/active_record_consume/batch_consumption.rb +4 -6
- data/lib/deimos/schema_backends/avro_schema_registry.rb +1 -1
- data/lib/deimos/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4c2fe121d207349905ce908ee4bdb3a2d420a545135c25b47aa4c99e5b5153ef
|
4
|
+
data.tar.gz: e28688edca132bd6d67ad4414d5e3616eb2f217274a6c27dd701816520241a76
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7ab87d73ff46dcbf415f65579f3a13202f9e7d0e61918672ef0f9e100babbeb4a27bfd1dce791bf5f36d38cea775881bd38ef424df8317cfaf440ce5b44414ed
|
7
|
+
data.tar.gz: 252d9a2a0e65a78c3faa5b420a1504230cd7d621714387930b369183724c33936240ec534181df024e6d4b5688ba8bca6bae2e0ca1572487dd1aadaf1960b97d
|
data/CHANGELOG.md
CHANGED
@@ -7,10 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
7
7
|
|
8
8
|
## UNRELEASED
|
9
9
|
|
10
|
-
## 1.11.
|
10
|
+
## 1.11.1 - 2021-08-27
|
11
11
|
|
12
12
|
- ### Fixes :wrench:
|
13
|
-
- Fixed issue where ActiveRecord batch consumption
|
13
|
+
- Fixed issue where ActiveRecord batch consumption would try to decode keys twice.
|
14
14
|
|
15
15
|
- ### Roadmap :car:
|
16
16
|
- TestHelper does not automatically reset Deimos config before each test. [#120](https://github.com/flipp-oss/deimos/pull/120).
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -880,8 +880,7 @@ Also see [deimos.rb](lib/deimos.rb) under `Configure tracing` to see how the tra
|
|
880
880
|
|
881
881
|
# Testing
|
882
882
|
|
883
|
-
Deimos comes with a test helper class which
|
884
|
-
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.
|
885
884
|
|
886
885
|
In `spec_helper.rb`:
|
887
886
|
```ruby
|
@@ -890,7 +889,56 @@ RSpec.configure do |config|
|
|
890
889
|
end
|
891
890
|
```
|
892
891
|
|
893
|
-
|
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:
|
894
942
|
```ruby
|
895
943
|
# Pass a consumer class (not instance) to validate a payload against it.
|
896
944
|
# This will fail if the payload does not match the schema the consumer
|
@@ -938,6 +986,8 @@ expect(message).to eq({
|
|
938
986
|
})
|
939
987
|
```
|
940
988
|
|
989
|
+
### Test Utilities
|
990
|
+
|
941
991
|
There is also a helper method that will let you test if an existing schema
|
942
992
|
would be compatible with a new version of it. You can use this in your
|
943
993
|
Ruby console but it would likely not be part of your RSpec test:
|
@@ -947,69 +997,6 @@ require 'deimos/test_helpers'
|
|
947
997
|
# Can pass a file path, a string or a hash into this:
|
948
998
|
Deimos::TestHelpers.schemas_compatible?(schema1, schema2)
|
949
999
|
```
|
950
|
-
### Test Helpers
|
951
|
-
|
952
|
-
There are helper methods available to configure Deimos for different types of testing scenarios.
|
953
|
-
Currently there are helpers defined for unit tests and for testing Kafka related code. You can use it as follows:
|
954
|
-
|
955
|
-
```ruby
|
956
|
-
# The following can be added to a rpsec file so that each unit
|
957
|
-
# test can have the same settings every time it is run
|
958
|
-
around(:each) do |example|
|
959
|
-
Deimos::TestHelpers.unit_test!
|
960
|
-
example.run
|
961
|
-
Deimos.config.reset!
|
962
|
-
end
|
963
|
-
|
964
|
-
# Similarly you can use the Kafka test helper
|
965
|
-
around(:each) do |example|
|
966
|
-
Deimos::TestHelpers.kafka_test!
|
967
|
-
example.run
|
968
|
-
Deimos.config.reset!
|
969
|
-
end
|
970
|
-
|
971
|
-
# Kakfa test helper using schema registry
|
972
|
-
around(:each) do |example|
|
973
|
-
Deimos::TestHelpers.full_integration_test!
|
974
|
-
example.run
|
975
|
-
Deimos.config.reset!
|
976
|
-
end
|
977
|
-
```
|
978
|
-
|
979
|
-
With the help of these helper methods, rspec examples can be written without having to tinker with Deimos settings.
|
980
|
-
This also prevents Deimos setting changes from leaking in to other examples.
|
981
|
-
|
982
|
-
This does not take away the ability to configure Deimos manually in individual examples. Deimos can still be configured like so:
|
983
|
-
```ruby
|
984
|
-
it 'should not fail this random test' do
|
985
|
-
|
986
|
-
Deimos.configure do |config|
|
987
|
-
config.consumers.fatal_error = proc { true }
|
988
|
-
config.consumers.reraise_errors = false
|
989
|
-
end
|
990
|
-
...
|
991
|
-
expect(some_object).to be_truthy
|
992
|
-
...
|
993
|
-
Deimos.config.reset!
|
994
|
-
end
|
995
|
-
```
|
996
|
-
If you are using one of the test helpers in an `around(:each)` block and want to override few settings for one example,
|
997
|
-
you can do it like in the example shown above. These settings would only apply to that specific example and the Deimos conifg should
|
998
|
-
reset once the example has finished running.
|
999
|
-
|
1000
|
-
|
1001
|
-
### Integration Test Helpers
|
1002
|
-
|
1003
|
-
When running integration tests, you'll want to override the default test helper settings:
|
1004
|
-
|
1005
|
-
```ruby
|
1006
|
-
config.before(:each, :my_integration_metadata) do
|
1007
|
-
Deimos.configure do
|
1008
|
-
producers.backend :kafka
|
1009
|
-
schema.backend :avro_schema_registry
|
1010
|
-
end
|
1011
|
-
end
|
1012
|
-
```
|
1013
1000
|
|
1014
1001
|
You can use the `InlineConsumer` class to help with integration testing,
|
1015
1002
|
with a full external Kafka running.
|
@@ -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
|
|
data/lib/deimos/version.rb
CHANGED