deimos-ruby 2.4.0.pre.beta1 → 2.4.0.pre.beta2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 597f226ba74e9b5acce2906ee0fea563a3ff2b7a5b47bef0d4e66d840410ed42
4
- data.tar.gz: 876b9a70bc598bb99084a0bad47d6285c728efa54d98346761346c4313dda968
3
+ metadata.gz: bc23c10fe732ab1eb2b6c0e2daf5bdb943a939510624b821456d0d383224f579
4
+ data.tar.gz: 84fdb7e495d76bb27b0592572f13249a7c8e28c3d123c68d15ac5d30ff883421
5
5
  SHA512:
6
- metadata.gz: 58d7dfcf2cfbbbda7c4ce3459931a89ba6bf6261f6bd4a2cdf1bc2de640200fdc2a9a36f0af414bbcfef3de45fe8b3053795cdd5b139cf10a747a16a82989ccc
7
- data.tar.gz: 35ab518ca7bcbc48d2810ec67ce30a9331816fdc08caa52c602406f6b79346f7bf806af3adc50b427e5d412ce478c55f5e29b49f0bc61f2c88dc1ca81b11f993
6
+ metadata.gz: 9b47d42b33e3c66ed3fd852570490e6a719d55c6709b706b38b58144a192b40a5edef6c6b5be516c89c3798069ea22f6be2134e1000f41ba3110f92b5face15d
7
+ data.tar.gz: 3fea215d836fbcc1e10df7971e7112194ada61a95dab4be1524cafc275d523b7ee186887298a0a89e162945aeaf2b83d5826031844e9b26dd25039d7797d6c75
data/README.md CHANGED
@@ -91,10 +91,11 @@ Currently we have the following possible schema backends:
91
91
  * Avro Schema Registry (use the Confluent Schema Registry)
92
92
  * Avro Validation (validate using an Avro schema but leave decoded - this is useful
93
93
  for unit testing and development)
94
+ * Protobuf Local (use pure Protobuf)
94
95
  * Protobuf Schema Registry (use Protobuf with the Confluent Schema Registry)
95
96
  * Mock (no actual encoding/decoding).
96
97
 
97
- Other possible schemas could [JSONSchema](https://json-schema.org/), etc. Feel free to
98
+ Other possible schemas could include [JSONSchema](https://json-schema.org/), etc. Feel free to
98
99
  contribute!
99
100
 
100
101
  To create a new schema backend, please see the existing examples [here](lib/deimos/schema_backends).
@@ -281,7 +282,7 @@ MyProducer.publish({
281
282
  ```
282
283
 
283
284
  > [!IMPORTANT]
284
- > Protobuf should *not* be used as a key schema, since the binary encoding is [unstable](https://protobuf.dev/programming-guides/encoding/#implications) and may break partitioning. Deimos will automatically convert key fields to plain values and key hashes to JSON.
285
+ > Protobuf should *not* be used as a key schema, since the binary encoding is [unstable](https://protobuf.dev/programming-guides/encoding/#implications) and may break partitioning. Deimos will automatically convert keys to sorted JSON, and will use JSON Schema in the schema registry.
285
286
 
286
287
  ## Instrumentation
287
288
 
@@ -1010,7 +1011,13 @@ end
1010
1011
  # test can have the same settings every time it is run
1011
1012
  after(:each) do
1012
1013
  Deimos.config.reset!
1013
- Deimos.config.schema.backend = :avro_validation
1014
+ # set specific settings here
1015
+ Deimos.config.schema.path = 'my/schema/path'
1016
+ end
1017
+
1018
+ around(:each) do |ex|
1019
+ # replace e.g. avro_schema_registry with avro_validation, proto_schema_registry with proto_local
1020
+ Deimos::TestHelpers.with_mock_backends { ex.run }
1014
1021
  end
1015
1022
  ```
1016
1023
 
@@ -38,10 +38,19 @@ module Deimos
38
38
  def add_fields(fields)
39
39
  return if @payload.to_h.with_indifferent_access.except(:payload_key, :partition_key).blank?
40
40
 
41
- if fields.include?('message_id')
41
+ if @payload.respond_to?(:message_id)
42
+ if fields.include?('message_id') && @payload.message_id.blank?
43
+ @payload.message_id = SecureRandom.uuid
44
+ end
45
+ elsif fields.include?('message_id')
42
46
  @payload['message_id'] ||= SecureRandom.uuid
43
47
  end
44
- if fields.include?('timestamp')
48
+
49
+ if @payload.respond_to?(:timestamp)
50
+ if fields.include?('timestamp') && @payload.timestamp.blank?
51
+ @payload.timestamp = Time.now.in_time_zone.to_s
52
+ end
53
+ elsif fields.include?('timestamp')
45
54
  @payload['timestamp'] ||= Time.now.in_time_zone.to_s
46
55
  end
47
56
  end
@@ -56,7 +56,7 @@ module Deimos
56
56
 
57
57
  # @param hash [Hash]
58
58
  # @return [String]
59
- def encode_proto_key(hash, topic: nil)
59
+ def encode_proto_key(hash, topic: nil, field: nil)
60
60
  hash.sort.to_h.to_json
61
61
  end
62
62
 
@@ -8,6 +8,11 @@ module Deimos
8
8
  # Encode / decode using the Protobuf schema registry.
9
9
  class ProtoSchemaRegistry < ProtoBase
10
10
 
11
+ # @override
12
+ def self.mock_backend
13
+ :proto_local
14
+ end
15
+
11
16
  # @override
12
17
  def decode_payload(payload, schema:)
13
18
  self.class.schema_registry.decode(payload)
@@ -50,6 +50,13 @@ module Deimos
50
50
  warn("unit_test! is deprecated and can be replaced by setting Deimos's schema backend " \
51
51
  'to `:avro_validation`. All other test behavior is provided by Karafka.')
52
52
  end
53
+
54
+ def with_mock_backends
55
+ Deimos.mock_backends = true
56
+ yield
57
+ Deimos.mock_backends = false
58
+ end
59
+
53
60
  end
54
61
 
55
62
  # get the difference of 2 hashes.
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Deimos
4
- VERSION = '2.4.0-beta1'
4
+ VERSION = '2.4.0-beta2'
5
5
  end
data/lib/deimos.rb CHANGED
@@ -54,6 +54,9 @@ module Deimos
54
54
 
55
55
  class << self
56
56
 
57
+ # @return [Boolean] for use in unit tests
58
+ attr_accessor :mock_backends
59
+
57
60
  # @param backend [Symbol, nil]
58
61
  # @return [Class<Deimos::SchemaBackends::Base>]
59
62
  def schema_backend_class(backend: nil)
@@ -61,7 +64,12 @@ module Deimos
61
64
 
62
65
  require "deimos/schema_backends/#{backend}"
63
66
 
64
- "Deimos::SchemaBackends::#{backend.to_s.classify}".constantize
67
+ klass = "Deimos::SchemaBackends::#{backend.to_s.classify}".constantize
68
+ if self.mock_backends
69
+ require "deimos/schema_backends/#{klass.mock_backend}"
70
+ klass = "Deimos::SchemaBackends::#{klass.mock_backend.to_s.classify}".constantize
71
+ end
72
+ klass
65
73
  end
66
74
 
67
75
  # @param schema [String, Symbol]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: deimos-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.4.0.pre.beta1
4
+ version: 2.4.0.pre.beta2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Orner