concurrent-ruby 0.6.0.pre.2 → 0.6.0
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/README.md +3 -8
- data/lib/concurrent.rb +2 -0
- data/lib/concurrent/actor/actor.rb +3 -3
- data/lib/concurrent/actor/postable.rb +1 -1
- data/lib/concurrent/actors.rb +0 -3
- data/lib/concurrent/actress.rb +75 -0
- data/lib/concurrent/actress/ad_hoc.rb +14 -0
- data/lib/concurrent/actress/context.rb +96 -0
- data/lib/concurrent/actress/core.rb +204 -0
- data/lib/concurrent/actress/core_delegations.rb +37 -0
- data/lib/concurrent/actress/doc.md +53 -0
- data/lib/concurrent/actress/envelope.rb +25 -0
- data/lib/concurrent/actress/errors.rb +14 -0
- data/lib/concurrent/actress/reference.rb +64 -0
- data/lib/concurrent/actress/type_check.rb +48 -0
- data/lib/concurrent/agent.rb +20 -11
- data/lib/concurrent/async.rb +54 -25
- data/lib/concurrent/atomic/atomic.rb +48 -0
- data/lib/concurrent/atomic/atomic_boolean.rb +13 -13
- data/lib/concurrent/atomic/atomic_fixnum.rb +9 -17
- data/lib/concurrent/atomic/copy_on_notify_observer_set.rb +7 -4
- data/lib/concurrent/atomic/copy_on_write_observer_set.rb +16 -14
- data/lib/concurrent/atomic/event.rb +11 -16
- data/lib/concurrent/atomics.rb +1 -0
- data/lib/concurrent/channel/channel.rb +4 -2
- data/lib/concurrent/collection/blocking_ring_buffer.rb +1 -1
- data/lib/concurrent/configuration.rb +59 -47
- data/lib/concurrent/delay.rb +28 -12
- data/lib/concurrent/dereferenceable.rb +6 -6
- data/lib/concurrent/errors.rb +30 -0
- data/lib/concurrent/executor/executor.rb +11 -4
- data/lib/concurrent/executor/immediate_executor.rb +1 -0
- data/lib/concurrent/executor/java_thread_pool_executor.rb +4 -0
- data/lib/concurrent/executor/one_by_one.rb +24 -12
- data/lib/concurrent/executor/per_thread_executor.rb +1 -0
- data/lib/concurrent/executor/ruby_single_thread_executor.rb +2 -1
- data/lib/concurrent/executor/ruby_thread_pool_executor.rb +7 -2
- data/lib/concurrent/executor/ruby_thread_pool_worker.rb +3 -0
- data/lib/concurrent/executor/timer_set.rb +1 -1
- data/lib/concurrent/future.rb +0 -2
- data/lib/concurrent/ivar.rb +31 -6
- data/lib/concurrent/logging.rb +17 -0
- data/lib/concurrent/mvar.rb +45 -0
- data/lib/concurrent/obligation.rb +61 -20
- data/lib/concurrent/observable.rb +7 -0
- data/lib/concurrent/promise.rb +1 -0
- data/lib/concurrent/runnable.rb +2 -2
- data/lib/concurrent/supervisor.rb +1 -2
- data/lib/concurrent/timer_task.rb +17 -13
- data/lib/concurrent/tvar.rb +113 -73
- data/lib/concurrent/utility/processor_count.rb +141 -116
- data/lib/concurrent/utility/timeout.rb +4 -5
- data/lib/concurrent/version.rb +1 -1
- data/spec/concurrent/actor/postable_shared.rb +1 -1
- data/spec/concurrent/actress_spec.rb +191 -0
- data/spec/concurrent/async_spec.rb +35 -3
- data/spec/concurrent/atomic/atomic_boolean_spec.rb +1 -1
- data/spec/concurrent/atomic/atomic_fixnum_spec.rb +1 -1
- data/spec/concurrent/atomic/atomic_spec.rb +133 -0
- data/spec/concurrent/atomic/count_down_latch_spec.rb +1 -1
- data/spec/concurrent/collection/priority_queue_spec.rb +1 -1
- data/spec/concurrent/configuration_spec.rb +5 -2
- data/spec/concurrent/delay_spec.rb +14 -0
- data/spec/concurrent/exchanger_spec.rb +4 -9
- data/spec/concurrent/executor/java_cached_thread_pool_spec.rb +1 -1
- data/spec/concurrent/executor/java_fixed_thread_pool_spec.rb +1 -1
- data/spec/concurrent/executor/java_single_thread_executor_spec.rb +1 -1
- data/spec/concurrent/executor/java_thread_pool_executor_spec.rb +1 -1
- data/spec/concurrent/executor/ruby_thread_pool_executor_spec.rb +4 -4
- data/spec/concurrent/ivar_spec.rb +2 -2
- data/spec/concurrent/obligation_spec.rb +113 -24
- data/spec/concurrent/observable_shared.rb +4 -0
- data/spec/concurrent/observable_spec.rb +8 -3
- data/spec/concurrent/runnable_spec.rb +2 -2
- data/spec/concurrent/scheduled_task_spec.rb +1 -0
- data/spec/concurrent/supervisor_spec.rb +26 -11
- data/spec/concurrent/timer_task_spec.rb +36 -35
- data/spec/concurrent/tvar_spec.rb +1 -1
- data/spec/concurrent/utility/timer_spec.rb +8 -8
- data/spec/spec_helper.rb +8 -18
- data/spec/support/example_group_extensions.rb +48 -0
- metadata +23 -16
- data/lib/concurrent/actor/actor_context.rb +0 -77
- data/lib/concurrent/actor/actor_ref.rb +0 -67
- data/lib/concurrent/actor/simple_actor_ref.rb +0 -94
- data/lib/concurrent_ruby_ext.bundle +0 -0
- data/spec/concurrent/actor/actor_context_spec.rb +0 -29
- data/spec/concurrent/actor/actor_ref_shared.rb +0 -263
- data/spec/concurrent/actor/simple_actor_ref_spec.rb +0 -135
- data/spec/support/functions.rb +0 -25
@@ -1,135 +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
|
-
create_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 = create_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 = create_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
|
-
create_actor_test_class.spawn(opts)
|
38
|
-
end
|
39
|
-
|
40
|
-
it 'calls #on_start on the actor' do
|
41
|
-
actor = double(:create_actor_test_class)
|
42
|
-
actor.should_receive(:on_start).once.with(no_args)
|
43
|
-
SimpleActorRef.new(actor)
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
context 'reset_on_error' do
|
48
|
-
|
49
|
-
it 'creates a new actor on exception when true' do
|
50
|
-
clazz = create_actor_test_class
|
51
|
-
args = [:foo, :bar, :hello, :world]
|
52
|
-
ref = clazz.spawn(reset_on_error: true, args: args)
|
53
|
-
clazz.should_receive(:new).once.with(*args)
|
54
|
-
ref.post(:poison)
|
55
|
-
end
|
56
|
-
|
57
|
-
it 'does not create a new actor on exception when false' do
|
58
|
-
clazz = create_actor_test_class
|
59
|
-
args = [:foo, :bar, :hello, :world]
|
60
|
-
ref = clazz.spawn(reset_on_error: true, args: args)
|
61
|
-
clazz.should_not_receive(:new).with(any_args)
|
62
|
-
ref.post(:poison)
|
63
|
-
end
|
64
|
-
|
65
|
-
it 'defaults to true' do
|
66
|
-
clazz = create_actor_test_class
|
67
|
-
args = [:foo, :bar, :hello, :world]
|
68
|
-
ref = clazz.spawn(args: args)
|
69
|
-
clazz.should_receive(:new).once.with(*args)
|
70
|
-
ref.post(:poison)
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
context 'rescue_exception' do
|
75
|
-
|
76
|
-
after(:each) do
|
77
|
-
@ref.shutdown if @ref
|
78
|
-
end
|
79
|
-
|
80
|
-
it 'rescues Exception in the actor thread when true' do
|
81
|
-
@ref = create_actor_test_class.spawn(
|
82
|
-
abort_on_exception: false,
|
83
|
-
rescue_exception: true
|
84
|
-
)
|
85
|
-
|
86
|
-
ivar = @ref.post(:poison)
|
87
|
-
sleep(0.1)
|
88
|
-
ivar.reason.should be_a StandardError
|
89
|
-
|
90
|
-
ivar = @ref.post(:bullet)
|
91
|
-
sleep(0.1)
|
92
|
-
ivar.reason.should be_a Exception
|
93
|
-
end
|
94
|
-
|
95
|
-
it 'rescues StandardError in the actor thread when false' do
|
96
|
-
@ref = create_actor_test_class.spawn(
|
97
|
-
abort_on_exception: false,
|
98
|
-
rescue_exception: false
|
99
|
-
)
|
100
|
-
|
101
|
-
ivar = @ref.post(:poison)
|
102
|
-
sleep(0.1)
|
103
|
-
ivar.reason.should be_a StandardError
|
104
|
-
|
105
|
-
ivar = @ref.post(:bullet)
|
106
|
-
sleep(0.1)
|
107
|
-
ivar.reason.should be_nil
|
108
|
-
end
|
109
|
-
|
110
|
-
it 'defaults to false' do
|
111
|
-
@ref = create_actor_test_class.spawn(abort_on_exception: false)
|
112
|
-
|
113
|
-
ivar = @ref.post(:poison)
|
114
|
-
sleep(0.1)
|
115
|
-
ivar.reason.should be_a StandardError
|
116
|
-
|
117
|
-
ivar = @ref.post(:bullet)
|
118
|
-
sleep(0.1)
|
119
|
-
ivar.reason.should be_nil
|
120
|
-
end
|
121
|
-
end
|
122
|
-
|
123
|
-
context '#shutdown' do
|
124
|
-
|
125
|
-
it 'calls #on_shutdown when shutdown' do
|
126
|
-
actor = subject.instance_variable_get(:@actor)
|
127
|
-
actor.should_receive(:on_shutdown).once.with(no_args)
|
128
|
-
subject << :foo
|
129
|
-
sleep(0.1)
|
130
|
-
|
131
|
-
subject.shutdown
|
132
|
-
end
|
133
|
-
end
|
134
|
-
end
|
135
|
-
end
|
data/spec/support/functions.rb
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
require 'rbconfig'
|
2
|
-
|
3
|
-
def delta(v1, v2)
|
4
|
-
if block_given?
|
5
|
-
v1 = yield(v1)
|
6
|
-
v2 = yield(v2)
|
7
|
-
end
|
8
|
-
return (v1 - v2).abs
|
9
|
-
end
|
10
|
-
|
11
|
-
def mri?
|
12
|
-
RbConfig::CONFIG['ruby_install_name']=~ /^ruby$/i
|
13
|
-
end
|
14
|
-
|
15
|
-
def jruby?
|
16
|
-
RbConfig::CONFIG['ruby_install_name']=~ /^jruby$/i
|
17
|
-
end
|
18
|
-
|
19
|
-
def rbx?
|
20
|
-
RbConfig::CONFIG['ruby_install_name']=~ /^rbx$/i
|
21
|
-
end
|
22
|
-
|
23
|
-
def reset_gem_configuration
|
24
|
-
Concurrent.instance_variable_set(:@configuration, Concurrent::Configuration.new)
|
25
|
-
end
|