thread_safe 0.3.5-java → 0.3.6-java
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 +4 -4
- data/.rspec +2 -0
- data/.travis.yml +23 -20
- data/Gemfile +5 -2
- data/README.md +5 -1
- data/Rakefile +10 -9
- data/lib/thread_safe/cache.rb +3 -5
- data/lib/thread_safe/jruby_cache_backend.jar +0 -0
- data/lib/thread_safe/mri_cache_backend.rb +0 -9
- data/lib/thread_safe/synchronized_delegator.rb +0 -17
- data/lib/thread_safe/util/atomic_reference.rb +0 -1
- data/lib/thread_safe/version.rb +1 -1
- data/spec/.gitignore +0 -0
- data/spec/spec_helper.rb +31 -0
- data/{test → spec}/src/thread_safe/SecurityManager.java +0 -0
- data/spec/support/.gitignore +0 -0
- data/spec/support/threads.rb +1 -0
- data/{test/test_helper.rb → spec/support/threadsafe_test.rb} +0 -59
- data/spec/thread_safe/.gitignore +0 -0
- data/spec/thread_safe/array_spec.rb +18 -0
- data/spec/thread_safe/cache_loops_spec.rb +507 -0
- data/spec/thread_safe/cache_spec.rb +943 -0
- data/spec/thread_safe/hash_spec.rb +17 -0
- data/spec/thread_safe/no_unsafe_spec.rb +27 -0
- data/spec/thread_safe/synchronized_delegator_spec.rb +85 -0
- data/thread_safe.gemspec +4 -4
- metadata +54 -41
- data/test/test_array.rb +0 -18
- data/test/test_cache.rb +0 -901
- data/test/test_cache_loops.rb +0 -449
- data/test/test_hash.rb +0 -17
- data/test/test_synchronized_delegator.rb +0 -84
@@ -1,84 +0,0 @@
|
|
1
|
-
require 'thread_safe/synchronized_delegator.rb'
|
2
|
-
require File.join(File.dirname(__FILE__), "test_helper")
|
3
|
-
|
4
|
-
class TestSynchronizedDelegator < Minitest::Test
|
5
|
-
|
6
|
-
def test_wraps_array
|
7
|
-
sync_array = SynchronizedDelegator.new(array = [])
|
8
|
-
|
9
|
-
array << 1
|
10
|
-
assert_equal 1, sync_array[0]
|
11
|
-
|
12
|
-
sync_array << 2
|
13
|
-
assert_equal 2, array[1]
|
14
|
-
end
|
15
|
-
|
16
|
-
def test_synchronizes_access
|
17
|
-
t1_continue, t2_continue = false, false
|
18
|
-
|
19
|
-
hash = Hash.new do |hash, key|
|
20
|
-
t2_continue = true
|
21
|
-
unless hash.find { |e| e[1] == key.to_s } # just to do something
|
22
|
-
hash[key] = key.to_s
|
23
|
-
Thread.pass until t1_continue
|
24
|
-
end
|
25
|
-
end
|
26
|
-
sync_hash = SynchronizedDelegator.new(hash)
|
27
|
-
sync_hash[1] = 'egy'
|
28
|
-
|
29
|
-
t1 = Thread.new do
|
30
|
-
sync_hash[2] = 'dva'
|
31
|
-
sync_hash[3] # triggers t2_continue
|
32
|
-
end
|
33
|
-
|
34
|
-
t2 = Thread.new do
|
35
|
-
Thread.pass until t2_continue
|
36
|
-
sync_hash[4] = '42'
|
37
|
-
end
|
38
|
-
|
39
|
-
sleep(0.05) # sleep some to allow threads to boot
|
40
|
-
|
41
|
-
until t2.status == 'sleep' do
|
42
|
-
Thread.pass
|
43
|
-
end
|
44
|
-
|
45
|
-
assert_equal 3, hash.keys.size
|
46
|
-
|
47
|
-
t1_continue = true
|
48
|
-
t1.join; t2.join
|
49
|
-
|
50
|
-
assert_equal 4, sync_hash.size
|
51
|
-
end
|
52
|
-
|
53
|
-
def test_synchronizes_access_with_block
|
54
|
-
t1_continue, t2_continue = false, false
|
55
|
-
|
56
|
-
sync_array = SynchronizedDelegator.new(array = [])
|
57
|
-
|
58
|
-
t1 = Thread.new do
|
59
|
-
sync_array << 1
|
60
|
-
sync_array.each do
|
61
|
-
t2_continue = true
|
62
|
-
Thread.pass until t1_continue
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
t2 = Thread.new do
|
67
|
-
# sleep(0.01)
|
68
|
-
Thread.pass until t2_continue
|
69
|
-
sync_array << 2
|
70
|
-
end
|
71
|
-
|
72
|
-
until t2.status == 'sleep' || t2.status == false do
|
73
|
-
Thread.pass
|
74
|
-
end
|
75
|
-
|
76
|
-
assert_equal 1, array.size
|
77
|
-
|
78
|
-
t1_continue = true
|
79
|
-
t1.join; t2.join
|
80
|
-
|
81
|
-
assert_equal [1, 2], array
|
82
|
-
end
|
83
|
-
|
84
|
-
end
|