celluloid 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,22 @@
1
+ require 'spec_helper'
2
+
3
+ describe Celluloid::Registry do
4
+ class Marilyn
5
+ include Celluloid::Actor
6
+
7
+ def sing_for(person)
8
+ "o/~ Happy birthday, #{person}"
9
+ end
10
+ end
11
+
12
+ it "registers Actors" do
13
+ Celluloid::Actor[:marilyn] = Marilyn.spawn
14
+ Celluloid::Actor[:marilyn].sing_for("Mr. President").should == "o/~ Happy birthday, Mr. President"
15
+ end
16
+
17
+ it "refuses to register non-Actors" do
18
+ proc do
19
+ Celluloid::Actor[:impostor] = Object.new
20
+ end.should raise_error(ArgumentError)
21
+ end
22
+ end
@@ -0,0 +1,9 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+ $LOAD_PATH.unshift File.dirname(__FILE__)
3
+
4
+ require 'rspec'
5
+ require 'celluloid'
6
+
7
+ # Requires supporting files with custom matchers and macros, etc,
8
+ # in ./support/ and its subdirectories.
9
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
@@ -0,0 +1,94 @@
1
+ require 'spec_helper'
2
+
3
+ describe Celluloid::Supervisor do
4
+ before do
5
+ class SubordinateDead < StandardError; end
6
+
7
+ class Subordinate
8
+ include Celluloid::Actor
9
+ attr_reader :state
10
+
11
+ def initialize(state)
12
+ @state = state
13
+ end
14
+
15
+ def crack_the_whip
16
+ case @state
17
+ when :idle
18
+ @state = :working
19
+ else raise SubordinateDead, "the spec purposely crashed me :("
20
+ end
21
+ end
22
+ end
23
+ end
24
+
25
+ it "restarts actors when they die" do
26
+ supervisor = Celluloid::Supervisor.supervise(Subordinate, :idle)
27
+ subordinate = supervisor.actor
28
+ subordinate.state.should == :idle
29
+
30
+ subordinate.crack_the_whip
31
+ subordinate.state.should == :working
32
+
33
+ proc do
34
+ subordinate.crack_the_whip
35
+ end.should raise_exception(SubordinateDead)
36
+ sleep 0.1 # hax to prevent race :(
37
+ subordinate.should_not be_alive
38
+
39
+ new_subordinate = supervisor.actor
40
+ new_subordinate.should_not == subordinate
41
+ new_subordinate.state.should == :idle
42
+ end
43
+
44
+ it "registers actors and reregisters them when they die" do
45
+ supervisor = Celluloid::Supervisor.supervise_as(:subordinate, Subordinate, :idle)
46
+ subordinate = Celluloid::Actor[:subordinate]
47
+ subordinate.state.should == :idle
48
+
49
+ subordinate.crack_the_whip
50
+ subordinate.state.should == :working
51
+
52
+ proc do
53
+ subordinate.crack_the_whip
54
+ end.should raise_exception(SubordinateDead)
55
+ sleep 0.1 # hax to prevent race :(
56
+ subordinate.should_not be_alive
57
+
58
+ new_subordinate = Celluloid::Actor[:subordinate]
59
+ new_subordinate.should_not == subordinate
60
+ new_subordinate.state.should == :idle
61
+ end
62
+
63
+ it "creates supervisors via Actor.supervise" do
64
+ supervisor = Subordinate.supervise(:working)
65
+ subordinate = supervisor.actor
66
+ subordinate.state.should == :working
67
+
68
+ proc do
69
+ subordinate.crack_the_whip
70
+ end.should raise_exception(SubordinateDead)
71
+ sleep 0.1 # hax to prevent race :(
72
+ subordinate.should_not be_alive
73
+
74
+ new_subordinate = supervisor.actor
75
+ new_subordinate.should_not == subordinate
76
+ new_subordinate.state.should == :working
77
+ end
78
+
79
+ it "creates supervisors and registers actors via Actor.supervise_as" do
80
+ supervisor = Subordinate.supervise_as(:subordinate, :working)
81
+ subordinate = Celluloid::Actor[:subordinate]
82
+ subordinate.state.should == :working
83
+
84
+ proc do
85
+ subordinate.crack_the_whip
86
+ end.should raise_exception(SubordinateDead)
87
+ sleep 0.1 # hax to prevent race :(
88
+ subordinate.should_not be_alive
89
+
90
+ new_subordinate = supervisor.actor
91
+ new_subordinate.should_not == subordinate
92
+ new_subordinate.state.should == :working
93
+ end
94
+ end
@@ -0,0 +1,34 @@
1
+ require 'spec_helper'
2
+
3
+ describe Celluloid::Waker do
4
+ it "blocks until awoken" do
5
+ waker = Celluloid::Waker.new
6
+ thread = Thread.new do
7
+ waker.wait
8
+ :done
9
+ end
10
+
11
+ # Assert that the thread can't be joined at this point
12
+ thread.join(0).should be_nil
13
+
14
+ waker.signal
15
+ thread.value.should == :done
16
+ end
17
+
18
+ it "returns an IO object that can be multiplexed with IO.select" do
19
+ waker = Celluloid::Waker.new
20
+ waker.io.should be_an_instance_of(IO)
21
+
22
+ thread = Thread.new do
23
+ readable, _, _ = select [waker.io]
24
+ waker.wait
25
+ :done
26
+ end
27
+
28
+ # Assert that the thread can't be joined at this point
29
+ thread.join(0).should be_nil
30
+
31
+ waker.signal
32
+ thread.value.should == :done
33
+ end
34
+ end
metadata ADDED
@@ -0,0 +1,138 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: celluloid
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.0.1
6
+ platform: ruby
7
+ authors:
8
+ - Tony Arcieri
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-05-11 00:00:00 -06:00
14
+ default_executable:
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: celluloid
18
+ requirement: &id001 !ruby/object:Gem::Requirement
19
+ none: false
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ type: :runtime
25
+ prerelease: false
26
+ version_requirements: *id001
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: &id002 !ruby/object:Gem::Requirement
30
+ none: false
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: 2.3.0
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: *id002
38
+ - !ruby/object:Gem::Dependency
39
+ name: bundler
40
+ requirement: &id003 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 1.0.0
46
+ type: :development
47
+ prerelease: false
48
+ version_requirements: *id003
49
+ - !ruby/object:Gem::Dependency
50
+ name: jeweler
51
+ requirement: &id004 !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ~>
55
+ - !ruby/object:Gem::Version
56
+ version: 1.5.2
57
+ type: :development
58
+ prerelease: false
59
+ version_requirements: *id004
60
+ description: Celluloid is a concurrent object framework inspired by the Actor Model
61
+ email: tony@medioh.com
62
+ executables: []
63
+
64
+ extensions: []
65
+
66
+ extra_rdoc_files:
67
+ - LICENSE.txt
68
+ - README.md
69
+ files:
70
+ - .autotest
71
+ - .document
72
+ - .rspec
73
+ - Gemfile
74
+ - Gemfile.lock
75
+ - LICENSE.txt
76
+ - README.md
77
+ - Rakefile
78
+ - VERSION
79
+ - celluloid.gemspec
80
+ - lib/celluloid.rb
81
+ - lib/celluloid/actor.rb
82
+ - lib/celluloid/actor_proxy.rb
83
+ - lib/celluloid/calls.rb
84
+ - lib/celluloid/core_ext.rb
85
+ - lib/celluloid/events.rb
86
+ - lib/celluloid/future.rb
87
+ - lib/celluloid/linking.rb
88
+ - lib/celluloid/mailbox.rb
89
+ - lib/celluloid/registry.rb
90
+ - lib/celluloid/responses.rb
91
+ - lib/celluloid/supervisor.rb
92
+ - lib/celluloid/waker.rb
93
+ - spec/actor_spec.rb
94
+ - spec/future_spec.rb
95
+ - spec/mailbox_spec.rb
96
+ - spec/registry_spec.rb
97
+ - spec/spec_helper.rb
98
+ - spec/supervisor_spec.rb
99
+ - spec/waker_spec.rb
100
+ has_rdoc: true
101
+ homepage: http://github.com/tarcieri/celluloid
102
+ licenses:
103
+ - MIT
104
+ post_install_message:
105
+ rdoc_options: []
106
+
107
+ require_paths:
108
+ - lib
109
+ required_ruby_version: !ruby/object:Gem::Requirement
110
+ none: false
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ hash: 4378761337148420305
115
+ segments:
116
+ - 0
117
+ version: "0"
118
+ required_rubygems_version: !ruby/object:Gem::Requirement
119
+ none: false
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ version: "0"
124
+ requirements: []
125
+
126
+ rubyforge_project:
127
+ rubygems_version: 1.6.2
128
+ signing_key:
129
+ specification_version: 3
130
+ summary: Ruby concurrency made easy! Or at least, easier...
131
+ test_files:
132
+ - spec/actor_spec.rb
133
+ - spec/future_spec.rb
134
+ - spec/mailbox_spec.rb
135
+ - spec/registry_spec.rb
136
+ - spec/spec_helper.rb
137
+ - spec/supervisor_spec.rb
138
+ - spec/waker_spec.rb