1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
|
#! /usr/bin/env ruby
# -*- coding: UTF-8 -*-
#
require 'spec_helper'
#
describe Edoors::Room do
#
before (:all) do
@spin = Edoors::Spin.new 'dom0'
end
#
before(:each) do
@spin.clear!
end
#
it "add_iota and add_link correctly" do
r0 = Edoors::Room.new 'room0', @spin
d0 = Edoors::Door.new 'door0', r0
expect(lambda { Edoors::Door.new('door0', r0) }).to raise_error(Edoors::Exception)
expect(lambda { r0.add_iota Edoors::Door.new('door1', r0) }).to raise_error(Edoors::Exception)
r0.add_link Edoors::Link.new 'door0', 'somewhere'
expect(lambda { r0.add_link(Edoors::Link.new('nowhere', 'somewhere')) }).to raise_error(Edoors::Exception)
end
#
it "start! and stop! should work" do
r0 = Edoors::Room.new 'room0', @spin
d0 = Fake.new 'fake', r0
expect(d0.start).to be_nil
expect(d0.stop).to be_nil
r0.start!
expect(d0.start).to be_truthy
expect(d0.stop).to be_nil
r0.stop!
expect(d0.start).to be_truthy
expect(d0.stop).to be_truthy
end
#
it "parent, spin and search_down should be ok" do
r0 = Edoors::Room.new 'r0', @spin
r1 = Edoors::Room.new 'r1', r0
r2 = Edoors::Room.new 'r2', r1
r3 = Edoors::Room.new 'r3', @spin
r4 = Edoors::Room.new 'r4', r3
expect(r2.parent).to be r1
expect(r1.parent).to be r0
expect(r0.parent).to be @spin
expect(r0.spin).to be @spin
expect(r1.spin).to be @spin
expect(r2.spin).to be @spin
expect(r3.spin).to be @spin
expect(@spin.search_down('dom0/r0/r1/r2')).to be r2
expect(r0.search_down('dom0/r0/r1/r2')).to be r2
expect(r1.search_down('dom0/r0/r1/r2')).to be r2
expect(r2.search_down('dom0/r0/r1/r2')).to be r2
expect(r1.search_down('dom0/r0/r1/r9')).to be nil
expect(r3.search_down('dom0/r0/r1/r2')).to be nil
expect(r4.search_down('dom0/r0/r1/r2')).to be nil
end
#
it "routing success (direct add_dst)" do
room0 = Edoors::Room.new 'room0', @spin
door0 = Edoors::Door.new 'door0', room0
p = @spin.require_p Edoors::Particle
p.init! Fake.new( 'fake', @spin)
p.add_dst 'get', 'door0'
room0.send_p p
expect(p.action).to eql 'get'
expect(p.dst).to be door0
end
#
it "routing success (direct send to self)" do
room0 = Edoors::Room.new 'room0', @spin
door0 = Edoors::Door.new 'door0', room0
p = @spin.require_p Edoors::Particle
p.init! Fake.new( 'fake', @spin)
door0.send_p p, 'get'
expect(p.action).to eql 'get'
expect(p.dst).to be door0
end
#
it "routing success (direct send to pointer)" do
room0 = Edoors::Room.new 'room0', @spin
door0 = Edoors::Door.new 'door0', room0
p = @spin.require_p Edoors::Particle
p.init! Fake.new( 'fake', @spin)
door0.send_p p, 'get', door0
expect(p.action).to eql 'get'
expect(p.dst).to be door0
end
#
it "routing success (direct send to path)" do
room0 = Edoors::Room.new 'room0', @spin
door0 = Edoors::Door.new 'door0', room0
p = @spin.require_p Edoors::Particle
p.init! Fake.new( 'fake', @spin)
door0.send_p p, 'get', door0.path
expect(p.action).to eql 'get'
expect(p.dst).to be door0
end
#
it "routing success through Spin@world" do
room0 = Edoors::Room.new 'room0', @spin
room1 = Edoors::Room.new 'room1', room0
door0 = Edoors::Door.new 'door0', room1
p = @spin.require_p Edoors::Particle
p.init! Fake.new('fake', @spin)
p.add_dst 'get', 'dom0/room0/room1/door0'
room0.send_p p
expect(p.action).to eql 'get'
expect(p.dst).to be door0
end
#
it "route error: no source" do
room = Edoors::Room.new 'room', @spin
p = @spin.require_p Edoors::Particle
p.add_dst 'get', 'room/door'
room.send_p p
expect(p.action).to eql Edoors::ACT_ERROR
expect(p[Edoors::FIELD_ERROR_MSG]).to eql Edoors::ERROR_ROUTE_NS
expect(p.dst).to be room.spin
end
#
it "route error: no destination no links" do
room = Edoors::Room.new 'room', @spin
p = @spin.require_p Edoors::Particle
p.init! Fake.new('fake', @spin)
room.send_p p
expect(p.action).to eql Edoors::ACT_ERROR
expect(p[Edoors::FIELD_ERROR_MSG]).to eql Edoors::ERROR_ROUTE_NDNL
expect(p.dst).to be p.src
end
#
it "route error: no rooom, wrong door -> right room wrong door" do
room0 = Edoors::Room.new 'room0', @spin
p = @spin.require_p Edoors::Particle
p.init! Fake.new('fake', @spin)
p.add_dst 'get', 'nodoor'
room0.send_p p
expect(p.action).to eql Edoors::ACT_ERROR
expect(p[Edoors::FIELD_ERROR_MSG]).to eql Edoors::ERROR_ROUTE_RRWD
expect(p.dst).to be p.src
end
#
it "route error: right rooom, wrong door -> right room wrong door" do
room0 = Edoors::Room.new 'room0', @spin
p = @spin.require_p Edoors::Particle
p.init! Fake.new('fake', @spin)
p.add_dst 'get', 'dom0/room0/nodoor'
room0.send_p p
expect(p.action).to eql Edoors::ACT_ERROR
expect(p[Edoors::FIELD_ERROR_MSG]).to eql Edoors::ERROR_ROUTE_RRWD
expect(p.dst).to be p.src
end
#
it "route error: right room, wrong door through Spin@world -> does not exists" do
room0 = Edoors::Room.new 'room0', @spin
room1 = Edoors::Room.new 'room1', room0
p = @spin.require_p Edoors::Particle
p.init! Fake.new('fake', room0)
p.add_dst 'get', 'dom0/room0/nodoor'
room1.send_p p
expect(p.action).to eql Edoors::ACT_ERROR
expect(p[Edoors::FIELD_ERROR_MSG]).to eql Edoors::ERROR_ROUTE_DNE
expect(p.dst).to be p.src
end
#
it "route error: wrong room, right door through Spin@world -> does not exists" do
room0 = Edoors::Room.new 'room0', @spin
room1 = Edoors::Room.new 'room1', room0
p = @spin.require_p Edoors::Particle
p.init! Fake.new('fake', @spin)
p.add_dst 'get', 'dom0/noroom/fake'
room1.send_p p
expect(p.action).to eql Edoors::ACT_ERROR
expect(p[Edoors::FIELD_ERROR_MSG]).to eql Edoors::ERROR_ROUTE_DNE
expect(p.dst).to be p.src
end
#
it "routing ~failure: no door name -> src" do
room0 = Edoors::Room.new 'room0', @spin
door0 = Edoors::Door.new 'door0', room0
p = @spin.require_p Edoors::Particle
p.init! door0
p.add_dst 'get'
room0.send_p p
expect(p.action).to eql 'get'
expect(p.dst).to be door0
end
#
it "routing success: unconditional link" do
room0 = Edoors::Room.new 'room0', @spin
door0 = Edoors::Door.new 'door0', room0
door1 = Edoors::Door.new 'door1', room0
room0.add_link Edoors::Link.new('door0', 'door1')
p = @spin.require_p Edoors::Particle
door0.send_p p
expect(p.action).to be_nil
expect(p.dst).to be door1
end
#
it "routing success: conditional link" do
room0 = Edoors::Room.new 'room0', @spin
door0 = Edoors::Door.new 'door0', room0
door1 = Edoors::Door.new 'door1', room0
room0.add_link Edoors::Link.new('door0', 'door1', 'keys', {'f0'=>'v0','f1'=>'v1'})
p = @spin.require_p Edoors::Particle
p['f0']='v0'
p['f1']='v1'
door0.send_p p
expect(p.action).to be_nil
expect(p.src).to be door0
expect(p.dst).to be door1
end
#
it "routing success: more then one matching link" do
room0 = Edoors::Room.new 'room0', @spin
door0 = Edoors::Door.new 'door0', room0
class Out < Edoors::Door
attr_reader :count
def receive_p p
@count ||= 0
expect(['0','1','2'][@count]).to be == p.next_dst
@count += 1
end
end
door1 = Out.new 'door1', room0
room0.add_link Edoors::Link.new('door0', ['door1','0'])
room0.add_link Edoors::Link.new('door0', ['door1','1'], 'keys', {'f0'=>'v0'})
room0.add_link Edoors::Link.new('door0', ['door1','2'], 'keys', {'f0'=>'v0','f1'=>'v1'})
room0.add_link Edoors::Link.new('door0', ['door1','3'], 'keys', {'f0'=>'v0','f1'=>'v2'})
room0.add_link Edoors::Link.new('door0', ['door1','4'], 'keys', {'f0'=>'v0','f2'=>'v1'})
p = @spin.require_p Edoors::Particle
p['f0']='v0'
p['f1']='v1'
door0.send_p p
@spin.spin!
expect(door1.count).to eql 3
end
#
it "system route error: system no destination" do
room0 = Edoors::Room.new 'room0', @spin
p = @spin.require_p Edoors::Particle
room0.send_sys_p p
expect(p.action).to eql Edoors::ACT_ERROR
expect(p[Edoors::FIELD_ERROR_MSG]).to eql Edoors::ERROR_ROUTE_SND
end
#
it "system routing success: action only" do
room0 = Edoors::Room.new 'room0', @spin
p = @spin.require_p Edoors::Particle
p.add_dst Edoors::SYS_ACT_ADD_LINK
room0.send_sys_p p
expect(p.action).to eql Edoors::SYS_ACT_ADD_LINK
expect(p.dst).to be room0.spin
end
#
it "system routing success (add_dst)" do
room0 = Edoors::Room.new 'room0', @spin
door0 = Edoors::Door.new 'door0', room0
p = @spin.require_p Edoors::Particle
p.add_dst Edoors::SYS_ACT_ADD_LINK, 'dom0/room0/door0'
room0.send_sys_p p
expect(p.action).to eql Edoors::SYS_ACT_ADD_LINK
expect(p.dst).to be door0
end
#
it "system routing success (send_sys_p)" do
room0 = Edoors::Room.new 'room0', @spin
door0 = Edoors::Door.new 'door0', room0
p = @spin.require_p Edoors::Particle
door0.send_sys_p p, Edoors::SYS_ACT_ADD_LINK
expect(p.action).to eql Edoors::SYS_ACT_ADD_LINK
expect(p.dst).to be door0
end
#
it "SYS_ACT_ADD_LINK" do
room0 = Edoors::Room.new 'room0', @spin
door0 = Edoors::Door.new 'door0', room0
door1 = Edoors::Door.new 'door1', room0
p0 = @spin.require_p Edoors::Particle
p0.set_data Edoors::LNK_SRC, 'door0'
p0.set_data Edoors::LNK_DSTS, 'door1'
p0.set_data Edoors::LNK_KEYS, 'keys'
p0.set_data Edoors::LNK_VALUE, {'f0'=>'v0','f1'=>'v1'}
p0.add_dst Edoors::SYS_ACT_ADD_LINK, room0.path
room0.send_sys_p p0
@spin.spin!
p = @spin.require_p Edoors::Particle
p['f0']='v0'
p['f1']='v1'
door0.send_p p
expect(p.action).to be_nil
expect(p.src).to be door0
expect(p.dst).to be door1
end
#
it "SYS_ACT_ADD_ROOM" do
room0 = Edoors::Room.new 'room0', @spin
p0 = @spin.require_p Edoors::Particle
p0.set_data Edoors::IOTA_NAME, 'roomX'
p0.add_dst Edoors::SYS_ACT_ADD_ROOM, room0.path
room0.send_sys_p p0
p1 = @spin.require_p Edoors::Particle
p1.set_data Edoors::IOTA_NAME, 'roomY'
p1.set_dst! Edoors::SYS_ACT_ADD_ROOM, room0
@spin.send_sys_p p1
@spin.spin!
expect(@spin.search_world('dom0/room0/roomX')).to be_a Edoors::Room
expect(@spin.search_world('dom0/room0/roomY')).to be_a Edoors::Room
expect(@spin.search_world('dom0/room0/roomZ')).to be nil
end
#
it "room->json->room" do
r0 = Edoors::Room.new 'r0', @spin
r1 = Edoors::Room.new 'r1', r0
r2 = Edoors::Room.new 'r2', r1
r3 = Edoors::Room.new 'r3', r1
r4 = Edoors::Room.new 'r4', r3
d0 = Edoors::Door.new 'd0', r1
d1 = Edoors::Door.new 'd1', r1
d2 = Edoors::Door.new 'd2', r2
r1.add_link Edoors::Link.new('d0', 'd1', 'keys', {'f0'=>'v0','f1'=>'v1'})
r1.add_link Edoors::Link.new('d0', 'd2')
r1.add_link Edoors::Link.new('d1', 'd0')
r2.add_link Edoors::Link.new('d2', 'd1', 'fies', {'f5'=>'v9','f1'=>'v1'})
rx = Edoors::Room.json_create( JSON.load( JSON.generate(r0) ) )
expect(JSON.generate(r0)).to eql JSON.generate(rx)
end#
#
end
#
# EOF
|