dramatis 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +7 -0
- data/License.txt +20 -0
- data/Manifest.txt +119 -0
- data/README.txt +57 -0
- data/Rakefile +4 -0
- data/config/hoe.rb +70 -0
- data/config/requirements.rb +17 -0
- data/examples/README.txt +20 -0
- data/examples/auction.rb +90 -0
- data/examples/bank/bank.rb +7 -0
- data/examples/bank/bank_test.rb +7 -0
- data/examples/exception.rb +40 -0
- data/examples/fib/conservative.rb +50 -0
- data/examples/fib/future.rb +5 -0
- data/examples/fib/original.rb +33 -0
- data/examples/fib/threads.rb +51 -0
- data/examples/im/distributed/chat/client.rb +49 -0
- data/examples/im/distributed/chat/screen/fox.rb +92 -0
- data/examples/im/distributed/chat/screen.rb +11 -0
- data/examples/im/distributed/chat/server.rb +72 -0
- data/examples/im/distributed/chat.rb +5 -0
- data/examples/im/distributed/client.rb +9 -0
- data/examples/im/distributed/run.rb +18 -0
- data/examples/im/distributed/server.rb +11 -0
- data/examples/im/single/chat/client.rb +50 -0
- data/examples/im/single/chat/screen/fox.rb +96 -0
- data/examples/im/single/chat/screen/wxs.rb +63 -0
- data/examples/im/single/chat/screen.rb +11 -0
- data/examples/im/single/chat/server.rb +72 -0
- data/examples/im/single/chat.rb +5 -0
- data/examples/im/single/fox.rb +18 -0
- data/examples/im/single/wxchat.rb +19 -0
- data/examples/pingpong/actor.rb +33 -0
- data/examples/pingpong/actor_rec.rb +34 -0
- data/examples/pingpong/pingpong.txt +315 -0
- data/examples/pingpong/scala.rb +41 -0
- data/examples/pingpong/serial.rb +26 -0
- data/examples/pretty.txt +108 -0
- data/examples/telephone/.irbrc +2 -0
- data/examples/telephone/3esl.txt +21877 -0
- data/examples/telephone/fifth/kid.rb +36 -0
- data/examples/telephone/fifth/run.rb +26 -0
- data/examples/telephone/first/kid.rb +31 -0
- data/examples/telephone/first/run.rb +20 -0
- data/examples/telephone/fourth/kid.rb +31 -0
- data/examples/telephone/fourth/run.rb +26 -0
- data/examples/telephone/mangler.rb +53 -0
- data/examples/telephone/second/kid.rb +26 -0
- data/examples/telephone/second/run.rb +20 -0
- data/examples/telephone/seventh/kid.rb +40 -0
- data/examples/telephone/seventh/run.rb +35 -0
- data/examples/telephone/seventh/test.rb +28 -0
- data/examples/telephone/seventh/test2.rb +10 -0
- data/examples/telephone/sixth/kid.rb +39 -0
- data/examples/telephone/sixth/run.rb +26 -0
- data/examples/telephone/third/kid.rb +31 -0
- data/examples/telephone/third/run.rb +21 -0
- data/lib/dramatis/actor/interface.rb +118 -0
- data/lib/dramatis/actor/name/interface.rb +128 -0
- data/lib/dramatis/actor/name.rb +44 -0
- data/lib/dramatis/actor.rb +96 -0
- data/lib/dramatis/deadlock.rb +123 -0
- data/lib/dramatis/error/uncaught.rb +19 -0
- data/lib/dramatis/error.rb +125 -0
- data/lib/dramatis/future/interface.rb +45 -0
- data/lib/dramatis/future.rb +32 -0
- data/lib/dramatis/runtime/actor/main.rb +3 -0
- data/lib/dramatis/runtime/actor.rb +294 -0
- data/lib/dramatis/runtime/gate.rb +244 -0
- data/lib/dramatis/runtime/scheduler.rb +374 -0
- data/lib/dramatis/runtime/task.rb +390 -0
- data/lib/dramatis/runtime/thread_pool.rb +149 -0
- data/lib/dramatis/runtime/timer.rb +5 -0
- data/lib/dramatis/runtime.rb +129 -0
- data/lib/dramatis/shoes/runtime.rb +7 -0
- data/lib/dramatis/shoes.rb +14 -0
- data/lib/dramatis/version.rb +8 -0
- data/lib/dramatis.rb +73 -0
- data/log/debug.log +0 -0
- data/script/destroy +14 -0
- data/script/generate +14 -0
- data/script/txt2html +74 -0
- data/setup.rb +1585 -0
- data/spec/dramatis/actor/become_spec.rb +17 -0
- data/spec/dramatis/actor/future_spec.rb +189 -0
- data/spec/dramatis/actor/name_spec.rb +141 -0
- data/spec/dramatis/actor/task_spec.rb +75 -0
- data/spec/dramatis/actor_spec.rb +492 -0
- data/spec/dramatis/dramatis_spec.rb +23 -0
- data/spec/dramatis/exc_spec.rb +78 -0
- data/spec/dramatis/runtime/gate_spec.rb +57 -0
- data/spec/dramatis/runtime/thread_pool.rb +30 -0
- data/spec/dramatis/shoes_spec.rb +11 -0
- data/spec/dramatis/simple_spec.rb +32 -0
- data/spec/exp_spec.rb +21 -0
- data/spec/simple2_spec.rb +36 -0
- data/spec/simple_spec.rb +30 -0
- data/spec/spec.opts +0 -0
- data/spec/spec_helper.rb +26 -0
- data/spec/thread_spec.rb +13 -0
- data/tasks/deployment.rake +34 -0
- data/tasks/environment.rake +7 -0
- data/tasks/rspec.rake +21 -0
- data/tasks/website.rake +17 -0
- data/test/jruby_lm.rb +13 -0
- data/test/test.rb +19 -0
- data/test/test10.rb +43 -0
- data/test/test11.rb +45 -0
- data/test/test12.rb +60 -0
- data/test/test13.rb +71 -0
- data/test/test2.rb +12 -0
- data/test/test3.rb +10 -0
- data/test/test4.rb +29 -0
- data/test/test5.rb +8 -0
- data/test/test6.rb +32 -0
- data/test/test7.rb +48 -0
- data/test/test8.rb +133 -0
- data/test/test9.rb +105 -0
- data/test/test_exc.rb +22 -0
- metadata +180 -0
@@ -0,0 +1,17 @@
|
|
1
|
+
describe "become" do
|
2
|
+
|
3
|
+
after do
|
4
|
+
begin
|
5
|
+
Dramatis::Runtime.current.quiesce
|
6
|
+
Dramatis::Runtime.current.exceptions.length.should equal( 0 )
|
7
|
+
Thread.list.length.should equal( 1 )
|
8
|
+
ensure
|
9
|
+
Dramatis::Runtime.reset
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should forward messages on become"
|
14
|
+
|
15
|
+
it "should do something with the patterns on become"
|
16
|
+
|
17
|
+
end
|
@@ -0,0 +1,189 @@
|
|
1
|
+
require File.join( File.dirname(__FILE__), "..", "..", '/spec_helper.rb' )
|
2
|
+
|
3
|
+
require 'dramatis/actor'
|
4
|
+
require 'dramatis/future'
|
5
|
+
|
6
|
+
# NB: don't use the module name here: rspec wants to include described
|
7
|
+
# modules ... and making the result into an actor, well, needless to say,
|
8
|
+
# it's not a good idea
|
9
|
+
|
10
|
+
describe "Dramatis::Actor" do
|
11
|
+
|
12
|
+
include Dramatis
|
13
|
+
|
14
|
+
include DramatisSpecHelper
|
15
|
+
|
16
|
+
after(:each) { runtime_check }
|
17
|
+
|
18
|
+
it "should allow future names to be created" do
|
19
|
+
|
20
|
+
object = Object.new
|
21
|
+
actor = Dramatis::Actor.new object
|
22
|
+
|
23
|
+
future_name = future( actor )
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should return a future when used" do
|
28
|
+
|
29
|
+
object = mock Object.new
|
30
|
+
object.should_receive(:foo).with(:bar).and_return(:foobar)
|
31
|
+
actor = Dramatis::Actor.new object
|
32
|
+
|
33
|
+
future_name = future( actor )
|
34
|
+
|
35
|
+
x = future_name.foo :bar
|
36
|
+
|
37
|
+
x.should be_kind_of( Dramatis::Future )
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should evalute to the right value when used" do
|
42
|
+
|
43
|
+
object = mock Object.new
|
44
|
+
object.should_receive(:foo).with(:bar).and_return(:foobar)
|
45
|
+
actor = Dramatis::Actor.new object
|
46
|
+
|
47
|
+
future_name = future( actor )
|
48
|
+
|
49
|
+
x = future_name.foo :bar
|
50
|
+
|
51
|
+
x.should be_kind_of( Dramatis::Future )
|
52
|
+
x.to_sym.should equal( :foobar )
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should raise as appropriate" do
|
57
|
+
|
58
|
+
object = Object.new
|
59
|
+
actor = Dramatis::Actor.new object
|
60
|
+
|
61
|
+
future_name = future( actor )
|
62
|
+
|
63
|
+
x = future_name.bar :bar
|
64
|
+
|
65
|
+
x.should be_kind_of( Dramatis::Future )
|
66
|
+
|
67
|
+
lambda { x.to_sym }.should raise_error( NoMethodError )
|
68
|
+
|
69
|
+
end
|
70
|
+
|
71
|
+
it "should act like an object ... to the extent possible" do
|
72
|
+
|
73
|
+
object = mock Object.new
|
74
|
+
object.should_receive(:foo).with(:bar).and_return(12345)
|
75
|
+
actor = Dramatis::Actor.new object
|
76
|
+
|
77
|
+
future_name = future( actor )
|
78
|
+
|
79
|
+
x = future_name.foo :bar
|
80
|
+
|
81
|
+
x.should be_kind_of( Dramatis::Future )
|
82
|
+
( x + 0 ).should == 12345
|
83
|
+
( 0 + x ).should == 12345
|
84
|
+
|
85
|
+
end
|
86
|
+
|
87
|
+
it "should have a value interface" do
|
88
|
+
object = mock Object.new
|
89
|
+
object.should_receive(:foo).with(:bar).and_return(12345)
|
90
|
+
actor = Dramatis::Actor.new object
|
91
|
+
|
92
|
+
future_name = future( actor )
|
93
|
+
|
94
|
+
x = future_name.foo :bar
|
95
|
+
|
96
|
+
x.should be_kind_of( Dramatis::Future )
|
97
|
+
|
98
|
+
x = interface( x ).value
|
99
|
+
|
100
|
+
x.should be_kind_of( Fixnum )
|
101
|
+
|
102
|
+
x.should == 12345
|
103
|
+
|
104
|
+
end
|
105
|
+
|
106
|
+
it "should have a ready? interface" do
|
107
|
+
aClass = Class.new do
|
108
|
+
include Dramatis::Actor
|
109
|
+
def initialize
|
110
|
+
actor.always :ready?, true
|
111
|
+
@state = nil
|
112
|
+
@future = nil
|
113
|
+
end
|
114
|
+
def caller callee
|
115
|
+
@future = future( callee ).callee
|
116
|
+
end
|
117
|
+
def ready?
|
118
|
+
interface( @future ).ready?
|
119
|
+
end
|
120
|
+
def value
|
121
|
+
interface( @future ).value
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
bClass = Class.new do
|
126
|
+
include Dramatis::Actor
|
127
|
+
attr_reader :state
|
128
|
+
def initialize
|
129
|
+
actor.refuse :callee
|
130
|
+
end
|
131
|
+
def allow
|
132
|
+
actor.default :callee
|
133
|
+
end
|
134
|
+
def callee
|
135
|
+
:foobar
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
a = aClass.new
|
140
|
+
b = bClass.new
|
141
|
+
|
142
|
+
a.caller b
|
143
|
+
|
144
|
+
a.ready?.should be_false
|
145
|
+
|
146
|
+
b.allow
|
147
|
+
|
148
|
+
Dramatis::Runtime.current.quiesce
|
149
|
+
|
150
|
+
a.ready?.should be_true
|
151
|
+
|
152
|
+
a.value.should equal( :foobar )
|
153
|
+
|
154
|
+
end
|
155
|
+
|
156
|
+
it "should evalute to the right value when used with a delay" do
|
157
|
+
|
158
|
+
aClass = Class.new do
|
159
|
+
include Dramatis::Actor
|
160
|
+
def inititialize
|
161
|
+
actor.always :state
|
162
|
+
@state = nil
|
163
|
+
@future = nil
|
164
|
+
end
|
165
|
+
def caller callee
|
166
|
+
@future = future( callee ).callee
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
bClass = Class.new do
|
171
|
+
include Dramatis::Actor
|
172
|
+
attr_reader :state
|
173
|
+
def initialize
|
174
|
+
actor.refuse :callee
|
175
|
+
end
|
176
|
+
def allow
|
177
|
+
actor.default :callee
|
178
|
+
end
|
179
|
+
def callee
|
180
|
+
:foobar
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
a = aClass.new
|
185
|
+
b = bClass.new
|
186
|
+
|
187
|
+
end
|
188
|
+
|
189
|
+
end
|
@@ -0,0 +1,141 @@
|
|
1
|
+
require File.join( File.dirname(__FILE__), "..", "..", '/spec_helper.rb' )
|
2
|
+
|
3
|
+
require 'dramatis/runtime'
|
4
|
+
require 'dramatis'
|
5
|
+
require 'dramatis/actor/name'
|
6
|
+
|
7
|
+
describe Dramatis do
|
8
|
+
|
9
|
+
include Dramatis
|
10
|
+
|
11
|
+
include DramatisSpecHelper
|
12
|
+
|
13
|
+
after(:each) { runtime_check }
|
14
|
+
|
15
|
+
it "should return NoMethodError as appropriate" do
|
16
|
+
actor = Dramatis::Actor.new Object.new
|
17
|
+
lambda { actor.foo }.should raise_error( NoMethodError )
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should recreate errors rather just forward them(?)"
|
21
|
+
|
22
|
+
it "should block other methods during a continuation"
|
23
|
+
|
24
|
+
it "should be creatable unbound" do
|
25
|
+
Dramatis::Actor.new
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should allow messages to unbound" do
|
29
|
+
lambda { Dramatis::Actor.new.foo }.
|
30
|
+
should raise_error( Dramatis::Deadlock )
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should be creatable bound" do
|
34
|
+
name = Dramatis::Actor.new Object.new
|
35
|
+
name.should be_kind_of( Dramatis::Actor::Name )
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should allow and execute messages to bound names" do
|
39
|
+
object = mock Object.new
|
40
|
+
object.should_receive(:foo).with(:bar).and_return(:foobar)
|
41
|
+
name = Dramatis::Actor.new object
|
42
|
+
result = name.foo :bar
|
43
|
+
result.should equal( :foobar )
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should deliver messages with nil continuations" do
|
47
|
+
object = mock(Object.new)
|
48
|
+
object.should_receive(:foo).with(:bar)
|
49
|
+
name = Dramatis::Actor.new object
|
50
|
+
interface( name ).continue(nil).foo( :bar )
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should have a nice short method for casts" do
|
54
|
+
object = mock(Object.new)
|
55
|
+
object.should_receive(:foo).with(:bar)
|
56
|
+
name = Dramatis::Actor.new object
|
57
|
+
release( name ).foo( :bar )
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should suport cast from the object interface"
|
61
|
+
|
62
|
+
it "shouldn't be possible to bind twice" do
|
63
|
+
name = Dramatis::Actor.new
|
64
|
+
interface( name ).bind Object.new
|
65
|
+
lambda { interface( name ).bind Object.new }.should raise_error( Dramatis::Error::Bind )
|
66
|
+
end
|
67
|
+
|
68
|
+
it "should allow and execute block continuations" do
|
69
|
+
|
70
|
+
actor = Object.new
|
71
|
+
name = Dramatis::Actor.new actor
|
72
|
+
actor.should_receive(:foo).with(:bar).and_return(:foobar)
|
73
|
+
|
74
|
+
result = nil
|
75
|
+
retval = ( interface( name ).continue { |value| result = value } ).foo :bar
|
76
|
+
retval.should be_nil
|
77
|
+
result.should be_nil
|
78
|
+
result.should be_nil # to perhaps highlight a threading problem
|
79
|
+
|
80
|
+
Dramatis::Runtime.current.quiesce
|
81
|
+
|
82
|
+
result.should equal( :foobar )
|
83
|
+
|
84
|
+
end
|
85
|
+
|
86
|
+
it "should execute messages to unbound names once bound" do
|
87
|
+
|
88
|
+
name = Dramatis::Actor.new
|
89
|
+
|
90
|
+
object = mock(Object.new)
|
91
|
+
object.should_receive(:foo).with(:bar).and_return(:foobar)
|
92
|
+
|
93
|
+
result = nil
|
94
|
+
|
95
|
+
retval = ( interface( name ).continue { |value| result = value } ).foo :bar
|
96
|
+
|
97
|
+
retval.should be_nil
|
98
|
+
result.should be_nil
|
99
|
+
|
100
|
+
Dramatis::Runtime.current.quiesce
|
101
|
+
|
102
|
+
result.should be_nil
|
103
|
+
|
104
|
+
interface( name ).bind object
|
105
|
+
|
106
|
+
Dramatis::Runtime.current.quiesce
|
107
|
+
|
108
|
+
result.should equal( :foobar )
|
109
|
+
|
110
|
+
end
|
111
|
+
|
112
|
+
it "rpc binds should return an actor name" do
|
113
|
+
name = Dramatis::Actor.new
|
114
|
+
retval = Dramatis.interface( name ).bind Hash.new
|
115
|
+
retval.should be_kind_of( Dramatis::Actor::Name )
|
116
|
+
end
|
117
|
+
|
118
|
+
it "should be possible to bind with a non-rpc continuation" do
|
119
|
+
name = Dramatis::Actor.new
|
120
|
+
result = nil
|
121
|
+
name = interface( name ).continue { |v| result = v }
|
122
|
+
retval = interface( name ).bind Object.new
|
123
|
+
retval.should equal( nil )
|
124
|
+
result.should equal( nil )
|
125
|
+
Dramatis::Runtime.current.quiesce
|
126
|
+
result.should_not be_nil
|
127
|
+
end
|
128
|
+
|
129
|
+
it "should provide a url, if asked" do
|
130
|
+
actor = Dramatis::Actor.new Object.new
|
131
|
+
url = interface( actor ).url
|
132
|
+
url.should match( %r[http://] )
|
133
|
+
end
|
134
|
+
|
135
|
+
it "unbound names should queue messages and deliver them in order"
|
136
|
+
|
137
|
+
it "messages should be delivered out of order sometimes"
|
138
|
+
|
139
|
+
it "flushing should guarantee message order"
|
140
|
+
|
141
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
require File.join( File.dirname(__FILE__), "..", "..", '/spec_helper.rb' )
|
2
|
+
|
3
|
+
require 'dramatis/runtime/task'
|
4
|
+
require 'dramatis/actor'
|
5
|
+
|
6
|
+
describe Dramatis::Runtime::Task do
|
7
|
+
|
8
|
+
include Dramatis
|
9
|
+
|
10
|
+
include DramatisSpecHelper
|
11
|
+
|
12
|
+
after(:each) { runtime_check }
|
13
|
+
|
14
|
+
it "should return errors to calling actor even when non-rpc (non-main)" do
|
15
|
+
callerClass = Class.new do
|
16
|
+
include Dramatis::Actor
|
17
|
+
def initalize
|
18
|
+
@exception = nil
|
19
|
+
end
|
20
|
+
def caller callee
|
21
|
+
release( callee ).callee
|
22
|
+
end
|
23
|
+
def dramatis_exception e
|
24
|
+
@exception = e
|
25
|
+
end
|
26
|
+
def exception
|
27
|
+
raise @exception if @exception
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
caller = callerClass.new
|
32
|
+
callee = Dramatis::Actor.new Object.new
|
33
|
+
|
34
|
+
caller.caller callee
|
35
|
+
|
36
|
+
Dramatis::Runtime.current.quiesce
|
37
|
+
|
38
|
+
lambda { caller.exception }.should raise_error( NoMethodError )
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should do something reasonable when the caller is main" do
|
42
|
+
callee = Dramatis::Actor.new Object.new
|
43
|
+
lambda { callee.callee }.should raise_error( NoMethodError )
|
44
|
+
release( callee ).callee
|
45
|
+
Dramatis::Runtime.current.warnings = false
|
46
|
+
lambda { Dramatis::Runtime.current.quiesce }.should raise_error( Dramatis::Error::Uncaught )
|
47
|
+
Dramatis::Runtime.current.warnings = true
|
48
|
+
Dramatis::Runtime.current.exceptions.length.should equal( 1 )
|
49
|
+
Dramatis::Runtime.current.clear_exceptions
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should default to global when no dramatis_exception defined" do
|
53
|
+
callerClass = Class.new do
|
54
|
+
include Dramatis::Actor
|
55
|
+
def caller callee
|
56
|
+
release( callee ).callee
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
caller = callerClass.new
|
61
|
+
callee = Dramatis::Actor.new Object.new
|
62
|
+
|
63
|
+
Dramatis::Runtime.current.warnings = false
|
64
|
+
caller.caller callee
|
65
|
+
lambda { Dramatis::Runtime.current.quiesce }.should raise_error( Dramatis::Error::Uncaught )
|
66
|
+
Dramatis::Runtime.current.warnings = true
|
67
|
+
|
68
|
+
lambda { raise Dramatis::Runtime.current.exceptions[0] }.should raise_error( NoMethodError )
|
69
|
+
Dramatis::Runtime.current.clear_exceptions
|
70
|
+
|
71
|
+
end
|
72
|
+
|
73
|
+
it "should call dramatis_exception on main if that works(?)"
|
74
|
+
|
75
|
+
end
|