iotas 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/spec/spin_spec.rb ADDED
@@ -0,0 +1,129 @@
1
+ #! /usr/bin/env ruby
2
+ # -*- coding: UTF-8 -*-
3
+ #
4
+
5
+ require 'spec_helper'
6
+ #
7
+ describe Iotas::Spin do
8
+ #
9
+ class MyP < Iotas::Particle; end
10
+ #
11
+ it "Particles pool" do
12
+ spin = Iotas::Spin.new 'dom0'
13
+ p0 = spin.require_p Iotas::Particle
14
+ p1 = spin.require_p Iotas::Particle
15
+ (p0===p1).should be_false
16
+ spin.release_p p0
17
+ p2 = spin.require_p Iotas::Particle
18
+ (p0===p2).should be_true
19
+ end
20
+ #
21
+ it "different Particles classes in pool" do
22
+ spin = Iotas::Spin.new 'dom0'
23
+ p0 = spin.require_p Iotas::Particle
24
+ p1 = spin.require_p Iotas::Particle
25
+ (p0===p1).should be_false
26
+ spin.release_p p0
27
+ p2 = spin.require_p MyP
28
+ p3 = spin.require_p MyP
29
+ (p2===p3).should be_false
30
+ spin.release_p p2
31
+ p4 = spin.require_p MyP
32
+ (p2===p4).should be_true
33
+ end
34
+ #
35
+ it "release of merged particles" do
36
+ spin = Iotas::Spin.new 'dom0'
37
+ p0 = spin.require_p Iotas::Particle
38
+ p1 = spin.require_p Iotas::Particle
39
+ (p0===p1).should be_false
40
+ p0.merge! p1
41
+ spin.release_p p0
42
+ p2 = spin.require_p Iotas::Particle
43
+ (p2===p0).should be_true
44
+ p3 = spin.require_p Iotas::Particle
45
+ (p3===p1).should be_true
46
+ end
47
+ #
48
+ it "clear!" do
49
+ spin = Iotas::Spin.new 'dom0'
50
+ p0 = spin.require_p Iotas::Particle
51
+ p1 = spin.require_p Iotas::Particle
52
+ spin.send_p p0
53
+ spin.release_p p1
54
+ spin.clear!
55
+ p2 = spin.require_p Iotas::Particle
56
+ (p2==p0).should be_false
57
+ (p2==p1).should be_false
58
+ end
59
+ #
60
+ it "post_p post_sys_p spin!" do
61
+ spin = Iotas::Spin.new 'dom0'
62
+ f = Fake.new 'fake', spin
63
+ p0 = spin.require_p Iotas::Particle
64
+ p0.dst_routed! f
65
+ p1 = spin.require_p Iotas::Particle
66
+ p1.dst_routed! f
67
+ spin.post_p p0
68
+ spin.post_sys_p p1
69
+ spin.run = true
70
+ spin.spin!
71
+ f.p.should be p0
72
+ f.sp.should be p1
73
+ spin.stop!
74
+ end
75
+ #
76
+ it "process_sys" do
77
+ spin = Iotas::Spin.new 'dom0'
78
+ p0 = spin.require_p Iotas::Particle
79
+ p0.set_dst! 'unknown'
80
+ spin.send_sys_p p0
81
+ spin.spin!
82
+ p1 = spin.require_p Iotas::Particle
83
+ p0.should be p0
84
+ end
85
+ #
86
+ it "option debug" do
87
+ spin = Iotas::Spin.new 'dom0'
88
+ spin.debug_routing.should be false
89
+ spin.debug_errors.should be false
90
+ spin = Iotas::Spin.new 'dom0', :debug_routing=>true, :debug_errors=>true
91
+ spin.debug_routing.should be true
92
+ spin.debug_errors.should be true
93
+ end
94
+ #
95
+ it "spin->json->spin" do
96
+ spin = Iotas::Spin.new 'dom0', :debug_routing=>true
97
+ r0 = Iotas::Room.new 'r0', spin
98
+ r1 = Iotas::Room.new 'r1', r0
99
+ r2 = Iotas::Room.new 'r2', r1
100
+ r3 = Iotas::Room.new 'r3', r1
101
+ r4 = Iotas::Room.new 'r4', r3
102
+ d0 = Iotas::Door.new 'd0', r1
103
+ d1 = Iotas::Door.new 'd1', r1
104
+ d2 = Iotas::Door.new 'd2', r2
105
+ p0 = spin.require_p Iotas::Particle
106
+ p1 = spin.require_p Iotas::Particle
107
+ p2 = spin.require_p Iotas::Particle
108
+ spin.post_p p0
109
+ spin.post_p p1
110
+ spin.post_sys_p p2
111
+ json = JSON.generate spin
112
+ dom0 = Iotas::Spin.json_create( JSON.load( json ) )
113
+ json.should eql JSON.generate(dom0)
114
+ end
115
+ #
116
+ it "hibernate! resume!" do
117
+ spin = Iotas::Spin.new 'dom0'
118
+ p0 = spin.require_p Iotas::Particle
119
+ p0.set_dst! Iotas::SYS_ACT_HIBERNATE
120
+ spin.send_sys_p p0
121
+ spin.spin!
122
+ dom0 = Iotas::Spin.resume! spin.hibernate_path
123
+ dom0.name.should eql spin.name
124
+ File.unlink dom0.hibernate_path
125
+ end
126
+ #
127
+ end
128
+ #
129
+ #EOF
data/spec/spot_spec.rb ADDED
@@ -0,0 +1,26 @@
1
+ #! /usr/bin/env ruby
2
+ # -*- coding: UTF-8 -*-
3
+ #
4
+
5
+ require 'spec_helper'
6
+ #
7
+ describe Iotas::Iota do
8
+ #
9
+ it "path construction" do
10
+ class S<Iotas::Iota
11
+ def add_iota s
12
+ end
13
+ end
14
+ s0 = S.new 'top', nil
15
+ s1 = S.new 'room0', s0
16
+ s2 = S.new 'room1', s1
17
+ s3 = S.new 'door', s2
18
+ s3.path.should eql 'top/room0/room1/door'
19
+ lambda { Iotas::Iota.new('do/or0', nil) }.should raise_error(Iotas::Exception)
20
+ lambda { Iotas::Iota.new('/door0', nil) }.should raise_error(Iotas::Exception)
21
+ lambda { Iotas::Iota.new('door0/', nil) }.should raise_error(Iotas::Exception)
22
+ end
23
+ #
24
+ end
25
+ #
26
+ # EOF
@@ -0,0 +1,168 @@
1
+ #! /usr/bin/env ruby
2
+ # -*- coding: UTF-8 -*-
3
+
4
+ require 'iotas'
5
+
6
+ HBN_PATH='hibernate.json'
7
+ #
8
+ class InputDoor < Iotas::Door
9
+ #
10
+ @count = 0
11
+ #
12
+ class << self
13
+ attr_accessor :count
14
+ end
15
+ #
16
+ def initialize n, p
17
+ super n, p
18
+ @lines = [ "#{name} says : hello", "world ( from #{path} )" ]
19
+ @idx = 0
20
+ end
21
+ #
22
+ def start!
23
+ puts " -> start #{self.class.name} (#{@path})"
24
+ # stimulate myself
25
+ p = require_p Iotas::Particle
26
+ p.set_dst! Iotas::ACT_GET, path
27
+ send_p p
28
+ end
29
+ #
30
+ def stop!
31
+ puts " >- stop #{self.class.name} (#{@path})"
32
+ end
33
+ #
34
+ def hibernate!
35
+ puts " !! hibernate #{self.class.name} (#{@path})"
36
+ # we want to remember where we are in the data flow
37
+ {'idx'=>@idx}
38
+ end
39
+ #
40
+ def resume! o
41
+ puts " !! resume #{self.class.name} (#{@path})"
42
+ # restore idx
43
+ @idx = o['idx']
44
+ end
45
+ #
46
+ def receive_p p
47
+ puts " @ #{self.class.name} (#{@path}) receive_p : #{p.action}"
48
+ if p.action==Iotas::ACT_GET
49
+ p.reset!
50
+ p.set_data 'line', @lines[@idx]
51
+ p.set_data 'f0', 'v0'
52
+ p.set_data 'f1', 'v1'
53
+ p.set_data 'f2', 'v2'
54
+ send_p p
55
+ @idx+=1
56
+ if @idx<@lines.length
57
+ # there is more to read, restimulate myself
58
+ p = require_p Iotas::Particle
59
+ p.set_dst! Iotas::ACT_GET, name
60
+ send_p p
61
+ end
62
+ else
63
+ # we can release it or let the Door do it
64
+ release_p p
65
+ end
66
+ # I want to hibernate now!
67
+ self.class.count+=1
68
+ if self.class.count==3
69
+ p = require_p Iotas::Particle
70
+ p[Iotas::FIELD_HIBERNATE_PATH] = HBN_PATH
71
+ p.set_dst! Iotas::SYS_ACT_HIBERNATE
72
+ send_sys_p p
73
+ end
74
+ end
75
+ #
76
+ end
77
+ #
78
+ class ConcatBoard < Iotas::Board
79
+ #
80
+ def initialize n, p, m=false
81
+ super n, p
82
+ @manual = m
83
+ end
84
+ #
85
+ def start!
86
+ puts " -> start #{self.class.name} (#{@path})"
87
+ end
88
+ #
89
+ def stop!
90
+ puts " >- stop #{self.class.name} (#{@path})"
91
+ end
92
+ #
93
+ def receive_p p
94
+ puts " @ #{self.class.name} receive_p : #{p.action}"
95
+ if p.action==Iotas::ACT_ERROR
96
+ #
97
+ else
98
+ if @manual
99
+ # cleanup unnecessary p2 Particle
100
+ p2 = p.merged_shift
101
+ p.set_data 'line', (p.data('line')+' '+p2.data('line'))
102
+ release_p p2
103
+ else
104
+ # Or let the system do it
105
+ p.set_data 'line', (p.data('line')+' '+p.merged(0).data('line'))
106
+ end
107
+ send_p p
108
+ end
109
+ end
110
+ #
111
+ end
112
+ #
113
+ class OutputDoor < Iotas::Door
114
+ #
115
+ def initialize n, p, c=false
116
+ super n, p
117
+ @clean = c
118
+ end
119
+ #
120
+ def start!
121
+ puts " -> start #{self.class.name} (#{@path})"
122
+ end
123
+ #
124
+ def stop!
125
+ puts " >- stop #{self.class.name} (#{@path})"
126
+ end
127
+ #
128
+ def receive_p p
129
+ puts " #==> #{self.class.name} (#{@path}) receive_p : #{p.get_data('line')}"
130
+ if @clean
131
+ release_p p
132
+ else
133
+ # we do nothing Iotas::Door#process_p will detect it and release it
134
+ end
135
+ end
136
+ #
137
+ end
138
+ #
139
+ spin = Iotas::Spin.new 'dom0', :debug_routing=>false, :debug_errors=>true
140
+ #
141
+ room0 = Iotas::Room.new 'room0', spin
142
+ room1 = Iotas::Room.new 'room1', spin
143
+ #
144
+ input0 = InputDoor.new 'input0', room0
145
+ output0 = OutputDoor.new 'output0', room0
146
+ #
147
+ input1 = InputDoor.new 'input1', room1
148
+ output1 = OutputDoor.new 'output1', room1, true
149
+ concat1 = ConcatBoard.new 'concat1', room1
150
+ #
151
+ room0.add_link Iotas::Link.new('input0', 'output0', nil, nil, nil)
152
+ #
153
+ p0 = spin.require_p Iotas::Particle
154
+ p0.set_data Iotas::LNK_SRC, 'input1'
155
+ p0.set_data Iotas::LNK_DSTS, 'concat1?follow,output1'
156
+ p0.set_data Iotas::LNK_FIELDS, 'f0,f2'
157
+ p0.set_data Iotas::LNK_CONDF, 'f0,f1,f2'
158
+ p0.set_data Iotas::LNK_CONDV, 'v0v1v2'
159
+ p0.set_dst! Iotas::SYS_ACT_ADD_LINK, room1.path
160
+ room1.send_sys_p p0 # send_sys_p -> room0 -> spin -> room1 -> input1
161
+ #
162
+ spin.spin!
163
+ #
164
+ dom0 = Iotas::Spin.resume! HBN_PATH
165
+ dom0.spin!
166
+ File.unlink HBN_PATH if File.exists? HBN_PATH
167
+ #
168
+ # EOF
metadata ADDED
@@ -0,0 +1,132 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: iotas
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Jérémy Zurcher
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-05-18 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: json
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rspec
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: '2.6'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '2.6'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rake
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ description: ! "Evenja propose a data centric paradigm. A traditional programm composed
63
+ of many functions\n is decomposed into small autonomous modifications applied
64
+ on the data implemented in different instances of Door base class.\n Routing
65
+ between these doors is handled through links or user application destinations."
66
+ email:
67
+ - jeremy@asynk.ch
68
+ executables: []
69
+ extensions: []
70
+ extra_rdoc_files: []
71
+ files:
72
+ - .gitignore
73
+ - .travis.yml
74
+ - Changelog
75
+ - Gemfile
76
+ - Gemfile.lock
77
+ - LICENSE
78
+ - README.md
79
+ - Rakefile
80
+ - iotas.gemspec
81
+ - lib/iotas.rb
82
+ - lib/iotas/board.rb
83
+ - lib/iotas/door.rb
84
+ - lib/iotas/iota.rb
85
+ - lib/iotas/link.rb
86
+ - lib/iotas/particle.rb
87
+ - lib/iotas/room.rb
88
+ - lib/iotas/spin.rb
89
+ - lib/version.rb
90
+ - spec/board_spec.rb
91
+ - spec/door_spec.rb
92
+ - spec/link_spec.rb
93
+ - spec/particle_spec.rb
94
+ - spec/room_spec.rb
95
+ - spec/spec_helper.rb
96
+ - spec/spin_spec.rb
97
+ - spec/spot_spec.rb
98
+ - test/test_evendoors.rb
99
+ homepage: http://github.com/jeremyz/iotas
100
+ licenses: []
101
+ post_install_message:
102
+ rdoc_options: []
103
+ require_paths:
104
+ - lib
105
+ required_ruby_version: !ruby/object:Gem::Requirement
106
+ none: false
107
+ requirements:
108
+ - - ! '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ required_rubygems_version: !ruby/object:Gem::Requirement
112
+ none: false
113
+ requirements:
114
+ - - ! '>='
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ requirements: []
118
+ rubyforge_project:
119
+ rubygems_version: 1.8.23
120
+ signing_key:
121
+ specification_version: 3
122
+ summary: ruby rewrite of C++ application framework evenja (http://www.revena.com/evenja)
123
+ test_files:
124
+ - spec/board_spec.rb
125
+ - spec/door_spec.rb
126
+ - spec/link_spec.rb
127
+ - spec/particle_spec.rb
128
+ - spec/room_spec.rb
129
+ - spec/spec_helper.rb
130
+ - spec/spin_spec.rb
131
+ - spec/spot_spec.rb
132
+ - test/test_evendoors.rb