suo 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/lib/suo.rb +15 -1
- data/lib/suo/client/base.rb +3 -3
- data/lib/suo/client/memcached.rb +1 -1
- data/lib/suo/client/redis.rb +2 -2
- data/lib/suo/version.rb +1 -1
- data/test/client_test.rb +9 -8
- data/test/test_helper.rb +0 -1
- metadata +1 -2
- data/lib/suo/clients.rb +0 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ef6a0837cc8be9a03a3767df546c630adf1e74cf
|
4
|
+
data.tar.gz: d2fefd52a16706479a3f62b4a89557ece8e74672
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4dc9fa8f2377e19efce5d6d4d009a145214360fd51efac442aaabcd9ba9077e49bdbad7828304c9aab9a273ad76b017c6fadce7bccf83c1d0897d31c63a0333d
|
7
|
+
data.tar.gz: a0de3ab597fc8d61fe6f47f2b239aeaa11baf9d6cde481481840f96a8f673150a9d10db13e53796cd552cafceb01fbedffaa4160228686b6396335444dbf64e5
|
data/CHANGELOG.md
CHANGED
data/lib/suo.rb
CHANGED
@@ -1,2 +1,16 @@
|
|
1
|
+
require "securerandom"
|
2
|
+
require "monitor"
|
3
|
+
|
4
|
+
require "dalli"
|
5
|
+
require "dalli/cas/client"
|
6
|
+
|
7
|
+
require "redis"
|
8
|
+
|
9
|
+
require "msgpack"
|
10
|
+
|
1
11
|
require "suo/version"
|
2
|
-
|
12
|
+
|
13
|
+
require "suo/errors"
|
14
|
+
require "suo/client/base"
|
15
|
+
require "suo/client/memcached"
|
16
|
+
require "suo/client/redis"
|
data/lib/suo/client/base.rb
CHANGED
@@ -49,7 +49,7 @@ module Suo
|
|
49
49
|
val, cas = get(key)
|
50
50
|
|
51
51
|
if val.nil?
|
52
|
-
|
52
|
+
initial_set(key)
|
53
53
|
next
|
54
54
|
end
|
55
55
|
|
@@ -94,7 +94,7 @@ module Suo
|
|
94
94
|
val, cas = get(key)
|
95
95
|
|
96
96
|
if val.nil?
|
97
|
-
|
97
|
+
initial_set(key)
|
98
98
|
next
|
99
99
|
end
|
100
100
|
|
@@ -123,7 +123,7 @@ module Suo
|
|
123
123
|
fail NotImplementedError
|
124
124
|
end
|
125
125
|
|
126
|
-
def
|
126
|
+
def initial_set(key) # rubocop:disable Lint/UnusedMethodArgument
|
127
127
|
fail NotImplementedError
|
128
128
|
end
|
129
129
|
|
data/lib/suo/client/memcached.rb
CHANGED
data/lib/suo/client/redis.rb
CHANGED
@@ -21,7 +21,7 @@ module Suo
|
|
21
21
|
multi.set(key, newval)
|
22
22
|
end
|
23
23
|
|
24
|
-
ret[0] == "OK"
|
24
|
+
ret && ret[0] == "OK"
|
25
25
|
end
|
26
26
|
|
27
27
|
def synchronize(key)
|
@@ -32,7 +32,7 @@ module Suo
|
|
32
32
|
@client.unwatch
|
33
33
|
end
|
34
34
|
|
35
|
-
def
|
35
|
+
def initial_set(key)
|
36
36
|
@client.set(key, "")
|
37
37
|
end
|
38
38
|
end
|
data/lib/suo/version.rb
CHANGED
data/test/client_test.rb
CHANGED
@@ -10,7 +10,7 @@ module ClientTests
|
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
|
-
def
|
13
|
+
def test_single_resource_locking
|
14
14
|
lock1 = @client.lock(TEST_KEY, 1)
|
15
15
|
refute_nil lock1
|
16
16
|
|
@@ -27,7 +27,7 @@ module ClientTests
|
|
27
27
|
assert_equal false, locked
|
28
28
|
end
|
29
29
|
|
30
|
-
def
|
30
|
+
def test_multiple_resource_locking
|
31
31
|
lock1 = @client.lock(TEST_KEY, 2)
|
32
32
|
refute_nil lock1
|
33
33
|
|
@@ -72,8 +72,9 @@ module ClientTests
|
|
72
72
|
output = Queue.new
|
73
73
|
threads = []
|
74
74
|
|
75
|
-
threads << Thread.new { @client.lock(TEST_KEY, 2) { output << "One"; sleep
|
76
|
-
threads << Thread.new { @client.lock(TEST_KEY, 2) { output << "Two"; sleep
|
75
|
+
threads << Thread.new { @client.lock(TEST_KEY, 2) { output << "One"; sleep 0.5 } }
|
76
|
+
threads << Thread.new { @client.lock(TEST_KEY, 2) { output << "Two"; sleep 0.5 } }
|
77
|
+
sleep 0.1
|
77
78
|
threads << Thread.new { @client.lock(TEST_KEY, 2) { output << "Three" } }
|
78
79
|
|
79
80
|
threads.map(&:join)
|
@@ -86,10 +87,10 @@ module ClientTests
|
|
86
87
|
ret.sort!
|
87
88
|
|
88
89
|
assert_equal 0, output.size
|
89
|
-
assert_equal
|
90
|
+
assert_equal %w(One Two), ret
|
90
91
|
end
|
91
92
|
|
92
|
-
def
|
93
|
+
def test_block_multiple_resource_locking
|
93
94
|
success_counter = Queue.new
|
94
95
|
failure_counter = Queue.new
|
95
96
|
|
@@ -97,7 +98,7 @@ module ClientTests
|
|
97
98
|
|
98
99
|
100.times.map do |i|
|
99
100
|
Thread.new do
|
100
|
-
success =
|
101
|
+
success = client.lock(TEST_KEY, 50) do
|
101
102
|
sleep(3)
|
102
103
|
success_counter << i
|
103
104
|
end
|
@@ -110,7 +111,7 @@ module ClientTests
|
|
110
111
|
assert_equal 50, failure_counter.size
|
111
112
|
end
|
112
113
|
|
113
|
-
def
|
114
|
+
def test_block_multiple_resource_locking_longer_timeout
|
114
115
|
success_counter = Queue.new
|
115
116
|
failure_counter = Queue.new
|
116
117
|
|
data/test/test_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: suo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nick Elser
|
@@ -131,7 +131,6 @@ files:
|
|
131
131
|
- lib/suo/client/base.rb
|
132
132
|
- lib/suo/client/memcached.rb
|
133
133
|
- lib/suo/client/redis.rb
|
134
|
-
- lib/suo/clients.rb
|
135
134
|
- lib/suo/errors.rb
|
136
135
|
- lib/suo/version.rb
|
137
136
|
- suo.gemspec
|
data/lib/suo/clients.rb
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
require "securerandom"
|
2
|
-
require "monitor"
|
3
|
-
|
4
|
-
require "dalli"
|
5
|
-
require "dalli/cas/client"
|
6
|
-
|
7
|
-
require "redis"
|
8
|
-
|
9
|
-
require "msgpack"
|
10
|
-
|
11
|
-
require "suo/errors"
|
12
|
-
require "suo/client/base"
|
13
|
-
require "suo/client/memcached"
|
14
|
-
require "suo/client/redis"
|