etcd 0.0.6 → 0.2.0.alpha
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 +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
@@ -1,70 +0,0 @@
|
|
1
|
-
shared_examples "lock" do
|
2
|
-
|
3
|
-
let(:other_client) do
|
4
|
-
Etcd.client
|
5
|
-
end
|
6
|
-
|
7
|
-
it "if the lock is already aquired then another lock acquisition should fail" do
|
8
|
-
key = random_key(4)
|
9
|
-
value = uuid.generate
|
10
|
-
# initialize the lock key
|
11
|
-
client.set(key, value)
|
12
|
-
thr = Thread.new do
|
13
|
-
client.lock(:key=>key, :value=>value) do
|
14
|
-
sleep 2
|
15
|
-
end
|
16
|
-
end
|
17
|
-
sleep 1
|
18
|
-
expect {
|
19
|
-
other_client.lock(:key=>key, :value=> value) do
|
20
|
-
puts "Do something"
|
21
|
-
end
|
22
|
-
}.to raise_error(Etcd::Lock::AcqusitionFailure)
|
23
|
-
thr.join
|
24
|
-
end
|
25
|
-
|
26
|
-
it "if the lock is not already aquired then new lock aquisition should pass" do
|
27
|
-
key = random_key(4)
|
28
|
-
value = uuid.generate
|
29
|
-
# initialize the lock key
|
30
|
-
client.set(key, value)
|
31
|
-
expect {
|
32
|
-
client.lock(:key=>key, :value=>value) do
|
33
|
-
:foo
|
34
|
-
end
|
35
|
-
}.to_not raise_error
|
36
|
-
end
|
37
|
-
|
38
|
-
it "should release the lock even if the given block raises exception" do
|
39
|
-
key = random_key(4)
|
40
|
-
value = uuid.generate
|
41
|
-
client.set(key, value)
|
42
|
-
expect {
|
43
|
-
client.lock(:key=>key, :value=>value) do
|
44
|
-
raise StandardError
|
45
|
-
end
|
46
|
-
}.to raise_error(StandardError)
|
47
|
-
|
48
|
-
expect{
|
49
|
-
other_client.lock(:key=>key, :value=>value) {}
|
50
|
-
}.to_not raise_error
|
51
|
-
end
|
52
|
-
|
53
|
-
it "should raise lock release exception if the lock key value is changed " do
|
54
|
-
key = random_key(4)
|
55
|
-
value = uuid.generate
|
56
|
-
# initialize the lock key
|
57
|
-
client.set(key, value)
|
58
|
-
thr = Thread.new do
|
59
|
-
expect{
|
60
|
-
client.lock(:key=>key, :value=>value) do
|
61
|
-
sleep 3
|
62
|
-
end
|
63
|
-
}.to raise_error(Etcd::Lock::ReleaseFailure)
|
64
|
-
|
65
|
-
end
|
66
|
-
sleep 1
|
67
|
-
other_client.set(key, uuid.generate)
|
68
|
-
thr.join
|
69
|
-
end
|
70
|
-
end
|
@@ -1,56 +0,0 @@
|
|
1
|
-
require 'uuid'
|
2
|
-
|
3
|
-
module Etcd
|
4
|
-
module FunctionalSpec
|
5
|
-
module Helpers
|
6
|
-
def start_etcd_servers
|
7
|
-
@tmpdir = Dir.mktmpdir
|
8
|
-
pid = spawn_etcd_server(@tmpdir+'/leader')
|
9
|
-
@pids = Array(pid)
|
10
|
-
puts "Etcd leader process id :#{pid}"
|
11
|
-
leader = '127.0.0.1:7001'
|
12
|
-
|
13
|
-
4.times do |n|
|
14
|
-
client_port = 4002 + n
|
15
|
-
server_port = 7002 + n
|
16
|
-
pid = spawn_etcd_server(@tmpdir+client_port.to_s, client_port, server_port, leader)
|
17
|
-
@pids << pid
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
def stop_etcd_servers
|
22
|
-
@pids.each do |pid|
|
23
|
-
Process.kill("HUP", pid)
|
24
|
-
puts "Killed #{pid}"
|
25
|
-
end
|
26
|
-
FileUtils.remove_entry_secure @tmpdir
|
27
|
-
end
|
28
|
-
|
29
|
-
def spawn_etcd_server(dir, client_port=4001, server_port=7001, leader = nil)
|
30
|
-
args = " -addr 127.0.0.1:#{client_port} -peer-addr 127.0.0.1:#{server_port} -data-dir #{dir} -name node_#{client_port}"
|
31
|
-
command = if leader.nil?
|
32
|
-
ETCD_BIN + args
|
33
|
-
else
|
34
|
-
ETCD_BIN + args + " -peers #{leader}"
|
35
|
-
end
|
36
|
-
puts command
|
37
|
-
pid = spawn(command)
|
38
|
-
Process.detach(pid)
|
39
|
-
sleep 1
|
40
|
-
pid
|
41
|
-
end
|
42
|
-
|
43
|
-
def uuid
|
44
|
-
@uuid ||= UUID.new
|
45
|
-
end
|
46
|
-
|
47
|
-
def random_key(n=1)
|
48
|
-
key=''
|
49
|
-
n.times do
|
50
|
-
key << '/'+ uuid.generate
|
51
|
-
end
|
52
|
-
key
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
data/spec/unit/etcd_spec.rb
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
|
2
|
-
require 'spec_helper'
|
3
|
-
|
4
|
-
describe Etcd do
|
5
|
-
describe "#client" do
|
6
|
-
it "should return a valid Etcd::Client object" do
|
7
|
-
expect(Etcd.client).to be_a_kind_of(Etcd::Client)
|
8
|
-
end
|
9
|
-
it "should pass the same options to Etcd::Client initilizer" do
|
10
|
-
opts = { :host => '10.10.10.10', :port=> 4001 }
|
11
|
-
Etcd::Client.should_receive(:new).with(opts)
|
12
|
-
Etcd.client(opts)
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|