ruote 2.1.10 → 2.1.11

Sign up to get free protection for your applications and to get access to all the features.
Files changed (94) hide show
  1. data/CHANGELOG.txt +51 -1
  2. data/CREDITS.txt +9 -0
  3. data/README.rdoc +13 -0
  4. data/Rakefile +50 -21
  5. data/TODO.txt +42 -4
  6. data/examples/pong.rb +37 -0
  7. data/lib/ruote/context.rb +19 -9
  8. data/lib/ruote/engine/process_error.rb +10 -0
  9. data/lib/ruote/engine/process_status.rb +140 -41
  10. data/lib/ruote/engine.rb +394 -27
  11. data/lib/ruote/exp/command.rb +2 -0
  12. data/lib/ruote/exp/fe_concurrence.rb +8 -0
  13. data/lib/ruote/exp/fe_concurrent_iterator.rb +3 -0
  14. data/lib/ruote/exp/fe_cursor.rb +48 -4
  15. data/lib/ruote/exp/fe_iterator.rb +40 -0
  16. data/lib/ruote/exp/fe_listen.rb +3 -3
  17. data/lib/ruote/exp/fe_participant.rb +30 -12
  18. data/lib/ruote/exp/fe_ref.rb +126 -0
  19. data/lib/ruote/exp/fe_subprocess.rb +20 -1
  20. data/lib/ruote/exp/fe_wait.rb +4 -1
  21. data/lib/ruote/exp/fe_when.rb +7 -10
  22. data/lib/ruote/exp/flowexpression.rb +23 -12
  23. data/lib/ruote/exp/ro_attributes.rb +5 -8
  24. data/lib/ruote/exp/ro_variables.rb +4 -2
  25. data/lib/ruote/fei.rb +2 -0
  26. data/lib/ruote/id/wfid_generator.rb +1 -1
  27. data/lib/ruote/log/pretty.rb +137 -0
  28. data/lib/ruote/log/storage_history.rb +1 -1
  29. data/lib/ruote/log/test_logger.rb +51 -126
  30. data/lib/ruote/log/wait_logger.rb +8 -13
  31. data/lib/ruote/parser/ruby_dsl.rb +4 -4
  32. data/lib/ruote/parser.rb +2 -2
  33. data/lib/ruote/part/block_participant.rb +1 -1
  34. data/lib/ruote/part/engine_participant.rb +1 -1
  35. data/lib/ruote/part/storage_participant.rb +27 -28
  36. data/lib/ruote/part/template.rb +8 -3
  37. data/lib/ruote/receiver/base.rb +24 -6
  38. data/lib/ruote/storage/base.rb +76 -11
  39. data/lib/ruote/storage/fs_storage.rb +10 -0
  40. data/lib/ruote/storage/hash_storage.rb +19 -8
  41. data/lib/ruote/{part → svc}/dispatch_pool.rb +3 -2
  42. data/lib/ruote/svc/dollar_sub.rb +265 -0
  43. data/lib/ruote/{error_handler.rb → svc/error_handler.rb} +6 -1
  44. data/lib/ruote/{exp → svc}/expression_map.rb +31 -37
  45. data/lib/ruote/{part → svc}/participant_list.rb +165 -25
  46. data/lib/ruote/{evt → svc}/tracker.rb +0 -0
  47. data/lib/ruote/{util → svc}/treechecker.rb +0 -0
  48. data/lib/ruote/util/look.rb +4 -1
  49. data/lib/ruote/util/ometa.rb +21 -5
  50. data/lib/ruote/{subprocess.rb → util/subprocess.rb} +0 -0
  51. data/lib/ruote/version.rb +1 -1
  52. data/lib/ruote/worker.rb +29 -69
  53. data/lib/ruote/workitem.rb +28 -1
  54. data/ruote.gemspec +26 -22
  55. data/test/functional/base.rb +3 -0
  56. data/test/functional/concurrent_base.rb +1 -0
  57. data/test/functional/crunner.sh +1 -1
  58. data/test/functional/ct_0_concurrence.rb +6 -0
  59. data/test/functional/ct_1_iterator.rb +3 -0
  60. data/test/functional/ct_2_cancel.rb +5 -0
  61. data/test/functional/eft_13_iterator.rb +39 -4
  62. data/test/functional/eft_14_cursor.rb +39 -0
  63. data/test/functional/eft_30_ref.rb +140 -0
  64. data/test/functional/eft_3_participant.rb +25 -23
  65. data/test/functional/ft_10_dollar.rb +17 -1
  66. data/test/functional/ft_14_re_apply.rb +76 -0
  67. data/test/functional/ft_1_process_status.rb +170 -29
  68. data/test/functional/ft_20_storage_participant.rb +14 -0
  69. data/test/functional/ft_24_block_participants.rb +1 -1
  70. data/test/functional/ft_26_participant_timeout.rb +93 -0
  71. data/test/functional/ft_2_errors.rb +24 -17
  72. data/test/functional/ft_30_smtp_participant.rb +7 -2
  73. data/test/functional/ft_38_participant_more.rb +15 -0
  74. data/test/functional/ft_39_wait_for.rb +34 -1
  75. data/test/functional/ft_3_participant_registration.rb +270 -2
  76. data/test/functional/ft_40_wait_logger.rb +61 -0
  77. data/test/functional/ft_42_storage_copy.rb +4 -0
  78. data/test/functional/{ft_40_participant_on_reply.rb → ft_43_participant_on_reply.rb} +17 -0
  79. data/test/functional/ft_44_var_participant.rb +35 -0
  80. data/test/functional/ft_45_participant_accept.rb +64 -0
  81. data/test/functional/ft_46_launch_single.rb +49 -0
  82. data/test/functional/ft_5_on_error.rb +39 -1
  83. data/test/functional/storage_helper.rb +7 -1
  84. data/test/test_helper.rb +1 -1
  85. data/test/unit/storage.rb +105 -32
  86. data/test/unit/ut_0_ruby_parser.rb +31 -1
  87. data/test/unit/ut_16_parser.rb +20 -0
  88. data/test/unit/ut_19_part_template.rb +11 -1
  89. data/test/unit/ut_20_composite_storage.rb +1 -1
  90. data/test/unit/ut_4_expmap.rb +1 -1
  91. data/test/unit/ut_6_condition.rb +2 -2
  92. metadata +112 -74
  93. data/lib/ruote/exp/raw.rb +0 -44
  94. data/lib/ruote/util/dollar.rb +0 -193
data/test/unit/storage.rb CHANGED
@@ -8,24 +8,33 @@
8
8
  require File.join(File.dirname(__FILE__), %w[ .. test_helper.rb ])
9
9
 
10
10
  require_json
11
- require_patron
11
+ #require_patron
12
12
 
13
13
  require File.join(File.dirname(__FILE__), %w[ .. functional storage_helper.rb ])
14
14
 
15
+ #
16
+ # note : using the 'errors' type, but this test is about generic storage, not
17
+ # about errors per se.
18
+ #
15
19
 
16
20
  class UtStorage < Test::Unit::TestCase
17
21
 
18
22
  def setup
23
+
19
24
  @s = determine_storage({})
20
- @s.add_type('dogfood')
25
+
26
+ #@s.add_type('errors')
27
+
21
28
  @s.put(
22
29
  '_id' => 'toto',
23
- 'type' => 'dogfood',
30
+ 'type' => 'errors',
24
31
  'message' => 'testing')
25
32
  end
26
33
  def teardown
27
34
 
28
- @s.get_many('dogfood').each { |d| @s.delete(d) }
35
+ @s.get_many('errors').each do |d|
36
+ @s.delete(d)
37
+ end
29
38
  end
30
39
 
31
40
  def test_get_configuration
@@ -35,24 +44,25 @@ class UtStorage < Test::Unit::TestCase
35
44
 
36
45
  def test_get
37
46
 
38
- h = @s.get('dogfood', 'toto')
47
+ h = @s.get('errors', 'toto')
39
48
 
40
49
  assert_not_nil h['_rev']
41
50
 
42
- h = @s.get('dogfood', 'nada')
51
+ h = @s.get('errors', 'nada')
43
52
 
44
53
  assert_nil h
45
54
  end
46
55
 
47
56
  def test_put
48
57
 
49
- doc = { '_id' => 'nada', 'type' => 'dogfood', 'message' => 'testing (2)' }
58
+ doc = {
59
+ '_id' => 'test_put', 'type' => 'errors', 'message' => 'testing (2)' }
50
60
 
51
61
  @s.put(doc)
52
62
 
53
63
  assert_nil doc['_rev']
54
64
 
55
- h = @s.get('dogfood', 'nada')
65
+ h = @s.get('errors', 'test_put')
56
66
 
57
67
  assert_not_nil h['_rev']
58
68
  assert_not_nil h['put_at']
@@ -60,7 +70,7 @@ class UtStorage < Test::Unit::TestCase
60
70
 
61
71
  def test_put_fail
62
72
 
63
- r = @s.put('_id' => 'toto', 'type' => 'dogfood', 'message' => 'more')
73
+ r = @s.put('_id' => 'toto', 'type' => 'errors', 'message' => 'more')
64
74
 
65
75
  assert_equal 'toto', r['_id']
66
76
  assert_not_nil r['_rev']
@@ -68,7 +78,7 @@ class UtStorage < Test::Unit::TestCase
68
78
 
69
79
  def test_put_update_rev
70
80
 
71
- doc = { '_id' => 'ouinouin', 'type' => 'dogfood', 'message' => 'more' }
81
+ doc = { '_id' => 'tpur', 'type' => 'errors', 'message' => 'more' }
72
82
 
73
83
  r = @s.put(doc, :update_rev => true)
74
84
 
@@ -77,15 +87,15 @@ class UtStorage < Test::Unit::TestCase
77
87
 
78
88
  def test_put_put_and_put
79
89
 
80
- doc = { '_id' => 'whiskas', 'type' => 'dogfood', 'message' => 'miam' }
90
+ doc = { '_id' => 'whiskas', 'type' => 'errors', 'message' => 'miam' }
81
91
 
82
92
  r = @s.put(doc)
83
- doc = @s.get('dogfood', 'whiskas')
93
+ doc = @s.get('errors', 'whiskas')
84
94
 
85
95
  r = @s.put(doc)
86
96
  assert_nil r
87
97
 
88
- doc = @s.get('dogfood', 'whiskas')
98
+ doc = @s.get('errors', 'whiskas')
89
99
 
90
100
  assert_not_nil doc['put_at']
91
101
 
@@ -95,12 +105,12 @@ class UtStorage < Test::Unit::TestCase
95
105
 
96
106
  def test_put_update_rev_twice
97
107
 
98
- doc = { '_id' => 'ouinouin', 'type' => 'dogfood', 'message' => 'more' }
108
+ doc = { '_id' => 'tpurt', 'type' => 'errors', 'message' => 'more' }
99
109
 
100
110
  r = @s.put(doc, :update_rev => true)
101
111
  assert_nil r
102
112
 
103
- doc = { '_id' => 'ouinouin', 'type' => 'dogfood', 'message' => 'more' }
113
+ doc = { '_id' => 'tpurt', 'type' => 'errors', 'message' => 'more' }
104
114
 
105
115
  r = @s.put(doc, :update_rev => true)
106
116
  assert_not_nil r
@@ -108,6 +118,8 @@ class UtStorage < Test::Unit::TestCase
108
118
 
109
119
  def test_delete_fail
110
120
 
121
+ # missing _rev
122
+
111
123
  assert_raise(ArgumentError) do
112
124
  @s.delete('_id' => 'toto')
113
125
  end
@@ -115,7 +127,7 @@ class UtStorage < Test::Unit::TestCase
115
127
 
116
128
  def test_delete
117
129
 
118
- doc = @s.get('dogfood', 'toto')
130
+ doc = @s.get('errors', 'toto')
119
131
 
120
132
  r = @s.delete(doc)
121
133
 
@@ -124,18 +136,18 @@ class UtStorage < Test::Unit::TestCase
124
136
 
125
137
  def test_delete_missing
126
138
 
127
- r = @s.delete('_id' => 'x', '_rev' => '12-13231123132', 'type' => 'dogfood')
139
+ r = @s.delete('_id' => 'x', '_rev' => '12-13231123132', 'type' => 'errors')
128
140
 
129
141
  assert_equal true, r
130
142
  end
131
143
 
132
144
  def test_keys_should_be_string
133
145
 
134
- doc = { '_id' => 'h0', 'type' => 'dogfood', :m0 => :z, :m1 => [ :a, :b ] }
146
+ doc = { '_id' => 'h0', 'type' => 'errors', :m0 => :z, :m1 => [ :a, :b ] }
135
147
 
136
148
  @s.put(doc)
137
149
 
138
- doc = @s.get('dogfood', 'h0')
150
+ doc = @s.get('errors', 'h0')
139
151
 
140
152
  assert_equal 'z', doc['m0']
141
153
  assert_equal %w[ a b ], doc['m1']
@@ -145,7 +157,7 @@ class UtStorage < Test::Unit::TestCase
145
157
  #
146
158
  def test_put_gone
147
159
 
148
- h = @s.get('dogfood', 'toto')
160
+ h = @s.get('errors', 'toto')
149
161
 
150
162
  assert_nil @s.delete(h)
151
163
 
@@ -156,31 +168,92 @@ class UtStorage < Test::Unit::TestCase
156
168
 
157
169
  def test_purge_type
158
170
 
159
- @s.purge_type!('dogfood')
171
+ @s.purge_type!('errors')
160
172
 
161
- assert_equal 0, @s.get_many('dogfood').size
173
+ assert_equal 0, @s.get_many('errors').size
162
174
  end
163
175
 
176
+ def test_clear
177
+
178
+ @s.clear
179
+
180
+ assert_equal 0, @s.get_many('errors').size
181
+ end
182
+
183
+ #def test_purge
184
+ # @s.purge!
185
+ # assert_equal 0, @s.get_many('errors').size
186
+ #end
187
+
164
188
  def test_ids
165
189
 
166
- @s.put('_id' => 'ouinouin', 'type' => 'dogfood', 'message' => 'testing')
167
- @s.put('_id' => 'nada', 'type' => 'dogfood', 'message' => 'testing')
168
- @s.put('_id' => 'estereo', 'type' => 'dogfood', 'message' => 'testing')
190
+ @s.put('_id' => 't_ids0', 'type' => 'errors', 'message' => 'testing')
191
+ @s.put('_id' => 't_ids1', 'type' => 'errors', 'message' => 'testing')
192
+ @s.put('_id' => 't_ids2', 'type' => 'errors', 'message' => 'testing')
169
193
 
170
- assert_equal %w[ estereo nada ouinouin toto ], @s.ids('dogfood').sort
194
+ assert_equal %w[ t_ids0 t_ids1 t_ids2 toto ], @s.ids('errors').sort
171
195
  end
172
196
 
173
197
  def test_get_many
174
198
 
175
199
  30.times do |i|
176
- @s.put('_id' => "xx!#{i}", 'type' => 'dogfood', 'msg' => "whatever #{i}")
200
+ @s.put(
201
+ '_id' => "xx!#{i}",
202
+ 'type' => 'errors',
203
+ 'wfid' => i.to_s,
204
+ 'msg' => "whatever #{i}")
177
205
  end
178
206
 
179
- assert_equal 31, @s.get_many('dogfood').size
180
- assert_equal 10, @s.get_many('dogfood', nil, :limit => 10).size
181
- assert_equal 1, @s.get_many('dogfood', /!7$/).size
182
- assert_equal 30, @s.get_many('dogfood', /^xx!/).size
183
- assert_equal 30, @s.get_many('dogfood', /x/).size
207
+ assert_equal 31, @s.get_many('errors').size
208
+ assert_equal 1, @s.get_many('errors', '7').size
209
+ assert_equal 1, @s.get_many('errors', /!7$/).size
210
+ assert_equal 30, @s.get_many('errors', /^xx!/).size
211
+ assert_equal 30, @s.get_many('errors', /x/).size
212
+ assert_equal 10, @s.get_many('errors', nil, :limit => 10).size
213
+ end
214
+
215
+ def test_get_many_options
216
+
217
+ 30.times do |i|
218
+ @s.put(
219
+ '_id' => sprintf("yy!%0.2d", i),
220
+ 'type' => 'errors',
221
+ 'msg' => "whatever #{i}")
222
+ end
223
+
224
+ # limit
225
+
226
+ assert_equal 10, @s.get_many('errors', nil, :limit => 10).size
227
+
228
+ # count
229
+
230
+ assert_equal 31, @s.get_many('errors', nil, :count => true)
231
+
232
+ # skip and limit
233
+
234
+ assert_equal(
235
+ %w[ toto yy!00 yy!01 yy!02 ],
236
+ @s.get_many(
237
+ 'errors', nil, :skip => 0, :limit => 4
238
+ ).collect { |d| d['_id'] })
239
+ assert_equal(
240
+ %w[ yy!02 yy!03 yy!04 ],
241
+ @s.get_many(
242
+ 'errors', nil, :skip => 3, :limit => 3
243
+ ).collect { |d| d['_id'] })
244
+
245
+ # skip, limit and reverse
246
+
247
+ assert_equal(
248
+ %w[ yy!29 yy!28 yy!27 ],
249
+ @s.get_many(
250
+ 'errors', nil, :skip => 0, :limit => 3, :descending => true
251
+ ).collect { |d| d['_id'] })
252
+ assert_equal(
253
+ %w[ yy!29 yy!28 yy!27 ],
254
+ @s.get_many(
255
+ 'errors', nil, :skip => 0, :limit => 3, :descending => true
256
+ ).collect { |d| d['_id'] })
184
257
  end
185
258
  end
186
259
 
@@ -7,7 +7,8 @@
7
7
 
8
8
  require File.join(File.dirname(__FILE__), '..', 'test_helper.rb')
9
9
 
10
- require 'ruote/parser/ruby_dsl'
10
+ require 'ruote/parser'
11
+ #require 'ruote/parser/ruby_dsl'
11
12
 
12
13
 
13
14
  class UtRubyParserTest < Test::Unit::TestCase
@@ -123,5 +124,34 @@ class UtRubyParserTest < Test::Unit::TestCase
123
124
  [ 'sequence', {}, [ [ 'alpha', {}, [] ], [ 'bravo', {}, [] ] ] ],
124
125
  Ruote.to_tree { sequence { alpha; bravo } })
125
126
  end
127
+
128
+ def test_raise
129
+
130
+ #assert_raise Nada do
131
+ Ruote::Parser.parse %{ Ruote.define { alpha } }
132
+ #end
133
+
134
+ assert_raise ArgumentError do
135
+ Ruote::Parser.parse %{ Ruote.define { abort } }
136
+ end
137
+ assert_raise ArgumentError do
138
+ Ruote::Parser.parse %{ Ruote.define { exit } }
139
+ end
140
+ assert_raise ArgumentError do
141
+ Ruote::Parser.parse %{ Ruote.define { exit! } }
142
+ end
143
+
144
+ assert_raise ArgumentError do
145
+ Ruote::Parser.parse %{ Ruote.define { x = Kernel } }
146
+ end
147
+
148
+ assert_raise ArgumentError do
149
+ Ruote::Parser.parse %{ Ruote.define { module Nada; end } }
150
+ end
151
+
152
+ assert_raise ArgumentError do
153
+ Ruote::Parser.parse %{ Ruote.define { File.read('stuff') } }
154
+ end
155
+ end
126
156
  end
127
157
 
@@ -139,5 +139,25 @@ end
139
139
 
140
140
  FileUtils.rm(fn)
141
141
  end
142
+
143
+ # Make sure that ruby method names like 'freeze' or 'clone' can be used
144
+ # in process definitions.
145
+ #
146
+ def test_ruby_blank_slate
147
+
148
+ t = Ruote::Parser.parse(%{
149
+ Ruote.define do
150
+ freeze
151
+ clone
152
+ untrust
153
+ end
154
+ })
155
+
156
+ assert_equal(
157
+ [ 'define', {}, [
158
+ [ 'freeze', {}, [] ], [ 'clone', {}, [] ], [ 'untrust', {}, [] ]
159
+ ] ],
160
+ t)
161
+ end
142
162
  end
143
163
 
@@ -8,19 +8,29 @@
8
8
  require File.join(File.dirname(__FILE__), '..', 'test_helper.rb')
9
9
 
10
10
  require_json
11
+ require 'ruote/context'
11
12
  require 'ruote/part/template'
13
+ require 'ruote/storage/hash_storage'
12
14
 
13
15
 
14
16
  class UtPartTemplateTest < Test::Unit::TestCase
15
17
 
16
18
  class MyParticipant
17
19
  include ::Ruote::TemplateMixin
20
+
21
+ def initialize
22
+
23
+ @context = ::Ruote::Context.new(::Ruote::HashStorage.new)
24
+ end
18
25
  end
19
26
 
20
27
  DEFAULT = %{
21
28
  workitem for gonzalo
22
29
 
23
- {"wfid":"20100304-bidehachina","expid":"0_0_1"}
30
+ {
31
+ "wfid": "20100304-bidehachina",
32
+ "expid": "0_0_1"
33
+ }
24
34
 
25
35
  - 'car' ==> "BMW"
26
36
  - 'model' ==> "BMW 328 Mille Miglia"
@@ -20,7 +20,7 @@ class UtCompositeStorageTest < Test::Unit::TestCase
20
20
 
21
21
  cs = Ruote::CompositeStorage.new(default, 'msgs' => msgs)
22
22
 
23
- cs.put('action' => 'terminate', 'type' => 'msgs', 'id' => 'xxx')
23
+ cs.put('action' => 'terminate', 'type' => 'msgs', '_id' => 'xxx')
24
24
  cs.put_msg('terminate', 'type' => 'msgs')
25
25
  cs.put_schedule('at', {}, Time.now + 10, 'action' => 'reply')
26
26
 
@@ -7,7 +7,7 @@
7
7
 
8
8
  require File.join(File.dirname(__FILE__), '..', 'test_helper.rb')
9
9
 
10
- require 'ruote/exp/expression_map'
10
+ require 'ruote/svc/expression_map'
11
11
 
12
12
 
13
13
  class UtExpMapTest < Test::Unit::TestCase
@@ -7,8 +7,8 @@
7
7
 
8
8
  require File.join(File.dirname(__FILE__), '..', 'test_helper.rb')
9
9
 
10
- require 'ruote/exp/expression_map'
11
- require 'ruote/util/treechecker'
10
+ require 'ruote/svc/treechecker'
11
+ require 'ruote/svc/expression_map'
12
12
 
13
13
 
14
14
  class ConditionTest < Test::Unit::TestCase