ruote 2.1.11 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (217) hide show
  1. data/CHANGELOG.txt +60 -0
  2. data/CREDITS.txt +22 -4
  3. data/LICENSE.txt +1 -1
  4. data/README.rdoc +6 -7
  5. data/Rakefile +58 -59
  6. data/TODO.txt +137 -65
  7. data/couch_url.txt +1 -0
  8. data/jruby_issue.txt +32 -0
  9. data/lib/ruote.rb +1 -1
  10. data/lib/ruote/context.rb +12 -10
  11. data/lib/ruote/engine.rb +280 -145
  12. data/lib/ruote/engine/process_error.rb +5 -5
  13. data/lib/ruote/engine/process_status.rb +47 -28
  14. data/lib/ruote/exp/command.rb +7 -10
  15. data/lib/ruote/exp/commanded.rb +2 -2
  16. data/lib/ruote/exp/condition.rb +130 -43
  17. data/lib/ruote/exp/fe_add_branches.rb +2 -2
  18. data/lib/ruote/exp/fe_apply.rb +1 -1
  19. data/lib/ruote/exp/fe_cancel_process.rb +3 -3
  20. data/lib/ruote/exp/fe_command.rb +3 -3
  21. data/lib/ruote/exp/fe_concurrence.rb +4 -4
  22. data/lib/ruote/exp/fe_concurrent_iterator.rb +17 -5
  23. data/lib/ruote/exp/fe_cron.rb +3 -3
  24. data/lib/ruote/exp/fe_cursor.rb +5 -5
  25. data/lib/ruote/exp/fe_define.rb +3 -3
  26. data/lib/ruote/exp/fe_echo.rb +3 -3
  27. data/lib/ruote/exp/fe_equals.rb +2 -2
  28. data/lib/ruote/exp/fe_error.rb +2 -2
  29. data/lib/ruote/exp/fe_filter.rb +519 -0
  30. data/lib/ruote/exp/fe_forget.rb +9 -2
  31. data/lib/ruote/exp/fe_given.rb +154 -0
  32. data/lib/ruote/exp/fe_if.rb +16 -13
  33. data/lib/ruote/exp/fe_inc.rb +3 -3
  34. data/lib/ruote/exp/fe_iterator.rb +4 -4
  35. data/lib/ruote/exp/fe_let.rb +75 -0
  36. data/lib/ruote/exp/fe_listen.rb +68 -12
  37. data/lib/ruote/exp/fe_lose.rb +110 -0
  38. data/lib/ruote/exp/fe_noop.rb +1 -1
  39. data/lib/ruote/exp/{fe_when.rb → fe_once.rb} +25 -21
  40. data/lib/ruote/exp/fe_participant.rb +14 -17
  41. data/lib/ruote/exp/fe_redo.rb +10 -6
  42. data/lib/ruote/exp/fe_ref.rb +1 -1
  43. data/lib/ruote/exp/fe_registerp.rb +112 -0
  44. data/lib/ruote/exp/fe_reserve.rb +3 -3
  45. data/lib/ruote/exp/fe_restore.rb +2 -2
  46. data/lib/ruote/exp/fe_save.rb +2 -2
  47. data/lib/ruote/exp/fe_sequence.rb +3 -4
  48. data/lib/ruote/exp/fe_set.rb +16 -7
  49. data/lib/ruote/exp/fe_subprocess.rb +23 -1
  50. data/lib/ruote/exp/fe_that.rb +92 -0
  51. data/lib/ruote/exp/fe_undo.rb +3 -3
  52. data/lib/ruote/exp/fe_unregisterp.rb +71 -0
  53. data/lib/ruote/exp/fe_wait.rb +2 -2
  54. data/lib/ruote/exp/flowexpression.rb +153 -78
  55. data/lib/ruote/exp/iterator.rb +2 -2
  56. data/lib/ruote/exp/merge.rb +2 -2
  57. data/lib/ruote/exp/ro_attributes.rb +14 -12
  58. data/lib/ruote/exp/ro_filters.rb +136 -0
  59. data/lib/ruote/exp/ro_persist.rb +51 -35
  60. data/lib/ruote/exp/ro_variables.rb +18 -27
  61. data/lib/ruote/fei.rb +73 -33
  62. data/lib/ruote/id/mnemo_wfid_generator.rb +1 -1
  63. data/lib/ruote/id/wfid_generator.rb +11 -4
  64. data/lib/ruote/log/default_history.rb +122 -0
  65. data/lib/ruote/log/pretty.rb +36 -8
  66. data/lib/ruote/log/storage_history.rb +37 -5
  67. data/lib/ruote/log/test_logger.rb +26 -24
  68. data/lib/ruote/log/wait_logger.rb +5 -3
  69. data/lib/ruote/part/block_participant.rb +22 -11
  70. data/lib/ruote/part/engine_participant.rb +6 -7
  71. data/lib/ruote/part/local_participant.rb +6 -12
  72. data/lib/ruote/part/no_op_participant.rb +4 -4
  73. data/lib/ruote/part/null_participant.rb +4 -4
  74. data/lib/ruote/part/smtp_participant.rb +4 -4
  75. data/lib/ruote/part/storage_participant.rb +40 -20
  76. data/lib/ruote/part/template.rb +4 -4
  77. data/lib/ruote/participant.rb +0 -1
  78. data/lib/ruote/{parser.rb → reader.rb} +30 -25
  79. data/lib/ruote/{parser → reader}/ruby_dsl.rb +28 -11
  80. data/lib/ruote/{parser → reader}/xml.rb +6 -5
  81. data/lib/ruote/receiver/base.rb +35 -13
  82. data/lib/ruote/storage/base.rb +20 -18
  83. data/lib/ruote/storage/composite_storage.rb +10 -10
  84. data/lib/ruote/storage/fs_storage.rb +17 -10
  85. data/lib/ruote/storage/hash_storage.rb +29 -18
  86. data/lib/ruote/svc/dispatch_pool.rb +41 -14
  87. data/lib/ruote/svc/dollar_sub.rb +50 -17
  88. data/lib/ruote/svc/error_handler.rb +19 -11
  89. data/lib/ruote/svc/expression_map.rb +4 -4
  90. data/lib/ruote/svc/participant_list.rb +105 -100
  91. data/lib/ruote/svc/tracker.rb +58 -18
  92. data/lib/ruote/svc/treechecker.rb +51 -24
  93. data/lib/ruote/tree_dot.rb +4 -4
  94. data/lib/ruote/util/filter.rb +440 -0
  95. data/lib/ruote/util/hashdot.rb +4 -4
  96. data/lib/ruote/util/look.rb +2 -6
  97. data/lib/ruote/util/lookup.rb +9 -7
  98. data/lib/ruote/util/misc.rb +40 -8
  99. data/lib/ruote/util/ometa.rb +1 -1
  100. data/lib/ruote/util/serializer.rb +4 -4
  101. data/lib/ruote/util/subprocess.rb +29 -9
  102. data/lib/ruote/util/time.rb +4 -4
  103. data/lib/ruote/util/tree.rb +3 -3
  104. data/lib/ruote/version.rb +2 -2
  105. data/lib/ruote/worker.rb +55 -32
  106. data/lib/ruote/workitem.rb +64 -11
  107. data/ruote.gemspec +31 -302
  108. data/test/bm/launch_bench.rb +37 -0
  109. data/test/functional/base.rb +60 -18
  110. data/test/functional/concurrent_base.rb +2 -2
  111. data/test/functional/ct_0_concurrence.rb +1 -1
  112. data/test/functional/ct_1_iterator.rb +1 -1
  113. data/test/functional/ct_2_cancel.rb +1 -1
  114. data/test/functional/eft_0_process_definition.rb +2 -2
  115. data/test/functional/eft_10_cancel_process.rb +1 -1
  116. data/test/functional/eft_11_wait.rb +19 -11
  117. data/test/functional/eft_12_listen.rb +79 -13
  118. data/test/functional/eft_13_iterator.rb +13 -10
  119. data/test/functional/eft_14_cursor.rb +98 -9
  120. data/test/functional/eft_15_loop.rb +6 -4
  121. data/test/functional/eft_16_if.rb +12 -0
  122. data/test/functional/eft_18_concurrent_iterator.rb +31 -32
  123. data/test/functional/eft_19_reserve.rb +4 -4
  124. data/test/functional/eft_1_echo.rb +9 -0
  125. data/test/functional/eft_20_save.rb +4 -4
  126. data/test/functional/{eft_28_when.rb → eft_28_once.rb} +33 -7
  127. data/test/functional/eft_30_ref.rb +17 -2
  128. data/test/functional/eft_31_registerp.rb +130 -0
  129. data/test/functional/eft_32_lose.rb +93 -0
  130. data/test/functional/eft_33_let.rb +31 -0
  131. data/test/functional/eft_34_given.rb +123 -0
  132. data/test/functional/eft_35_filter.rb +269 -0
  133. data/test/functional/eft_3_participant.rb +4 -6
  134. data/test/functional/eft_4_set.rb +16 -2
  135. data/test/functional/eft_5_subprocess.rb +2 -4
  136. data/test/functional/eft_6_concurrence.rb +29 -29
  137. data/test/functional/eft_8_undo.rb +39 -3
  138. data/test/functional/eft_9_redo.rb +94 -2
  139. data/test/functional/ft_10_dollar.rb +81 -2
  140. data/test/functional/ft_11_recursion.rb +13 -17
  141. data/test/functional/ft_12_launchitem.rb +9 -5
  142. data/test/functional/ft_13_variables.rb +7 -9
  143. data/test/functional/ft_14_re_apply.rb +6 -9
  144. data/test/functional/ft_15_timeout.rb +18 -18
  145. data/test/functional/ft_16_participant_params.rb +1 -3
  146. data/test/functional/ft_17_conditional.rb +25 -2
  147. data/test/functional/ft_18_kill.rb +65 -12
  148. data/test/functional/ft_1_process_status.rb +147 -71
  149. data/test/functional/ft_20_storage_participant.rb +0 -1
  150. data/test/functional/ft_21_forget.rb +82 -1
  151. data/test/functional/{ft_24_block_participants.rb → ft_24_block_participant.rb} +42 -11
  152. data/test/functional/ft_25_receiver.rb +47 -17
  153. data/test/functional/{ft_26_participant_timeout.rb → ft_26_participant_rtimeout.rb} +56 -19
  154. data/test/functional/ft_29_part_template.rb +6 -5
  155. data/test/functional/ft_2_errors.rb +21 -37
  156. data/test/functional/ft_30_smtp_participant.rb +1 -1
  157. data/test/functional/ft_31_part_blocking.rb +8 -6
  158. data/test/functional/ft_34_cursor_rewind.rb +13 -10
  159. data/test/functional/ft_35_add_service.rb +1 -1
  160. data/test/functional/ft_36_storage_history.rb +24 -1
  161. data/test/functional/ft_37_default_history.rb +109 -0
  162. data/test/functional/ft_38_participant_more.rb +10 -10
  163. data/test/functional/ft_39_wait_for.rb +12 -9
  164. data/test/functional/ft_3_participant_registration.rb +111 -32
  165. data/test/functional/ft_40_wait_logger.rb +2 -1
  166. data/test/functional/ft_41_participants.rb +30 -4
  167. data/test/functional/ft_43_participant_on_reply.rb +6 -23
  168. data/test/functional/ft_45_participant_accept.rb +4 -4
  169. data/test/functional/ft_46_launch_single.rb +36 -2
  170. data/test/functional/ft_47_wfid_generator.rb +54 -0
  171. data/test/functional/ft_48_lose.rb +112 -0
  172. data/test/functional/ft_49_engine_on_error.rb +201 -0
  173. data/test/functional/ft_4_cancel.rb +66 -6
  174. data/test/functional/ft_50_engine_config.rb +22 -0
  175. data/test/functional/ft_51_misc.rb +67 -0
  176. data/test/functional/ft_52_case.rb +134 -0
  177. data/test/functional/ft_53_engine_on_terminate.rb +95 -0
  178. data/test/functional/ft_54_patterns.rb +104 -0
  179. data/test/functional/{ft_37_engine_participant.rb → ft_55_engine_participant.rb} +4 -5
  180. data/test/functional/ft_56_filter_attribute.rb +259 -0
  181. data/test/functional/ft_5_on_error.rb +77 -30
  182. data/test/functional/ft_6_on_cancel.rb +66 -11
  183. data/test/functional/ft_7_tags.rb +94 -5
  184. data/test/functional/ft_8_participant_consumption.rb +36 -5
  185. data/test/functional/ft_9_subprocesses.rb +10 -10
  186. data/test/functional/rt_1_listen.rb +3 -3
  187. data/test/functional/{rt_3_when.rb → rt_3_once.rb} +4 -4
  188. data/test/functional/storage_helper.rb +15 -13
  189. data/test/functional/test.rb +1 -3
  190. data/test/test_helper.rb +0 -8
  191. data/test/unit/storage.rb +154 -10
  192. data/test/unit/{ut_0_ruby_parser.rb → ut_0_ruby_reader.rb} +61 -11
  193. data/test/unit/ut_11_lookup.rb +7 -0
  194. data/test/unit/ut_13_serializer.rb +1 -1
  195. data/test/unit/ut_15_util.rb +23 -0
  196. data/test/unit/{ut_16_parser.rb → ut_16_reader.rb} +11 -13
  197. data/test/unit/ut_1_fei.rb +57 -10
  198. data/test/unit/ut_20_composite_storage.rb +25 -11
  199. data/test/unit/ut_21_participant_list.rb +47 -0
  200. data/test/unit/ut_22_filter.rb +903 -0
  201. data/test/unit/ut_3_wait_logger.rb +2 -6
  202. data/test/unit/ut_6_condition.rb +164 -17
  203. data/test/unit/ut_7_workitem.rb +28 -0
  204. data/test/unit/ut_8_tree_to_dot.rb +1 -1
  205. data/test/unit/{ut_9_xml_parser.rb → ut_9_xml_reader.rb} +5 -5
  206. metadata +108 -84
  207. data/.gitignore +0 -4
  208. data/examples/barley.rb +0 -391
  209. data/examples/flickr_report.rb +0 -107
  210. data/examples/pong.rb +0 -37
  211. data/examples/ruote_quickstart.rb +0 -43
  212. data/examples/web_first_page.rb +0 -68
  213. data/lib/ruote/part/hash_participant.rb +0 -91
  214. data/test/README.rdoc +0 -15
  215. data/test/functional/crunner.sh +0 -19
  216. data/test/pdef.xml +0 -7
  217. data/test/unit/ut_2_wfidgen.rb +0 -21
@@ -0,0 +1,259 @@
1
+
2
+ #
3
+ # testing ruote
4
+ #
5
+ # Tue Feb 8 12:39:35 JST 2011
6
+ #
7
+
8
+ require File.join(File.dirname(__FILE__), 'base')
9
+
10
+
11
+ class FtFilterAttributeTest < Test::Unit::TestCase
12
+ include FunctionalBase
13
+
14
+ class AlphaParticipant
15
+ include Ruote::LocalParticipant
16
+
17
+ def consume(workitem)
18
+
19
+ @context.tracer << 'fields: ' + workitem.fields.keys.sort.join(' ') + "\n"
20
+
21
+ reply_to_engine(workitem)
22
+ end
23
+ end
24
+
25
+ def test_filter_in_variable
26
+
27
+ pdef = Ruote.define do
28
+ set 'v:f' => {
29
+ :in => [ { :fields => '/^private_/', :remove => true } ],
30
+ :out => [ { :fields => '/^~~.private_/', :merge_to => '.' } ]
31
+ }
32
+ alpha :filter => 'f'
33
+ alpha
34
+ end
35
+
36
+ @engine.register :alpha, AlphaParticipant
37
+
38
+ #noisy
39
+
40
+ wfid = @engine.launch(
41
+ pdef,
42
+ 'private_a' => 'x', 'a' => 'y')
43
+
44
+ @engine.wait_for(wfid)
45
+
46
+ assert_equal(
47
+ "fields: a dispatched_at params\n" +
48
+ "fields: a dispatched_at params private_a",
49
+ @tracer.to_s)
50
+ end
51
+
52
+ def test_filter_restore
53
+
54
+ pdef = Ruote.define do
55
+ set 'v:f' => {
56
+ :in => [],
57
+ :out => [
58
+ { :fields => '/^protected_/', :restore => true },
59
+ { :fields => '__result__', :del => true }
60
+ ]
61
+ }
62
+ sequence :filter => 'f' do
63
+ bravo
64
+ echo '${f:protected_thing}'
65
+ end
66
+ end
67
+
68
+ @engine.register :bravo do |wi|
69
+ wi.fields['protected_thing'] = 'stolen'
70
+ wi.fields['other_thing'] = 'stolen'
71
+ end
72
+
73
+ #noisy
74
+
75
+ wfid = @engine.launch(
76
+ pdef,
77
+ 'protected_thing' => 'here', 'other_thing' => 'here')
78
+
79
+ r = @engine.wait_for(wfid)
80
+
81
+ assert_equal(
82
+ { 'protected_thing' => 'here', 'other_thing' => 'stolen' },
83
+ r['workitem']['fields'])
84
+ end
85
+
86
+ def test_broken_filter_apply
87
+
88
+ pdef = Ruote.define do
89
+ alpha :filter => 'f'
90
+ end
91
+
92
+ @engine.register :alpha, Ruote::NoOpParticipant
93
+
94
+ #noisy
95
+
96
+ wfid = @engine.launch(pdef)
97
+
98
+ r = @engine.wait_for(wfid)
99
+
100
+ assert_not_nil r['error']
101
+ assert_equal 'ArgumentError', r['error']['class']
102
+ end
103
+
104
+ def test_broken_filter_reply
105
+
106
+ pdef = Ruote.define do
107
+ set 'v:f' => {
108
+ :in => [],
109
+ :out => 'nada'
110
+ }
111
+ alpha :filter => 'f'
112
+ end
113
+
114
+ @engine.register :alpha, AlphaParticipant
115
+
116
+ #noisy
117
+
118
+ wfid = @engine.launch(pdef)
119
+
120
+ r = @engine.wait_for(wfid)
121
+
122
+ assert_not_nil r['error']
123
+ assert_equal 'ArgumentError', r['error']['class']
124
+ end
125
+
126
+ class AaFilterParticipant
127
+ def consume(wi)
128
+ (wi.fields['seen'] ||= []) << wi.fields['__filter_direction__']
129
+ end
130
+ end
131
+
132
+ def test_filter_participant__consume
133
+
134
+ pdef = Ruote.define do
135
+ alpha :filter => 'filter_a'
136
+ end
137
+
138
+ @engine.register :alpha, AlphaParticipant
139
+ @engine.register :filter_a, AaFilterParticipant
140
+
141
+ #noisy
142
+
143
+ wfid = @engine.launch(pdef)
144
+
145
+ r = @engine.wait_for(wfid)
146
+
147
+ assert_nil r['workitem']['fields']['__filter_direction__']
148
+ assert_equal %w[ in out ], r['workitem']['fields']['seen']
149
+ assert_equal 'fields: dispatched_at params seen', @tracer.to_s
150
+ end
151
+
152
+ class BbFilterParticipant
153
+ def filter(fields, direction)
154
+ (fields['seen'] ||= []) << direction
155
+ fields
156
+ end
157
+ end
158
+
159
+ def test_filter_participant__filter
160
+
161
+ pdef = Ruote.define do
162
+ alpha :filter => 'filter_b'
163
+ end
164
+
165
+ @engine.register :alpha, AlphaParticipant
166
+ @engine.register :filter_b, BbFilterParticipant
167
+
168
+ #noisy
169
+
170
+ wfid = @engine.launch(pdef)
171
+
172
+ r = @engine.wait_for(wfid)
173
+
174
+ assert_equal %w[ in out ], r['workitem']['fields']['seen']
175
+ assert_equal 'fields: dispatched_at params seen', @tracer.to_s
176
+ end
177
+
178
+ class CcFilterParticipant
179
+ def consume(wi)
180
+ raise 'something goes horribly wrong'
181
+ end
182
+ end
183
+
184
+ def test_filter_participant_with_error
185
+
186
+ pdef = Ruote.define do
187
+ alpha :filter => 'filter_c'
188
+ end
189
+
190
+ @engine.register :alpha, AlphaParticipant
191
+ @engine.register :filter_c, CcFilterParticipant
192
+
193
+ #noisy
194
+
195
+ wfid = @engine.launch(pdef)
196
+
197
+ @engine.wait_for(wfid)
198
+
199
+ assert_equal 1, @engine.ps(wfid).errors.size
200
+ assert_equal '', @tracer.to_s
201
+ end
202
+
203
+ class DdFilterParticipant
204
+ def consume(workitem)
205
+ workitem.fields[workitem.participant_name] =
206
+ workitem.fields['__filter_direction__']
207
+ end
208
+ end
209
+
210
+ def test_filter_participant__in_and_out
211
+
212
+ pdef = Ruote.define do
213
+ alpha :filter => { :in => 'f0', :out => 'f1' }
214
+ end
215
+
216
+ @engine.register :alpha, AlphaParticipant
217
+ @engine.register :f0, DdFilterParticipant
218
+ @engine.register :f1, DdFilterParticipant
219
+
220
+ #noisy
221
+
222
+ wfid = @engine.launch(pdef)
223
+
224
+ r = @engine.wait_for(wfid)
225
+
226
+ assert_equal({ 'f0' => 'in', 'f1' => 'out' }, r['workitem']['fields'])
227
+ assert_equal('fields: dispatched_at f0 params', @tracer.to_s)
228
+ end
229
+
230
+ # def test_filter_record
231
+ #
232
+ # pdef = Ruote.define do
233
+ # set 'v:f' => {
234
+ # :in => [ { :fields => 'x', :type => 'number' } ],
235
+ # :out => []
236
+ # }
237
+ # alpha :filter => 'f'
238
+ # end
239
+ #
240
+ # @engine.register :alpha, AlphaParticipant
241
+ #
242
+ # #noisy
243
+ #
244
+ # wfid = @engine.launch(
245
+ # pdef,
246
+ # 'x' => 'not a number')
247
+ #
248
+ # @engine.wait_for(wfid)
249
+ #
250
+ # assert_equal(
251
+ # "fields: a dispatched_at params\n" +
252
+ # "fields: a dispatched_at params private_a",
253
+ # @tracer.to_s)
254
+ # end
255
+ #
256
+ # in the fridge for now
257
+
258
+ end
259
+
@@ -42,10 +42,10 @@ class FtOnErrorTest < Test::Unit::TestCase
42
42
  participant :mark_finished
43
43
  end
44
44
 
45
- @marks = []
45
+ @engine.context.stash[:marks] = []
46
46
 
47
47
  @engine.register_participant 'mark\_.+' do |workitem|
48
- @marks << workitem.participant_name
48
+ stash[:marks] << workitem.participant_name
49
49
  end
50
50
 
51
51
  #noisy
@@ -54,7 +54,9 @@ class FtOnErrorTest < Test::Unit::TestCase
54
54
 
55
55
  wait_for(wfid)
56
56
 
57
- assert_equal %w[ mark_started mark_failed mark_finished ], @marks
57
+ assert_equal(
58
+ %w[ mark_started mark_failed mark_finished ],
59
+ @engine.context.stash[:marks])
58
60
  end
59
61
 
60
62
  def test_on_error_unknown_participant_name_2
@@ -65,10 +67,10 @@ class FtOnErrorTest < Test::Unit::TestCase
65
67
  participant :mark_finished
66
68
  end
67
69
 
68
- @marks = []
70
+ @engine.context.stash[:marks] = []
69
71
 
70
72
  @engine.register_participant 'mark\_.+' do |workitem|
71
- @marks << workitem.participant_name
73
+ stash[:marks] << workitem.participant_name
72
74
  end
73
75
 
74
76
  #noisy
@@ -77,7 +79,9 @@ class FtOnErrorTest < Test::Unit::TestCase
77
79
 
78
80
  wait_for(wfid)
79
81
 
80
- assert_equal %w[ mark_started mark_failed mark_finished ], @marks
82
+ assert_equal(
83
+ %w[ mark_started mark_failed mark_finished ],
84
+ @engine.context.stash[:marks])
81
85
  end
82
86
 
83
87
  def test_on_error_neutralization
@@ -103,6 +107,21 @@ class FtOnErrorTest < Test::Unit::TestCase
103
107
  assert_equal(1, ps.errors.size)
104
108
  end
105
109
 
110
+ class TroubleMaker
111
+ include Ruote::LocalParticipant
112
+ def consume(workitem)
113
+ hits = (workitem.fields['hits'] || 0) + 1
114
+ workitem.fields['hits'] = hits
115
+ workitem.trace << "#{hits.to_s}\n"
116
+ raise 'Houston, we have a problem !' if hits == 1
117
+ workitem.trace << 'done.'
118
+ reply(workitem)
119
+ end
120
+ def cancel(fei, flavour)
121
+ # nothing to do
122
+ end
123
+ end
124
+
106
125
  def test_on_error_redo
107
126
 
108
127
  pdef = Ruote.process_definition do
@@ -111,16 +130,22 @@ class FtOnErrorTest < Test::Unit::TestCase
111
130
  end
112
131
  end
113
132
 
114
- hits = 0
133
+ #noisy
115
134
 
116
- @engine.register_participant :troublemaker do
117
- hits += 1
118
- @tracer << "#{hits.to_s}\n"
119
- raise 'Houston, we have a problem !' if hits == 1
120
- @tracer << 'done.'
135
+ @engine.register_participant :troublemaker, TroubleMaker
136
+
137
+ assert_trace(%w[ 1 2 done. ], pdef)
138
+ end
139
+
140
+ def test_on_error_retry
141
+
142
+ pdef = Ruote.process_definition do
143
+ sequence :on_error => :retry do
144
+ troublemaker
145
+ end
121
146
  end
122
147
 
123
- #noisy
148
+ @engine.register_participant :troublemaker, TroubleMaker
124
149
 
125
150
  assert_trace(%w[ 1 2 done. ], pdef)
126
151
  end
@@ -146,7 +171,7 @@ class FtOnErrorTest < Test::Unit::TestCase
146
171
  assert_nil @engine.process(wfid)
147
172
  end
148
173
 
149
- def test_on_error_undo__pass
174
+ def test_on_error_undo_single_expression
150
175
 
151
176
  @engine.register_participant :nemo do |wi|
152
177
  wi.fields['fail_count'] = 1
@@ -166,6 +191,27 @@ class FtOnErrorTest < Test::Unit::TestCase
166
191
  assert_nil @engine.process(wfid)
167
192
  end
168
193
 
194
+ def test_on_error_pass
195
+
196
+ pdef = Ruote.process_definition do
197
+ sequence do
198
+ echo 'a'
199
+ sequence :on_error => :pass do
200
+ echo 'b'
201
+ nemo
202
+ echo 'c'
203
+ end
204
+ echo 'd'
205
+ end
206
+ end
207
+
208
+ #noisy
209
+
210
+ wfid = assert_trace(%w[ a b d ], pdef)
211
+
212
+ assert_nil @engine.process(wfid)
213
+ end
214
+
169
215
  def test_missing_handler_triggers_regular_error
170
216
 
171
217
  pdef = Ruote.process_definition :on_error => 'failpath' do
@@ -210,16 +256,17 @@ class FtOnErrorTest < Test::Unit::TestCase
210
256
  end
211
257
  end
212
258
 
213
- a_count = 0
214
- e_count = 0
215
- @engine.register_participant(:alpha) { |wi| a_count += 1 }
216
- @engine.register_participant(:emil) { |wi| e_count += 1 }
259
+ @engine.context.stash[:a_count] = 0
260
+ @engine.context.stash[:e_count] = 0
261
+
262
+ @engine.register_participant(:alpha) { |wi| stash[:a_count] += 1 }
263
+ @engine.register_participant(:emil) { |wi| stash[:e_count] += 1 }
217
264
 
218
265
  #noisy
219
266
 
220
267
  assert_trace 'done.', pdef
221
- assert_equal 1, a_count
222
- assert_equal 1, e_count
268
+ assert_equal 1, @engine.context.stash[:a_count]
269
+ assert_equal 1, @engine.context.stash[:e_count]
223
270
  end
224
271
 
225
272
  def test_participant_on_error
@@ -231,14 +278,12 @@ class FtOnErrorTest < Test::Unit::TestCase
231
278
  end
232
279
  end
233
280
 
234
- workitem = nil
235
-
236
281
  @engine.register_participant :troublemaker do |wi|
237
282
  wi.fields['seen'] = true
238
283
  raise 'Beijing, we have a problem !'
239
284
  end
240
285
  @engine.register_participant :troublespotter do |wi|
241
- workitem = wi
286
+ stash[:workitem] = wi
242
287
  @tracer << 'err...'
243
288
  end
244
289
 
@@ -251,21 +296,23 @@ class FtOnErrorTest < Test::Unit::TestCase
251
296
  #puts er.message
252
297
  #puts er.trace
253
298
 
299
+ wi = @engine.context.stash[:workitem]
300
+
254
301
  assert_equal 'err...', @tracer.to_s
255
- assert_equal 5, workitem.error.size
256
- assert_equal 'RuntimeError', workitem.error[2]
257
- assert_equal 'Beijing, we have a problem !', workitem.error[3]
258
- assert_equal Array, workitem.error[4].class
259
- assert_equal true, workitem.fields['seen']
302
+ assert_equal 5, wi.error.size
303
+ assert_equal 'RuntimeError', wi.error['class']
304
+ assert_equal 'Beijing, we have a problem !', wi.error['message']
305
+ assert_equal Array, wi.error['trace'].class
306
+ assert_equal true, wi.fields['seen']
260
307
  end
261
308
 
262
309
  class Murphy
263
310
  include Ruote::LocalParticipant
264
311
 
265
- def cancel (fei, flavour)
312
+ def cancel(fei, flavour)
266
313
  # nothing to do
267
314
  end
268
- def consume (workitem)
315
+ def consume(workitem)
269
316
  raise "something got wrong"
270
317
  end
271
318
  end