etcd 0.0.6 → 0.2.0.alpha
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +13 -5
- data/.coco.yml +5 -0
- data/.gitignore +0 -9
- data/.travis.yml +3 -7
- data/Gemfile +2 -0
- data/README.md +4 -3
- data/build_etcd +8 -0
- data/etcd.gemspec +1 -3
- data/lib/etcd.rb +2 -2
- data/lib/etcd/client.rb +129 -0
- data/lib/etcd/exceptions.rb +78 -0
- data/lib/etcd/keys.rb +147 -0
- data/lib/etcd/log.rb +10 -0
- data/lib/etcd/mod/leader.rb +28 -0
- data/lib/etcd/mod/lock.rb +59 -0
- data/lib/etcd/node.rb +44 -0
- data/lib/etcd/response.rb +33 -0
- data/lib/etcd/stats.rb +25 -0
- data/lib/etcd/version.rb +5 -0
- data/spec/etcd/client_spec.rb +54 -0
- data/spec/etcd/keys_spec.rb +26 -0
- data/spec/etcd/leader_spec.rb +29 -0
- data/spec/etcd/lock_spec.rb +46 -0
- data/spec/etcd/node_spec.rb +27 -0
- data/spec/{functional → etcd}/read_only_client_spec.rb +11 -2
- data/spec/etcd/readme_spec.rb +312 -0
- data/spec/etcd/stats_spec.rb +40 -0
- data/spec/{functional → etcd}/test_and_set_spec.rb +11 -3
- data/spec/{functional → etcd}/watch_spec.rb +13 -4
- data/spec/spec_helper.rb +88 -8
- metadata +46 -68
- data/spec/functional/client_spec.rb +0 -59
- data/spec/functional/lock_spec.rb +0 -70
- data/spec/functional_spec_helpers.rb +0 -56
- data/spec/unit/etcd_spec.rb +0 -15
@@ -0,0 +1,40 @@
|
|
1
|
+
# Encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Etcd::Stats do
|
6
|
+
|
7
|
+
let(:client) do
|
8
|
+
Etcd.client
|
9
|
+
end
|
10
|
+
|
11
|
+
describe 'of leader' do
|
12
|
+
|
13
|
+
let(:stats) do
|
14
|
+
client.stats(:leader)
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'should contain a key for leader' do
|
18
|
+
expect(stats['leader']).to_not be_nil
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'should have 4 followers (since we spawn 5 node etcd cluster)' do
|
22
|
+
expect(stats['followers'].keys.size).to eq(4)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'should show self statsistics' do
|
27
|
+
expect(client.stats(:self)['name']).to_not be_nil
|
28
|
+
expect(client.stats(:self)['state']).to_not be_nil
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'should show store statistics' do
|
32
|
+
expect(client.stats(:store).keys).to_not be_empty
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'should raise error for invalid types' do
|
36
|
+
expect do
|
37
|
+
client.stats(:foo)
|
38
|
+
end.to raise_error
|
39
|
+
end
|
40
|
+
end
|
@@ -1,4 +1,13 @@
|
|
1
|
-
|
1
|
+
# Encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe "Etcd test_and_set" do
|
6
|
+
|
7
|
+
let(:client) do
|
8
|
+
Etcd.client
|
9
|
+
end
|
10
|
+
|
2
11
|
it "should pass when prev value is correct" do
|
3
12
|
key = random_key(2)
|
4
13
|
old_value = uuid.generate
|
@@ -12,7 +21,7 @@ shared_examples "test_and_set" do
|
|
12
21
|
key = random_key(2)
|
13
22
|
value = uuid.generate
|
14
23
|
client.set(key, value)
|
15
|
-
expect{ client.test_and_set(key, 10, 2)}.to raise_error(
|
24
|
+
expect{ client.test_and_set(key, 10, 2)}.to raise_error(Etcd::TestFailed)
|
16
25
|
end
|
17
26
|
|
18
27
|
it "#create should succeed when the key is absent and update should fail" do
|
@@ -41,4 +50,3 @@ shared_examples "test_and_set" do
|
|
41
50
|
}.to_not raise_error
|
42
51
|
end
|
43
52
|
end
|
44
|
-
|
@@ -1,4 +1,13 @@
|
|
1
|
-
|
1
|
+
# Encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe "Etcd watch" do
|
6
|
+
|
7
|
+
let(:client) do
|
8
|
+
Etcd.client
|
9
|
+
end
|
10
|
+
|
2
11
|
it "without index, returns the value at a particular index" do
|
3
12
|
key = random_key(4)
|
4
13
|
value1 = uuid.generate
|
@@ -7,8 +16,8 @@ shared_examples "watch" do
|
|
7
16
|
index1 = client.create(key, value1).node.modifiedIndex
|
8
17
|
index2 = client.test_and_set(key, value2, value1).node.modifiedIndex
|
9
18
|
|
10
|
-
expect(client.watch(key, index: index1).value).to eq(value1)
|
11
|
-
expect(client.watch(key, index: index2).value).to eq(value2)
|
19
|
+
expect(client.watch(key, index: index1).node.value).to eq(value1)
|
20
|
+
expect(client.watch(key, index: index2).node.value).to eq(value2)
|
12
21
|
end
|
13
22
|
|
14
23
|
it "with index, waits and return when the key is updated" do
|
@@ -20,6 +29,6 @@ shared_examples "watch" do
|
|
20
29
|
end
|
21
30
|
client.set(key, value)
|
22
31
|
thr.join
|
23
|
-
expect(response.value).to eq(value)
|
32
|
+
expect(response.node.value).to eq(value)
|
24
33
|
end
|
25
34
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,14 +1,94 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
|
-
require 'simplecov'
|
4
|
-
|
5
|
-
SimpleCov.start do
|
6
|
-
add_filter "/.bundle/"
|
7
|
-
add_filter "/spec/"
|
8
|
-
end
|
9
|
-
|
10
3
|
$:.unshift(File.expand_path("../lib", __FILE__))
|
11
4
|
$:.unshift(File.expand_path("../spec", __FILE__))
|
12
5
|
|
6
|
+
require 'coco'
|
7
|
+
require 'uuid'
|
13
8
|
require 'etcd'
|
14
|
-
|
9
|
+
|
10
|
+
module Etcd
|
11
|
+
module SpecHelper
|
12
|
+
|
13
|
+
@@pids = []
|
14
|
+
|
15
|
+
def self.etcd_binary
|
16
|
+
if File.exists? './etcd/etcd'
|
17
|
+
'./etcd/etcd'
|
18
|
+
elsif !! ENV['ETCD_BIN']
|
19
|
+
ENV['ETCD_BIN']
|
20
|
+
else
|
21
|
+
raise 'etcd binary not found., you need to set ETCD_BIN'
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.start_etcd_servers
|
26
|
+
@@tmpdir = Dir.mktmpdir
|
27
|
+
pid = spawn_etcd_server(@@tmpdir+'/leader')
|
28
|
+
@@pids = Array(pid)
|
29
|
+
leader = '127.0.0.1:7001'
|
30
|
+
4.times do |n|
|
31
|
+
client_port = 4002 + n
|
32
|
+
server_port = 7002 + n
|
33
|
+
pid = spawn_etcd_server(@@tmpdir+client_port.to_s, client_port, server_port, leader)
|
34
|
+
@@pids << pid
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.stop_etcd_servers
|
39
|
+
@@pids.each do |pid|
|
40
|
+
Process.kill("TERM", pid)
|
41
|
+
end
|
42
|
+
FileUtils.remove_entry_secure(@@tmpdir, true)
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.spawn_etcd_server(dir, client_port=4001, server_port=7001, leader = nil)
|
46
|
+
args = " -addr 127.0.0.1:#{client_port} -peer-addr 127.0.0.1:#{server_port} -data-dir #{dir} -name node_#{client_port}"
|
47
|
+
command = if leader.nil?
|
48
|
+
etcd_binary + args
|
49
|
+
else
|
50
|
+
etcd_binary + args + " -peers #{leader}"
|
51
|
+
end
|
52
|
+
pid = spawn(command, out: '/dev/null')
|
53
|
+
Process.detach(pid)
|
54
|
+
sleep 1
|
55
|
+
pid
|
56
|
+
end
|
57
|
+
|
58
|
+
def uuid
|
59
|
+
@uuid ||= UUID.new
|
60
|
+
end
|
61
|
+
|
62
|
+
def random_key(n=1)
|
63
|
+
key=''
|
64
|
+
n.times do
|
65
|
+
key << '/'+ uuid.generate
|
66
|
+
end
|
67
|
+
key
|
68
|
+
end
|
69
|
+
|
70
|
+
def etcd_servers
|
71
|
+
(1..5).map{|n| "http://127.0.0.1:700#{n}"}
|
72
|
+
end
|
73
|
+
|
74
|
+
def other_client
|
75
|
+
Etcd.client
|
76
|
+
end
|
77
|
+
|
78
|
+
def read_only_client
|
79
|
+
Etcd.client(:allow_redirect=>false, :port=> 4004)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
RSpec.configure do |c|
|
85
|
+
|
86
|
+
c.include Etcd::SpecHelper
|
87
|
+
c.before(:suite) do
|
88
|
+
Etcd::SpecHelper.start_etcd_servers
|
89
|
+
end
|
90
|
+
c.after(:suite) do
|
91
|
+
Etcd::SpecHelper.stop_etcd_servers
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
metadata
CHANGED
@@ -1,111 +1,83 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: etcd
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.2.0.alpha
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ranjib Dey
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2014-01-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: mixlib-cli
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - '>='
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '0'
|
20
|
-
type: :runtime
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - '>='
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '0'
|
27
13
|
- !ruby/object:Gem::Dependency
|
28
14
|
name: mixlib-log
|
29
15
|
requirement: !ruby/object:Gem::Requirement
|
30
16
|
requirements:
|
31
|
-
- - '>='
|
17
|
+
- - ! '>='
|
32
18
|
- !ruby/object:Gem::Version
|
33
19
|
version: '0'
|
34
20
|
type: :runtime
|
35
21
|
prerelease: false
|
36
22
|
version_requirements: !ruby/object:Gem::Requirement
|
37
23
|
requirements:
|
38
|
-
- - '>='
|
24
|
+
- - ! '>='
|
39
25
|
- !ruby/object:Gem::Version
|
40
26
|
version: '0'
|
41
27
|
- !ruby/object:Gem::Dependency
|
42
28
|
name: uuid
|
43
29
|
requirement: !ruby/object:Gem::Requirement
|
44
30
|
requirements:
|
45
|
-
- - '>='
|
31
|
+
- - ! '>='
|
46
32
|
- !ruby/object:Gem::Version
|
47
33
|
version: '0'
|
48
|
-
type: :
|
34
|
+
type: :development
|
49
35
|
prerelease: false
|
50
36
|
version_requirements: !ruby/object:Gem::Requirement
|
51
37
|
requirements:
|
52
|
-
- - '>='
|
38
|
+
- - ! '>='
|
53
39
|
- !ruby/object:Gem::Version
|
54
40
|
version: '0'
|
55
41
|
- !ruby/object:Gem::Dependency
|
56
42
|
name: bundler
|
57
43
|
requirement: !ruby/object:Gem::Requirement
|
58
44
|
requirements:
|
59
|
-
- - '>='
|
45
|
+
- - ! '>='
|
60
46
|
- !ruby/object:Gem::Version
|
61
47
|
version: '0'
|
62
48
|
type: :development
|
63
49
|
prerelease: false
|
64
50
|
version_requirements: !ruby/object:Gem::Requirement
|
65
51
|
requirements:
|
66
|
-
- - '>='
|
52
|
+
- - ! '>='
|
67
53
|
- !ruby/object:Gem::Version
|
68
54
|
version: '0'
|
69
55
|
- !ruby/object:Gem::Dependency
|
70
56
|
name: rake
|
71
57
|
requirement: !ruby/object:Gem::Requirement
|
72
58
|
requirements:
|
73
|
-
- - '>='
|
59
|
+
- - ! '>='
|
74
60
|
- !ruby/object:Gem::Version
|
75
61
|
version: '0'
|
76
62
|
type: :development
|
77
63
|
prerelease: false
|
78
64
|
version_requirements: !ruby/object:Gem::Requirement
|
79
65
|
requirements:
|
80
|
-
- - '>='
|
66
|
+
- - ! '>='
|
81
67
|
- !ruby/object:Gem::Version
|
82
68
|
version: '0'
|
83
69
|
- !ruby/object:Gem::Dependency
|
84
70
|
name: rspec
|
85
71
|
requirement: !ruby/object:Gem::Requirement
|
86
72
|
requirements:
|
87
|
-
- - '>='
|
73
|
+
- - ! '>='
|
88
74
|
- !ruby/object:Gem::Version
|
89
75
|
version: '0'
|
90
76
|
type: :development
|
91
77
|
prerelease: false
|
92
78
|
version_requirements: !ruby/object:Gem::Requirement
|
93
79
|
requirements:
|
94
|
-
- - '>='
|
95
|
-
- !ruby/object:Gem::Version
|
96
|
-
version: '0'
|
97
|
-
- !ruby/object:Gem::Dependency
|
98
|
-
name: simplecov
|
99
|
-
requirement: !ruby/object:Gem::Requirement
|
100
|
-
requirements:
|
101
|
-
- - '>='
|
102
|
-
- !ruby/object:Gem::Version
|
103
|
-
version: '0'
|
104
|
-
type: :development
|
105
|
-
prerelease: false
|
106
|
-
version_requirements: !ruby/object:Gem::Requirement
|
107
|
-
requirements:
|
108
|
-
- - '>='
|
80
|
+
- - ! '>='
|
109
81
|
- !ruby/object:Gem::Version
|
110
82
|
version: '0'
|
111
83
|
description: Ruby client library for etcd
|
@@ -115,6 +87,7 @@ executables: []
|
|
115
87
|
extensions: []
|
116
88
|
extra_rdoc_files: []
|
117
89
|
files:
|
90
|
+
- .coco.yml
|
118
91
|
- .gitignore
|
119
92
|
- .rspec
|
120
93
|
- .travis.yml
|
@@ -122,25 +95,30 @@ files:
|
|
122
95
|
- LICENSE.txt
|
123
96
|
- README.md
|
124
97
|
- Rakefile
|
98
|
+
- build_etcd
|
125
99
|
- etcd.gemspec
|
126
100
|
- lib/etcd.rb
|
127
101
|
- lib/etcd/client.rb
|
128
|
-
- lib/etcd/
|
102
|
+
- lib/etcd/exceptions.rb
|
103
|
+
- lib/etcd/keys.rb
|
129
104
|
- lib/etcd/log.rb
|
130
|
-
- lib/etcd/
|
131
|
-
- lib/etcd/
|
105
|
+
- lib/etcd/mod/leader.rb
|
106
|
+
- lib/etcd/mod/lock.rb
|
107
|
+
- lib/etcd/node.rb
|
108
|
+
- lib/etcd/response.rb
|
109
|
+
- lib/etcd/stats.rb
|
132
110
|
- lib/etcd/version.rb
|
133
|
-
- spec/
|
134
|
-
- spec/
|
135
|
-
- spec/
|
136
|
-
- spec/
|
137
|
-
- spec/
|
138
|
-
- spec/
|
111
|
+
- spec/etcd/client_spec.rb
|
112
|
+
- spec/etcd/keys_spec.rb
|
113
|
+
- spec/etcd/leader_spec.rb
|
114
|
+
- spec/etcd/lock_spec.rb
|
115
|
+
- spec/etcd/node_spec.rb
|
116
|
+
- spec/etcd/read_only_client_spec.rb
|
117
|
+
- spec/etcd/readme_spec.rb
|
118
|
+
- spec/etcd/stats_spec.rb
|
119
|
+
- spec/etcd/test_and_set_spec.rb
|
120
|
+
- spec/etcd/watch_spec.rb
|
139
121
|
- spec/spec_helper.rb
|
140
|
-
- spec/unit/etcd/client_spec.rb
|
141
|
-
- spec/unit/etcd/log_spec.rb
|
142
|
-
- spec/unit/etcd/mixins/helpers_spec.rb
|
143
|
-
- spec/unit/etcd_spec.rb
|
144
122
|
homepage: https://github.com/ranjib/etcd-ruby
|
145
123
|
licenses:
|
146
124
|
- MIT
|
@@ -151,29 +129,29 @@ require_paths:
|
|
151
129
|
- lib
|
152
130
|
required_ruby_version: !ruby/object:Gem::Requirement
|
153
131
|
requirements:
|
154
|
-
- - '>='
|
132
|
+
- - ! '>='
|
155
133
|
- !ruby/object:Gem::Version
|
156
134
|
version: '0'
|
157
135
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
158
136
|
requirements:
|
159
|
-
- - '
|
137
|
+
- - ! '>'
|
160
138
|
- !ruby/object:Gem::Version
|
161
|
-
version:
|
139
|
+
version: 1.3.1
|
162
140
|
requirements: []
|
163
141
|
rubyforge_project:
|
164
|
-
rubygems_version: 2.
|
142
|
+
rubygems_version: 2.1.11
|
165
143
|
signing_key:
|
166
144
|
specification_version: 4
|
167
145
|
summary: Ruby client library for etcd
|
168
146
|
test_files:
|
169
|
-
- spec/
|
170
|
-
- spec/
|
171
|
-
- spec/
|
172
|
-
- spec/
|
173
|
-
- spec/
|
174
|
-
- spec/
|
147
|
+
- spec/etcd/client_spec.rb
|
148
|
+
- spec/etcd/keys_spec.rb
|
149
|
+
- spec/etcd/leader_spec.rb
|
150
|
+
- spec/etcd/lock_spec.rb
|
151
|
+
- spec/etcd/node_spec.rb
|
152
|
+
- spec/etcd/read_only_client_spec.rb
|
153
|
+
- spec/etcd/readme_spec.rb
|
154
|
+
- spec/etcd/stats_spec.rb
|
155
|
+
- spec/etcd/test_and_set_spec.rb
|
156
|
+
- spec/etcd/watch_spec.rb
|
175
157
|
- spec/spec_helper.rb
|
176
|
-
- spec/unit/etcd/client_spec.rb
|
177
|
-
- spec/unit/etcd/log_spec.rb
|
178
|
-
- spec/unit/etcd/mixins/helpers_spec.rb
|
179
|
-
- spec/unit/etcd_spec.rb
|
@@ -1,59 +0,0 @@
|
|
1
|
-
$:<< "lib/"
|
2
|
-
|
3
|
-
require 'etcd'
|
4
|
-
require 'uuid'
|
5
|
-
|
6
|
-
ETCD_BIN = ENV['ETCD_BIN'] || './etcd/etcd'
|
7
|
-
|
8
|
-
require 'functional_spec_helpers'
|
9
|
-
require 'functional/lock_spec'
|
10
|
-
require 'functional/read_only_client_spec'
|
11
|
-
require 'functional/test_and_set_spec'
|
12
|
-
require 'functional/watch_spec'
|
13
|
-
|
14
|
-
include Etcd::FunctionalSpec::Helpers
|
15
|
-
|
16
|
-
describe "Functional Test Suite" do
|
17
|
-
|
18
|
-
before(:all) do
|
19
|
-
start_etcd_servers
|
20
|
-
end
|
21
|
-
|
22
|
-
let(:etcd_servers) do
|
23
|
-
(1..5).map{|n| "http://127.0.0.1:700#{n}"}
|
24
|
-
end
|
25
|
-
|
26
|
-
after(:all) do
|
27
|
-
stop_etcd_servers
|
28
|
-
end
|
29
|
-
|
30
|
-
let(:client) do
|
31
|
-
Etcd.client
|
32
|
-
end
|
33
|
-
|
34
|
-
let(:read_only_client) do
|
35
|
-
Etcd.client(:allow_redirect=>false, :port=> 4004)
|
36
|
-
end
|
37
|
-
|
38
|
-
|
39
|
-
include_examples "read only client"
|
40
|
-
include_examples "lock"
|
41
|
-
include_examples "test_and_set"
|
42
|
-
include_examples "watch"
|
43
|
-
|
44
|
-
it "#set/#get" do
|
45
|
-
key = random_key
|
46
|
-
value = uuid.generate
|
47
|
-
client.set(key, value)
|
48
|
-
expect(client.get(key).value).to eq(value)
|
49
|
-
end
|
50
|
-
|
51
|
-
|
52
|
-
it "#leader" do
|
53
|
-
expect(etcd_servers).to include(client.leader)
|
54
|
-
end
|
55
|
-
|
56
|
-
it "#machines" do
|
57
|
-
expect(client.machines).to include('http://127.0.0.1:4001')
|
58
|
-
end
|
59
|
-
end
|