fastly_nsq 0.5.1 → 0.6.0
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/README.md +1 -1
- data/Rakefile +1 -1
- data/lib/fastly_nsq/fake_message_queue.rb +1 -1
- data/lib/fastly_nsq/message_queue/producer.rb +16 -15
- data/lib/fastly_nsq/version.rb +1 -1
- data/spec/lib/fastly_nsq/fake_message_queue_spec.rb +7 -28
- data/spec/lib/fastly_nsq/message_queue/producer_spec.rb +29 -58
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 912a3507f9a1f2aa279cae728bbfef969339efa4
|
4
|
+
data.tar.gz: 58b52a9f841f21cd58385b87e81e9a73a7397648
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c4b5b7230487629c39cfc004f5f0cdac24c2912bbefc8f4938a38ca1d975fccf320f7347c210b769fb8b00bfe4d28461dabc9824fce2dc8fd2ea11063a3a6a7b
|
7
|
+
data.tar.gz: dedc25afac6237e9efc24ce889e57d5fa3b27fc658bd36d92cccb3207064fd6582d21def6580707cb0dfd0682f9b5c1b2d05b79b43130965f28605e1cee1bb85
|
data/README.md
CHANGED
data/Rakefile
CHANGED
@@ -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
|
-
|
6
|
-
|
7
|
-
|
8
|
-
end
|
7
|
+
extend Forwardable
|
8
|
+
def_delegator :connection, :terminate
|
9
|
+
def_delegator :connection, :write
|
9
10
|
|
10
|
-
def
|
11
|
-
@
|
12
|
-
|
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
|
-
|
19
|
+
DEFAULT_CONNECTOR = ->(params) { MessageQueue.strategy::Producer.new params }
|
21
20
|
|
22
|
-
|
23
|
-
|
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:
|
29
|
-
topic:
|
29
|
+
nsqd: ENV.fetch('NSQD_TCP_ADDRESS'),
|
30
|
+
topic: topic,
|
30
31
|
ssl_context: ssl_context.to_h,
|
31
32
|
}
|
32
33
|
end
|
data/lib/fastly_nsq/version.rb
CHANGED
@@ -37,38 +37,21 @@ RSpec.describe FakeMessageQueue do
|
|
37
37
|
end
|
38
38
|
|
39
39
|
RSpec.describe FakeMessageQueue::Producer do
|
40
|
-
|
41
|
-
|
42
|
-
end
|
40
|
+
let(:topic) { 'death_star' }
|
41
|
+
let(:producer) { FakeMessageQueue::Producer.new topic: topic }
|
43
42
|
|
44
|
-
|
45
|
-
|
46
|
-
topic = 'death_star'
|
43
|
+
it 'adds a new message to the queue' do
|
44
|
+
producer.write('hello')
|
47
45
|
|
48
|
-
|
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
|
-
|
59
|
-
|
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
|
-
|
5
|
-
|
6
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
22
|
-
|
23
|
-
|
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
|
-
|
38
|
-
it
|
39
|
-
|
40
|
-
|
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
|
-
|
45
|
-
|
26
|
+
it 'forwards #terminate' do
|
27
|
+
expect(backend).to receive(:terminate)
|
28
|
+
producer.terminate
|
46
29
|
end
|
47
30
|
end
|
48
31
|
|
49
|
-
describe '
|
50
|
-
|
51
|
-
|
52
|
-
|
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
|
-
|
65
|
-
|
66
|
-
|
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
|
-
|
75
|
-
|
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.
|
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
|
+
date: 2016-05-13 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: awesome_print
|