Skip to content

Commit

Permalink
Merge pull request #87 from flipp-oss/GH-50
Browse files Browse the repository at this point in the history
GH-50: Raise error if no topic is given while producing messages
  • Loading branch information
Daniel Orner committed Sep 16, 2020
2 parents d83a3ba + 99d30b3 commit 49b0924
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## UNRELEASED

### Fixes :wrench:
- Raise error if producing without a topic
(fixes [#50](https://github.com/flipp-oss/deimos/issues/50))


## 1.8.2-beta2 - 2020-09-15

### Features :star:
Expand Down
2 changes: 2 additions & 0 deletions lib/deimos/producer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ def publish_list(payloads, sync: nil, force_send: false, topic: self.topic)
Deimos.config.producers.disabled ||
Deimos.producers_disabled?(self)

raise 'Topic not specified. Please specify the topic.' if topic.blank?

backend_class = determine_backend_class(sync, force_send)
Deimos.instrument(
'encode_messages',
Expand Down
33 changes: 33 additions & 0 deletions spec/producer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,14 @@ def self.partition_key(payload)
end
stub_const('MyErrorProducer', producer_class)

producer_class = Class.new(Deimos::Producer) do
schema 'MySchema'
namespace 'com.my-namespace'
topic nil
key_config none: true
end
stub_const('MyNoTopicProducer', producer_class)

end

it 'should fail on invalid message with error handler' do
Expand Down Expand Up @@ -296,6 +304,31 @@ def self.partition_key(payload)
)
end

it 'should raise error if blank topic is passed in explicitly' do
expect {
MyProducer.publish_list(
[{ 'test_id' => 'foo',
'some_int' => 123 },
{ 'test_id' => 'bar',
'some_int' => 124 }],
topic: ''
)
}.to raise_error(RuntimeError,
'Topic not specified. Please specify the topic.')
end

it 'should raise error if the producer has not been initialized with a topic' do
expect {
MyNoTopicProducer.publish_list(
[{ 'test_id' => 'foo',
'some_int' => 123 },
{ 'test_id' => 'bar',
'some_int' => 124 }]
)
}.to raise_error(RuntimeError,
'Topic not specified. Please specify the topic.')
end

it 'should error with nothing set' do
expect {
MyErrorProducer.publish_list(
Expand Down

0 comments on commit 49b0924

Please sign in to comment.