zk 1.9.6 → 1.10.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -13
- data/.github/workflows/build.yml +55 -0
- data/Gemfile +15 -6
- data/README.markdown +9 -9
- data/RELEASES.markdown +10 -1
- data/lib/zk/client.rb +1 -1
- data/lib/zk/event_handler.rb +15 -7
- data/lib/zk/fork_hook.rb +2 -2
- data/lib/zk/locker/locker_base.rb +13 -0
- data/lib/zk/locker/semaphore.rb +1 -3
- data/lib/zk/node_deletion_watcher.rb +3 -4
- data/lib/zk/pool.rb +11 -11
- data/lib/zk/version.rb +1 -1
- data/spec/event_catcher_spec.rb +1 -1
- data/spec/message_queue_spec.rb +6 -6
- data/spec/shared/client_examples.rb +81 -81
- data/spec/shared/locker_examples.rb +13 -13
- data/spec/spec_helper.rb +10 -11
- data/spec/zk/00_forked_client_integration_spec.rb +3 -3
- data/spec/zk/client/locking_and_session_death_spec.rb +2 -2
- data/spec/zk/client_spec.rb +19 -19
- data/spec/zk/election_spec.rb +44 -44
- data/spec/zk/extensions_spec.rb +2 -2
- data/spec/zk/locker/exclusive_locker_spec.rb +41 -41
- data/spec/zk/locker/locker_basic_spec.rb +55 -33
- data/spec/zk/locker/semaphore_spec.rb +39 -32
- data/spec/zk/locker/shared_exclusive_integration_spec.rb +37 -37
- data/spec/zk/locker/shared_locker_spec.rb +43 -43
- data/spec/zk/locker_spec.rb +2 -2
- data/spec/zk/module_spec.rb +25 -25
- data/spec/zk/mongoid_spec.rb +47 -47
- data/spec/zk/node_deletion_watcher_spec.rb +39 -31
- data/spec/zk/pool_spec.rb +56 -65
- data/spec/zk/threaded_callback_spec.rb +10 -10
- data/spec/zk/threadpool_spec.rb +25 -25
- data/spec/zk/watch_spec.rb +67 -79
- data/spec/zk/zookeeper_spec.rb +31 -31
- data/zk.gemspec +1 -1
- metadata +23 -24
- data/.travis.yml +0 -30
@@ -9,17 +9,17 @@ shared_examples_for 'ZK::Locker::SharedLocker' do
|
|
9
9
|
|
10
10
|
it %[should raise LockAssertionFailedError if there is an exclusive lock with a number lower than ours] do
|
11
11
|
# this should *really* never happen
|
12
|
-
locker.lock.
|
12
|
+
expect(locker.lock).to be(true)
|
13
13
|
shl_path = locker.lock_path
|
14
14
|
|
15
|
-
locker2.lock.
|
15
|
+
expect(locker2.lock).to be(true)
|
16
16
|
|
17
|
-
locker.unlock.
|
18
|
-
locker.
|
17
|
+
expect(locker.unlock).to be(true)
|
18
|
+
expect(locker).not_to be_locked
|
19
19
|
|
20
|
-
zk.exists?(shl_path).
|
20
|
+
expect(zk.exists?(shl_path)).to be(false)
|
21
21
|
|
22
|
-
locker2.lock_path.
|
22
|
+
expect(locker2.lock_path).not_to eq(shl_path)
|
23
23
|
|
24
24
|
# convert the first shared lock path into a exclusive one
|
25
25
|
|
@@ -27,7 +27,7 @@ shared_examples_for 'ZK::Locker::SharedLocker' do
|
|
27
27
|
|
28
28
|
zk.create(exl_path, :ephemeral => true)
|
29
29
|
|
30
|
-
|
30
|
+
expect { locker2.assert! }.to raise_error(ZK::Exceptions::LockAssertionFailedError)
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
@@ -35,18 +35,18 @@ shared_examples_for 'ZK::Locker::SharedLocker' do
|
|
35
35
|
describe %[with default options] do
|
36
36
|
it %[should work if the lock root doesn't exist] do
|
37
37
|
zk.rm_rf(ZK::Locker.default_root_lock_node)
|
38
|
-
locker.
|
38
|
+
expect(locker).to be_acquirable
|
39
39
|
end
|
40
40
|
|
41
41
|
it %[should check local state of lockedness] do
|
42
|
-
locker.lock.
|
43
|
-
locker.
|
42
|
+
expect(locker.lock).to be(true)
|
43
|
+
expect(locker).to be_acquirable
|
44
44
|
end
|
45
45
|
|
46
46
|
it %[should check if any participants would prevent us from acquiring the lock] do
|
47
47
|
ex_lock = ZK::Locker.exclusive_locker(zk, path)
|
48
|
-
ex_lock.lock.
|
49
|
-
locker.
|
48
|
+
expect(ex_lock.lock).to be(true)
|
49
|
+
expect(locker).not_to be_acquirable
|
50
50
|
end
|
51
51
|
end
|
52
52
|
end
|
@@ -59,13 +59,13 @@ shared_examples_for 'ZK::Locker::SharedLocker' do
|
|
59
59
|
end
|
60
60
|
|
61
61
|
it %[should acquire the first lock] do
|
62
|
-
@rval.
|
63
|
-
locker.
|
62
|
+
expect(@rval).to be(true)
|
63
|
+
expect(locker).to be_locked
|
64
64
|
end
|
65
65
|
|
66
66
|
it %[should acquire the second lock] do
|
67
|
-
@rval2.
|
68
|
-
locker2.
|
67
|
+
expect(@rval2).to be(true)
|
68
|
+
expect(locker2).to be_locked
|
69
69
|
end
|
70
70
|
end
|
71
71
|
|
@@ -77,11 +77,11 @@ shared_examples_for 'ZK::Locker::SharedLocker' do
|
|
77
77
|
end
|
78
78
|
|
79
79
|
it %[should return false] do
|
80
|
-
@rval.
|
80
|
+
expect(@rval).to be(false)
|
81
81
|
end
|
82
82
|
|
83
83
|
it %[should not be locked] do
|
84
|
-
locker.
|
84
|
+
expect(locker).not_to be_locked
|
85
85
|
end
|
86
86
|
end
|
87
87
|
|
@@ -96,7 +96,7 @@ shared_examples_for 'ZK::Locker::SharedLocker' do
|
|
96
96
|
it %[should acquire the lock after the write lock is released old-style] do
|
97
97
|
ary = []
|
98
98
|
|
99
|
-
locker.lock.
|
99
|
+
expect(locker.lock).to be(false)
|
100
100
|
|
101
101
|
th = Thread.new do
|
102
102
|
locker.lock(true)
|
@@ -104,24 +104,24 @@ shared_examples_for 'ZK::Locker::SharedLocker' do
|
|
104
104
|
end
|
105
105
|
|
106
106
|
locker.wait_until_blocked(5)
|
107
|
-
locker.
|
108
|
-
locker.
|
109
|
-
ary.
|
107
|
+
expect(locker).to be_waiting
|
108
|
+
expect(locker).not_to be_locked
|
109
|
+
expect(ary).to be_empty
|
110
110
|
|
111
111
|
zk.delete(@write_lock_path)
|
112
112
|
|
113
|
-
th.join(2).
|
113
|
+
expect(th.join(2)).to eq(th)
|
114
114
|
|
115
|
-
ary.
|
116
|
-
ary.length.
|
115
|
+
expect(ary).not_to be_empty
|
116
|
+
expect(ary.length).to eq(1)
|
117
117
|
|
118
|
-
locker.
|
118
|
+
expect(locker).to be_locked
|
119
119
|
end
|
120
120
|
|
121
121
|
it %[should acquire the lock after the write lock is released new-style] do
|
122
122
|
ary = []
|
123
123
|
|
124
|
-
locker.lock.
|
124
|
+
expect(locker.lock).to be(false)
|
125
125
|
|
126
126
|
th = Thread.new do
|
127
127
|
locker.lock(:wait => true)
|
@@ -129,18 +129,18 @@ shared_examples_for 'ZK::Locker::SharedLocker' do
|
|
129
129
|
end
|
130
130
|
|
131
131
|
locker.wait_until_blocked(5)
|
132
|
-
locker.
|
133
|
-
locker.
|
134
|
-
ary.
|
132
|
+
expect(locker).to be_waiting
|
133
|
+
expect(locker).not_to be_locked
|
134
|
+
expect(ary).to be_empty
|
135
135
|
|
136
136
|
zk.delete(@write_lock_path)
|
137
137
|
|
138
|
-
th.join(2).
|
138
|
+
expect(th.join(2)).to eq(th)
|
139
139
|
|
140
|
-
ary.
|
141
|
-
ary.length.
|
140
|
+
expect(ary).not_to be_empty
|
141
|
+
expect(ary.length).to eq(1)
|
142
142
|
|
143
|
-
locker.
|
143
|
+
expect(locker).to be_locked
|
144
144
|
end
|
145
145
|
end
|
146
146
|
|
@@ -150,9 +150,9 @@ shared_examples_for 'ZK::Locker::SharedLocker' do
|
|
150
150
|
|
151
151
|
write_lock_dir = File.dirname(@write_lock_path)
|
152
152
|
|
153
|
-
zk.children(write_lock_dir).length.
|
153
|
+
expect(zk.children(write_lock_dir).length).to eq(1)
|
154
154
|
|
155
|
-
locker.lock.
|
155
|
+
expect(locker.lock).to be(false)
|
156
156
|
|
157
157
|
th = Thread.new do
|
158
158
|
begin
|
@@ -164,16 +164,16 @@ shared_examples_for 'ZK::Locker::SharedLocker' do
|
|
164
164
|
end
|
165
165
|
|
166
166
|
locker.wait_until_blocked(5)
|
167
|
-
locker.
|
168
|
-
locker.
|
169
|
-
ary.
|
167
|
+
expect(locker).to be_waiting
|
168
|
+
expect(locker).not_to be_locked
|
169
|
+
expect(ary).to be_empty
|
170
170
|
|
171
|
-
th.join(2).
|
171
|
+
expect(th.join(2)).to eq(th)
|
172
172
|
|
173
|
-
zk.children(write_lock_dir).length.
|
173
|
+
expect(zk.children(write_lock_dir).length).to eq(1)
|
174
174
|
|
175
|
-
ary.
|
176
|
-
@exc.
|
175
|
+
expect(ary).to be_empty
|
176
|
+
expect(@exc).to be_kind_of(ZK::Exceptions::LockWaitTimeoutError)
|
177
177
|
end
|
178
178
|
|
179
179
|
end
|
data/spec/zk/locker_spec.rb
CHANGED
@@ -14,9 +14,9 @@ describe ZK::Locker do
|
|
14
14
|
|
15
15
|
ZK::Locker.cleanup(@zk)
|
16
16
|
|
17
|
-
|
17
|
+
expect { locker.assert! }.not_to raise_error
|
18
18
|
|
19
|
-
bogus_lock_dir_names.each { |n| @zk.stat("#{ZK::Locker.default_root_lock_node}/#{n}").
|
19
|
+
bogus_lock_dir_names.each { |n| expect(@zk.stat("#{ZK::Locker.default_root_lock_node}/#{n}")).not_to exist }
|
20
20
|
|
21
21
|
end
|
22
22
|
end
|
data/spec/zk/module_spec.rb
CHANGED
@@ -21,7 +21,7 @@ describe ZK do
|
|
21
21
|
|
22
22
|
describe %[with a chrooted connection string and a :chroot => '/path'] do
|
23
23
|
it %[should raise an ArgumentError] do
|
24
|
-
|
24
|
+
expect { @zk = ZK.new("#{connection_host}/zktest", :chroot => '/zktest') }.to raise_error(ArgumentError)
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
@@ -29,7 +29,7 @@ describe ZK do
|
|
29
29
|
before { @zk = ZK.new }
|
30
30
|
|
31
31
|
it %[should create a default connection] do
|
32
|
-
@zk.
|
32
|
+
expect(@zk).to be_connected
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
@@ -54,10 +54,10 @@ describe ZK do
|
|
54
54
|
before { @zk = ZK.new(:chroot => chroot_path) }
|
55
55
|
|
56
56
|
it %[should use the default connection string, create the chroot and return the connection] do
|
57
|
-
@zk.exists?('/').
|
57
|
+
expect(@zk.exists?('/')).to be(true)
|
58
58
|
@zk.create('/blah', 'data')
|
59
59
|
|
60
|
-
@unchroot.get("#{chroot_path}/blah").first.
|
60
|
+
expect(@unchroot.get("#{chroot_path}/blah").first).to eq('data')
|
61
61
|
end
|
62
62
|
end
|
63
63
|
|
@@ -69,10 +69,10 @@ describe ZK do
|
|
69
69
|
end
|
70
70
|
|
71
71
|
it %[should create the chroot path and then return the connection] do
|
72
|
-
@zk.exists?('/').
|
72
|
+
expect(@zk.exists?('/')).to be(true)
|
73
73
|
@zk.create('/blah', 'data')
|
74
74
|
|
75
|
-
@unchroot.get("#{chroot_path}/blah").first.
|
75
|
+
expect(@unchroot.get("#{chroot_path}/blah").first).to eq('data')
|
76
76
|
end
|
77
77
|
end
|
78
78
|
|
@@ -82,26 +82,26 @@ describe ZK do
|
|
82
82
|
end
|
83
83
|
|
84
84
|
it %[should create the chroot path and then return the connection] do
|
85
|
-
@zk.exists?('/').
|
85
|
+
expect(@zk.exists?('/')).to be(true)
|
86
86
|
@zk.create('/blah', 'data')
|
87
87
|
|
88
|
-
@unchroot.get("#{chroot_path}/blah").first.
|
88
|
+
expect(@unchroot.get("#{chroot_path}/blah").first).to eq('data')
|
89
89
|
end
|
90
90
|
end
|
91
91
|
|
92
92
|
describe %[and :chroot => :check] do
|
93
93
|
it %[should barf with a ChrootPathDoesNotExistError] do
|
94
|
-
|
94
|
+
expect do
|
95
95
|
# assign in case of a bug, that way this connection will get torn down
|
96
96
|
@zk = ZK.new("#{connection_host}#{chroot_path}", :chroot => :check)
|
97
|
-
end.
|
97
|
+
end.to raise_error(ZK::Exceptions::ChrootPathDoesNotExistError)
|
98
98
|
end
|
99
99
|
end
|
100
100
|
|
101
101
|
describe %[and :chroot => :do_nothing] do
|
102
102
|
it %[should return a connection in a weird state] do
|
103
103
|
@zk = ZK.new("#{connection_host}#{chroot_path}", :chroot => :do_nothing)
|
104
|
-
|
104
|
+
expect { @zk.get('/') }.to raise_error(ZK::Exceptions::NoNode)
|
105
105
|
end
|
106
106
|
end
|
107
107
|
|
@@ -109,10 +109,10 @@ describe ZK do
|
|
109
109
|
before { @zk = ZK.new(connection_host, :chroot => chroot_path) }
|
110
110
|
|
111
111
|
it %[should create the chroot path and then return the connection] do
|
112
|
-
@zk.exists?('/').
|
112
|
+
expect(@zk.exists?('/')).to be(true)
|
113
113
|
@zk.create('/blah', 'data')
|
114
114
|
|
115
|
-
@unchroot.get("#{chroot_path}/blah").first.
|
115
|
+
expect(@unchroot.get("#{chroot_path}/blah").first).to eq('data')
|
116
116
|
end
|
117
117
|
end
|
118
118
|
end # as a connection string
|
@@ -125,10 +125,10 @@ describe ZK do
|
|
125
125
|
before { @zk = ZK.new(:chroot => chroot_path) }
|
126
126
|
|
127
127
|
it %[should use the default connection string and totally work] do
|
128
|
-
@zk.exists?('/').
|
128
|
+
expect(@zk.exists?('/')).to be(true)
|
129
129
|
@zk.create('/blah', 'data')
|
130
130
|
|
131
|
-
@unchroot.get("#{chroot_path}/blah").first.
|
131
|
+
expect(@unchroot.get("#{chroot_path}/blah").first).to eq('data')
|
132
132
|
end
|
133
133
|
end
|
134
134
|
|
@@ -139,10 +139,10 @@ describe ZK do
|
|
139
139
|
end
|
140
140
|
|
141
141
|
it %[should totally work] do
|
142
|
-
@zk.exists?('/').
|
142
|
+
expect(@zk.exists?('/')).to be(true)
|
143
143
|
@zk.create('/blah', 'data')
|
144
144
|
|
145
|
-
@unchroot.get("#{chroot_path}/blah").first.
|
145
|
+
expect(@unchroot.get("#{chroot_path}/blah").first).to eq('data')
|
146
146
|
end
|
147
147
|
end
|
148
148
|
|
@@ -152,26 +152,26 @@ describe ZK do
|
|
152
152
|
end
|
153
153
|
|
154
154
|
it %[should totally work] do
|
155
|
-
@zk.exists?('/').
|
155
|
+
expect(@zk.exists?('/')).to be(true)
|
156
156
|
@zk.create('/blah', 'data')
|
157
157
|
|
158
|
-
@unchroot.get("#{chroot_path}/blah").first.
|
158
|
+
expect(@unchroot.get("#{chroot_path}/blah").first).to eq('data')
|
159
159
|
end
|
160
160
|
end
|
161
161
|
|
162
162
|
describe %[and :chroot => :check] do
|
163
163
|
it %[should totally work] do
|
164
|
-
|
164
|
+
expect do
|
165
165
|
# assign in case of a bug, that way this connection will get torn down
|
166
166
|
@zk = ZK.new("#{connection_host}#{chroot_path}", :chroot => :check)
|
167
|
-
end.
|
167
|
+
end.not_to raise_error
|
168
168
|
end
|
169
169
|
end
|
170
170
|
|
171
171
|
describe %[and :chroot => :do_nothing] do
|
172
172
|
it %[should totally work] do
|
173
173
|
@zk = ZK.new("#{connection_host}#{chroot_path}", :chroot => :do_nothing)
|
174
|
-
|
174
|
+
expect { @zk.get('/') }.not_to raise_error
|
175
175
|
end
|
176
176
|
end
|
177
177
|
|
@@ -179,15 +179,15 @@ describe ZK do
|
|
179
179
|
before { @zk = ZK.new(connection_host, :chroot => chroot_path) }
|
180
180
|
|
181
181
|
it %[should totally work] do
|
182
|
-
@zk.exists?('/').
|
182
|
+
expect(@zk.exists?('/')).to be(true)
|
183
183
|
@zk.create('/blah', 'data')
|
184
184
|
|
185
|
-
@unchroot.get("#{chroot_path}/blah").first.
|
185
|
+
expect(@unchroot.get("#{chroot_path}/blah").first).to eq('data')
|
186
186
|
end
|
187
187
|
end
|
188
188
|
end # as a connection string
|
189
189
|
end # that exists
|
190
|
-
end # with a chroot
|
190
|
+
end # with a chroot
|
191
191
|
end # :new
|
192
192
|
end # ZK
|
193
193
|
|
data/spec/zk/mongoid_spec.rb
CHANGED
@@ -18,7 +18,7 @@ describe ZK::Mongoid::Locking do
|
|
18
18
|
unless th.join(5) == th
|
19
19
|
logger.warn { "Forcing pool closed!" }
|
20
20
|
ZK::Mongoid::Locking.zk_lock_pool.force_close!
|
21
|
-
th.join(5).
|
21
|
+
expect(th.join(5)).to eq(th)
|
22
22
|
end
|
23
23
|
|
24
24
|
ZK::Mongoid::Locking.zk_lock_pool = nil
|
@@ -35,8 +35,8 @@ describe ZK::Mongoid::Locking do
|
|
35
35
|
end
|
36
36
|
|
37
37
|
th.join_until { !@lock_state.nil? }
|
38
|
-
@lock_state.
|
39
|
-
@lock_state.
|
38
|
+
expect(@lock_state).not_to be_nil
|
39
|
+
expect(@lock_state).to be(true)
|
40
40
|
end
|
41
41
|
|
42
42
|
it %[should allow another thread to enter the shared lock] do
|
@@ -52,10 +52,10 @@ describe ZK::Mongoid::Locking do
|
|
52
52
|
end
|
53
53
|
|
54
54
|
@th1.join_until { @counter > 0 }
|
55
|
-
@counter.
|
55
|
+
expect(@counter).to be > 0
|
56
56
|
|
57
57
|
@th1.join_until { @queue.num_waiting > 0 }
|
58
|
-
@queue.num_waiting.
|
58
|
+
expect(@queue.num_waiting).to be > 0
|
59
59
|
|
60
60
|
@th2 = Thread.new do
|
61
61
|
@other_doc.with_shared_lock do
|
@@ -64,9 +64,9 @@ describe ZK::Mongoid::Locking do
|
|
64
64
|
end
|
65
65
|
|
66
66
|
@th2.join_until { @counter == 2 }
|
67
|
-
@counter.
|
67
|
+
expect(@counter).to eq(2)
|
68
68
|
|
69
|
-
@th2.join(2).
|
69
|
+
expect(@th2.join(2)).to eq(@th2)
|
70
70
|
ensure
|
71
71
|
@queue << :unlock
|
72
72
|
|
@@ -102,32 +102,32 @@ describe ZK::Mongoid::Locking do
|
|
102
102
|
end
|
103
103
|
|
104
104
|
@th1.join_until { q2.num_waiting >= 1 }
|
105
|
-
q2.num_waiting.
|
105
|
+
expect(q2.num_waiting).to be >= 1
|
106
106
|
|
107
107
|
@th2.join_until { q1.size == 0 }
|
108
|
-
q1.size.
|
108
|
+
expect(q1.size).to be_zero
|
109
109
|
|
110
|
-
@got_exclusive_lock.
|
110
|
+
expect(@got_exclusive_lock).not_to be(true)
|
111
111
|
|
112
112
|
q2.enq(:release)
|
113
113
|
|
114
114
|
@th1.join_until { q2.size == 0 }
|
115
|
-
q2.size.
|
115
|
+
expect(q2.size).to be_zero
|
116
116
|
|
117
117
|
@th2.join_until(5) { @got_exclusive_lock }
|
118
|
-
@got_exclusive_lock.
|
118
|
+
expect(@got_exclusive_lock).to be(true)
|
119
119
|
|
120
120
|
rescue Exception => e
|
121
121
|
$stderr.puts e.to_std_format
|
122
122
|
raise e
|
123
|
-
ensure
|
123
|
+
ensure
|
124
124
|
q2 << :release
|
125
125
|
|
126
126
|
unless @th1.join(2)
|
127
127
|
$stderr.puts "UH OH! @th1 IS HUNG!!"
|
128
128
|
end
|
129
129
|
|
130
|
-
unless @th2.join(2)
|
130
|
+
unless @th2.join(2)
|
131
131
|
$stderr.puts "UH OH! @th2 IS HUNG!!"
|
132
132
|
end
|
133
133
|
end
|
@@ -145,8 +145,8 @@ describe ZK::Mongoid::Locking do
|
|
145
145
|
end
|
146
146
|
|
147
147
|
th.join_until { !@lock_state.nil? }
|
148
|
-
@lock_state.
|
149
|
-
@lock_state.
|
148
|
+
expect(@lock_state).not_to be_nil
|
149
|
+
expect(@lock_state).to be(true)
|
150
150
|
end
|
151
151
|
|
152
152
|
it %[should allow the same thread to re-enter the lock] do
|
@@ -165,7 +165,7 @@ describe ZK::Mongoid::Locking do
|
|
165
165
|
end
|
166
166
|
|
167
167
|
th.join_until { @counter >= 2 }
|
168
|
-
@counter.
|
168
|
+
expect(@counter).to eq(2)
|
169
169
|
end
|
170
170
|
|
171
171
|
it %[should block another thread from entering the lock] do
|
@@ -181,9 +181,9 @@ describe ZK::Mongoid::Locking do
|
|
181
181
|
end
|
182
182
|
|
183
183
|
th1.join_until { @counter == 1 }
|
184
|
-
@counter.
|
184
|
+
expect(@counter).to eq(1)
|
185
185
|
|
186
|
-
th1.zk_mongoid_lock_registry[:exclusive].
|
186
|
+
expect(th1.zk_mongoid_lock_registry[:exclusive]).to include(@doc.zk_lock_name)
|
187
187
|
|
188
188
|
th2 = Thread.new do
|
189
189
|
@other_doc.lock_for_update do
|
@@ -196,17 +196,17 @@ describe ZK::Mongoid::Locking do
|
|
196
196
|
|
197
197
|
# this is not a deterministic check of whether or not th2 ran and did not
|
198
198
|
# get the lock but probably close enough
|
199
|
-
|
200
|
-
@counter.
|
201
|
-
@other_doc_got_lock.
|
202
|
-
th2.zk_mongoid_lock_registry[:exclusive].
|
199
|
+
|
200
|
+
expect(@counter).to eq(1)
|
201
|
+
expect(@other_doc_got_lock).to eq(false)
|
202
|
+
expect(th2.zk_mongoid_lock_registry[:exclusive]).not_to include(@other_doc.zk_lock_name)
|
203
203
|
|
204
204
|
queue << :release_lock
|
205
|
-
th1.join(5).
|
205
|
+
expect(th1.join(5)).to eq(th1)
|
206
206
|
|
207
207
|
th2.join_until { @counter == 2 }
|
208
|
-
@counter.
|
209
|
-
@other_doc_got_lock.
|
208
|
+
expect(@counter).to eq(2)
|
209
|
+
expect(@other_doc_got_lock).to be(true)
|
210
210
|
end
|
211
211
|
|
212
212
|
describe :with_name do
|
@@ -217,7 +217,7 @@ describe ZK::Mongoid::Locking do
|
|
217
217
|
after do
|
218
218
|
if @queue.num_waiting > 0
|
219
219
|
@queue << :bogus
|
220
|
-
@th1.join(5).
|
220
|
+
expect(@th1.join(5)).to eq(@th1)
|
221
221
|
end
|
222
222
|
end
|
223
223
|
|
@@ -235,9 +235,9 @@ describe ZK::Mongoid::Locking do
|
|
235
235
|
end
|
236
236
|
|
237
237
|
@th1.join_until { @counter == 1 }
|
238
|
-
@counter.
|
238
|
+
expect(@counter).to eq(1)
|
239
239
|
|
240
|
-
@th1.zk_mongoid_lock_registry[:exclusive].
|
240
|
+
expect(@th1.zk_mongoid_lock_registry[:exclusive]).to include(@doc.zk_lock_name(@name))
|
241
241
|
|
242
242
|
@th2 = Thread.new do
|
243
243
|
@other_doc.lock_for_update(@name) do
|
@@ -250,16 +250,16 @@ describe ZK::Mongoid::Locking do
|
|
250
250
|
|
251
251
|
# this is not a deterministic check of whether or not @th2 ran and did not
|
252
252
|
# get the lock but probably close enough
|
253
|
-
|
254
|
-
@counter.
|
255
|
-
@other_doc_got_lock.
|
253
|
+
|
254
|
+
expect(@counter).to eq(1)
|
255
|
+
expect(@other_doc_got_lock).to eq(false)
|
256
256
|
|
257
257
|
@queue << :release_lock
|
258
|
-
@th1.join(5).
|
258
|
+
expect(@th1.join(5)).to eq(@th1)
|
259
259
|
|
260
260
|
@th2.join_until { @counter == 2 }
|
261
|
-
@counter.
|
262
|
-
@other_doc_got_lock.
|
261
|
+
expect(@counter).to eq(2)
|
262
|
+
expect(@other_doc_got_lock).to be(true)
|
263
263
|
end
|
264
264
|
|
265
265
|
it %[should not affect another thread using a different name] do
|
@@ -276,9 +276,9 @@ describe ZK::Mongoid::Locking do
|
|
276
276
|
end
|
277
277
|
|
278
278
|
@th1.join_until { @counter == 1 }
|
279
|
-
@counter.
|
279
|
+
expect(@counter).to eq(1)
|
280
280
|
|
281
|
-
@th1.zk_mongoid_lock_registry[:exclusive].
|
281
|
+
expect(@th1.zk_mongoid_lock_registry[:exclusive]).to include(@doc.zk_lock_name(@name))
|
282
282
|
|
283
283
|
@th2 = Thread.new do
|
284
284
|
@other_doc.lock_for_update do
|
@@ -288,41 +288,41 @@ describe ZK::Mongoid::Locking do
|
|
288
288
|
end
|
289
289
|
|
290
290
|
@th2.join_until { @other_doc_got_lock }
|
291
|
-
@other_doc_got_lock.
|
292
|
-
|
293
|
-
@counter.
|
291
|
+
expect(@other_doc_got_lock).to be(true)
|
292
|
+
|
293
|
+
expect(@counter).to eq(2)
|
294
294
|
|
295
295
|
@queue << :release_lock
|
296
|
-
@th1.join(2).
|
296
|
+
expect(@th1.join(2)).to eq(@th1)
|
297
297
|
end
|
298
298
|
end
|
299
299
|
end
|
300
300
|
|
301
301
|
describe :assert_locked_for_update! do
|
302
302
|
it %[should raise MustBeExclusivelyLockedException if the current thread does not hold the lock] do
|
303
|
-
|
303
|
+
expect { @doc.assert_locked_for_update! }.to raise_error(ZK::Exceptions::MustBeExclusivelyLockedException)
|
304
304
|
end
|
305
305
|
|
306
306
|
it %[should not raise an exception if the current thread holds the lock] do
|
307
|
-
|
307
|
+
expect do
|
308
308
|
@doc.lock_for_update do
|
309
309
|
@doc.assert_locked_for_update!
|
310
310
|
end
|
311
|
-
end.
|
311
|
+
end.not_to raise_error
|
312
312
|
end
|
313
313
|
end
|
314
314
|
|
315
315
|
describe :assert_locked_for_share! do
|
316
316
|
it %[should raise MustBeShareLockedException if the current thread does not hold a shared lock] do
|
317
|
-
|
317
|
+
expect { @doc.assert_locked_for_share! }.to raise_error(ZK::Exceptions::MustBeShareLockedException)
|
318
318
|
end
|
319
319
|
|
320
320
|
it %[should not raise an exception if the current thread holds a shared lock] do
|
321
|
-
|
321
|
+
expect do
|
322
322
|
@doc.with_shared_lock do
|
323
323
|
@doc.assert_locked_for_share!
|
324
324
|
end
|
325
|
-
end.
|
325
|
+
end.not_to raise_error
|
326
326
|
end
|
327
327
|
end
|
328
328
|
end
|