concurrent-ruby 0.6.0.pre.1 → 0.6.0.pre.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +16 -0
- data/lib/concurrent.rb +9 -29
- data/lib/concurrent/{actor.rb → actor/actor.rb} +3 -3
- data/lib/concurrent/actor/actor_context.rb +77 -0
- data/lib/concurrent/actor/actor_ref.rb +67 -0
- data/lib/concurrent/{postable.rb → actor/postable.rb} +1 -1
- data/lib/concurrent/actor/simple_actor_ref.rb +94 -0
- data/lib/concurrent/actors.rb +5 -0
- data/lib/concurrent/agent.rb +81 -47
- data/lib/concurrent/async.rb +35 -35
- data/lib/concurrent/atomic/atomic_boolean.rb +157 -0
- data/lib/concurrent/atomic/atomic_fixnum.rb +170 -0
- data/lib/concurrent/{condition.rb → atomic/condition.rb} +0 -0
- data/lib/concurrent/{copy_on_notify_observer_set.rb → atomic/copy_on_notify_observer_set.rb} +48 -13
- data/lib/concurrent/{copy_on_write_observer_set.rb → atomic/copy_on_write_observer_set.rb} +41 -20
- data/lib/concurrent/atomic/count_down_latch.rb +116 -0
- data/lib/concurrent/atomic/cyclic_barrier.rb +106 -0
- data/lib/concurrent/atomic/event.rb +103 -0
- data/lib/concurrent/{thread_local_var.rb → atomic/thread_local_var.rb} +0 -0
- data/lib/concurrent/atomics.rb +9 -0
- data/lib/concurrent/channel/buffered_channel.rb +6 -4
- data/lib/concurrent/channel/channel.rb +30 -2
- data/lib/concurrent/channel/unbuffered_channel.rb +2 -2
- data/lib/concurrent/channel/waitable_list.rb +3 -1
- data/lib/concurrent/channels.rb +5 -0
- data/lib/concurrent/{channel → collection}/blocking_ring_buffer.rb +16 -5
- data/lib/concurrent/collection/priority_queue.rb +305 -0
- data/lib/concurrent/{channel → collection}/ring_buffer.rb +6 -1
- data/lib/concurrent/collections.rb +3 -0
- data/lib/concurrent/configuration.rb +68 -19
- data/lib/concurrent/dataflow.rb +9 -9
- data/lib/concurrent/delay.rb +21 -13
- data/lib/concurrent/dereferenceable.rb +40 -33
- data/lib/concurrent/exchanger.rb +3 -0
- data/lib/concurrent/{cached_thread_pool.rb → executor/cached_thread_pool.rb} +8 -9
- data/lib/concurrent/executor/executor.rb +222 -0
- data/lib/concurrent/{fixed_thread_pool.rb → executor/fixed_thread_pool.rb} +6 -7
- data/lib/concurrent/{immediate_executor.rb → executor/immediate_executor.rb} +5 -5
- data/lib/concurrent/executor/java_cached_thread_pool.rb +31 -0
- data/lib/concurrent/{java_fixed_thread_pool.rb → executor/java_fixed_thread_pool.rb} +7 -11
- data/lib/concurrent/executor/java_single_thread_executor.rb +21 -0
- data/lib/concurrent/{java_thread_pool_executor.rb → executor/java_thread_pool_executor.rb} +66 -77
- data/lib/concurrent/executor/one_by_one.rb +65 -0
- data/lib/concurrent/{per_thread_executor.rb → executor/per_thread_executor.rb} +4 -4
- data/lib/concurrent/executor/ruby_cached_thread_pool.rb +29 -0
- data/lib/concurrent/{ruby_fixed_thread_pool.rb → executor/ruby_fixed_thread_pool.rb} +5 -4
- data/lib/concurrent/executor/ruby_single_thread_executor.rb +72 -0
- data/lib/concurrent/executor/ruby_thread_pool_executor.rb +282 -0
- data/lib/concurrent/{ruby_thread_pool_worker.rb → executor/ruby_thread_pool_worker.rb} +6 -6
- data/lib/concurrent/{safe_task_executor.rb → executor/safe_task_executor.rb} +20 -13
- data/lib/concurrent/executor/single_thread_executor.rb +35 -0
- data/lib/concurrent/executor/thread_pool_executor.rb +68 -0
- data/lib/concurrent/executor/timer_set.rb +138 -0
- data/lib/concurrent/executors.rb +9 -0
- data/lib/concurrent/future.rb +39 -40
- data/lib/concurrent/ivar.rb +22 -15
- data/lib/concurrent/mvar.rb +2 -1
- data/lib/concurrent/obligation.rb +9 -3
- data/lib/concurrent/observable.rb +33 -0
- data/lib/concurrent/options_parser.rb +46 -0
- data/lib/concurrent/promise.rb +23 -24
- data/lib/concurrent/scheduled_task.rb +21 -45
- data/lib/concurrent/timer_task.rb +204 -126
- data/lib/concurrent/tvar.rb +1 -1
- data/lib/concurrent/utilities.rb +3 -36
- data/lib/concurrent/{processor_count.rb → utility/processor_count.rb} +1 -1
- data/lib/concurrent/utility/timeout.rb +36 -0
- data/lib/concurrent/utility/timer.rb +21 -0
- data/lib/concurrent/version.rb +1 -1
- data/lib/concurrent_ruby_ext.bundle +0 -0
- data/spec/concurrent/{actor_context_spec.rb → actor/actor_context_spec.rb} +0 -8
- data/spec/concurrent/{actor_ref_shared.rb → actor/actor_ref_shared.rb} +9 -59
- data/spec/concurrent/{actor_spec.rb → actor/actor_spec.rb} +43 -41
- data/spec/concurrent/{postable_shared.rb → actor/postable_shared.rb} +0 -0
- data/spec/concurrent/actor/simple_actor_ref_spec.rb +135 -0
- data/spec/concurrent/agent_spec.rb +160 -71
- data/spec/concurrent/atomic/atomic_boolean_spec.rb +172 -0
- data/spec/concurrent/atomic/atomic_fixnum_spec.rb +186 -0
- data/spec/concurrent/{condition_spec.rb → atomic/condition_spec.rb} +2 -2
- data/spec/concurrent/{copy_on_notify_observer_set_spec.rb → atomic/copy_on_notify_observer_set_spec.rb} +0 -0
- data/spec/concurrent/{copy_on_write_observer_set_spec.rb → atomic/copy_on_write_observer_set_spec.rb} +0 -0
- data/spec/concurrent/atomic/count_down_latch_spec.rb +151 -0
- data/spec/concurrent/atomic/cyclic_barrier_spec.rb +248 -0
- data/spec/concurrent/{event_spec.rb → atomic/event_spec.rb} +18 -3
- data/spec/concurrent/{observer_set_shared.rb → atomic/observer_set_shared.rb} +15 -6
- data/spec/concurrent/{thread_local_var_spec.rb → atomic/thread_local_var_spec.rb} +0 -0
- data/spec/concurrent/channel/buffered_channel_spec.rb +1 -1
- data/spec/concurrent/channel/channel_spec.rb +6 -4
- data/spec/concurrent/channel/probe_spec.rb +37 -9
- data/spec/concurrent/channel/unbuffered_channel_spec.rb +2 -2
- data/spec/concurrent/{channel → collection}/blocking_ring_buffer_spec.rb +0 -0
- data/spec/concurrent/collection/priority_queue_spec.rb +317 -0
- data/spec/concurrent/{channel → collection}/ring_buffer_spec.rb +0 -0
- data/spec/concurrent/configuration_spec.rb +4 -70
- data/spec/concurrent/dereferenceable_shared.rb +5 -4
- data/spec/concurrent/exchanger_spec.rb +10 -5
- data/spec/concurrent/{cached_thread_pool_shared.rb → executor/cached_thread_pool_shared.rb} +15 -37
- data/spec/concurrent/{fixed_thread_pool_shared.rb → executor/fixed_thread_pool_shared.rb} +0 -0
- data/spec/concurrent/{global_thread_pool_shared.rb → executor/global_thread_pool_shared.rb} +10 -8
- data/spec/concurrent/{immediate_executor_spec.rb → executor/immediate_executor_spec.rb} +0 -0
- data/spec/concurrent/{java_cached_thread_pool_spec.rb → executor/java_cached_thread_pool_spec.rb} +1 -21
- data/spec/concurrent/{java_fixed_thread_pool_spec.rb → executor/java_fixed_thread_pool_spec.rb} +0 -0
- data/spec/concurrent/executor/java_single_thread_executor_spec.rb +21 -0
- data/spec/concurrent/{java_thread_pool_executor_spec.rb → executor/java_thread_pool_executor_spec.rb} +0 -0
- data/spec/concurrent/{per_thread_executor_spec.rb → executor/per_thread_executor_spec.rb} +0 -4
- data/spec/concurrent/{ruby_cached_thread_pool_spec.rb → executor/ruby_cached_thread_pool_spec.rb} +1 -1
- data/spec/concurrent/{ruby_fixed_thread_pool_spec.rb → executor/ruby_fixed_thread_pool_spec.rb} +0 -0
- data/spec/concurrent/executor/ruby_single_thread_executor_spec.rb +18 -0
- data/spec/concurrent/{ruby_thread_pool_executor_spec.rb → executor/ruby_thread_pool_executor_spec.rb} +12 -24
- data/spec/concurrent/executor/safe_task_executor_spec.rb +103 -0
- data/spec/concurrent/{thread_pool_class_cast_spec.rb → executor/thread_pool_class_cast_spec.rb} +12 -0
- data/spec/concurrent/{thread_pool_executor_shared.rb → executor/thread_pool_executor_shared.rb} +0 -0
- data/spec/concurrent/{thread_pool_shared.rb → executor/thread_pool_shared.rb} +84 -119
- data/spec/concurrent/executor/timer_set_spec.rb +183 -0
- data/spec/concurrent/future_spec.rb +12 -0
- data/spec/concurrent/ivar_spec.rb +11 -1
- data/spec/concurrent/observable_shared.rb +173 -0
- data/spec/concurrent/observable_spec.rb +51 -0
- data/spec/concurrent/options_parser_spec.rb +71 -0
- data/spec/concurrent/runnable_shared.rb +6 -0
- data/spec/concurrent/scheduled_task_spec.rb +60 -40
- data/spec/concurrent/timer_task_spec.rb +130 -144
- data/spec/concurrent/{processor_count_spec.rb → utility/processor_count_spec.rb} +0 -0
- data/spec/concurrent/{utilities_spec.rb → utility/timeout_spec.rb} +0 -0
- data/spec/concurrent/utility/timer_spec.rb +52 -0
- metadata +147 -108
- data/lib/concurrent/actor_context.rb +0 -31
- data/lib/concurrent/actor_ref.rb +0 -39
- data/lib/concurrent/atomic.rb +0 -121
- data/lib/concurrent/channel/probe.rb +0 -19
- data/lib/concurrent/count_down_latch.rb +0 -60
- data/lib/concurrent/event.rb +0 -80
- data/lib/concurrent/java_cached_thread_pool.rb +0 -45
- data/lib/concurrent/ruby_cached_thread_pool.rb +0 -37
- data/lib/concurrent/ruby_thread_pool_executor.rb +0 -268
- data/lib/concurrent/simple_actor_ref.rb +0 -124
- data/lib/concurrent/thread_pool_executor.rb +0 -30
- data/spec/concurrent/atomic_spec.rb +0 -201
- data/spec/concurrent/count_down_latch_spec.rb +0 -125
- data/spec/concurrent/safe_task_executor_spec.rb +0 -58
- data/spec/concurrent/simple_actor_ref_spec.rb +0 -219
@@ -1,58 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'concurrent/safe_task_executor'
|
3
|
-
|
4
|
-
module Concurrent
|
5
|
-
|
6
|
-
describe SafeTaskExecutor do
|
7
|
-
|
8
|
-
describe '#execute' do
|
9
|
-
|
10
|
-
context 'happy execution' do
|
11
|
-
|
12
|
-
let(:task) { Proc.new { 42 } }
|
13
|
-
let(:executor) { SafeTaskExecutor.new(task) }
|
14
|
-
|
15
|
-
it 'should return success' do
|
16
|
-
success, value, reason = executor.execute
|
17
|
-
success.should be_true
|
18
|
-
end
|
19
|
-
|
20
|
-
it 'should return task value' do
|
21
|
-
success, value, reason = executor.execute
|
22
|
-
value.should eq 42
|
23
|
-
end
|
24
|
-
|
25
|
-
it 'should return a nil reason' do
|
26
|
-
success, value, reason = executor.execute
|
27
|
-
reason.should be_nil
|
28
|
-
end
|
29
|
-
|
30
|
-
end
|
31
|
-
|
32
|
-
context 'failing execution' do
|
33
|
-
|
34
|
-
let(:task) { Proc.new { raise StandardError.new('an error') } }
|
35
|
-
let(:executor) { SafeTaskExecutor.new(task) }
|
36
|
-
|
37
|
-
it 'should return false success' do
|
38
|
-
success, value, reason = executor.execute
|
39
|
-
success.should be_false
|
40
|
-
end
|
41
|
-
|
42
|
-
it 'should return a nil value' do
|
43
|
-
success, value, reason = executor.execute
|
44
|
-
value.should be_nil
|
45
|
-
end
|
46
|
-
|
47
|
-
it 'should return the reason' do
|
48
|
-
success, value, reason = executor.execute
|
49
|
-
reason.should be_a(StandardError)
|
50
|
-
reason.message.should eq 'an error'
|
51
|
-
end
|
52
|
-
|
53
|
-
end
|
54
|
-
|
55
|
-
end
|
56
|
-
|
57
|
-
end
|
58
|
-
end
|
@@ -1,219 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require_relative 'actor_ref_shared'
|
3
|
-
|
4
|
-
module Concurrent
|
5
|
-
|
6
|
-
describe SimpleActorRef do
|
7
|
-
|
8
|
-
after(:each) do
|
9
|
-
subject.shutdown
|
10
|
-
sleep(0.1)
|
11
|
-
end
|
12
|
-
|
13
|
-
subject do
|
14
|
-
shared_actor_test_class.spawn
|
15
|
-
end
|
16
|
-
|
17
|
-
it_should_behave_like :actor_ref
|
18
|
-
|
19
|
-
context 'construction' do
|
20
|
-
|
21
|
-
it 'supports :args being nil' do
|
22
|
-
subject = shared_actor_test_class.spawn
|
23
|
-
actor = subject.instance_variable_get(:@actor)
|
24
|
-
actor.argv.should be_empty
|
25
|
-
end
|
26
|
-
|
27
|
-
it 'passes all :args option to the actor constructor' do
|
28
|
-
subject = shared_actor_test_class.spawn(args: [1, 2, 3, 4])
|
29
|
-
actor = subject.instance_variable_get(:@actor)
|
30
|
-
actor.argv.should eq [1, 2, 3, 4]
|
31
|
-
end
|
32
|
-
|
33
|
-
it 'passes the options hash to the ActorRef constructor' do
|
34
|
-
subject # prevent the after(:all) block from breaking this test
|
35
|
-
opts = {foo: :bar, hello: :world}
|
36
|
-
described_class.should_receive(:new).once.with(anything, opts)
|
37
|
-
shared_actor_test_class.spawn(opts)
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
context 'supervision' do
|
42
|
-
|
43
|
-
it 'does not start a new thread on construction' do
|
44
|
-
Thread.should_not_receive(:new).with(any_args)
|
45
|
-
subject = shared_actor_test_class.spawn
|
46
|
-
end
|
47
|
-
|
48
|
-
it 'starts a new thread on the first post' do
|
49
|
-
thread = Thread.new{ nil }
|
50
|
-
Thread.should_receive(:new).once.with(no_args).and_return(thread)
|
51
|
-
subject << :foo
|
52
|
-
end
|
53
|
-
|
54
|
-
it 'does not start a new thread after the first post' do
|
55
|
-
subject << :foo
|
56
|
-
sleep(0.1)
|
57
|
-
expected = Thread.list.length
|
58
|
-
5.times{ subject << :foo }
|
59
|
-
Thread.list.length.should eq expected
|
60
|
-
end
|
61
|
-
|
62
|
-
it 'starts a new thread when the prior thread has died' do
|
63
|
-
subject << :foo
|
64
|
-
sleep(0.1)
|
65
|
-
|
66
|
-
subject << :terminate
|
67
|
-
sleep(0.1)
|
68
|
-
|
69
|
-
thread = Thread.new{ nil }
|
70
|
-
Thread.should_receive(:new).once.with(no_args).and_return(thread)
|
71
|
-
subject << :foo
|
72
|
-
end
|
73
|
-
|
74
|
-
it 'does not reset the thread after shutdown' do
|
75
|
-
thread = Thread.new{ nil }
|
76
|
-
Thread.should_receive(:new).once.with(no_args).and_return(thread)
|
77
|
-
subject << :foo
|
78
|
-
sleep(0.1)
|
79
|
-
|
80
|
-
subject.shutdown
|
81
|
-
sleep(0.1)
|
82
|
-
|
83
|
-
subject << :foo
|
84
|
-
end
|
85
|
-
|
86
|
-
it 'calls #on_start when the thread is first started' do
|
87
|
-
actor = subject.instance_variable_get(:@actor)
|
88
|
-
actor.should_receive(:on_start).once.with(no_args)
|
89
|
-
subject << :foo
|
90
|
-
end
|
91
|
-
|
92
|
-
it 'calls #on_reset when the thread is started after the first time' do
|
93
|
-
actor = subject.instance_variable_get(:@actor)
|
94
|
-
actor.should_receive(:on_reset).once.with(no_args)
|
95
|
-
subject << :terminate
|
96
|
-
sleep(0.1)
|
97
|
-
subject << :foo
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
101
|
-
context 'abort_on_exception' do
|
102
|
-
|
103
|
-
after(:each) do
|
104
|
-
@ref.shutdown if @ref
|
105
|
-
end
|
106
|
-
|
107
|
-
it 'gets set on the actor thread' do
|
108
|
-
@ref = shared_actor_test_class.spawn(abort_on_exception: true)
|
109
|
-
@ref << :foo
|
110
|
-
sleep(0.1)
|
111
|
-
@ref.instance_variable_get(:@thread).abort_on_exception.should be_true
|
112
|
-
|
113
|
-
@ref = shared_actor_test_class.spawn(abort_on_exception: false)
|
114
|
-
@ref << :foo
|
115
|
-
sleep(0.1)
|
116
|
-
@ref.instance_variable_get(:@thread).abort_on_exception.should be_false
|
117
|
-
end
|
118
|
-
|
119
|
-
it 'defaults to true' do
|
120
|
-
@ref = shared_actor_test_class.spawn
|
121
|
-
@ref << :foo
|
122
|
-
sleep(0.1)
|
123
|
-
@ref.instance_variable_get(:@thread).abort_on_exception.should be_true
|
124
|
-
end
|
125
|
-
end
|
126
|
-
|
127
|
-
context 'reset_on_error' do
|
128
|
-
|
129
|
-
after(:each) do
|
130
|
-
@ref.shutdown if @ref
|
131
|
-
end
|
132
|
-
|
133
|
-
it 'causes #on_reset to be called on exception when true' do
|
134
|
-
@ref = shared_actor_test_class.spawn(reset_on_error: true)
|
135
|
-
actor = @ref.instance_variable_get(:@actor)
|
136
|
-
actor.should_receive(:on_reset).once.with(no_args)
|
137
|
-
@ref << :poison
|
138
|
-
sleep(0.1)
|
139
|
-
end
|
140
|
-
|
141
|
-
it 'prevents #on_reset form being called on exception when false' do
|
142
|
-
@ref = shared_actor_test_class.spawn(reset_on_error: false)
|
143
|
-
actor = @ref.instance_variable_get(:@actor)
|
144
|
-
actor.should_not_receive(:on_reset).with(any_args)
|
145
|
-
@ref << :poison
|
146
|
-
sleep(0.1)
|
147
|
-
end
|
148
|
-
|
149
|
-
it 'defaults to true' do
|
150
|
-
@ref = shared_actor_test_class.spawn
|
151
|
-
actor = @ref.instance_variable_get(:@actor)
|
152
|
-
actor.should_receive(:on_reset).once.with(no_args)
|
153
|
-
@ref << :poison
|
154
|
-
sleep(0.1)
|
155
|
-
end
|
156
|
-
end
|
157
|
-
|
158
|
-
context 'rescue_exception' do
|
159
|
-
|
160
|
-
after(:each) do
|
161
|
-
@ref.shutdown if @ref
|
162
|
-
end
|
163
|
-
|
164
|
-
it 'rescues Exception in the actor thread when true' do
|
165
|
-
@ref = shared_actor_test_class.spawn(
|
166
|
-
abort_on_exception: false,
|
167
|
-
rescue_exception: true
|
168
|
-
)
|
169
|
-
|
170
|
-
ivar = @ref.post(:poison)
|
171
|
-
sleep(0.1)
|
172
|
-
ivar.reason.should be_a StandardError
|
173
|
-
|
174
|
-
ivar = @ref.post(:bullet)
|
175
|
-
sleep(0.1)
|
176
|
-
ivar.reason.should be_a Exception
|
177
|
-
end
|
178
|
-
|
179
|
-
it 'rescues StandardError in the actor thread when false' do
|
180
|
-
@ref = shared_actor_test_class.spawn(
|
181
|
-
abort_on_exception: false,
|
182
|
-
rescue_exception: false
|
183
|
-
)
|
184
|
-
|
185
|
-
ivar = @ref.post(:poison)
|
186
|
-
sleep(0.1)
|
187
|
-
ivar.reason.should be_a StandardError
|
188
|
-
|
189
|
-
ivar = @ref.post(:bullet)
|
190
|
-
sleep(0.1)
|
191
|
-
ivar.reason.should be_nil
|
192
|
-
end
|
193
|
-
|
194
|
-
it 'defaults to false' do
|
195
|
-
@ref = shared_actor_test_class.spawn(abort_on_exception: false)
|
196
|
-
|
197
|
-
ivar = @ref.post(:poison)
|
198
|
-
sleep(0.1)
|
199
|
-
ivar.reason.should be_a StandardError
|
200
|
-
|
201
|
-
ivar = @ref.post(:bullet)
|
202
|
-
sleep(0.1)
|
203
|
-
ivar.reason.should be_nil
|
204
|
-
end
|
205
|
-
end
|
206
|
-
|
207
|
-
context '#shutdown' do
|
208
|
-
|
209
|
-
it 'calls #on_shutdown when shutdown' do
|
210
|
-
actor = subject.instance_variable_get(:@actor)
|
211
|
-
actor.should_receive(:on_shutdown).once.with(no_args)
|
212
|
-
subject << :foo
|
213
|
-
sleep(0.1)
|
214
|
-
|
215
|
-
subject.shutdown
|
216
|
-
end
|
217
|
-
end
|
218
|
-
end
|
219
|
-
end
|