fastly_nsq 0.5.1 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6b814efb023751a7379ea0190cbff20bd92eb082
4
- data.tar.gz: b750d879dc3b688c4b3286294b373e02ae576db8
3
+ metadata.gz: 912a3507f9a1f2aa279cae728bbfef969339efa4
4
+ data.tar.gz: 58b52a9f841f21cd58385b87e81e9a73a7397648
5
5
  SHA512:
6
- metadata.gz: 34d1cd71cd955642569c2228f70bf78f8e15b14c599f6527e30078cd8fbc4dc4e9db8d29928085fb24f5610dc903a791fb665889e6e833e5bd073359045f9ade
7
- data.tar.gz: f226f49a4282418dcd558ad9207a11647e03b9d2ea791844e682d5303a9b40e8106ac8b4f9428e4195aac1911c1284a2e922cea8785d3cc26e8f11d0565ac1ac
6
+ metadata.gz: c4b5b7230487629c39cfc004f5f0cdac24c2912bbefc8f4938a38ca1d975fccf320f7347c210b769fb8b00bfe4d28461dabc9824fce2dc8fd2ea11063a3a6a7b
7
+ data.tar.gz: dedc25afac6237e9efc24ce889e57d5fa3b27fc658bd36d92cccb3207064fd6582d21def6580707cb0dfd0682f9b5c1b2d05b79b43130965f28605e1cee1bb85
data/README.md CHANGED
@@ -60,7 +60,7 @@ message_data = {
60
60
  producer = MessageQueue::Producer.new(
61
61
  nsqd: ENV.fetch('NSQD_TCP_ADDRESS'),
62
62
  topic: topic,
63
- ).connection
63
+ )
64
64
 
65
65
  producer.write(message_data.to_json)
66
66
  ```
data/Rakefile CHANGED
@@ -11,7 +11,7 @@ end
11
11
  require 'rake'
12
12
 
13
13
  require 'rubygems/tasks'
14
- Gem::Tasks.new scm: {status: false, tag: false}
14
+ Gem::Tasks.new
15
15
 
16
16
  require 'rdoc/task'
17
17
  RDoc::Task.new
@@ -32,7 +32,7 @@ module FakeMessageQueue
32
32
  end
33
33
 
34
34
  class Producer
35
- def initialize(nsqd:, topic:, ssl_context: nil)
35
+ def initialize(topic:, nsqd: nil, ssl_context: nil)
36
36
  end
37
37
 
38
38
  def write(string)
@@ -1,32 +1,33 @@
1
+ require 'forwardable'
2
+
1
3
  class InvalidParameterError < StandardError; end
2
4
 
3
5
  module MessageQueue
4
6
  class Producer
5
- def initialize(topic:, ssl_context: nil)
6
- @topic = topic
7
- @ssl_context = SSLContext.new(ssl_context)
8
- end
7
+ extend Forwardable
8
+ def_delegator :connection, :terminate
9
+ def_delegator :connection, :write
9
10
 
10
- def connection
11
- @producer ||= producer.new(params)
12
- end
13
-
14
- def terminate
15
- @producer.terminate
11
+ def initialize(topic:, ssl_context: nil, connector: nil)
12
+ @topic = topic
13
+ @ssl_context = SSLContext.new(ssl_context)
14
+ @connector = connector || DEFAULT_CONNECTOR
16
15
  end
17
16
 
18
17
  private
19
18
 
20
- attr_reader :topic, :ssl_context
19
+ DEFAULT_CONNECTOR = ->(params) { MessageQueue.strategy::Producer.new params }
21
20
 
22
- def producer
23
- MessageQueue.strategy::Producer
21
+ attr_reader :connector, :topic, :ssl_context
22
+
23
+ def connection
24
+ @connection ||= connector.call(params)
24
25
  end
25
26
 
26
27
  def params
27
28
  {
28
- nsqd: ENV.fetch('NSQD_TCP_ADDRESS'),
29
- topic: topic,
29
+ nsqd: ENV.fetch('NSQD_TCP_ADDRESS'),
30
+ topic: topic,
30
31
  ssl_context: ssl_context.to_h,
31
32
  }
32
33
  end
@@ -1,3 +1,3 @@
1
1
  module FastlyNsq
2
- VERSION = '0.5.1'.freeze
2
+ VERSION = '0.6.0'.freeze
3
3
  end
@@ -37,38 +37,21 @@ RSpec.describe FakeMessageQueue do
37
37
  end
38
38
 
39
39
  RSpec.describe FakeMessageQueue::Producer do
40
- after do
41
- FakeMessageQueue.reset!
42
- end
40
+ let(:topic) { 'death_star' }
41
+ let(:producer) { FakeMessageQueue::Producer.new topic: topic }
43
42
 
44
- describe '#write' do
45
- it 'adds a new message to the queue' do
46
- topic = 'death_star'
43
+ it 'adds a new message to the queue' do
44
+ producer.write('hello')
47
45
 
48
- producer = FakeMessageQueue::Producer.new(
49
- nsqd: ENV.fetch('NSQD_TCP_ADDRESS'),
50
- topic: topic,
51
- )
52
- producer.write('hello')
53
-
54
- expect(FakeMessageQueue.queue.size).to eq 1
55
- end
46
+ expect(FakeMessageQueue.queue.size).to eq 1
56
47
  end
57
48
 
58
- describe '#terminate' do
59
- it 'has a `terminate` method which is a noop' do
60
- producer = instance_double('FakeMessageQueue::Producer')
61
-
62
- allow(producer).to receive(:terminate)
63
- end
49
+ it 'has a `terminate` method which is a noop' do
50
+ expect(producer).to respond_to(:terminate)
64
51
  end
65
52
  end
66
53
 
67
54
  RSpec.describe FakeMessageQueue::Message do
68
- after do
69
- FakeMessageQueue.reset!
70
- end
71
-
72
55
  describe '#body' do
73
56
  it 'returns the body of the message' do
74
57
  topic = 'death_star'
@@ -92,10 +75,6 @@ RSpec.describe FakeMessageQueue::Consumer do
92
75
  let(:channel) { 'star_killer_base' }
93
76
  let(:consumer) { FakeMessageQueue::Consumer.new topic: topic, channel: channel }
94
77
 
95
- after do
96
- FakeMessageQueue.reset!
97
- end
98
-
99
78
  describe 'when there are no messages on the queue' do
100
79
  it 'tells you there are 0 messages in the queue' do
101
80
  expect(consumer.size).to eq 0
@@ -1,78 +1,49 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  RSpec.describe MessageQueue::Producer do
4
- describe '#connection' do
5
- describe 'when using the real queue', fake_queue: false do
6
- it 'returns an instance of the queue producer' do
7
- allow(Nsq::Producer).to receive(:new)
8
- topic = 'death_star'
4
+ let(:topic) { 'death_star' }
5
+ let(:producer) { MessageQueue::Producer.new(topic: topic) }
6
+ let(:backend) { double 'Producer' }
9
7
 
10
- MessageQueue::Producer.new(topic: topic).connection
8
+ describe 'when the ENV is set incorrectly' do
9
+ it 'raises with a helpful error' do
10
+ allow(ENV).to receive(:[]).with('FAKE_QUEUE').and_return('taco')
11
11
 
12
- expect(Nsq::Producer).to have_received(:new).
13
- with(
14
- nsqd: ENV.fetch('NSQD_TCP_ADDRESS'),
15
- topic: topic,
16
- ssl_context: nil,
17
- ).at_least(:once)
18
- end
12
+ expect { producer.terminate }.to raise_error(InvalidParameterError)
19
13
  end
14
+ end
20
15
 
21
- describe 'when using the fake queue', fake_queue: true do
22
- it 'returns an instance of the queue producer' do
23
- allow(FakeMessageQueue::Producer).to receive(:new)
24
- topic = 'death_star'
25
-
26
- MessageQueue::Producer.new(topic: topic).connection
27
-
28
- expect(FakeMessageQueue::Producer).to have_received(:new).
29
- with(
30
- nsqd: ENV.fetch('NSQD_TCP_ADDRESS'),
31
- topic: topic,
32
- ssl_context: nil,
33
- ).at_least(:once)
34
- end
16
+ describe 'when connector connects to a backend Producer' do
17
+ let(:producer) do
18
+ MessageQueue::Producer.new topic: topic, connector: ->(_) { backend }
35
19
  end
36
20
 
37
- describe 'when the ENV is set incorrectly' do
38
- it 'raises with a helpful error' do
39
- allow(ENV).to receive(:[]).with('FAKE_QUEUE').and_return('taco')
40
- topic = 'death_star'
41
-
42
- producer = MessageQueue::Producer.new(topic: topic)
21
+ it 'forwards #write' do
22
+ expect(backend).to receive(:write).with("it's a message")
23
+ producer.write "it's a message"
24
+ end
43
25
 
44
- expect { producer.connection }.to raise_error(InvalidParameterError)
45
- end
26
+ it 'forwards #terminate' do
27
+ expect(backend).to receive(:terminate)
28
+ producer.terminate
46
29
  end
47
30
  end
48
31
 
49
- describe '#terminate' do
50
- describe 'when using the real queue', fake_queue: false do
51
- it 'closes the connection' do
52
- producer = double('Producer', connection: nil, terminate: nil)
53
- allow(Nsq::Producer).to receive(:new).and_return(producer)
54
- topic = 'death_star'
55
-
56
- live_producer = MessageQueue::Producer.new(topic: topic)
57
- live_producer.connection
58
- live_producer.terminate
59
-
60
- expect(producer).to have_received(:terminate)
32
+ describe 'using the default connector' do
33
+ module TestStrategy
34
+ module Producer
35
+ def self.new(*_); end
61
36
  end
62
37
  end
63
38
 
64
- describe 'when using the fake queue', fake_queue: true do
65
- it 'closes the connection' do
66
- producer = double('Producer', connection: nil, terminate: nil)
67
- allow(FakeMessageQueue::Producer).to receive(:new).and_return(producer)
68
- topic = 'death_star'
69
-
70
- live_producer = MessageQueue::Producer.new(topic: topic)
71
- live_producer.connection
72
- live_producer.terminate
39
+ before do
40
+ allow(MessageQueue).to receive(:strategy).and_return(TestStrategy)
41
+ end
73
42
 
74
- expect(producer).to have_received(:terminate)
75
- end
43
+ it 'instantiates a producer via Strategy' do
44
+ allow(backend).to receive(:terminate)
45
+ expect(TestStrategy::Producer).to receive(:new).and_return(backend)
46
+ producer.terminate
76
47
  end
77
48
  end
78
49
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fastly_nsq
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tommy O'Neil
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-05-12 00:00:00.000000000 Z
12
+ date: 2016-05-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: awesome_print