rabbitmq-cluster 0.0.18 → 0.0.19
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/rabbitmq-cluster +0 -0
- data/bin/rabbitmq-cluster-discovery +0 -0
- data/bin/rabbitmq-cluster-prestart +0 -0
- data/lib/rabbitmq/cluster/etcd.rb +15 -11
- data/lib/rabbitmq/cluster/server.rb +1 -1
- data/lib/rabbitmq/cluster/version.rb +1 -1
- data/rabbitmq-cluster.gemspec +1 -1
- data/spec/unit/etcd_spec.rb +36 -32
- data/spec/unit/server_spec.rb +1 -1
- metadata +5 -5
data/bin/rabbitmq-cluster
CHANGED
File without changes
|
File without changes
|
File without changes
|
@@ -7,39 +7,43 @@ class RabbitMQ::Cluster
|
|
7
7
|
|
8
8
|
def self.build
|
9
9
|
new(
|
10
|
-
::Etcd::Client.new(
|
10
|
+
::Etcd::Client.new(host: ENV['ETCD_HOST'])
|
11
11
|
)
|
12
12
|
end
|
13
13
|
|
14
14
|
def initialize(client)
|
15
15
|
self.client = client
|
16
|
-
client.connect
|
17
16
|
end
|
18
17
|
|
19
|
-
def
|
20
|
-
|
21
|
-
sleep 1 until lock = client.update('/rabbitmq/lock', true, false)
|
22
|
-
end
|
18
|
+
def acquire_lock
|
19
|
+
client.compare_and_swap('/rabbitmq/lock', value: true, prevValue: false)
|
23
20
|
yield
|
21
|
+
rescue ::Etcd::TestFailed
|
22
|
+
client.watch('/rabbitmq/lock')
|
23
|
+
retry
|
24
24
|
ensure
|
25
|
-
client.
|
25
|
+
client.set('/rabbitmq/lock', value: false)
|
26
26
|
end
|
27
27
|
|
28
28
|
def nodes
|
29
29
|
with_retry do
|
30
|
-
|
30
|
+
begin
|
31
|
+
client.get('/rabbitmq/nodes').children.map(&:value).sort
|
32
|
+
rescue ::Etcd::KeyNotFound
|
33
|
+
[]
|
34
|
+
end
|
31
35
|
end
|
32
36
|
end
|
33
37
|
|
34
38
|
def register(node_name, wait=nil)
|
35
39
|
with_retry(wait) do
|
36
|
-
client.set(key_for(node_name), node_name, ttl: 10)
|
40
|
+
client.set(key_for(node_name), value: node_name, ttl: 10)
|
37
41
|
end
|
38
42
|
end
|
39
43
|
|
40
44
|
def erlang_cookie
|
41
45
|
with_retry do
|
42
|
-
client.get('/rabbitmq/erlang_cookie')
|
46
|
+
client.get('/rabbitmq/erlang_cookie').value
|
43
47
|
end
|
44
48
|
end
|
45
49
|
|
@@ -47,7 +51,7 @@ class RabbitMQ::Cluster
|
|
47
51
|
with_retry do
|
48
52
|
client.set(
|
49
53
|
'/rabbitmq/erlang_cookie',
|
50
|
-
erlang_cookie
|
54
|
+
value: erlang_cookie
|
51
55
|
)
|
52
56
|
end
|
53
57
|
end
|
data/rabbitmq-cluster.gemspec
CHANGED
@@ -19,7 +19,7 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
21
|
spec.add_dependency 'rabbitmq_manager'
|
22
|
-
spec.add_dependency 'etcd
|
22
|
+
spec.add_dependency 'etcd'
|
23
23
|
|
24
24
|
spec.add_development_dependency "bundler", "~> 1.5"
|
25
25
|
spec.add_development_dependency "rake"
|
data/spec/unit/etcd_spec.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe RabbitMQ::Cluster::Etcd do
|
4
|
-
let(:etcd_client) { double(:etcd
|
4
|
+
let(:etcd_client) { double(:etcd) }
|
5
5
|
subject { described_class.new(etcd_client) }
|
6
6
|
|
7
7
|
describe '.build' do
|
@@ -18,16 +18,25 @@ describe RabbitMQ::Cluster::Etcd do
|
|
18
18
|
describe '#nodes' do
|
19
19
|
it 'returns the list of nodes registed in etcd' do
|
20
20
|
allow(etcd_client).to receive(:get).with('/rabbitmq/nodes').and_return(
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
21
|
+
double(:response,
|
22
|
+
children: [
|
23
|
+
double(:response, value: "rabbit@rabbit1"),
|
24
|
+
double(:response, value: "rabbit@rabbit2")
|
25
|
+
]
|
26
|
+
)
|
25
27
|
)
|
26
28
|
expect(subject.nodes).to eq ["rabbit@rabbit1", "rabbit@rabbit2"]
|
27
29
|
end
|
28
30
|
|
29
31
|
it 'returns an empty array if there are no nodes registered' do
|
30
|
-
allow(etcd_client).to receive(:get).with('/rabbitmq/nodes')
|
32
|
+
allow(etcd_client).to receive(:get).with('/rabbitmq/nodes').and_return(
|
33
|
+
double(:response, children: [])
|
34
|
+
)
|
35
|
+
expect(subject.nodes).to eq []
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'returns an empty array if the nodes directory has not been created' do
|
39
|
+
allow(etcd_client).to receive(:get).with('/rabbitmq/nodes').and_raise(Etcd::KeyNotFound)
|
31
40
|
expect(subject.nodes).to eq []
|
32
41
|
end
|
33
42
|
end
|
@@ -39,7 +48,7 @@ describe RabbitMQ::Cluster::Etcd do
|
|
39
48
|
expect(etcd_client).to receive(:set)
|
40
49
|
.with(
|
41
50
|
"/rabbitmq/nodes/#{nodename}",
|
42
|
-
nodename,
|
51
|
+
value: nodename,
|
43
52
|
ttl: 10
|
44
53
|
)
|
45
54
|
subject.register(nodename)
|
@@ -63,7 +72,7 @@ describe RabbitMQ::Cluster::Etcd do
|
|
63
72
|
before do
|
64
73
|
allow(etcd_client).to receive(:get)
|
65
74
|
.with('/rabbitmq/erlang_cookie')
|
66
|
-
.and_return(erlang_cookie)
|
75
|
+
.and_return(double(:response, value: erlang_cookie))
|
67
76
|
end
|
68
77
|
|
69
78
|
it 'has a getter' do
|
@@ -74,55 +83,50 @@ describe RabbitMQ::Cluster::Etcd do
|
|
74
83
|
expect(etcd_client).to receive(:set)
|
75
84
|
.with(
|
76
85
|
'/rabbitmq/erlang_cookie',
|
77
|
-
erlang_cookie
|
86
|
+
value: erlang_cookie
|
78
87
|
)
|
79
88
|
subject.erlang_cookie = erlang_cookie
|
80
89
|
end
|
81
90
|
end
|
82
91
|
|
83
|
-
describe '#
|
84
|
-
let(:thingy) { double(run: nil) }
|
92
|
+
describe '#acquire_lock' do
|
85
93
|
before do
|
86
|
-
allow(etcd_client).to receive(:
|
87
|
-
allow(etcd_client).to receive(:
|
94
|
+
allow(etcd_client).to receive(:compare_and_swap).with('/rabbitmq/lock', value: true, prevValue: false)
|
95
|
+
allow(etcd_client).to receive(:set).with('/rabbitmq/lock', value: false)
|
88
96
|
end
|
89
97
|
|
90
98
|
describe 'when we can get the lock' do
|
91
99
|
it 'runs the code' do
|
92
|
-
expect(etcd_client).to receive(:
|
93
|
-
expect(
|
94
|
-
|
95
|
-
subject.aquire_lock { thingy.run }
|
100
|
+
expect(etcd_client).to receive(:compare_and_swap).with('/rabbitmq/lock', value: true, prevValue: false)
|
101
|
+
expect { |b| subject.acquire_lock(&b) }.to yield_control
|
96
102
|
end
|
97
103
|
|
98
104
|
it 'gives the lock back when its done' do
|
99
|
-
expect(etcd_client).to receive(:
|
100
|
-
|
101
|
-
subject.aquire_lock { thingy.run }
|
105
|
+
expect(etcd_client).to receive(:set).with('/rabbitmq/lock', value: false)
|
106
|
+
expect { |b| subject.acquire_lock(&b) }.to yield_control
|
102
107
|
end
|
103
108
|
end
|
104
109
|
|
105
110
|
describe "when we can't get the lock" do
|
106
|
-
it 'retries till the lock can be
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
111
|
+
it 'retries till the lock can be acquired' do
|
112
|
+
allow(etcd_client).to receive(:watch)
|
113
|
+
call_count = 0
|
114
|
+
expect(etcd_client).to receive(:compare_and_swap).with('/rabbitmq/lock', value: true, prevValue: false) do
|
115
|
+
call_count += 1
|
116
|
+
raise Etcd::TestFailed unless call_count == 3
|
117
|
+
end
|
118
|
+
expect { |b| subject.acquire_lock(&b) }.to yield_control
|
114
119
|
end
|
115
120
|
end
|
116
121
|
|
117
122
|
describe 'when something explodes' do
|
118
123
|
before do
|
119
|
-
allow(etcd_client).to receive(:
|
120
|
-
allow(etcd_client).to receive(:update).with('/rabbitmq/lock', true, false).and_return(true)
|
124
|
+
allow(etcd_client).to receive(:compare_and_swap)
|
121
125
|
end
|
122
126
|
|
123
127
|
it 'gives the lock back' do
|
124
|
-
expect(etcd_client).to receive(:
|
125
|
-
expect { subject.
|
128
|
+
expect(etcd_client).to receive(:set).with('/rabbitmq/lock', value: false)
|
129
|
+
expect { subject.acquire_lock { fail } }.to raise_error
|
126
130
|
end
|
127
131
|
end
|
128
132
|
end
|
data/spec/unit/server_spec.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rabbitmq-cluster
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.19
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-07-
|
12
|
+
date: 2014-07-14 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rabbitmq_manager
|
@@ -28,7 +28,7 @@ dependencies:
|
|
28
28
|
- !ruby/object:Gem::Version
|
29
29
|
version: '0'
|
30
30
|
- !ruby/object:Gem::Dependency
|
31
|
-
name: etcd
|
31
|
+
name: etcd
|
32
32
|
requirement: !ruby/object:Gem::Requirement
|
33
33
|
none: false
|
34
34
|
requirements:
|
@@ -148,7 +148,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
148
148
|
version: '0'
|
149
149
|
segments:
|
150
150
|
- 0
|
151
|
-
hash: -
|
151
|
+
hash: -1414004565124595041
|
152
152
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
153
153
|
none: false
|
154
154
|
requirements:
|
@@ -157,7 +157,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
157
157
|
version: '0'
|
158
158
|
segments:
|
159
159
|
- 0
|
160
|
-
hash: -
|
160
|
+
hash: -1414004565124595041
|
161
161
|
requirements: []
|
162
162
|
rubyforge_project:
|
163
163
|
rubygems_version: 1.8.25
|