beetle 3.5.0 → 3.5.4
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/Rakefile +9 -13
- data/beetle.gemspec +8 -5
- data/examples/redundant.rb +1 -1
- data/examples/rpc.rb +1 -1
- data/features/redis_auto_failover.feature +20 -0
- data/features/step_definitions/redis_auto_failover_steps.rb +35 -11
- data/features/support/test_daemons/redis_configuration_server.rb +2 -1
- data/lib/beetle/client.rb +6 -2
- data/lib/beetle/publisher.rb +3 -1
- data/lib/beetle/version.rb +1 -1
- data/lib/beetle.rb +2 -6
- data/test/beetle/amqp_gem_behavior_test.rb +1 -1
- data/test/beetle/base_test.rb +1 -1
- data/test/beetle/beetle_test.rb +7 -4
- data/test/beetle/client_test.rb +45 -6
- data/test/beetle/deduplication_store_test.rb +1 -1
- data/test/beetle/publisher_test.rb +15 -6
- data/test/beetle/subscriber_test.rb +9 -5
- data/test/test_helper.rb +9 -8
- metadata +77 -37
- data/README.rdoc +0 -233
- data/REDIS_AUTO_FAILOVER.rdoc +0 -116
- data/RELEASE_NOTES.rdoc +0 -379
- data/examples/README.rdoc +0 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 38849c0467ba80b057fa8bc659ad98b025dd1c6d9ce416a4f2c48dff91f50fac
|
4
|
+
data.tar.gz: 791b45e82bcddf8bca2923db816475aa16bb81efa96d7c38381de12ea18fe65b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cbd464c6759316b86ab5732029fefa39518360dc40f055e729d585b9304ad84c9597c7e37908826bfc0347c109c89e7729db8096b2bf51ec64c536c272c9b6b3
|
7
|
+
data.tar.gz: c7ef92729c7d9cf38c7ec5e0a90fff5147fb4350d568c82c93e58c76b5c358d74929517b888bb8f96386230f0b2f50272488981668d183294fbda5ac86893ade
|
data/Rakefile
CHANGED
@@ -98,7 +98,7 @@ namespace :consul do
|
|
98
98
|
end
|
99
99
|
|
100
100
|
Cucumber::Rake::Task.new(:cucumber) do |t|
|
101
|
-
t.cucumber_opts = "features --format progress"
|
101
|
+
t.cucumber_opts = ["features", "--format progress"]
|
102
102
|
end
|
103
103
|
|
104
104
|
task :cucumber => :clean
|
@@ -115,18 +115,14 @@ Rake::TestTask.new do |t|
|
|
115
115
|
t.warning = false
|
116
116
|
end
|
117
117
|
|
118
|
-
|
119
|
-
|
120
|
-
RDoc::Task.new do |rdoc|
|
121
|
-
rdoc.rdoc_dir = 'site/rdoc'
|
122
|
-
rdoc.title = 'Beetle'
|
123
|
-
rdoc.main = 'README.rdoc'
|
124
|
-
rdoc.options << '--line-numbers' << '--inline-source' << '--quiet'
|
125
|
-
rdoc.rdoc_files.include('**/*.rdoc')
|
126
|
-
rdoc.rdoc_files.include('MIT-LICENSE')
|
127
|
-
rdoc.rdoc_files.include('lib/**/*.rb')
|
118
|
+
task :clean do
|
119
|
+
sh "rm -f tmp/*.output tmp/*.log tmp/master-dir/* tmp/slave-dir/* tmp/*lock tmp/*pid test.log" unless ENV['GITHUB_ACTIONS']
|
128
120
|
end
|
129
121
|
|
130
|
-
|
131
|
-
|
122
|
+
require 'yard'
|
123
|
+
|
124
|
+
YARD::Rake::YardocTask.new do |t|
|
125
|
+
OTHER_PATHS = %w()
|
126
|
+
t.files = ['lib/**/*.rb'] + OTHER_PATHS
|
127
|
+
t.options = %w(--markup-provider=redcarpet --markup=markdown --main=README.md --output-dir=site/yard)
|
132
128
|
end
|
data/beetle.gemspec
CHANGED
@@ -24,23 +24,26 @@ Gem::Specification.new do |s|
|
|
24
24
|
|
25
25
|
s.specification_version = 3
|
26
26
|
s.add_runtime_dependency "bunny", "~> 0.7.12"
|
27
|
-
s.add_runtime_dependency "redis", ">= 4.2.1"
|
27
|
+
s.add_runtime_dependency "redis", [">= 4.2.1", "< 5.0"]
|
28
28
|
s.add_runtime_dependency "hiredis", ">= 0.4.5"
|
29
29
|
s.add_runtime_dependency "amq-protocol", "= 2.3.2"
|
30
30
|
s.add_runtime_dependency "amqp", "= 1.8.0"
|
31
31
|
s.add_runtime_dependency "activesupport", ">= 2.3.4"
|
32
32
|
|
33
33
|
s.add_development_dependency "activerecord", "~> 5.0"
|
34
|
-
s.add_development_dependency "cucumber", "~>
|
34
|
+
s.add_development_dependency "cucumber", "~> 8.0.0"
|
35
35
|
s.add_development_dependency "daemon_controller", "~> 1.2.0"
|
36
36
|
s.add_development_dependency "daemons", ">= 1.2.0"
|
37
37
|
s.add_development_dependency "i18n"
|
38
38
|
s.add_development_dependency "minitest", "~> 5.1"
|
39
|
-
s.add_development_dependency "mocha", "~> 1.
|
40
|
-
s.add_development_dependency "mysql2", "~> 0.
|
39
|
+
s.add_development_dependency "mocha", "~> 1.14"
|
40
|
+
s.add_development_dependency "mysql2", "~> 0.5"
|
41
41
|
s.add_development_dependency "rake", "~> 13.0"
|
42
|
-
s.add_development_dependency "rdoc", "~> 4.0"
|
43
42
|
s.add_development_dependency "simplecov", "~> 0.15"
|
44
43
|
s.add_development_dependency "webmock", "~> 3.0"
|
45
44
|
s.add_development_dependency "websocket-eventmachine-client"
|
45
|
+
s.add_development_dependency 'yard'
|
46
|
+
s.add_development_dependency 'redcarpet'
|
47
|
+
s.add_development_dependency 'github-markup'
|
48
|
+
s.add_development_dependency 'byebug'
|
46
49
|
end
|
data/examples/redundant.rb
CHANGED
@@ -17,7 +17,7 @@ Beetle.config.logger.level = Logger::INFO
|
|
17
17
|
client = Beetle::Client.new
|
18
18
|
|
19
19
|
# use two servers
|
20
|
-
Beetle.config.servers = "localhost:5672, localhost:5673"
|
20
|
+
Beetle.config.servers = ENV["RABBITMQ_SERVERS"] || "localhost:5672, localhost:5673"
|
21
21
|
# instantiate a client
|
22
22
|
client = Beetle::Client.new
|
23
23
|
|
data/examples/rpc.rb
CHANGED
@@ -4,7 +4,7 @@ require File.expand_path(File.dirname(__FILE__)+"/../lib/beetle")
|
|
4
4
|
|
5
5
|
# suppress debug messages
|
6
6
|
Beetle.config.logger.level = Logger::INFO
|
7
|
-
Beetle.config.servers = "localhost:5672, localhost:5673"
|
7
|
+
Beetle.config.servers = ENV["RABBITMQ_SERVERS"] || "localhost:5672, localhost:5673"
|
8
8
|
# instantiate a client
|
9
9
|
|
10
10
|
client = Beetle::Client.new
|
@@ -24,6 +24,26 @@ Feature: Redis auto failover
|
|
24
24
|
Given a redis server "redis-1" exists as master
|
25
25
|
Then the role of redis server "redis-1" should be "slave"
|
26
26
|
|
27
|
+
Scenario: Successful redis master switch with multiple slaves
|
28
|
+
And a redis server "redis-3" exists as slave of "redis-3"
|
29
|
+
Given a redis configuration server using redis servers "redis-1,redis-2,redis-3" with clients "rc-client-1,rc-client-2" exists
|
30
|
+
And a redis configuration client "rc-client-1" using redis servers "redis-1,redis-2,redis-3" exists
|
31
|
+
And a redis configuration client "rc-client-2" using redis servers "redis-1,redis-2,redis-3" exists
|
32
|
+
And a beetle handler using the redis-master file from "rc-client-1" exists
|
33
|
+
And redis server "redis-1" is down
|
34
|
+
And the retry timeout for the redis master check is reached
|
35
|
+
Then a system notification for "redis-1" not being available should be sent
|
36
|
+
And the role of redis server "redis-2" should be "master"
|
37
|
+
And the redis master file of the redis configuration server should contain "redis-2"
|
38
|
+
And the redis master of "rc-client-1" should be "redis-2"
|
39
|
+
And the redis master of "rc-client-2" should be "redis-2"
|
40
|
+
And the redis master of the beetle handler should be "redis-2"
|
41
|
+
And a system notification for switching from "redis-1" to "redis-2" should be sent
|
42
|
+
Given a redis server "redis-1" exists as master
|
43
|
+
Then the role of redis server "redis-1" should be "slave"
|
44
|
+
And the redis server "redis-1" is a slave of "redis-2"
|
45
|
+
And the redis server "redis-3" is a slave of "redis-2"
|
46
|
+
|
27
47
|
Scenario: Successful single redis master switch with multiple failover sets
|
28
48
|
Given a redis server "redis-3" exists as master
|
29
49
|
And a redis server "redis-4" exists as slave of "redis-3"
|
@@ -1,8 +1,9 @@
|
|
1
1
|
Given /^consul state has been cleared$/ do
|
2
|
+
consul_host = ENV["CONSUL_HOST"] || "localhost:8500"
|
2
3
|
system "killall beetle beetle_handler >/dev/null 2>/dev/null"
|
3
|
-
system "curl --silent --request PUT http
|
4
|
-
system "curl --silent --request PUT http
|
5
|
-
system "curl --silent --request DELETE http
|
4
|
+
system "curl --silent --request PUT http://#{consul_host}/v1/kv/apps/beetle/config/ >/dev/null"
|
5
|
+
system "curl --silent --request PUT http://#{consul_host}/v1/kv/shared/config/ >/dev/null"
|
6
|
+
system "curl --silent --request DELETE http://#{consul_host}/v1/kv/apps/beetle/state/redis_master_file_content >/dev/null"
|
6
7
|
end
|
7
8
|
|
8
9
|
Given /^a redis server "([^\"]*)" exists as master$/ do |redis_name|
|
@@ -93,7 +94,6 @@ Given /^an old redis master file for "([^\"]*)" with master "([^\"]*)" exists$/
|
|
93
94
|
end
|
94
95
|
end
|
95
96
|
|
96
|
-
|
97
97
|
Then /^the role of redis server "([^\"]*)" should be "(master|slave)"$/ do |redis_name, role|
|
98
98
|
expected_role = false
|
99
99
|
10.times do
|
@@ -103,6 +103,16 @@ Then /^the role of redis server "([^\"]*)" should be "(master|slave)"$/ do |redi
|
|
103
103
|
assert expected_role, "#{redis_name} is not a #{role}"
|
104
104
|
end
|
105
105
|
|
106
|
+
Then /^the redis server "([^\"]*)" is a slave of "([^\"]*)"$/ do |redis_name, redis_master_name|
|
107
|
+
master = TestDaemons::Redis[redis_master_name].redis
|
108
|
+
slave = TestDaemons::Redis[redis_name].redis
|
109
|
+
3.times do
|
110
|
+
sleep 1
|
111
|
+
break if slave.slave_of?(master.host, master.port)
|
112
|
+
end
|
113
|
+
assert slave.slave_of?(master.host, master.port)
|
114
|
+
end
|
115
|
+
|
106
116
|
Then /^the redis master of "([^\"]*)" (?:in system "([^"]*)" )?should be "([^\"]*)"$/ do |redis_configuration_client_name, system_name, redis_name|
|
107
117
|
system_name ||= "system"
|
108
118
|
master_file = redis_master_file(redis_configuration_client_name)
|
@@ -143,11 +153,21 @@ end
|
|
143
153
|
Then /^the redis master of the beetle handler should be "([^\"]*)"$/ do |redis_name|
|
144
154
|
Beetle.config.servers = "127.0.0.1:5672" # rabbitmq
|
145
155
|
Beetle.config.logger.level = Logger::INFO
|
146
|
-
|
147
|
-
|
148
|
-
|
156
|
+
redis_master = TestDaemons::Redis[redis_name].ip_with_port
|
157
|
+
response = nil
|
158
|
+
expected_response = ['OK', redis_master]
|
159
|
+
3.times do |i|
|
160
|
+
client = Beetle::Client.new.configure :auto_delete => true do |config|
|
161
|
+
config.queue(:echo, :lazy => true, :dead_lettering => true)
|
162
|
+
config.message(:echo)
|
163
|
+
end
|
164
|
+
t1 = Time.now
|
165
|
+
response = client.rpc(:echo, 'echo')
|
166
|
+
t2 = Time.now
|
167
|
+
# puts "OK,#{redis_master} =?= #{response.join(',')} after #{t2-t1}, attempt #{i+1}"
|
168
|
+
break if expected_response == response
|
149
169
|
end
|
150
|
-
|
170
|
+
assert_equal expected_response, response
|
151
171
|
end
|
152
172
|
|
153
173
|
Then /^a system notification for "([^\"]*)" not being available should be sent$/ do |redis_name|
|
@@ -166,8 +186,12 @@ end
|
|
166
186
|
|
167
187
|
Then /^a system notification for no slave available to become new master should be sent$/ do
|
168
188
|
text = "Redis master could not be switched, no slave available to become new master"
|
169
|
-
|
170
|
-
|
189
|
+
tail = ""
|
190
|
+
3.times do
|
191
|
+
lines = File.readlines(system_notification_log_path)
|
192
|
+
tail = (["","",""]+lines)[-3..-1].join("\n")
|
193
|
+
sleep 0.1 unless tail =~ /#{text}/
|
194
|
+
end
|
171
195
|
assert_match /#{text}/, tail
|
172
196
|
end
|
173
197
|
|
@@ -179,7 +203,7 @@ end
|
|
179
203
|
|
180
204
|
Given /^an immediate master switch is initiated and responds with (\d+)$/ do |response_code|
|
181
205
|
response = TestDaemons::RedisConfigurationServer.initiate_master_switch
|
182
|
-
assert_equal response_code, response.code, "unexpected response code #{response.code}, message: #{response.body}"
|
206
|
+
assert_equal response_code.to_s, response.code, "unexpected response code #{response.code}, message: #{response.body}"
|
183
207
|
sleep 1
|
184
208
|
end
|
185
209
|
|
@@ -25,9 +25,10 @@ module TestDaemons
|
|
25
25
|
|
26
26
|
def self.daemon_controller
|
27
27
|
clients_parameter_string = @@redis_configuration_clients.blank? ? "" : "--client-ids #{@@redis_configuration_clients}"
|
28
|
+
consul_host = ENV["CONSUL_HOST"] || "localhost:8500"
|
28
29
|
DaemonController.new(
|
29
30
|
:identifier => "Redis configuration test server",
|
30
|
-
:start_command => "./beetle configuration_server -v -d --redis-master-file #{redis_master_file} --redis-servers '#{@@redis_servers}' #{clients_parameter_string} --redis-master-retry-interval 1 --pid-file #{pid_file} --log-file #{log_file} --redis-failover-confidence-level #{@@confidence_level} --consul http
|
31
|
+
:start_command => "./beetle configuration_server -v -d --redis-master-file #{redis_master_file} --redis-servers '#{@@redis_servers}' #{clients_parameter_string} --redis-master-retry-interval 1 --pid-file #{pid_file} --log-file #{log_file} --redis-failover-confidence-level #{@@confidence_level} --consul http://#{consul_host}",
|
31
32
|
:ping_command => lambda{ answers_text_requests? },
|
32
33
|
:pid_file => pid_file,
|
33
34
|
:log_file => log_file,
|
data/lib/beetle/client.rb
CHANGED
@@ -385,8 +385,12 @@ module Beetle
|
|
385
385
|
end
|
386
386
|
|
387
387
|
def load_brokers_from_config
|
388
|
-
@servers = config.servers
|
389
|
-
@additional_subscription_servers = config.additional_subscription_servers
|
388
|
+
@servers = parse_server_list(config.servers)
|
389
|
+
@additional_subscription_servers = parse_server_list(config.additional_subscription_servers) - @servers
|
390
|
+
end
|
391
|
+
|
392
|
+
def parse_server_list(s)
|
393
|
+
s.split(/ *, */).uniq.reject(&:blank?)
|
390
394
|
end
|
391
395
|
end
|
392
396
|
end
|
data/lib/beetle/publisher.rb
CHANGED
@@ -34,7 +34,7 @@ module Beetle
|
|
34
34
|
Bunny::ConnectionError, Bunny::ForcedChannelCloseError, Bunny::ForcedConnectionCloseError,
|
35
35
|
Bunny::MessageError, Bunny::ProtocolError, Bunny::ServerDownError, Bunny::UnsubscribeError,
|
36
36
|
Bunny::AcknowledgementError, Qrack::BufferOverflowError, Qrack::InvalidTypeError,
|
37
|
-
Errno::EHOSTUNREACH, Errno::ECONNRESET, Timeout::Error
|
37
|
+
Errno::EHOSTUNREACH, Errno::ECONNRESET, Errno::ETIMEDOUT, Timeout::Error
|
38
38
|
]
|
39
39
|
end
|
40
40
|
|
@@ -66,6 +66,7 @@ module Beetle
|
|
66
66
|
logger.debug "Beetle: message sent!"
|
67
67
|
published = 1
|
68
68
|
rescue *bunny_exceptions => e
|
69
|
+
logger.warn("Beetle: publishing exception #{e} #{e.backtrace[0..4].join("\n")}")
|
69
70
|
stop!(e)
|
70
71
|
tries -= 1
|
71
72
|
# retry same server on receiving the first exception for it (might have been a normal restart)
|
@@ -98,6 +99,7 @@ module Beetle
|
|
98
99
|
published << @server
|
99
100
|
logger.debug "Beetle: message sent (#{published})!"
|
100
101
|
rescue *bunny_exceptions => e
|
102
|
+
logger.warn("Beetle: publishing exception #{e} #{e.backtrace[0..4].join("\n")}")
|
101
103
|
stop!(e)
|
102
104
|
retry if (tries += 1) == 1
|
103
105
|
mark_server_dead
|
data/lib/beetle/version.rb
CHANGED
data/lib/beetle.rb
CHANGED
@@ -39,12 +39,8 @@ module Beetle
|
|
39
39
|
# determine the fully qualified domainname of the host we're running on
|
40
40
|
def self.hostname
|
41
41
|
name = Socket.gethostname
|
42
|
-
|
43
|
-
|
44
|
-
name
|
45
|
-
else
|
46
|
-
Socket.gethostbyname(parts.first).first rescue name
|
47
|
-
end
|
42
|
+
host = name.split('.').first
|
43
|
+
Addrinfo.getaddrinfo(host, nil, nil, :STREAM, nil, Socket::AI_CANONNAME).first.canonname rescue name
|
48
44
|
end
|
49
45
|
|
50
46
|
# use ruby's autoload mechanism for loading beetle classes
|
@@ -7,7 +7,7 @@ class AMQPGemBehaviorTest < Minitest::Test
|
|
7
7
|
begin
|
8
8
|
exception = nil
|
9
9
|
EM.run do
|
10
|
-
AMQP.start(:
|
10
|
+
AMQP.start(logging: false, host: ENV['RABBITMQ_SERVERS'] || 'localhost') do |connection|
|
11
11
|
EM::Timer.new(1){ connection.close { EM.stop }}
|
12
12
|
channel = AMQP::Channel.new(connection)
|
13
13
|
channel.on_error { puts "woot"}
|
data/test/beetle/base_test.rb
CHANGED
data/test/beetle/beetle_test.rb
CHANGED
@@ -2,15 +2,18 @@ require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
|
|
2
2
|
|
3
3
|
module Beetle
|
4
4
|
class HostnameTest < Minitest::Test
|
5
|
-
|
5
|
+
test "should use canonical name if possible " do
|
6
|
+
addr = mock("addr")
|
7
|
+
addr.expects(:canonname).returns("a.b.com")
|
6
8
|
Socket.expects(:gethostname).returns("a.b.com")
|
9
|
+
Addrinfo.expects(:getaddrinfo).with("a", nil, nil, :STREAM, nil, Socket::AI_CANONNAME).returns([addr])
|
7
10
|
assert_equal "a.b.com", Beetle.hostname
|
8
11
|
end
|
9
12
|
|
10
|
-
test "should use Socket.
|
13
|
+
test "should use Socket.gethostbyname if Addrinfo raises" do
|
11
14
|
Socket.expects(:gethostname).returns("a")
|
12
|
-
|
13
|
-
assert_equal "a
|
15
|
+
Addrinfo.expects(:getaddrinfo).with("a", nil, nil, :STREAM, nil, Socket::AI_CANONNAME).raises("murks")
|
16
|
+
assert_equal "a", Beetle.hostname
|
14
17
|
end
|
15
18
|
end
|
16
19
|
end
|
data/test/beetle/client_test.rb
CHANGED
@@ -8,7 +8,7 @@ module Beetle
|
|
8
8
|
end
|
9
9
|
|
10
10
|
test "should have a default server" do
|
11
|
-
|
11
|
+
assert !@client.servers.empty?
|
12
12
|
end
|
13
13
|
|
14
14
|
test "should have no additional subscription servers" do
|
@@ -327,7 +327,9 @@ module Beetle
|
|
327
327
|
client.register_queue("b_queue")
|
328
328
|
client.register_queue("a_queue")
|
329
329
|
client.send(:subscriber).expects(:listen_queues).with {|value| value.include?("a_queue") && value.include?("b_queue")}.yields
|
330
|
-
|
330
|
+
called = false
|
331
|
+
client.listen { called = true }
|
332
|
+
assert called
|
331
333
|
end
|
332
334
|
|
333
335
|
test "trying to listen to a message is no longer supported and should raise an exception" do
|
@@ -338,22 +340,24 @@ module Beetle
|
|
338
340
|
client = Client.new
|
339
341
|
client.register_queue(:test)
|
340
342
|
client.send(:subscriber).expects(:listen_queues).with(['test']).yields
|
341
|
-
|
343
|
+
called = false
|
344
|
+
client.listen_queues([:test]) { called = true }
|
345
|
+
assert called
|
342
346
|
end
|
343
347
|
|
344
348
|
test "trying to listen to an unknown queue should raise an exception" do
|
345
349
|
client = Client.new
|
346
|
-
assert_raises(UnknownQueue) {
|
350
|
+
assert_raises(UnknownQueue) { client.listen_queues([:foobar])}
|
347
351
|
end
|
348
352
|
|
349
353
|
test "trying to pause listening on an unknown queue should raise an exception" do
|
350
354
|
client = Client.new
|
351
|
-
assert_raises(UnknownQueue) {
|
355
|
+
assert_raises(UnknownQueue) { client.pause_listening(:foobar)}
|
352
356
|
end
|
353
357
|
|
354
358
|
test "trying to resume listening on an unknown queue should raise an exception" do
|
355
359
|
client = Client.new
|
356
|
-
assert_raises(UnknownQueue) {
|
360
|
+
assert_raises(UnknownQueue) { client.pause_listening(:foobar)}
|
357
361
|
end
|
358
362
|
|
359
363
|
test "should delegate stop_listening to the subscriber instance" do
|
@@ -457,4 +461,39 @@ module Beetle
|
|
457
461
|
msg_stub
|
458
462
|
end
|
459
463
|
end
|
464
|
+
|
465
|
+
class ServerDeduplicationTest < Minitest::Test
|
466
|
+
def setup
|
467
|
+
@config = Configuration.new
|
468
|
+
@config.servers = "localhost:5672,localhost:5672"
|
469
|
+
@config.additional_subscription_servers = @config.servers + ",localhost:1234,localhost:1234"
|
470
|
+
@client = Client.new(@config)
|
471
|
+
end
|
472
|
+
|
473
|
+
test "duplicates are removed from the server list" do
|
474
|
+
assert_equal ["localhost:5672"], @client.servers
|
475
|
+
end
|
476
|
+
|
477
|
+
test "duplicates and servers in the server list are removed from the additional subscription server list" do
|
478
|
+
assert_equal ["localhost:1234"], @client.additional_subscription_servers
|
479
|
+
end
|
480
|
+
end
|
481
|
+
|
482
|
+
class EmptyServerStringTest < Minitest::Test
|
483
|
+
def setup
|
484
|
+
@config = Configuration.new
|
485
|
+
@config.servers = "localhost:5672,\t,localhost:5672, "
|
486
|
+
@config.additional_subscription_servers = @config.servers + ",localhost:1234, , ,,"
|
487
|
+
@client = Client.new(@config)
|
488
|
+
end
|
489
|
+
|
490
|
+
test "empty strings are removed from the server list" do
|
491
|
+
assert_equal ["localhost:5672"], @client.servers
|
492
|
+
end
|
493
|
+
|
494
|
+
test "empty strings are removed from the additional subscription server list" do
|
495
|
+
assert_equal ["localhost:1234"], @client.additional_subscription_servers
|
496
|
+
end
|
497
|
+
end
|
498
|
+
|
460
499
|
end
|
@@ -87,7 +87,7 @@ module Beetle
|
|
87
87
|
private
|
88
88
|
def redis_test_master_file(server_string)
|
89
89
|
tmp_dir = File.expand_path("../../../tmp", __FILE__)
|
90
|
-
Dir.mkdir(tmp_dir) unless File.
|
90
|
+
Dir.mkdir(tmp_dir) unless File.exist?(tmp_dir)
|
91
91
|
path = tmp_dir + "/redis-master-for-unit-tests"
|
92
92
|
File.open(path, "w"){|f| f.puts server_string}
|
93
93
|
path
|
@@ -77,7 +77,9 @@ module Beetle
|
|
77
77
|
|
78
78
|
class PublisherPublishingTest < Minitest::Test
|
79
79
|
def setup
|
80
|
-
@
|
80
|
+
@config = Configuration.new
|
81
|
+
@config.servers = ENV['RABBITMQ_SERVERS'].split(',').first if ENV['RABBITMQ_SERVERS']
|
82
|
+
@client = Client.new(@config)
|
81
83
|
@pub = Publisher.new(@client)
|
82
84
|
@pub.stubs(:bind_queues_for_exchange)
|
83
85
|
@client.register_queue("mama", :exchange => "mama-exchange")
|
@@ -277,6 +279,7 @@ module Beetle
|
|
277
279
|
class PublisherQueueManagementTest < Minitest::Test
|
278
280
|
def setup
|
279
281
|
@config = Configuration.new
|
282
|
+
@config.servers = ENV['RABBITMQ_SERVERS'] if ENV['RABBITMQ_SERVERS']
|
280
283
|
@client = Client.new(@config)
|
281
284
|
@pub = Publisher.new(@client)
|
282
285
|
end
|
@@ -305,7 +308,9 @@ module Beetle
|
|
305
308
|
@client.register_queue('test_queue_2', :exchange => 'test_exchange')
|
306
309
|
@client.register_queue('test_queue_3', :exchange => 'test_exchange_2')
|
307
310
|
queue = mock("queue")
|
308
|
-
|
311
|
+
@pub.expects(:bind_queue!).with(queue, "test_exchange", {:key => "test_queue_1"}).once
|
312
|
+
@pub.expects(:bind_queue!).with(queue, "test_exchange", {:key => "test_queue_2"}).once
|
313
|
+
@pub.expects(:bind_queue!).with(queue, "test_exchange_2", {:key => "test_queue_3"}).once
|
309
314
|
@pub.expects(:declare_queue!).returns(queue).times(3)
|
310
315
|
@pub.send(:bind_queues_for_exchange, 'test_exchange')
|
311
316
|
@pub.send(:bind_queues_for_exchange, 'test_exchange_2')
|
@@ -315,18 +320,21 @@ module Beetle
|
|
315
320
|
@client.register_queue('test_queue_1', :exchange => 'test_exchange')
|
316
321
|
@client.register_queue('test_queue_2', :exchange => 'test_exchange')
|
317
322
|
queue = mock("queue")
|
318
|
-
queue.expects(:bind).twice
|
319
323
|
@pub.expects(:declare_queue!).returns(queue).twice
|
324
|
+
@pub.expects(:bind_queue!).with(queue, "test_exchange", {:key => "test_queue_1"}).once
|
325
|
+
@pub.expects(:bind_queue!).with(queue, "test_exchange", {:key => "test_queue_2"}).once
|
320
326
|
@pub.send(:bind_queues_for_exchange, 'test_exchange')
|
321
327
|
@pub.send(:bind_queues_for_exchange, 'test_exchange')
|
322
328
|
end
|
323
329
|
|
324
330
|
test "should declare queues only once even with many bindings" do
|
331
|
+
|
325
332
|
@client.register_queue('test_queue', :exchange => 'test_exchange')
|
326
333
|
@client.register_binding('test_queue', :exchange => 'test_exchange', :key => 'sir-message-a-lot')
|
327
334
|
queue = mock("queue")
|
328
|
-
queue.expects(:bind).twice
|
329
335
|
@pub.expects(:declare_queue!).returns(queue).once
|
336
|
+
@pub.expects(:bind_queue!).with(queue, "test_exchange", {:key => "test_queue"}).once
|
337
|
+
@pub.expects(:bind_queue!).with(queue, "test_exchange", {:key => "sir-message-a-lot"}).once
|
330
338
|
@pub.send(:bind_queues_for_exchange, 'test_exchange')
|
331
339
|
end
|
332
340
|
|
@@ -549,10 +557,11 @@ module Beetle
|
|
549
557
|
end
|
550
558
|
end
|
551
559
|
|
552
|
-
|
553
560
|
class RPCTest < Minitest::Test
|
554
561
|
def setup
|
555
|
-
@
|
562
|
+
@config = Configuration.new
|
563
|
+
@config.servers = ENV['RABBITMQ_SERVERS'].split(',').first if ENV['RABBITMQ_SERVERS']
|
564
|
+
@client = Client.new(@config)
|
556
565
|
@pub = Publisher.new(@client)
|
557
566
|
@client.register_message(:test, :exchange => :some_exchange)
|
558
567
|
end
|
@@ -41,9 +41,9 @@ module Beetle
|
|
41
41
|
|
42
42
|
test "stop! should close all connections if the reactor is not running" do
|
43
43
|
connection1 = mock('conection1')
|
44
|
-
connection1.expects(:close)
|
44
|
+
connection1.expects(:close)
|
45
45
|
connection2 = mock('connection2')
|
46
|
-
connection2.expects(:close)
|
46
|
+
connection2.expects(:close)
|
47
47
|
@sub.instance_variable_set "@connections", [["server1", connection1], ["server2", connection2]]
|
48
48
|
EM.expects(:reactor_running?).returns(false)
|
49
49
|
@sub.send(:stop!)
|
@@ -52,7 +52,9 @@ module Beetle
|
|
52
52
|
|
53
53
|
class SubscriberPauseAndResumeTest < Minitest::Test
|
54
54
|
def setup
|
55
|
-
@
|
55
|
+
@config = Configuration.new
|
56
|
+
@config.servers = "localhost:5672"
|
57
|
+
@client = Client.new(@config)
|
56
58
|
@sub = @client.send(:subscriber)
|
57
59
|
@sub.servers << "localhost:7777"
|
58
60
|
@server1, @server2 = @sub.servers
|
@@ -127,7 +129,7 @@ module Beetle
|
|
127
129
|
@sub = @client.send(:subscriber)
|
128
130
|
end
|
129
131
|
|
130
|
-
test "subscribers server list should contain
|
132
|
+
test "subscribers server list should contain additional subcription hosts" do
|
131
133
|
assert_equal ["localhost:5672", "localhost:1234"], @sub.servers
|
132
134
|
end
|
133
135
|
end
|
@@ -342,7 +344,9 @@ module Beetle
|
|
342
344
|
|
343
345
|
class SubscriptionTest < Minitest::Test
|
344
346
|
def setup
|
345
|
-
@
|
347
|
+
@config = Configuration.new
|
348
|
+
@config.servers = "locahost:5672"
|
349
|
+
@client = Client.new(@config)
|
346
350
|
@sub = @client.send(:subscriber)
|
347
351
|
end
|
348
352
|
|
data/test/test_helper.rb
CHANGED
@@ -8,7 +8,7 @@ end
|
|
8
8
|
require 'minitest/autorun'
|
9
9
|
require 'minitest/unit'
|
10
10
|
require 'minitest/pride' if ENV['RAINBOW_COLORED_TESTS'] == "1" && $stdout.tty?
|
11
|
-
require 'mocha/
|
11
|
+
require 'mocha/minitest'
|
12
12
|
|
13
13
|
require File.expand_path(File.dirname(__FILE__) + '/../lib/beetle')
|
14
14
|
require 'eventmachine'
|
@@ -27,12 +27,14 @@ end
|
|
27
27
|
I18n.enforce_available_locales = false
|
28
28
|
|
29
29
|
Beetle.config.logger = Logger.new(File.dirname(__FILE__) + '/../test.log')
|
30
|
-
|
31
|
-
|
32
|
-
|
30
|
+
Beetle.config.servers = ENV["RABBITMQ_SERVERS"] || "localhost:5672"
|
31
|
+
|
32
|
+
if system('docker -v >/dev/null') && `docker inspect beetle-redis-master -f '{{.State.Status}}'`.chomp == "running"
|
33
|
+
Beetle.config.redis_server = ENV["REDIS_SERVER"] || "localhost:6370"
|
34
|
+
Beetle.config.redis_servers = ENV["REDIS_SERVERS"] || "localhost:6370,localhost:6380"
|
33
35
|
else
|
34
|
-
Beetle.config.redis_server = "localhost:6379"
|
35
|
-
Beetle.config.redis_servers = "localhost:6379,localhost:6380"
|
36
|
+
Beetle.config.redis_server = ENV["REDIS_SERVER"] || "localhost:6379"
|
37
|
+
Beetle.config.redis_servers = ENV["REDIS_SERVERS"] || "localhost:6379,localhost:6380"
|
36
38
|
end
|
37
39
|
|
38
40
|
def header_with_params(opts = {})
|
@@ -43,7 +45,6 @@ def header_with_params(opts = {})
|
|
43
45
|
header
|
44
46
|
end
|
45
47
|
|
46
|
-
|
47
48
|
def redis_stub(name, opts = {})
|
48
49
|
default_port = opts['port'] || "1234"
|
49
50
|
default_host = opts['host'] || "foo"
|
@@ -51,6 +52,6 @@ def redis_stub(name, opts = {})
|
|
51
52
|
stub(name, opts)
|
52
53
|
end
|
53
54
|
|
54
|
-
if `docker inspect beetle-mysql -f '{{.State.Status}}'`.chomp == "running"
|
55
|
+
if system('docker -v >/dev/null') && `docker inspect beetle-mysql -f '{{.State.Status}}'`.chomp == "running"
|
55
56
|
ENV['MYSQL_PORT'] = '6612'
|
56
57
|
end
|