fastly_nsq 0.13.2 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.env +4 -0
- data/.overcommit.yml +3 -3
- data/.rubocop.yml +11 -1
- data/.travis.yml +8 -1
- data/Gemfile +9 -0
- data/README.md +52 -82
- data/Rakefile +2 -0
- data/bin/fastly_nsq +1 -0
- data/docker-compose.yml +23 -0
- data/examples/.sample.env +0 -3
- data/fastly_nsq.gemspec +7 -8
- data/lib/fastly_nsq.rb +44 -50
- data/lib/fastly_nsq/cli.rb +20 -14
- data/lib/fastly_nsq/consumer.rb +26 -30
- data/lib/fastly_nsq/feeder.rb +16 -0
- data/lib/fastly_nsq/http/nsqd.rb +7 -1
- data/lib/fastly_nsq/http/nsqlookupd.rb +1 -1
- data/lib/fastly_nsq/launcher.rb +31 -23
- data/lib/fastly_nsq/listener.rb +34 -103
- data/lib/fastly_nsq/manager.rb +48 -72
- data/lib/fastly_nsq/message.rb +2 -0
- data/lib/fastly_nsq/messenger.rb +5 -5
- data/lib/fastly_nsq/priority_queue.rb +12 -0
- data/lib/fastly_nsq/priority_thread_pool.rb +32 -0
- data/lib/fastly_nsq/producer.rb +52 -32
- data/lib/fastly_nsq/testing.rb +239 -0
- data/lib/fastly_nsq/tls_options.rb +2 -0
- data/lib/fastly_nsq/version.rb +3 -1
- data/spec/{lib/fastly_nsq/cli_spec.rb → cli_spec.rb} +2 -0
- data/spec/consumer_spec.rb +59 -0
- data/spec/fastly_nsq_spec.rb +72 -0
- data/spec/feeder_spec.rb +22 -0
- data/spec/{lib/fastly_nsq/http → http}/nsqd_spec.rb +1 -1
- data/spec/{lib/fastly_nsq/http → http}/nsqlookupd_spec.rb +1 -1
- data/spec/{lib/fastly_nsq/http_spec.rb → http_spec.rb} +3 -1
- data/spec/integration_spec.rb +48 -0
- data/spec/launcher_spec.rb +50 -0
- data/spec/listener_spec.rb +184 -0
- data/spec/manager_spec.rb +111 -0
- data/spec/matchers/delegate.rb +32 -0
- data/spec/{lib/fastly_nsq/message_spec.rb → message_spec.rb} +2 -0
- data/spec/{lib/fastly_nsq/messenger_spec.rb → messenger_spec.rb} +7 -5
- data/spec/priority_thread_pool_spec.rb +19 -0
- data/spec/producer_spec.rb +94 -0
- data/spec/spec_helper.rb +32 -28
- data/spec/support/http.rb +37 -0
- data/spec/support/webmock.rb +22 -0
- data/spec/{lib/fastly_nsq/tls_options_spec.rb → tls_options_spec.rb} +2 -0
- metadata +54 -96
- data/env_configuration_for_local_gem_tests.yml +0 -5
- data/example_config_class.rb +0 -20
- data/examples/Rakefile +0 -41
- data/lib/fastly_nsq/fake_backend.rb +0 -114
- data/lib/fastly_nsq/listener/config.rb +0 -35
- data/lib/fastly_nsq/rake_task.rb +0 -78
- data/lib/fastly_nsq/strategy.rb +0 -36
- data/spec/lib/fastly_nsq/consumer_spec.rb +0 -72
- data/spec/lib/fastly_nsq/fake_backend_spec.rb +0 -135
- data/spec/lib/fastly_nsq/fastly_nsq_spec.rb +0 -10
- data/spec/lib/fastly_nsq/launcher_spec.rb +0 -56
- data/spec/lib/fastly_nsq/listener_spec.rb +0 -213
- data/spec/lib/fastly_nsq/manager_spec.rb +0 -127
- data/spec/lib/fastly_nsq/producer_spec.rb +0 -60
- data/spec/lib/fastly_nsq/rake_task_spec.rb +0 -142
- data/spec/lib/fastly_nsq/strategy_spec.rb +0 -36
- data/spec/lib/fastly_nsq_spec.rb +0 -18
- data/spec/support/env_helpers.rb +0 -15
@@ -1,142 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'fastly_nsq/rake_task'
|
3
|
-
|
4
|
-
RSpec.describe FastlyNsq::RakeTask do
|
5
|
-
before(:each) do
|
6
|
-
Rake::Task.clear
|
7
|
-
@original_logger = FastlyNsq.logger
|
8
|
-
FastlyNsq.logger = Logger.new(nil)
|
9
|
-
end
|
10
|
-
|
11
|
-
after do
|
12
|
-
FastlyNsq.logger = @original_logger
|
13
|
-
end
|
14
|
-
|
15
|
-
describe 'when defining tasks' do
|
16
|
-
context 'when no task name is provided' do
|
17
|
-
it 'creates a task with the default name' do
|
18
|
-
default_task_name = 'begin_listening'
|
19
|
-
|
20
|
-
FastlyNsq::RakeTask.new
|
21
|
-
defined_tasks = Rake::Task.tasks
|
22
|
-
first_task_name = defined_tasks.first.name
|
23
|
-
|
24
|
-
expect(first_task_name).to eq default_task_name
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
context 'when a task name is passed in' do
|
29
|
-
it 'creates a task with the provided name' do
|
30
|
-
task_name = 'test_name'
|
31
|
-
|
32
|
-
FastlyNsq::RakeTask.new(task_name.to_sym)
|
33
|
-
defined_tasks = Rake::Task.tasks
|
34
|
-
first_task_name = defined_tasks.first.name
|
35
|
-
|
36
|
-
expect(first_task_name).to eq task_name
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
describe 'when running tasks' do
|
42
|
-
context 'when no channel is provided' do
|
43
|
-
it 'raises an error' do
|
44
|
-
expect do
|
45
|
-
FastlyNsq::RakeTask.new(:begin_listening, [:channel])
|
46
|
-
Rake::Task['begin_listening'].execute
|
47
|
-
end.to raise_error(ArgumentError, /required.+channel/)
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
context 'when no topics are provided' do
|
52
|
-
it 'raises an error' do
|
53
|
-
channel = 'best_server_number_1'
|
54
|
-
|
55
|
-
expect do
|
56
|
-
FastlyNsq::RakeTask.new(:begin_listening, [:channel])
|
57
|
-
Rake::Task['begin_listening'].execute(channel: channel)
|
58
|
-
end.to raise_error(ArgumentError, /required.+topics/)
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
context 'when a channel and topics are defined' do
|
63
|
-
let(:channel) { 'clown_generating_service' }
|
64
|
-
let(:topics) { { customer_created: :fake_processor } }
|
65
|
-
let(:listener) { class_double FastlyNsq::Listener, listen_to: nil }
|
66
|
-
|
67
|
-
it 'configures via a block if one is given' do
|
68
|
-
FastlyNsq::RakeTask.new(:begin_listening, %i[channel topics]) do |task|
|
69
|
-
task.channel = channel
|
70
|
-
task.topics = topics
|
71
|
-
task.listener = listener
|
72
|
-
end
|
73
|
-
|
74
|
-
Rake::Task['begin_listening'].execute
|
75
|
-
|
76
|
-
expect(listener).to have_received(:listen_to).
|
77
|
-
with(hash_including(topic: :customer_created, channel: channel))
|
78
|
-
end
|
79
|
-
|
80
|
-
it 'prefers inline channel definition over block assignments' do
|
81
|
-
new_channel = 'send_balloons_to_customer_service'
|
82
|
-
|
83
|
-
FastlyNsq::RakeTask.new(:begin_listening, %i[channel topics]) do |task|
|
84
|
-
task.channel = channel
|
85
|
-
task.topics = topics
|
86
|
-
task.listener = listener
|
87
|
-
end
|
88
|
-
|
89
|
-
Rake::Task['begin_listening'].execute(channel: new_channel, topics: topics, listener: listener)
|
90
|
-
|
91
|
-
expect(listener).to have_received(:listen_to).
|
92
|
-
with(hash_including(topic: :customer_created, channel: channel))
|
93
|
-
end
|
94
|
-
|
95
|
-
it 'configures a listener for each topic if there are multiple' do
|
96
|
-
topics = %w[foo bar baz quuz etc]
|
97
|
-
|
98
|
-
FastlyNsq::RakeTask.new(:begin_listening, %i[channel topics listener])
|
99
|
-
Rake::Task['begin_listening'].execute(channel: channel, topics: topics, listener: listener)
|
100
|
-
|
101
|
-
topics.each do |(topic, processor)|
|
102
|
-
expect(listener).to have_received(:listen_to).
|
103
|
-
with(hash_including(topic: topic, channel: channel, processor: processor))
|
104
|
-
end
|
105
|
-
end
|
106
|
-
|
107
|
-
context 'and preprocessor is defined' do
|
108
|
-
it 'passes preprocessor to the listener' do
|
109
|
-
FastlyNsq::RakeTask.new(:begin_listening) do |task|
|
110
|
-
task.channel = channel
|
111
|
-
task.topics = topics
|
112
|
-
task.listener = listener
|
113
|
-
task.preprocessor = :noop
|
114
|
-
end
|
115
|
-
|
116
|
-
Rake::Task['begin_listening'].execute
|
117
|
-
|
118
|
-
expect(listener).to have_received(:listen_to).
|
119
|
-
with(hash_including(preprocessor: :noop))
|
120
|
-
end
|
121
|
-
end
|
122
|
-
|
123
|
-
context 'and logger is defined' do
|
124
|
-
let(:logger) { double 'Logger', info: nil }
|
125
|
-
|
126
|
-
it 'passes logger to the listener' do
|
127
|
-
FastlyNsq::RakeTask.new(:begin_listening) do |task|
|
128
|
-
task.channel = channel
|
129
|
-
task.topics = topics
|
130
|
-
task.listener = listener
|
131
|
-
task.logger = logger
|
132
|
-
end
|
133
|
-
|
134
|
-
Rake::Task['begin_listening'].execute
|
135
|
-
|
136
|
-
expect(listener).to have_received(:listen_to).
|
137
|
-
with(hash_including(logger: logger))
|
138
|
-
end
|
139
|
-
end
|
140
|
-
end
|
141
|
-
end
|
142
|
-
end
|
@@ -1,36 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
RSpec.describe FastlyNsq::Strategy do
|
4
|
-
describe 'when FAKE_QUEUE is falsy' do
|
5
|
-
it 'returns the strategy based on the ENV variable' do
|
6
|
-
[false, 0, '0', 'false', 'FALSE', 'off', 'OFF', nil].each do |no|
|
7
|
-
allow(ENV).to receive(:[]).with('FAKE_QUEUE').and_return(no)
|
8
|
-
|
9
|
-
strategy = FastlyNsq::Strategy.for_queue
|
10
|
-
|
11
|
-
expect(strategy).to eq Nsq
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
describe 'when FAKE_QUEUE is truthy' do
|
17
|
-
it 'returns the strategy based on the ENV variable' do
|
18
|
-
[true, 1, '1', 'true', 'TRUE', 'on', 'ON'].each do |yes|
|
19
|
-
allow(ENV).to receive(:[]).with('FAKE_QUEUE').and_return(yes)
|
20
|
-
|
21
|
-
strategy = FastlyNsq::Strategy.for_queue
|
22
|
-
|
23
|
-
expect(strategy).to eq FastlyNsq::FakeBackend
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
describe 'when the ENV is set incorrectly' do
|
29
|
-
it 'raises with a helpful error' do
|
30
|
-
allow(ENV).to receive(:[]).with('FAKE_QUEUE').and_return('taco')
|
31
|
-
|
32
|
-
expect { FastlyNsq::Strategy.for_queue }.to \
|
33
|
-
raise_error(FastlyNsq::Strategy::InvalidParameterError)
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
data/spec/lib/fastly_nsq_spec.rb
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
RSpec.describe FastlyNsq do
|
4
|
-
module TestStrategy; end
|
5
|
-
|
6
|
-
it 'allows the logger to be set and retrieved' do
|
7
|
-
logger = Logger.new(STDOUT)
|
8
|
-
FastlyNsq.logger = logger
|
9
|
-
|
10
|
-
expect(FastlyNsq.logger).to eq logger
|
11
|
-
end
|
12
|
-
|
13
|
-
it 'returns the current Strategy' do
|
14
|
-
allow(FastlyNsq::Strategy).to receive(:for_queue).and_return(TestStrategy)
|
15
|
-
|
16
|
-
expect(FastlyNsq.strategy).to eql(TestStrategy)
|
17
|
-
end
|
18
|
-
end
|
data/spec/support/env_helpers.rb
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
module EnvHelpers
|
2
|
-
def use_fake_connection
|
3
|
-
allow(ENV).to receive(:[]).with('FAKE_QUEUE').and_return(true)
|
4
|
-
yield
|
5
|
-
end
|
6
|
-
|
7
|
-
def use_real_connection
|
8
|
-
allow(ENV).to receive(:[]).with('FAKE_QUEUE').and_return(false)
|
9
|
-
yield
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
RSpec.configure do |config|
|
14
|
-
config.include EnvHelpers
|
15
|
-
end
|