deimos-ruby 1.8.1.pre.beta5 → 1.8.2.pre.beta1

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: 516d09f0dc29c3388d1885c67d7faf3c2f240eede7278ad1ac76dfa46727e4e7
4
- data.tar.gz: c9fcf141d5dfca3de041d82079f773c53b6a2f663fe7a8b3aa5fbee28964fb19
3
+ metadata.gz: ce4c0e112957a2a8983372b2eda22b139e1eadac18945d4cbd9945c31e181b9d
4
+ data.tar.gz: 43df5dcfd68305868cc2ac19f33c070bfc2d6b3c3679fc85116d81939e3a5ce2
5
5
  SHA512:
6
- metadata.gz: f4b5feee05510a8e6c9d85c9af85aff48f01c43419b5e5600a853d60a62d4b06f8430bb91b11047f6fd2579f23a89e8b9cbafe41a40ed84f7448a54b47115587
7
- data.tar.gz: e4c1a0b181f4e5289f995056338b78cab4a8da3cb50863e70ba9f78e8526e470a52a035eaa3a34a0261b1ad14dbff41d2e25a3ffff5e75218408e31aa94a9ed0
6
+ metadata.gz: ffdbf97e2ad36eafd643cf958b44990a16315da4d346e8b5aaa8dacbdf8d0caecfd493063305b888e240091ab26f5a39bf044b8c3919419f2a6c35c460d774f8
7
+ data.tar.gz: cb200f4a2d47519f2cb3f0f577a0295690842eb7a8367867749a3cc75236d7205eddb413cc22c28efba7b44b6c8d8a4a98744cd4d3adacedfbc2d64d690397d7
@@ -7,6 +7,32 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## UNRELEASED
9
9
 
10
+ ## 1.8.2-beta1 - 2020-09-09
11
+
12
+ ### Features :star:
13
+
14
+ - Added the ability to specify the topic for `publish`
15
+ and `publish_list` in a producer
16
+
17
+ ## 1.8.1-beta9 - 2020-08-27
18
+
19
+ ### Fixes :wrench:
20
+ - Moved the TestHelpers hook to `before(:suite)` to allow for
21
+ overriding e.g. in integration tests.
22
+
23
+ ## 1.8.1-beta7 - 2020-08-25
24
+
25
+ ### Fixes :wrench:
26
+ - Fix for crash when sending pending metrics with DB producer.
27
+ - Fix for compacting messages if all the keys are already unique
28
+ (fixes [#75](https://github.com/flipp-oss/deimos/issues/75))
29
+
30
+ ## 1.8.1-beta6 - 2020-08-13
31
+
32
+ ### Fixes :wrench:
33
+
34
+ - Fix for consuming nil payloads with Ruby 2.3.
35
+
10
36
  ## 1.8.1-beta5 - 2020-08-13
11
37
 
12
38
  ### Fixes :wrench:
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- deimos-ruby (1.8.1.pre.beta4)
4
+ deimos-ruby (1.8.2.pre.beta1)
5
5
  avro_turf (~> 0.11)
6
6
  phobos (~> 1.9)
7
7
  ruby-kafka (~> 0.7)
data/README.md CHANGED
@@ -108,6 +108,7 @@ class MyProducer < Deimos::Producer
108
108
  'some-key2' => an_object.bar
109
109
  }
110
110
  # You can also publish an array with self.publish_list(payloads)
111
+ # You may specify the topic here with self.publish(payload, topic: 'my-topic')
111
112
  self.publish(payload)
112
113
  end
113
114
 
@@ -921,6 +922,17 @@ Deimos::TestHelpers.schemas_compatible?(schema1, schema2)
921
922
 
922
923
  ### Integration Test Helpers
923
924
 
925
+ When running integration tests, you'll want to override the default test helper settings:
926
+
927
+ ```ruby
928
+ config.before(:each, :my_integration_metadata) do
929
+ Deimos.configure do
930
+ producers.backend :kafka
931
+ schema.backend :avro_schema_registry
932
+ end
933
+ end
934
+ ```
935
+
924
936
  You can use the `InlineConsumer` class to help with integration testing,
925
937
  with a full external Kafka running.
926
938
 
@@ -10,7 +10,7 @@ module Deimos
10
10
 
11
11
  # :nodoc:
12
12
  def around_consume(payload, metadata)
13
- decoded_payload = payload.dup
13
+ decoded_payload = payload.nil? ? nil : payload.dup
14
14
  new_metadata = metadata.dup
15
15
  benchmark = Benchmark.measure do
16
16
  _with_span do
@@ -87,8 +87,9 @@ module Deimos
87
87
 
88
88
  # Publish the payload to the topic.
89
89
  # @param payload [Hash] with an optional payload_key hash key.
90
- def publish(payload)
91
- publish_list([payload])
90
+ # @param topic [String] if specifying the topic
91
+ def publish(payload, topic: self.topic)
92
+ publish_list([payload], topic: topic)
92
93
  end
93
94
 
94
95
  # Publish a list of messages.
@@ -97,7 +98,8 @@ module Deimos
97
98
  # whether to publish synchronously.
98
99
  # @param force_send [Boolean] if true, ignore the configured backend
99
100
  # and send immediately to Kafka.
100
- def publish_list(payloads, sync: nil, force_send: false)
101
+ # @param topic [String] if specifying the topic
102
+ def publish_list(payloads, sync: nil, force_send: false, topic: self.topic)
101
103
  return if Deimos.config.kafka.seed_brokers.blank? ||
102
104
  Deimos.config.producers.disabled ||
103
105
  Deimos.producers_disabled?(self)
@@ -110,7 +112,7 @@ module Deimos
110
112
  payloads: payloads
111
113
  ) do
112
114
  messages = Array(payloads).map { |p| Deimos::Message.new(p, self) }
113
- messages.each(&method(:_process_message))
115
+ messages.each { |m| _process_message(m, topic) }
114
116
  messages.in_groups_of(MAX_BATCH_SIZE, false) do |batch|
115
117
  self.produce_batch(backend_class, batch)
116
118
  end
@@ -163,7 +165,8 @@ module Deimos
163
165
  private
164
166
 
165
167
  # @param message [Message]
166
- def _process_message(message)
168
+ # @param topic [String]
169
+ def _process_message(message, topic)
167
170
  # this violates the Law of Demeter but it has to happen in a very
168
171
  # specific order and requires a bunch of methods on the producer
169
172
  # to work correctly.
@@ -175,7 +178,7 @@ module Deimos
175
178
  message.payload = nil if message.payload.blank?
176
179
  message.coerce_fields(encoder)
177
180
  message.encoded_key = _encode_key(message.key)
178
- message.topic = self.topic
181
+ message.topic = topic
179
182
  message.encoded_payload = if message.payload.nil?
180
183
  nil
181
184
  else
@@ -30,18 +30,19 @@ module Deimos
30
30
  d_config.consumers.reraise_errors = true
31
31
  d_config.kafka.seed_brokers ||= ['test_broker']
32
32
  d_config.schema.backend = Deimos.schema_backend_class.mock_backend
33
+ d_config.producers.backend = :test
33
34
  end
34
35
  end
35
- end
36
36
 
37
- before(:each) do
38
- client = double('client').as_null_object
39
- allow(client).to receive(:time) do |*_args, &block|
40
- block.call
37
+ config.before(:each) do
38
+ client = double('client').as_null_object
39
+ allow(client).to receive(:time) do |*_args, &block|
40
+ block.call
41
+ end
42
+ Deimos::Backends::Test.sent_messages.clear
41
43
  end
42
- Deimos.configure { |c| c.producers.backend = :test }
43
- Deimos::Backends::Test.sent_messages.clear
44
44
  end
45
+
45
46
  end
46
47
 
47
48
  # @deprecated
@@ -161,7 +161,7 @@ module Deimos
161
161
  # the oldest message, or the last time we processed, whichever comes
162
162
  # last.
163
163
  if message_record
164
- record_earliest = record.earliest
164
+ record_earliest = message_record.earliest
165
165
  # SQLite gives a string here
166
166
  if record_earliest.is_a?(String)
167
167
  record_earliest = Time.zone.parse(record_earliest)
@@ -231,7 +231,7 @@ module Deimos
231
231
  return batch if config.compact_topics != :all &&
232
232
  !config.compact_topics.include?(topic)
233
233
 
234
- batch.reverse.uniq!(&:key).reverse!
234
+ batch.reverse.uniq(&:key).reverse!
235
235
  end
236
236
  end
237
237
  end
@@ -19,7 +19,7 @@ module Deimos
19
19
  offset = last_offset - num_messages
20
20
  if offset.positive?
21
21
  Deimos.config.logger.info("Seeking to #{offset}")
22
- @consumer.seek(topic, 0, offset)
22
+ @consumer.seek(topic, 1, offset)
23
23
  end
24
24
  rescue StandardError => e
25
25
  "Could not seek to offset: #{e.message}"
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Deimos
4
- VERSION = '1.8.1-beta5'
4
+ VERSION = '1.8.2-beta1'
5
5
  end
@@ -32,6 +32,12 @@ module ConsumerTest
32
32
  end
33
33
  end
34
34
 
35
+ it 'should consume a nil message' do
36
+ test_consume_message(MyConsumer, nil) do |payload, _metadata|
37
+ expect(payload).to be_nil
38
+ end
39
+ end
40
+
35
41
  it 'should consume a message idempotently' do
36
42
  # testing for a crash and re-consuming the same message/metadata
37
43
  key = { 'test_id' => 'foo' }
@@ -102,6 +102,33 @@ module ProducerTest
102
102
  expect('my-topic').not_to have_sent('test_id' => 'foo2', 'some_int' => 123)
103
103
  end
104
104
 
105
+ it 'should allow setting the topic from publish_list' do
106
+ expect(described_class).to receive(:produce_batch).once.with(
107
+ Deimos::Backends::Test,
108
+ [
109
+ Deimos::Message.new({ 'test_id' => 'foo', 'some_int' => 123 },
110
+ MyProducer,
111
+ topic: 'a-new-topic',
112
+ partition_key: 'foo',
113
+ key: 'foo'),
114
+ Deimos::Message.new({ 'test_id' => 'bar', 'some_int' => 124 },
115
+ MyProducer,
116
+ topic: 'a-new-topic',
117
+ partition_key: 'bar',
118
+ key: 'bar')
119
+ ]
120
+ ).and_call_original
121
+
122
+ MyProducer.publish_list(
123
+ [{ 'test_id' => 'foo', 'some_int' => 123 },
124
+ { 'test_id' => 'bar', 'some_int' => 124 }],
125
+ topic: 'a-new-topic'
126
+ )
127
+ expect('a-new-topic').to have_sent('test_id' => 'foo', 'some_int' => 123)
128
+ expect('my-topic').not_to have_sent('test_id' => 'foo', 'some_int' => 123)
129
+ expect('my-topic').not_to have_sent('test_id' => 'foo2', 'some_int' => 123)
130
+ end
131
+
105
132
  it 'should add a message ID' do
106
133
  payload = { 'test_id' => 'foo',
107
134
  'some_int' => 123,
@@ -183,6 +183,7 @@ RSpec.configure do |config|
183
183
  config.before(:each) do
184
184
  Deimos.config.reset!
185
185
  Deimos.configure do |deimos_config|
186
+ deimos_config.producers.backend = :test
186
187
  deimos_config.phobos_config_file = File.join(File.dirname(__FILE__), 'phobos.yml')
187
188
  deimos_config.schema.path = File.join(File.expand_path(__dir__), 'schemas')
188
189
  deimos_config.consumers.reraise_errors = true
@@ -155,6 +155,10 @@ each_db_config(Deimos::Utils::DbProducer) do
155
155
  Deimos.configure { |c| c.db_producer.compact_topics = [] }
156
156
  end
157
157
 
158
+ it 'should compact messages when all messages are unique' do
159
+ Deimos.configure { |c| c.db_producer.compact_topics = %w(my-topic my-topic2) }
160
+ expect(producer.compact_messages(deduped_batch)).to eq(deduped_batch)
161
+ end
158
162
  end
159
163
  end
160
164
 
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.8.1.pre.beta5
4
+ version: 1.8.2.pre.beta1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Orner
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-08-13 00:00:00.000000000 Z
11
+ date: 2020-09-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: avro_turf