celluloid 0.15.2 → 0.16.0.pre3
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/LICENSE.txt +20 -0
- data/README.md +25 -2
- data/lib/celluloid/actor.rb +88 -147
- data/lib/celluloid/actor_system.rb +107 -0
- data/lib/celluloid/call_chain.rb +1 -1
- data/lib/celluloid/calls.rb +16 -16
- data/lib/celluloid/cell.rb +89 -0
- data/lib/celluloid/condition.rb +25 -8
- data/lib/celluloid/cpu_counter.rb +27 -18
- data/lib/celluloid/evented_mailbox.rb +10 -16
- data/lib/celluloid/exceptions.rb +23 -0
- data/lib/celluloid/future.rb +1 -1
- data/lib/celluloid/handlers.rb +41 -0
- data/lib/celluloid/internal_pool.rb +49 -40
- data/lib/celluloid/logger.rb +30 -0
- data/lib/celluloid/logging/incident_logger.rb +1 -1
- data/lib/celluloid/mailbox.rb +35 -31
- data/lib/celluloid/method.rb +8 -0
- data/lib/celluloid/pool_manager.rb +19 -2
- data/lib/celluloid/probe.rb +73 -0
- data/lib/celluloid/properties.rb +2 -2
- data/lib/celluloid/proxies/actor_proxy.rb +9 -41
- data/lib/celluloid/proxies/cell_proxy.rb +68 -0
- data/lib/celluloid/proxies/sync_proxy.rb +1 -1
- data/lib/celluloid/receivers.rb +5 -13
- data/lib/celluloid/registry.rb +1 -8
- data/lib/celluloid/stack_dump.rb +34 -11
- data/lib/celluloid/supervision_group.rb +26 -14
- data/lib/celluloid/tasks/task_fiber.rb +6 -0
- data/lib/celluloid/tasks/task_thread.rb +2 -1
- data/lib/celluloid/tasks.rb +28 -9
- data/lib/celluloid/thread_handle.rb +2 -2
- data/lib/celluloid.rb +68 -73
- data/spec/celluloid/actor_spec.rb +1 -1
- data/spec/celluloid/actor_system_spec.rb +69 -0
- data/spec/celluloid/block_spec.rb +1 -1
- data/spec/celluloid/calls_spec.rb +1 -1
- data/spec/celluloid/condition_spec.rb +14 -3
- data/spec/celluloid/cpu_counter_spec.rb +82 -0
- data/spec/celluloid/fsm_spec.rb +1 -1
- data/spec/celluloid/future_spec.rb +1 -1
- data/spec/celluloid/notifications_spec.rb +1 -1
- data/spec/celluloid/pool_spec.rb +34 -1
- data/spec/celluloid/probe_spec.rb +121 -0
- data/spec/celluloid/registry_spec.rb +6 -6
- data/spec/celluloid/stack_dump_spec.rb +37 -8
- data/spec/celluloid/supervision_group_spec.rb +7 -1
- data/spec/celluloid/supervisor_spec.rb +12 -1
- data/spec/celluloid/tasks/task_fiber_spec.rb +1 -1
- data/spec/celluloid/tasks/task_thread_spec.rb +1 -1
- data/spec/celluloid/thread_handle_spec.rb +7 -3
- data/spec/celluloid/timer_spec.rb +48 -0
- data/spec/spec_helper.rb +20 -7
- data/spec/support/actor_examples.rb +58 -15
- data/spec/support/mailbox_examples.rb +9 -3
- data/spec/support/task_examples.rb +2 -0
- metadata +48 -22
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
class DummyActor; include Celluloid; end
|
|
4
|
+
|
|
5
|
+
class TestProbeClient
|
|
6
|
+
include Celluloid
|
|
7
|
+
include Celluloid::Notifications
|
|
8
|
+
|
|
9
|
+
attr_reader :buffer
|
|
10
|
+
|
|
11
|
+
def initialize()
|
|
12
|
+
@condition = Condition.new
|
|
13
|
+
subscribe(/celluloid\.events\..+/, :event_received)
|
|
14
|
+
@buffer = []
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def wait
|
|
18
|
+
@condition.wait
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def wait_event(topic, expected_actor1 = nil, expected_actor2 = nil)
|
|
22
|
+
loop do
|
|
23
|
+
wait
|
|
24
|
+
while ev = @buffer.shift()
|
|
25
|
+
if (ev[0] == topic) && (ev[1].mailbox.address == expected_actor1.mailbox.address) &&
|
|
26
|
+
(expected_actor2.nil? || (ev[2].mailbox.address == expected_actor2.mailbox.address) )
|
|
27
|
+
return ev
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def event_received(topic, args)
|
|
34
|
+
@buffer << [topic, args[0], args[1]]
|
|
35
|
+
@condition.signal
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
describe "Probe", actor_system: :global do
|
|
40
|
+
describe 'on boot' do
|
|
41
|
+
it 'should capture system actor spawn' do
|
|
42
|
+
client = TestProbeClient.new
|
|
43
|
+
Celluloid::Probe.run
|
|
44
|
+
create_events = []
|
|
45
|
+
received_named_events = {
|
|
46
|
+
:default_incident_reporter => nil,
|
|
47
|
+
:notifications_fanout => nil
|
|
48
|
+
}
|
|
49
|
+
# wait for the events we seek
|
|
50
|
+
Timeout.timeout(5) do
|
|
51
|
+
loop do
|
|
52
|
+
client.wait
|
|
53
|
+
while ev = client.buffer.shift
|
|
54
|
+
if ev[0] == 'celluloid.events.actor_created'
|
|
55
|
+
create_events << ev
|
|
56
|
+
elsif ev[0] == 'celluloid.events.actor_named'
|
|
57
|
+
if received_named_events.keys.include?(ev[1].name)
|
|
58
|
+
received_named_events[ev[1].name] = ev[1].mailbox.address
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
if received_named_events.all?{|_, v| v != nil }
|
|
63
|
+
break
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
received_named_events.all?{|_, v| v != nil }.should == true
|
|
68
|
+
# now check we got the create events for every actors
|
|
69
|
+
received_named_events.each do |_, mailbox_address|
|
|
70
|
+
found = create_events.detect{|_, aa| aa.mailbox.address == mailbox_address }
|
|
71
|
+
found.should_not == nil
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
describe 'after boot' do
|
|
77
|
+
it 'should send a notification when an actor is spawned' do
|
|
78
|
+
client = TestProbeClient.new
|
|
79
|
+
Celluloid::Probe.run
|
|
80
|
+
a = DummyActor.new
|
|
81
|
+
event = Timeout.timeout(5) do
|
|
82
|
+
client.wait_event('celluloid.events.actor_created', a)
|
|
83
|
+
end
|
|
84
|
+
event.should_not == nil
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
it 'should send a notification when an actor is named' do
|
|
88
|
+
client = TestProbeClient.new
|
|
89
|
+
Celluloid::Probe.run
|
|
90
|
+
a = DummyActor.new
|
|
91
|
+
Celluloid::Actor['a name'] = a
|
|
92
|
+
event = Timeout.timeout(5) do
|
|
93
|
+
client.wait_event('celluloid.events.actor_named', a)
|
|
94
|
+
end
|
|
95
|
+
event.should_not == nil
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
it 'should send a notification when actor dies' do
|
|
99
|
+
client = TestProbeClient.new
|
|
100
|
+
Celluloid::Probe.run
|
|
101
|
+
a = DummyActor.new
|
|
102
|
+
a.terminate
|
|
103
|
+
event = Timeout.timeout(5) do
|
|
104
|
+
client.wait_event('celluloid.events.actor_died', a)
|
|
105
|
+
end
|
|
106
|
+
event.should_not == nil
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
it 'should send a notification when actors are linked' do
|
|
110
|
+
client = TestProbeClient.new
|
|
111
|
+
Celluloid::Probe.run
|
|
112
|
+
a = DummyActor.new
|
|
113
|
+
b = DummyActor.new
|
|
114
|
+
a.link(b)
|
|
115
|
+
event = Timeout.timeout(5) do
|
|
116
|
+
client.wait_event('celluloid.events.actors_linked', a, b)
|
|
117
|
+
end
|
|
118
|
+
event.should_not == nil
|
|
119
|
+
end
|
|
120
|
+
end
|
|
121
|
+
end
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
2
|
|
|
3
|
-
describe Celluloid::Registry do
|
|
3
|
+
describe Celluloid::Registry, actor_system: :global do
|
|
4
4
|
class Marilyn
|
|
5
5
|
include Celluloid
|
|
6
6
|
|
|
@@ -27,21 +27,21 @@ describe Celluloid::Registry do
|
|
|
27
27
|
|
|
28
28
|
it "knows its name once registered" do
|
|
29
29
|
Celluloid::Actor[:marilyn] = Marilyn.new
|
|
30
|
-
Celluloid::Actor[:marilyn].
|
|
30
|
+
Celluloid::Actor[:marilyn].registered_name.should == :marilyn
|
|
31
31
|
end
|
|
32
32
|
|
|
33
33
|
describe :delete do
|
|
34
34
|
before do
|
|
35
35
|
Celluloid::Actor[:marilyn] ||= Marilyn.new
|
|
36
36
|
end
|
|
37
|
-
|
|
37
|
+
|
|
38
38
|
it "removes reference to actors' name from the registry" do
|
|
39
|
-
Celluloid::
|
|
39
|
+
Celluloid::Actor.delete(:marilyn)
|
|
40
40
|
Celluloid::Actor.registered.should_not include :marilyn
|
|
41
41
|
end
|
|
42
|
-
|
|
42
|
+
|
|
43
43
|
it "returns actor removed from the registry" do
|
|
44
|
-
rval = Celluloid::
|
|
44
|
+
rval = Celluloid::Actor.delete(:marilyn)
|
|
45
45
|
rval.should be_kind_of(Marilyn)
|
|
46
46
|
end
|
|
47
47
|
end
|
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
2
|
|
|
3
3
|
describe Celluloid::StackDump do
|
|
4
|
+
let(:actor_system) do
|
|
5
|
+
Celluloid::ActorSystem.new
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
subject do
|
|
9
|
+
actor_system.stack_dump
|
|
10
|
+
end
|
|
11
|
+
|
|
4
12
|
class BlockingActor
|
|
5
13
|
include Celluloid
|
|
6
14
|
|
|
@@ -14,22 +22,43 @@ describe Celluloid::StackDump do
|
|
|
14
22
|
actor_klass = Class.new(BlockingActor) do
|
|
15
23
|
task_class task_klass
|
|
16
24
|
end
|
|
17
|
-
actor =
|
|
25
|
+
actor = actor_system.within do
|
|
26
|
+
actor_klass.new
|
|
27
|
+
end
|
|
18
28
|
actor.async.blocking
|
|
19
29
|
end
|
|
20
30
|
|
|
21
|
-
|
|
22
|
-
Thread.current.role = :testing
|
|
31
|
+
@active_thread = actor_system.get_thread do
|
|
23
32
|
sleep
|
|
24
33
|
end
|
|
34
|
+
@active_thread.role = :other_thing
|
|
35
|
+
@idle_thread = actor_system.get_thread do
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
sleep 0.01
|
|
25
39
|
end
|
|
26
40
|
|
|
27
|
-
|
|
28
|
-
|
|
41
|
+
describe '#actors' do
|
|
42
|
+
it 'should include all actors' do
|
|
43
|
+
subject.actors.size.should == actor_system.running.size
|
|
44
|
+
end
|
|
29
45
|
end
|
|
30
46
|
|
|
31
|
-
|
|
32
|
-
pending
|
|
33
|
-
|
|
47
|
+
describe '#threads' do
|
|
48
|
+
it 'should include threads that are not actors', pending: 'flaky' do
|
|
49
|
+
expect(subject.threads.size).to eq(3)
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
it 'should include idle threads' do
|
|
53
|
+
subject.threads.map(&:thread_id).should include(@idle_thread.object_id)
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
it 'should include threads checked out of the pool for roles other than :actor' do
|
|
57
|
+
subject.threads.map(&:thread_id).should include(@active_thread.object_id)
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
it 'should have the correct roles', pending: 'flaky' do
|
|
61
|
+
expect(subject.threads.map(&:role)).to include(nil, :other_thing, :task)
|
|
62
|
+
end
|
|
34
63
|
end
|
|
35
64
|
end
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
2
|
|
|
3
|
-
describe Celluloid::SupervisionGroup do
|
|
3
|
+
describe Celluloid::SupervisionGroup, actor_system: :global do
|
|
4
4
|
before :all do
|
|
5
5
|
class MyActor
|
|
6
6
|
include Celluloid
|
|
@@ -55,5 +55,11 @@ describe Celluloid::SupervisionGroup do
|
|
|
55
55
|
Celluloid::Actor[:example_pool].args.should eq ['foo']
|
|
56
56
|
Celluloid::Actor[:example_pool].size.should be 3
|
|
57
57
|
end
|
|
58
|
+
|
|
59
|
+
it "allows external access to the internal registry" do
|
|
60
|
+
supervisor = MyGroup.run!
|
|
61
|
+
|
|
62
|
+
supervisor[:example].should be_a MyActor
|
|
63
|
+
end
|
|
58
64
|
end
|
|
59
65
|
end
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
2
|
|
|
3
|
-
describe Celluloid::Supervisor do
|
|
3
|
+
describe Celluloid::Supervisor, actor_system: :global do
|
|
4
4
|
class SubordinateDead < StandardError; end
|
|
5
5
|
|
|
6
6
|
class Subordinate
|
|
@@ -89,4 +89,15 @@ describe Celluloid::Supervisor do
|
|
|
89
89
|
new_subordinate.should_not eq subordinate
|
|
90
90
|
new_subordinate.state.should be(:working)
|
|
91
91
|
end
|
|
92
|
+
|
|
93
|
+
it "removes an actor if it terminates cleanly" do
|
|
94
|
+
supervisor = Subordinate.supervise(:working)
|
|
95
|
+
subordinate = supervisor.actors.first
|
|
96
|
+
|
|
97
|
+
supervisor.actors.should == [subordinate]
|
|
98
|
+
|
|
99
|
+
subordinate.terminate
|
|
100
|
+
|
|
101
|
+
supervisor.actors.should be_empty
|
|
102
|
+
end
|
|
92
103
|
end
|
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
2
|
|
|
3
3
|
describe Celluloid::ThreadHandle do
|
|
4
|
+
let(:actor_system) do
|
|
5
|
+
Celluloid::ActorSystem.new
|
|
6
|
+
end
|
|
7
|
+
|
|
4
8
|
it "knows thread liveliness" do
|
|
5
9
|
queue = Queue.new
|
|
6
|
-
handle = Celluloid::ThreadHandle.new { queue.pop }
|
|
10
|
+
handle = Celluloid::ThreadHandle.new(actor_system) { queue.pop }
|
|
7
11
|
handle.should be_alive
|
|
8
12
|
|
|
9
13
|
queue << :die
|
|
@@ -13,10 +17,10 @@ describe Celluloid::ThreadHandle do
|
|
|
13
17
|
end
|
|
14
18
|
|
|
15
19
|
it "joins to thread handles" do
|
|
16
|
-
Celluloid::ThreadHandle.new { sleep 0.01 }.join
|
|
20
|
+
Celluloid::ThreadHandle.new(actor_system) { sleep 0.01 }.join
|
|
17
21
|
end
|
|
18
22
|
|
|
19
23
|
it "supports passing a role" do
|
|
20
|
-
Celluloid::ThreadHandle.new(:useful) { Thread.current.role.should == :useful }.join
|
|
24
|
+
Celluloid::ThreadHandle.new(actor_system, :useful) { Thread.current.role.should == :useful }.join
|
|
21
25
|
end
|
|
22
26
|
end
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
class EveryActor
|
|
4
|
+
include Celluloid
|
|
5
|
+
|
|
6
|
+
def initialize
|
|
7
|
+
@trace = []
|
|
8
|
+
@times = []
|
|
9
|
+
@start = Time.now
|
|
10
|
+
|
|
11
|
+
every(1) { log(1) }
|
|
12
|
+
every(2) { log(2) }
|
|
13
|
+
every(1) { log(11) }
|
|
14
|
+
every(2) { log(22) }
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def log(t)
|
|
18
|
+
@trace << t
|
|
19
|
+
|
|
20
|
+
offset = Time.now - @start
|
|
21
|
+
@times << offset
|
|
22
|
+
|
|
23
|
+
# puts "log(#{t}) @ #{offset}"
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
attr :trace
|
|
27
|
+
attr :times
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
describe Celluloid::Actor do
|
|
31
|
+
it "run every(t) task several times" do
|
|
32
|
+
Celluloid.boot
|
|
33
|
+
|
|
34
|
+
every_actor = EveryActor.new
|
|
35
|
+
|
|
36
|
+
sleep 5.5
|
|
37
|
+
|
|
38
|
+
times = every_actor.times
|
|
39
|
+
trace = every_actor.trace
|
|
40
|
+
|
|
41
|
+
Celluloid.shutdown
|
|
42
|
+
|
|
43
|
+
expect(trace.count(1)).to be == 5
|
|
44
|
+
expect(trace.count(11)).to be == 5
|
|
45
|
+
expect(trace.count(2)).to be == 2
|
|
46
|
+
expect(trace.count(22)).to be == 2
|
|
47
|
+
end
|
|
48
|
+
end
|
data/spec/spec_helper.rb
CHANGED
|
@@ -4,11 +4,12 @@ Coveralls.wear!
|
|
|
4
4
|
require 'rubygems'
|
|
5
5
|
require 'bundler/setup'
|
|
6
6
|
require 'celluloid/rspec'
|
|
7
|
+
require 'celluloid/probe'
|
|
7
8
|
|
|
8
9
|
logfile = File.open(File.expand_path("../../log/test.log", __FILE__), 'a')
|
|
9
10
|
logfile.sync = true
|
|
10
11
|
|
|
11
|
-
|
|
12
|
+
Celluloid.logger = Logger.new(logfile)
|
|
12
13
|
|
|
13
14
|
Celluloid.shutdown_timeout = 1
|
|
14
15
|
|
|
@@ -18,14 +19,26 @@ RSpec.configure do |config|
|
|
|
18
19
|
config.filter_run :focus => true
|
|
19
20
|
config.run_all_when_everything_filtered = true
|
|
20
21
|
|
|
21
|
-
config.
|
|
22
|
-
Celluloid.
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
Celluloid.internal_pool.assert_inactive
|
|
22
|
+
config.around do |ex|
|
|
23
|
+
Celluloid.actor_system = nil
|
|
24
|
+
Thread.list.each do |thread|
|
|
25
|
+
next if thread == Thread.current
|
|
26
|
+
thread.kill
|
|
27
27
|
end
|
|
28
28
|
|
|
29
|
+
ex.run
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
config.around actor_system: :global do |ex|
|
|
29
33
|
Celluloid.boot
|
|
34
|
+
ex.run
|
|
35
|
+
Celluloid.shutdown
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
config.around actor_system: :within do |ex|
|
|
39
|
+
Celluloid::ActorSystem.new.within do
|
|
40
|
+
ex.run
|
|
41
|
+
end
|
|
30
42
|
end
|
|
43
|
+
|
|
31
44
|
end
|
|
@@ -65,6 +65,19 @@ shared_examples "Celluloid::Actor examples" do |included_module, task_klass|
|
|
|
65
65
|
method.arity.should be(1)
|
|
66
66
|
end
|
|
67
67
|
|
|
68
|
+
it "supports #name calls via #method" do
|
|
69
|
+
method = actor_class.new("Troy McClure").method(:greet)
|
|
70
|
+
method.name.should == :greet
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
it "supports #parameters via #method" do
|
|
74
|
+
method = actor_class.new("Troy McClure").method(:greet)
|
|
75
|
+
method.parameters.should == []
|
|
76
|
+
|
|
77
|
+
method = actor_class.new("Troy McClure").method(:change_name)
|
|
78
|
+
method.parameters.should == [[:req, :new_name]]
|
|
79
|
+
end
|
|
80
|
+
|
|
68
81
|
it "supports future(:method) syntax for synchronous future calls" do
|
|
69
82
|
actor = actor_class.new "Troy McClure"
|
|
70
83
|
future = actor.future :greet
|
|
@@ -148,7 +161,6 @@ shared_examples "Celluloid::Actor examples" do |included_module, task_klass|
|
|
|
148
161
|
end
|
|
149
162
|
end
|
|
150
163
|
|
|
151
|
-
Celluloid.logger = double.as_null_object
|
|
152
164
|
Celluloid.logger.should_receive(:warn).with(/Dangerously suspending task: type=:call, meta={:method_name=>:initialize}, status=:sleeping/)
|
|
153
165
|
|
|
154
166
|
actor = klass.new
|
|
@@ -175,7 +187,6 @@ shared_examples "Celluloid::Actor examples" do |included_module, task_klass|
|
|
|
175
187
|
end
|
|
176
188
|
end
|
|
177
189
|
|
|
178
|
-
Celluloid.logger = double.as_null_object
|
|
179
190
|
Celluloid.logger.should_receive(:warn).with(/Dangerously suspending task: type=:finalizer, meta={:method_name=>:cleanup}, status=:sleeping/)
|
|
180
191
|
|
|
181
192
|
actor = klass.new
|
|
@@ -221,7 +232,7 @@ shared_examples "Celluloid::Actor examples" do |included_module, task_klass|
|
|
|
221
232
|
|
|
222
233
|
it "inspects properly" do
|
|
223
234
|
actor = actor_class.new "Troy McClure"
|
|
224
|
-
actor.inspect.should match(/Celluloid::
|
|
235
|
+
actor.inspect.should match(/Celluloid::CellProxy\(/)
|
|
225
236
|
actor.inspect.should match(/#{actor_class}/)
|
|
226
237
|
actor.inspect.should include('@name="Troy McClure"')
|
|
227
238
|
actor.inspect.should_not include("@celluloid")
|
|
@@ -230,7 +241,7 @@ shared_examples "Celluloid::Actor examples" do |included_module, task_klass|
|
|
|
230
241
|
it "inspects properly when dead" do
|
|
231
242
|
actor = actor_class.new "Troy McClure"
|
|
232
243
|
actor.terminate
|
|
233
|
-
actor.inspect.should match(/Celluloid::
|
|
244
|
+
actor.inspect.should match(/Celluloid::CellProxy\(/)
|
|
234
245
|
actor.inspect.should match(/#{actor_class}/)
|
|
235
246
|
actor.inspect.should include('dead')
|
|
236
247
|
end
|
|
@@ -252,7 +263,7 @@ shared_examples "Celluloid::Actor examples" do |included_module, task_klass|
|
|
|
252
263
|
itchy.other = scratchy
|
|
253
264
|
|
|
254
265
|
inspection = itchy.inspect
|
|
255
|
-
inspection.should match(/Celluloid::
|
|
266
|
+
inspection.should match(/Celluloid::CellProxy\(/)
|
|
256
267
|
inspection.should include("...")
|
|
257
268
|
end
|
|
258
269
|
|
|
@@ -274,6 +285,31 @@ shared_examples "Celluloid::Actor examples" do |included_module, task_klass|
|
|
|
274
285
|
actor.send('foo').should eq('oof')
|
|
275
286
|
end
|
|
276
287
|
|
|
288
|
+
context "when executing under JRuby" do
|
|
289
|
+
let(:klass) {
|
|
290
|
+
Class.new do
|
|
291
|
+
include included_module
|
|
292
|
+
task_class task_klass
|
|
293
|
+
|
|
294
|
+
def current_thread_name
|
|
295
|
+
java_thread.get_name
|
|
296
|
+
end
|
|
297
|
+
|
|
298
|
+
def java_thread
|
|
299
|
+
Thread.current.to_java.getNativeThread
|
|
300
|
+
end
|
|
301
|
+
end
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
it "sets execution info" do
|
|
305
|
+
klass.new.current_thread_name.should == "Class#current_thread_name"
|
|
306
|
+
end
|
|
307
|
+
|
|
308
|
+
it "unsets execution info after task completion" do
|
|
309
|
+
klass.new.java_thread.get_name.should == "<unused>"
|
|
310
|
+
end
|
|
311
|
+
end if RUBY_PLATFORM == "java"
|
|
312
|
+
|
|
277
313
|
context "mocking methods" do
|
|
278
314
|
let(:actor) { actor_class.new "Troy McClure" }
|
|
279
315
|
|
|
@@ -300,27 +336,27 @@ shared_examples "Celluloid::Actor examples" do |included_module, task_klass|
|
|
|
300
336
|
end
|
|
301
337
|
|
|
302
338
|
it "includes both sender and receiver in exception traces" do
|
|
303
|
-
|
|
339
|
+
example_receiver = Class.new do
|
|
304
340
|
include included_module
|
|
305
341
|
task_class task_klass
|
|
306
342
|
|
|
307
|
-
|
|
343
|
+
define_method(:receiver_method) do
|
|
308
344
|
raise ExampleCrash, "the spec purposely crashed me :("
|
|
309
345
|
end
|
|
310
346
|
end
|
|
311
347
|
|
|
312
|
-
|
|
348
|
+
excample_caller = Class.new do
|
|
313
349
|
include included_module
|
|
314
350
|
task_class task_klass
|
|
315
351
|
|
|
316
|
-
|
|
317
|
-
|
|
352
|
+
define_method(:sender_method) do
|
|
353
|
+
example_receiver.new.receiver_method
|
|
318
354
|
end
|
|
319
355
|
end
|
|
320
356
|
|
|
321
357
|
ex = nil
|
|
322
358
|
begin
|
|
323
|
-
|
|
359
|
+
excample_caller.new.sender_method
|
|
324
360
|
rescue => ex
|
|
325
361
|
end
|
|
326
362
|
|
|
@@ -404,6 +440,15 @@ shared_examples "Celluloid::Actor examples" do |included_module, task_klass|
|
|
|
404
440
|
end.to raise_exception(Celluloid::DeadActorError)
|
|
405
441
|
end
|
|
406
442
|
|
|
443
|
+
it "terminates cleanly on Celluloid shutdown" do
|
|
444
|
+
Celluloid::Actor.stub(:kill).and_call_original
|
|
445
|
+
|
|
446
|
+
actor = actor_class.new "Arnold Schwarzenegger"
|
|
447
|
+
|
|
448
|
+
Celluloid.shutdown
|
|
449
|
+
Celluloid::Actor.should_not have_received(:kill)
|
|
450
|
+
end
|
|
451
|
+
|
|
407
452
|
it "raises the right DeadActorError if terminate! called after terminated" do
|
|
408
453
|
actor = actor_class.new "Arnold Schwarzenegger"
|
|
409
454
|
actor.terminate
|
|
@@ -414,8 +459,7 @@ shared_examples "Celluloid::Actor examples" do |included_module, task_klass|
|
|
|
414
459
|
end
|
|
415
460
|
|
|
416
461
|
it "logs a warning when terminating tasks" do
|
|
417
|
-
Celluloid.logger =
|
|
418
|
-
Celluloid.logger.should_receive(:warn).with("Terminating task: type=:call, meta={:method_name=>:sleepy}, status=:sleeping")
|
|
462
|
+
Celluloid.logger.should_receive(:warn).with(/^Terminating task: type=:call, meta={:method_name=>:sleepy}, status=:sleeping\n/)
|
|
419
463
|
|
|
420
464
|
actor = actor_class.new "Arnold Schwarzenegger"
|
|
421
465
|
actor.async.sleepy 10
|
|
@@ -923,7 +967,7 @@ shared_examples "Celluloid::Actor examples" do |included_module, task_klass|
|
|
|
923
967
|
end
|
|
924
968
|
|
|
925
969
|
context :proxy_class do
|
|
926
|
-
class ExampleProxy < Celluloid::
|
|
970
|
+
class ExampleProxy < Celluloid::CellProxy
|
|
927
971
|
def subclass_proxy?
|
|
928
972
|
true
|
|
929
973
|
end
|
|
@@ -1000,7 +1044,6 @@ shared_examples "Celluloid::Actor examples" do |included_module, task_klass|
|
|
|
1000
1044
|
|
|
1001
1045
|
context "raw message sends" do
|
|
1002
1046
|
it "logs on unhandled messages" do
|
|
1003
|
-
Celluloid.logger = double.as_null_object
|
|
1004
1047
|
Celluloid.logger.should_receive(:debug).with("Discarded message (unhandled): first")
|
|
1005
1048
|
|
|
1006
1049
|
actor = actor_class.new "Irma Gladden"
|
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
shared_context "a Celluloid Mailbox" do
|
|
2
|
+
after do
|
|
3
|
+
Celluloid.logger.stub(:debug)
|
|
4
|
+
subject.shutdown if subject.alive?
|
|
5
|
+
end
|
|
6
|
+
|
|
2
7
|
it "receives messages" do
|
|
3
8
|
message = :ohai
|
|
4
9
|
|
|
@@ -34,7 +39,10 @@ shared_context "a Celluloid Mailbox" do
|
|
|
34
39
|
interval = 0.1
|
|
35
40
|
started_at = Time.now
|
|
36
41
|
|
|
37
|
-
|
|
42
|
+
expect do
|
|
43
|
+
subject.receive(interval) { false }
|
|
44
|
+
end.to raise_exception(Celluloid::TimeoutError)
|
|
45
|
+
|
|
38
46
|
(Time.now - started_at).should be_within(Celluloid::TIMER_QUANTUM).of interval
|
|
39
47
|
end
|
|
40
48
|
|
|
@@ -55,7 +63,6 @@ shared_context "a Celluloid Mailbox" do
|
|
|
55
63
|
end
|
|
56
64
|
|
|
57
65
|
it "logs discarded messages" do
|
|
58
|
-
Celluloid.logger = double.as_null_object
|
|
59
66
|
Celluloid.logger.should_receive(:debug).with("Discarded message (mailbox is dead): third")
|
|
60
67
|
|
|
61
68
|
subject.max_size = 2
|
|
@@ -65,7 +72,6 @@ shared_context "a Celluloid Mailbox" do
|
|
|
65
72
|
end
|
|
66
73
|
|
|
67
74
|
it "discard messages when dead" do
|
|
68
|
-
Celluloid.logger = double.as_null_object
|
|
69
75
|
Celluloid.logger.should_receive(:debug).with("Discarded message (mailbox is dead): first")
|
|
70
76
|
Celluloid.logger.should_receive(:debug).with("Discarded message (mailbox is dead): second")
|
|
71
77
|
Celluloid.logger.should_receive(:debug).with("Discarded message (mailbox is dead): third")
|
|
@@ -17,11 +17,13 @@ shared_context "a Celluloid Task" do |task_class|
|
|
|
17
17
|
subject { task_class.new(task_type, {}) { Celluloid::Task.suspend(suspend_state) } }
|
|
18
18
|
|
|
19
19
|
before :each do
|
|
20
|
+
Thread.current[:celluloid_actor_system] = Celluloid.actor_system
|
|
20
21
|
Thread.current[:celluloid_actor] = actor
|
|
21
22
|
end
|
|
22
23
|
|
|
23
24
|
after :each do
|
|
24
25
|
Thread.current[:celluloid_actor] = nil
|
|
26
|
+
Thread.current[:celluloid_actor_system] = nil
|
|
25
27
|
end
|
|
26
28
|
|
|
27
29
|
it "begins with status :new" do
|