forked from zk-ruby/zk
/
client_spec.rb
102 lines (79 loc) · 2.11 KB
/
client_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
require 'spec_helper'
describe ZK::Client do
before do
@zk = ZK.new("localhost:#{ZK_TEST_PORT}")
wait_until{ @zk.connected? }
@zk.rm_rf('/test')
end
after do
@zk.rm_rf('/test')
@zk.close!
wait_until(2) { @zk.closed? }
end
describe :mkdir_p do
before(:each) do
@path_ary = %w[test mkdir_p path creation]
@bogus_path = File.join('/', *@path_ary)
end
it %[should create all intermediate paths for the path givem] do
@zk.should_not be_exists(@bogus_path)
@zk.should_not be_exists(File.dirname(@bogus_path))
@zk.mkdir_p(@bogus_path)
@zk.should be_exists(@bogus_path)
end
end
describe :stat do
describe 'for a missing node' do
before do
@missing_path = '/thispathdoesnotexist'
@zk.delete(@missing_path) rescue ZK::Exceptions::NoNode
end
it %[should not raise any error] do
lambda { @zk.stat(@missing_path) }.should_not raise_error
end
it %[should return a Stat object] do
@zk.stat(@missing_path).should be_kind_of(ZookeeperStat::Stat)
end
it %[should return a stat that not exists?] do
@zk.stat(@missing_path).should_not be_exists
end
end
end
describe :block_until_node_deleted do
before do
@path = '/_bogualkjdhsna'
end
describe 'no node initially' do
before do
@zk.exists?(@path).should be_false
end
it %[should not block] do
@a = false
th = Thread.new do
@zk.block_until_node_deleted(@path)
@a = true
end
th.join(2)
@a.should be_true
end
end
describe 'node exists initially' do
before do
@zk.create(@path, '', :mode => :ephemeral)
@zk.exists?(@path).should be_true
end
it %[should block until the node is deleted] do
@a = false
th = Thread.new do
@zk.block_until_node_deleted(@path)
@a = true
end
Thread.pass
@a.should be_false
@zk.delete(@path)
wait_until(2) { @a }
@a.should be_true
end
end
end
end