fastly_nsq 1.15.0 → 1.17.1
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/.git-blame-ignore-revs +6 -0
- data/.ruby-version +1 -1
- data/.travis.yml +4 -3
- data/ChangeLog.md +24 -1
- data/Gemfile +8 -8
- data/README.md +5 -1
- data/Rakefile +10 -11
- data/fastly_nsq.gemspec +26 -26
- data/lib/fastly_nsq/cli.rb +43 -50
- data/lib/fastly_nsq/consumer.rb +6 -6
- data/lib/fastly_nsq/feeder.rb +5 -7
- data/lib/fastly_nsq/http/nsqd.rb +28 -28
- data/lib/fastly_nsq/http/nsqlookupd.rb +11 -11
- data/lib/fastly_nsq/http.rb +4 -4
- data/lib/fastly_nsq/launcher.rb +16 -16
- data/lib/fastly_nsq/listener.rb +17 -16
- data/lib/fastly_nsq/manager.rb +13 -12
- data/lib/fastly_nsq/message.rb +9 -5
- data/lib/fastly_nsq/messenger.rb +25 -15
- data/lib/fastly_nsq/new_relic.rb +8 -8
- data/lib/fastly_nsq/priority_queue.rb +2 -2
- data/lib/fastly_nsq/priority_thread_pool.rb +3 -3
- data/lib/fastly_nsq/producer.rb +7 -7
- data/lib/fastly_nsq/safe_thread.rb +1 -1
- data/lib/fastly_nsq/testing.rb +12 -2
- data/lib/fastly_nsq/tls_options.rb +6 -6
- data/lib/fastly_nsq/version.rb +1 -1
- data/lib/fastly_nsq.rb +27 -29
- data/spec/cli_spec.rb +2 -2
- data/spec/consumer_spec.rb +12 -12
- data/spec/fastly_nsq_spec.rb +31 -31
- data/spec/feeder_spec.rb +4 -4
- data/spec/http/nsqd_spec.rb +23 -23
- data/spec/http/nsqlookupd_spec.rb +19 -19
- data/spec/http_spec.rb +22 -22
- data/spec/integration_spec.rb +10 -10
- data/spec/launcher_spec.rb +21 -21
- data/spec/listener_spec.rb +50 -50
- data/spec/manager_spec.rb +27 -27
- data/spec/matchers/delegate.rb +4 -4
- data/spec/message_spec.rb +20 -20
- data/spec/messenger_spec.rb +71 -59
- data/spec/new_relic.rb +27 -27
- data/spec/priority_thread_pool_spec.rb +2 -2
- data/spec/producer_spec.rb +30 -30
- data/spec/spec_helper.rb +12 -12
- data/spec/support/http.rb +2 -2
- data/spec/support/webmock.rb +1 -1
- data/spec/testing_spec.rb +12 -12
- data/spec/tls_options_spec.rb +47 -47
- metadata +14 -15
- data/.rubocop.yml +0 -68
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
class FastlyNsq::PriorityThreadPool < Concurrent::ThreadPoolExecutor
|
4
|
-
|
4
|
+
alias_method :max_threads, :max_length
|
5
5
|
|
6
6
|
def initialize(*)
|
7
7
|
super
|
@@ -15,7 +15,7 @@ class FastlyNsq::PriorityThreadPool < Concurrent::ThreadPoolExecutor
|
|
15
15
|
# @!visibility private
|
16
16
|
def ns_enqueue(*args, &task)
|
17
17
|
if !ns_limited_queue? || @queue.size < @max_queue
|
18
|
-
@queue.push([task, args[1
|
18
|
+
@queue.push([task, args[1..]], args[0])
|
19
19
|
true
|
20
20
|
else
|
21
21
|
false
|
@@ -27,6 +27,6 @@ class FastlyNsq::PriorityThreadPool < Concurrent::ThreadPoolExecutor
|
|
27
27
|
#
|
28
28
|
# @!visibility private
|
29
29
|
def ns_assign_worker(*args, &task)
|
30
|
-
super(args[1
|
30
|
+
super(args[1..], &task)
|
31
31
|
end
|
32
32
|
end
|
data/lib/fastly_nsq/producer.rb
CHANGED
@@ -31,10 +31,10 @@ class FastlyNsq::Producer
|
|
31
31
|
# @param logger [Logger] defaults to FastlyNsq.logger
|
32
32
|
# @param connect_timeout [Integer] NSQ connection timeout in seconds
|
33
33
|
def initialize(topic:, tls_options: nil, logger: FastlyNsq.logger, connect_timeout: DEFAULT_CONNECTION_TIMEOUT)
|
34
|
-
@topic
|
35
|
-
@tls_options
|
34
|
+
@topic = topic
|
35
|
+
@tls_options = FastlyNsq::TlsOptions.as_hash(tls_options)
|
36
36
|
@connect_timeout = connect_timeout
|
37
|
-
@logger
|
37
|
+
@logger = logger
|
38
38
|
|
39
39
|
connect
|
40
40
|
end
|
@@ -75,14 +75,14 @@ class FastlyNsq::Producer
|
|
75
75
|
|
76
76
|
@connection ||= Nsq::Producer.new(
|
77
77
|
tls_options.merge(
|
78
|
-
nsqlookupd:
|
79
|
-
topic:
|
80
|
-
)
|
78
|
+
nsqlookupd: lookupd,
|
79
|
+
topic: topic
|
80
|
+
)
|
81
81
|
)
|
82
82
|
|
83
83
|
timeout_args = [connect_timeout, FastlyNsq::ConnectionFailed]
|
84
84
|
|
85
|
-
if RUBY_VERSION >
|
85
|
+
if RUBY_VERSION > "2.4.0"
|
86
86
|
timeout_args << "Failed connection to #{lookupd} within #{connect_timeout} seconds"
|
87
87
|
end
|
88
88
|
|
data/lib/fastly_nsq/testing.rb
CHANGED
@@ -98,7 +98,7 @@ module FastlyNsq
|
|
98
98
|
# processor_klass.call(test_message)
|
99
99
|
# expect(Post.find(post_data['id']).not_to be nil
|
100
100
|
def message(data:, meta: nil)
|
101
|
-
test_message = FastlyNsq::TestMessage.new(JSON.dump(
|
101
|
+
test_message = FastlyNsq::TestMessage.new(JSON.dump("data" => data, "meta" => meta))
|
102
102
|
FastlyNsq::Message.new(test_message)
|
103
103
|
end
|
104
104
|
end
|
@@ -121,7 +121,7 @@ module FastlyNsq
|
|
121
121
|
|
122
122
|
def initialize(raw_body)
|
123
123
|
@raw_body = raw_body
|
124
|
-
@id
|
124
|
+
@id = Digest::SHA1.hexdigest(raw_body.to_s + Time.now.to_s)
|
125
125
|
@attempts = 0
|
126
126
|
end
|
127
127
|
|
@@ -249,6 +249,11 @@ module FastlyNsq
|
|
249
249
|
|
250
250
|
FastlyNsq::Listener.prepend(ListenerTesting)
|
251
251
|
|
252
|
+
class FakeConnection
|
253
|
+
def connected?
|
254
|
+
end
|
255
|
+
end
|
256
|
+
|
252
257
|
module ConsumerTesting
|
253
258
|
module ClassMethods
|
254
259
|
def messages(topic = nil)
|
@@ -278,6 +283,11 @@ module FastlyNsq
|
|
278
283
|
@connected
|
279
284
|
end
|
280
285
|
|
286
|
+
def connect(*args)
|
287
|
+
return super(*args) unless FastlyNsq::Testing.enabled?
|
288
|
+
@connected = FakeConnection.new
|
289
|
+
end
|
290
|
+
|
281
291
|
def empty?
|
282
292
|
FastlyNsq::Testing.enabled? ? messages.empty? : super
|
283
293
|
end
|
@@ -20,7 +20,7 @@ module FastlyNsq
|
|
20
20
|
else
|
21
21
|
{
|
22
22
|
tls_v1: true,
|
23
|
-
tls_options: @context
|
23
|
+
tls_options: @context
|
24
24
|
}
|
25
25
|
end
|
26
26
|
end
|
@@ -28,19 +28,19 @@ module FastlyNsq
|
|
28
28
|
private
|
29
29
|
|
30
30
|
def env_key
|
31
|
-
ENV.fetch(
|
31
|
+
ENV.fetch("NSQ_SSL_KEY", nil)
|
32
32
|
end
|
33
33
|
|
34
34
|
def env_certificate
|
35
|
-
ENV.fetch(
|
35
|
+
ENV.fetch("NSQ_SSL_CERTIFICATE", nil)
|
36
36
|
end
|
37
37
|
|
38
38
|
def env_ca_certificate
|
39
|
-
ENV.fetch(
|
39
|
+
ENV.fetch("NSQ_SSL_CA_CERTIFICATE", nil)
|
40
40
|
end
|
41
41
|
|
42
42
|
def verify_mode
|
43
|
-
ENV.fetch(
|
43
|
+
ENV.fetch("NSQ_SSL_VERIFY_MODE", nil)
|
44
44
|
end
|
45
45
|
|
46
46
|
def env_default_hash
|
@@ -48,7 +48,7 @@ module FastlyNsq
|
|
48
48
|
key: env_key,
|
49
49
|
certificate: env_certificate,
|
50
50
|
ca_certificate: env_ca_certificate,
|
51
|
-
verify_mode: verify_mode
|
51
|
+
verify_mode: verify_mode
|
52
52
|
}
|
53
53
|
end
|
54
54
|
|
data/lib/fastly_nsq/version.rb
CHANGED
data/lib/fastly_nsq.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
7
|
-
require
|
8
|
-
require
|
9
|
-
require
|
3
|
+
require "nsq"
|
4
|
+
require "concurrent"
|
5
|
+
require "fc"
|
6
|
+
require "set"
|
7
|
+
require "logger"
|
8
|
+
require "forwardable"
|
9
|
+
require "digest/md5"
|
10
10
|
|
11
11
|
module FastlyNsq
|
12
12
|
NotConnectedError = Class.new(StandardError)
|
@@ -58,7 +58,7 @@ module FastlyNsq
|
|
58
58
|
def logger
|
59
59
|
return @logger if @logger
|
60
60
|
|
61
|
-
self.logger = Logger.new(
|
61
|
+
self.logger = Logger.new($stderr)
|
62
62
|
end
|
63
63
|
|
64
64
|
##
|
@@ -112,21 +112,21 @@ module FastlyNsq
|
|
112
112
|
# @return [Integer]
|
113
113
|
# @see https://nsq.io/components/nsqd.html#command-line-options
|
114
114
|
def max_req_timeout
|
115
|
-
@max_req_timeout ||= ENV.fetch(
|
115
|
+
@max_req_timeout ||= ENV.fetch("MAX_REQ_TIMEOUT", 60 * 60 * 1_000).to_i
|
116
116
|
end
|
117
117
|
|
118
118
|
# Maximum number of threads for FastlyNsq::PriorityThreadPool
|
119
119
|
# Default setting is 5 and can be set via ENV['MAX_PROCESSING_POOL_THREADS']
|
120
120
|
# @return [Integer]
|
121
121
|
def max_processing_pool_threads
|
122
|
-
@max_processing_pool_threads ||= ENV.fetch(
|
122
|
+
@max_processing_pool_threads ||= ENV.fetch("MAX_PROCESSING_POOL_THREADS", 5).to_i
|
123
123
|
end
|
124
124
|
|
125
125
|
##
|
126
126
|
# Return an array of NSQ lookupd http addresses sourced from ENV['NSQLOOKUPD_HTTP_ADDRESS']
|
127
127
|
# @return [Array<String>] list of nsqlookupd http addresses
|
128
128
|
def lookupd_http_addresses
|
129
|
-
ENV.fetch(
|
129
|
+
ENV.fetch("NSQLOOKUPD_HTTP_ADDRESS").split(",").map(&:strip)
|
130
130
|
end
|
131
131
|
|
132
132
|
# Register a block to run at a point in the lifecycle.
|
@@ -151,11 +151,9 @@ module FastlyNsq
|
|
151
151
|
def fire_event(event)
|
152
152
|
blocks = FastlyNsq.events.fetch(event)
|
153
153
|
blocks.each do |block|
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
logger.error "[#{event}] #{e.inspect}"
|
158
|
-
end
|
154
|
+
block.call
|
155
|
+
rescue => e
|
156
|
+
logger.error "[#{event}] #{e.inspect}"
|
159
157
|
end
|
160
158
|
end
|
161
159
|
|
@@ -168,16 +166,16 @@ module FastlyNsq
|
|
168
166
|
end
|
169
167
|
end
|
170
168
|
|
171
|
-
require
|
172
|
-
require
|
173
|
-
require
|
174
|
-
require
|
175
|
-
require
|
176
|
-
require
|
177
|
-
require
|
178
|
-
require
|
179
|
-
require
|
180
|
-
require
|
181
|
-
require
|
182
|
-
require
|
183
|
-
require
|
169
|
+
require "fastly_nsq/consumer"
|
170
|
+
require "fastly_nsq/feeder"
|
171
|
+
require "fastly_nsq/launcher"
|
172
|
+
require "fastly_nsq/listener"
|
173
|
+
require "fastly_nsq/manager"
|
174
|
+
require "fastly_nsq/message"
|
175
|
+
require "fastly_nsq/messenger"
|
176
|
+
require "fastly_nsq/new_relic"
|
177
|
+
require "fastly_nsq/priority_queue"
|
178
|
+
require "fastly_nsq/priority_thread_pool"
|
179
|
+
require "fastly_nsq/producer"
|
180
|
+
require "fastly_nsq/tls_options"
|
181
|
+
require "fastly_nsq/version"
|
data/spec/cli_spec.rb
CHANGED
data/spec/consumer_spec.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require "spec_helper"
|
4
4
|
|
5
5
|
RSpec.describe FastlyNsq::Consumer do
|
6
|
-
let!(:topic)
|
7
|
-
let!(:channel) {
|
8
|
-
let!(:queue)
|
6
|
+
let!(:topic) { "fnsq" }
|
7
|
+
let!(:channel) { "fnsq" }
|
8
|
+
let!(:queue) { nil }
|
9
9
|
|
10
10
|
subject { described_class.new(topic: topic, channel: channel, queue: queue) }
|
11
11
|
|
@@ -16,15 +16,15 @@ RSpec.describe FastlyNsq::Consumer do
|
|
16
16
|
|
17
17
|
it { should be_connected }
|
18
18
|
|
19
|
-
it
|
19
|
+
it "should terminate" do
|
20
20
|
expect { subject.terminate }.to change(subject, :connected?).to(false)
|
21
21
|
end
|
22
22
|
|
23
|
-
describe
|
23
|
+
describe "with a specified queue" do
|
24
24
|
let!(:queue) { Queue.new }
|
25
25
|
|
26
|
-
it
|
27
|
-
message =
|
26
|
+
it "passes #queue to Nsq::Consumer" do
|
27
|
+
message = "foo"
|
28
28
|
|
29
29
|
FastlyNsq::Messenger.deliver(message: message, topic: topic)
|
30
30
|
|
@@ -41,16 +41,16 @@ RSpec.describe FastlyNsq::Consumer do
|
|
41
41
|
it { should delegate(:pop).to(:connection) }
|
42
42
|
it { should delegate(:pop_without_blocking).to(:connection) }
|
43
43
|
|
44
|
-
describe
|
45
|
-
let(:message) {
|
44
|
+
describe "with a message" do
|
45
|
+
let(:message) { "foo" }
|
46
46
|
|
47
47
|
before { FastlyNsq::Messenger.deliver(message: message, topic: topic) }
|
48
48
|
|
49
|
-
it
|
49
|
+
it "should not be empty" do
|
50
50
|
expect { subject }.to eventually(be_empty).within(15)
|
51
51
|
end
|
52
52
|
|
53
|
-
describe
|
53
|
+
describe "that has finished" do
|
54
54
|
before { subject.pop.finish }
|
55
55
|
|
56
56
|
it { should be_empty }
|
data/spec/fastly_nsq_spec.rb
CHANGED
@@ -1,89 +1,89 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require "spec_helper"
|
4
4
|
|
5
5
|
RSpec.describe FastlyNsq do
|
6
|
-
describe
|
6
|
+
describe "#configure" do
|
7
7
|
specify { expect { |b| described_class.configure(&b) }.to yield_with_args(described_class) }
|
8
8
|
end
|
9
9
|
|
10
|
-
describe
|
10
|
+
describe "#listen" do
|
11
11
|
let!(:default_channel) { subject.channel }
|
12
|
-
let!(:topic) {
|
12
|
+
let!(:topic) { "fnsq" }
|
13
13
|
|
14
|
-
before { subject.channel =
|
14
|
+
before { subject.channel = "fnsq" }
|
15
15
|
after { subject.channel = default_channel }
|
16
16
|
|
17
|
-
it
|
17
|
+
it "creates a listener" do
|
18
18
|
expect { subject.listen topic, ->(*) {} }.to change { subject.manager.topics }.to([topic])
|
19
19
|
end
|
20
20
|
|
21
|
-
it
|
21
|
+
it "creates a listener with a specific priority" do
|
22
22
|
listener = subject.listen topic, ->(*) {}, priority: 10
|
23
23
|
expect(listener.priority).to eq(10)
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
|
-
describe
|
27
|
+
describe "#channel=" do
|
28
28
|
let!(:default_channel) { subject.channel }
|
29
29
|
after { subject.channel = default_channel }
|
30
30
|
|
31
|
-
it
|
31
|
+
it "allows the channel to be set and retrieved" do
|
32
32
|
expect(subject.channel).to be_nil
|
33
|
-
subject.channel =
|
34
|
-
expect(subject.channel).to eq(
|
33
|
+
subject.channel = "foo"
|
34
|
+
expect(subject.channel).to eq("foo")
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
38
|
-
describe
|
38
|
+
describe "#logger" do
|
39
39
|
let!(:default_logger) { subject.logger }
|
40
40
|
after { subject.logger = default_logger }
|
41
41
|
|
42
|
-
it
|
42
|
+
it "returns the set logger" do
|
43
43
|
logger = Logger.new(nil)
|
44
44
|
subject.logger = logger
|
45
45
|
|
46
46
|
expect(subject.logger).to eq logger
|
47
47
|
end
|
48
48
|
|
49
|
-
it
|
49
|
+
it "sets the default logger if none is set" do
|
50
50
|
subject.instance_variable_set(:@logger, nil)
|
51
51
|
expect(subject.instance_variable_get(:@logger)).to be nil
|
52
52
|
logger = subject.logger
|
53
53
|
|
54
54
|
expect(logger).to be_instance_of(Logger)
|
55
|
-
expect(logger.instance_variable_get(:@logdev).dev).to eq(
|
55
|
+
expect(logger.instance_variable_get(:@logdev).dev).to eq($stderr)
|
56
56
|
expect(logger).to eq(Nsq.logger)
|
57
57
|
end
|
58
58
|
end
|
59
59
|
|
60
|
-
describe
|
60
|
+
describe "#logger=" do
|
61
61
|
let!(:default_logger) { subject.logger }
|
62
62
|
after { subject.logger = default_logger }
|
63
63
|
|
64
|
-
it
|
65
|
-
logger = Logger.new(
|
64
|
+
it "allows the logger to be set and retrieved" do
|
65
|
+
logger = Logger.new($stdout)
|
66
66
|
subject.logger = logger
|
67
67
|
|
68
68
|
expect(subject.logger).to eq logger
|
69
69
|
end
|
70
70
|
|
71
|
-
it
|
72
|
-
logger = Logger.new(
|
71
|
+
it "sets Nsq.logger" do
|
72
|
+
logger = Logger.new($stdout)
|
73
73
|
subject.logger = logger
|
74
74
|
|
75
75
|
expect(Nsq.logger).to eq logger
|
76
76
|
end
|
77
77
|
end
|
78
78
|
|
79
|
-
describe
|
80
|
-
it
|
79
|
+
describe "#manager" do
|
80
|
+
it "represents the active default manager" do
|
81
81
|
expect(subject.manager).not_to be_stopped
|
82
82
|
end
|
83
83
|
end
|
84
84
|
|
85
|
-
describe
|
86
|
-
it
|
85
|
+
describe "#manager=" do
|
86
|
+
it "transfers to specified manager" do
|
87
87
|
old_manager = subject.manager
|
88
88
|
new_manager = FastlyNsq::Manager.new
|
89
89
|
|
@@ -93,17 +93,17 @@ RSpec.describe FastlyNsq do
|
|
93
93
|
end
|
94
94
|
end
|
95
95
|
|
96
|
-
describe
|
97
|
-
it
|
98
|
-
expect(subject.lookupd_http_addresses).to eq(ENV[
|
96
|
+
describe "#lookupd_http_addresses" do
|
97
|
+
it "retreives NSQLOOKUPD_HTTP_ADDRESS" do
|
98
|
+
expect(subject.lookupd_http_addresses).to eq(ENV["NSQLOOKUPD_HTTP_ADDRESS"].split(","))
|
99
99
|
end
|
100
100
|
end
|
101
101
|
|
102
|
-
describe
|
102
|
+
describe "#on" do
|
103
103
|
before { FastlyNsq.events.each { |(_, v)| v.clear } }
|
104
|
-
after
|
104
|
+
after { FastlyNsq.events.each { |(_, v)| v.clear } }
|
105
105
|
|
106
|
-
it
|
106
|
+
it "registers callbacks for events" do
|
107
107
|
%i[startup shutdown heartbeat].each do |event|
|
108
108
|
block = -> {}
|
109
109
|
FastlyNsq.on(event, &block)
|
@@ -111,7 +111,7 @@ RSpec.describe FastlyNsq do
|
|
111
111
|
end
|
112
112
|
end
|
113
113
|
|
114
|
-
it
|
114
|
+
it "limits callback registration to valid events" do
|
115
115
|
expect { FastlyNsq.on(:foo, &-> {}) }.to raise_error(ArgumentError, /Invalid event name/)
|
116
116
|
end
|
117
117
|
end
|
data/spec/feeder_spec.rb
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require "spec_helper"
|
4
4
|
|
5
5
|
RSpec.describe FastlyNsq::Feeder do
|
6
|
-
describe
|
7
|
-
it
|
6
|
+
describe "#push" do
|
7
|
+
it "sends message to processor with the specified priority" do
|
8
8
|
messages = []
|
9
9
|
processor = ->(m) { messages << m }
|
10
10
|
priority = 5
|
11
|
-
message =
|
11
|
+
message = "foo"
|
12
12
|
|
13
13
|
feeder = described_class.new(processor, priority)
|
14
14
|
|
data/spec/http/nsqd_spec.rb
CHANGED
@@ -1,77 +1,77 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
3
|
+
require "spec_helper"
|
4
|
+
require "fastly_nsq/http/nsqd"
|
5
5
|
|
6
6
|
RSpec.describe FastlyNsq::Http::Nsqd, :webmock do
|
7
|
-
let(:base_uri) {
|
7
|
+
let(:base_uri) { "http://example.com" }
|
8
8
|
|
9
|
-
it
|
9
|
+
it "makes simple get requests" do
|
10
10
|
%w[ping info config/nsqlookupd_tcp_addresses].each do |api|
|
11
11
|
url = "#{base_uri}/#{api}"
|
12
12
|
stub_request(:get, url)
|
13
|
-
FastlyNsq::Http::Nsqd.send(api.tr(
|
13
|
+
FastlyNsq::Http::Nsqd.send(api.tr("/", "_").to_sym, base_uri: base_uri)
|
14
14
|
|
15
15
|
expect(a_request(:get, url)).to have_been_requested
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
|
-
describe
|
20
|
-
it
|
19
|
+
describe "stats" do
|
20
|
+
it "can fetch stats" do
|
21
21
|
url = "#{base_uri}/stats?topic=lol&channel=foo&format=json"
|
22
22
|
stub_request(:get, url)
|
23
|
-
data = {
|
23
|
+
data = {topic: "lol", channel: "foo", format: "json"}
|
24
24
|
|
25
|
-
FastlyNsq::Http::Nsqd.stats(topic:
|
25
|
+
FastlyNsq::Http::Nsqd.stats(topic: "lol", channel: "foo", base_uri: base_uri)
|
26
26
|
|
27
27
|
expect(a_request(:get, url).with(query: data)).to have_been_requested
|
28
28
|
end
|
29
29
|
|
30
|
-
it
|
30
|
+
it "raises InvaildFormatError if provided format is not in list" do
|
31
31
|
expect do
|
32
|
-
FastlyNsq::Http::Nsqd.stats(format:
|
32
|
+
FastlyNsq::Http::Nsqd.stats(format: "foo")
|
33
33
|
end.to raise_error(FastlyNsq::Http::Nsqd::InvalidFormatError)
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
37
|
-
it
|
37
|
+
it "can publish messages" do
|
38
38
|
url = "#{base_uri}/pub?topic=lol&defer=999"
|
39
39
|
stub_request(:post, url)
|
40
|
-
data = {
|
40
|
+
data = {topic: "lol", defer: 999}
|
41
41
|
|
42
|
-
FastlyNsq::Http::Nsqd.pub(topic:
|
42
|
+
FastlyNsq::Http::Nsqd.pub(topic: "lol", defer: 999, message: "SOMETHING", base_uri: base_uri)
|
43
43
|
|
44
|
-
expect(a_request(:post, url).with(query: data, body:
|
44
|
+
expect(a_request(:post, url).with(query: data, body: "SOMETHING")).to have_been_requested
|
45
45
|
end
|
46
46
|
|
47
|
-
it
|
47
|
+
it "can publish multiple messages" do
|
48
48
|
url = "#{base_uri}/mpub?topic=lol&binary=false"
|
49
49
|
stub_request(:post, url)
|
50
|
-
data = {
|
50
|
+
data = {topic: "lol"}
|
51
51
|
body = "ONE MESSAGE\nTWO MESSAGE\nRED MESSAGE\nBLUE MESSAGE"
|
52
52
|
|
53
|
-
FastlyNsq::Http::Nsqd.mpub(topic:
|
53
|
+
FastlyNsq::Http::Nsqd.mpub(topic: "lol", message: body, base_uri: base_uri)
|
54
54
|
|
55
55
|
expect(a_request(:post, url).with(query: data, body: body)).to have_been_requested
|
56
56
|
end
|
57
57
|
|
58
|
-
it
|
58
|
+
it "can create, delete, empty, pause and unpause topics and channels" do
|
59
59
|
verbs = %w[create delete empty pause unpause]
|
60
60
|
|
61
61
|
verbs.each do |verb|
|
62
62
|
url = "#{base_uri}/topic/#{verb}?topic=lol"
|
63
63
|
stub_request(:post, url)
|
64
|
-
data = {
|
64
|
+
data = {topic: "lol"}
|
65
65
|
|
66
|
-
FastlyNsq::Http::Nsqd.send("topic_#{verb}".to_sym, topic:
|
66
|
+
FastlyNsq::Http::Nsqd.send("topic_#{verb}".to_sym, topic: "lol", base_uri: base_uri)
|
67
67
|
|
68
68
|
expect(a_request(:post, url).with(query: data)).to have_been_requested
|
69
69
|
|
70
70
|
url = "#{base_uri}/channel/#{verb}?topic=lol&channel=foo"
|
71
71
|
stub_request(:post, url)
|
72
|
-
data = {
|
72
|
+
data = {topic: "lol", channel: "foo"}
|
73
73
|
|
74
|
-
FastlyNsq::Http::Nsqd.send("channel_#{verb}".to_sym, topic:
|
74
|
+
FastlyNsq::Http::Nsqd.send("channel_#{verb}".to_sym, topic: "lol", channel: "foo", base_uri: base_uri)
|
75
75
|
|
76
76
|
expect(a_request(:post, url).with(query: data)).to have_been_requested
|
77
77
|
end
|