ruote-maestrodev 2.2.1

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 (265) hide show
  1. data/CHANGELOG.txt +290 -0
  2. data/CREDITS.txt +99 -0
  3. data/LICENSE.txt +21 -0
  4. data/README.rdoc +88 -0
  5. data/Rakefile +108 -0
  6. data/TODO.txt +488 -0
  7. data/lib/ruote.rb +7 -0
  8. data/lib/ruote/context.rb +194 -0
  9. data/lib/ruote/engine.rb +1062 -0
  10. data/lib/ruote/engine/process_error.rb +122 -0
  11. data/lib/ruote/engine/process_status.rb +448 -0
  12. data/lib/ruote/exp/command.rb +87 -0
  13. data/lib/ruote/exp/commanded.rb +69 -0
  14. data/lib/ruote/exp/condition.rb +227 -0
  15. data/lib/ruote/exp/fe_add_branches.rb +138 -0
  16. data/lib/ruote/exp/fe_apply.rb +154 -0
  17. data/lib/ruote/exp/fe_cancel_process.rb +78 -0
  18. data/lib/ruote/exp/fe_command.rb +156 -0
  19. data/lib/ruote/exp/fe_concurrence.rb +321 -0
  20. data/lib/ruote/exp/fe_concurrent_iterator.rb +219 -0
  21. data/lib/ruote/exp/fe_cron.rb +141 -0
  22. data/lib/ruote/exp/fe_cursor.rb +324 -0
  23. data/lib/ruote/exp/fe_define.rb +112 -0
  24. data/lib/ruote/exp/fe_echo.rb +60 -0
  25. data/lib/ruote/exp/fe_equals.rb +115 -0
  26. data/lib/ruote/exp/fe_error.rb +82 -0
  27. data/lib/ruote/exp/fe_filter.rb +648 -0
  28. data/lib/ruote/exp/fe_forget.rb +88 -0
  29. data/lib/ruote/exp/fe_given.rb +154 -0
  30. data/lib/ruote/exp/fe_if.rb +127 -0
  31. data/lib/ruote/exp/fe_inc.rb +205 -0
  32. data/lib/ruote/exp/fe_iterator.rb +234 -0
  33. data/lib/ruote/exp/fe_let.rb +75 -0
  34. data/lib/ruote/exp/fe_listen.rb +304 -0
  35. data/lib/ruote/exp/fe_lose.rb +110 -0
  36. data/lib/ruote/exp/fe_noop.rb +45 -0
  37. data/lib/ruote/exp/fe_once.rb +215 -0
  38. data/lib/ruote/exp/fe_participant.rb +287 -0
  39. data/lib/ruote/exp/fe_read.rb +69 -0
  40. data/lib/ruote/exp/fe_redo.rb +82 -0
  41. data/lib/ruote/exp/fe_ref.rb +152 -0
  42. data/lib/ruote/exp/fe_registerp.rb +110 -0
  43. data/lib/ruote/exp/fe_reserve.rb +126 -0
  44. data/lib/ruote/exp/fe_restore.rb +102 -0
  45. data/lib/ruote/exp/fe_save.rb +72 -0
  46. data/lib/ruote/exp/fe_sequence.rb +59 -0
  47. data/lib/ruote/exp/fe_set.rb +154 -0
  48. data/lib/ruote/exp/fe_subprocess.rb +211 -0
  49. data/lib/ruote/exp/fe_that.rb +92 -0
  50. data/lib/ruote/exp/fe_undo.rb +67 -0
  51. data/lib/ruote/exp/fe_unregisterp.rb +69 -0
  52. data/lib/ruote/exp/fe_wait.rb +95 -0
  53. data/lib/ruote/exp/flowexpression.rb +886 -0
  54. data/lib/ruote/exp/iterator.rb +81 -0
  55. data/lib/ruote/exp/merge.rb +118 -0
  56. data/lib/ruote/exp/ro_attributes.rb +212 -0
  57. data/lib/ruote/exp/ro_filters.rb +136 -0
  58. data/lib/ruote/exp/ro_persist.rb +154 -0
  59. data/lib/ruote/exp/ro_variables.rb +189 -0
  60. data/lib/ruote/exp/ro_vf.rb +68 -0
  61. data/lib/ruote/fei.rb +260 -0
  62. data/lib/ruote/id/mnemo_wfid_generator.rb +43 -0
  63. data/lib/ruote/id/wfid_generator.rb +81 -0
  64. data/lib/ruote/log/default_history.rb +122 -0
  65. data/lib/ruote/log/pretty.rb +176 -0
  66. data/lib/ruote/log/storage_history.rb +159 -0
  67. data/lib/ruote/log/test_logger.rb +208 -0
  68. data/lib/ruote/log/wait_logger.rb +64 -0
  69. data/lib/ruote/part/block_participant.rb +137 -0
  70. data/lib/ruote/part/code_participant.rb +81 -0
  71. data/lib/ruote/part/engine_participant.rb +189 -0
  72. data/lib/ruote/part/local_participant.rb +138 -0
  73. data/lib/ruote/part/no_op_participant.rb +60 -0
  74. data/lib/ruote/part/null_participant.rb +54 -0
  75. data/lib/ruote/part/rev_participant.rb +169 -0
  76. data/lib/ruote/part/smtp_participant.rb +116 -0
  77. data/lib/ruote/part/storage_participant.rb +392 -0
  78. data/lib/ruote/part/template.rb +84 -0
  79. data/lib/ruote/participant.rb +7 -0
  80. data/lib/ruote/reader.rb +278 -0
  81. data/lib/ruote/reader/json.rb +49 -0
  82. data/lib/ruote/reader/radial.rb +290 -0
  83. data/lib/ruote/reader/ruby_dsl.rb +186 -0
  84. data/lib/ruote/reader/xml.rb +99 -0
  85. data/lib/ruote/receiver/base.rb +212 -0
  86. data/lib/ruote/storage/base.rb +364 -0
  87. data/lib/ruote/storage/composite_storage.rb +121 -0
  88. data/lib/ruote/storage/fs_storage.rb +139 -0
  89. data/lib/ruote/storage/hash_storage.rb +211 -0
  90. data/lib/ruote/svc/dispatch_pool.rb +158 -0
  91. data/lib/ruote/svc/dollar_sub.rb +298 -0
  92. data/lib/ruote/svc/error_handler.rb +138 -0
  93. data/lib/ruote/svc/expression_map.rb +97 -0
  94. data/lib/ruote/svc/participant_list.rb +397 -0
  95. data/lib/ruote/svc/tracker.rb +172 -0
  96. data/lib/ruote/svc/treechecker.rb +141 -0
  97. data/lib/ruote/tree_dot.rb +85 -0
  98. data/lib/ruote/util/filter.rb +525 -0
  99. data/lib/ruote/util/hashdot.rb +79 -0
  100. data/lib/ruote/util/look.rb +128 -0
  101. data/lib/ruote/util/lookup.rb +127 -0
  102. data/lib/ruote/util/misc.rb +167 -0
  103. data/lib/ruote/util/ometa.rb +71 -0
  104. data/lib/ruote/util/serializer.rb +103 -0
  105. data/lib/ruote/util/subprocess.rb +88 -0
  106. data/lib/ruote/util/time.rb +100 -0
  107. data/lib/ruote/util/tree.rb +58 -0
  108. data/lib/ruote/version.rb +29 -0
  109. data/lib/ruote/worker.rb +386 -0
  110. data/lib/ruote/workitem.rb +394 -0
  111. data/phil.txt +14 -0
  112. data/ruote.gemspec +44 -0
  113. data/test/bm/ci.rb +55 -0
  114. data/test/bm/ici.rb +71 -0
  115. data/test/bm/juuman.rb +54 -0
  116. data/test/bm/launch_bench.rb +37 -0
  117. data/test/bm/load_26c.rb +97 -0
  118. data/test/bm/mega.rb +64 -0
  119. data/test/bm/seq_thousand.rb +31 -0
  120. data/test/bm/t.rb +35 -0
  121. data/test/functional/base.rb +247 -0
  122. data/test/functional/concurrent_base.rb +98 -0
  123. data/test/functional/crunner.rb +31 -0
  124. data/test/functional/ct_0_concurrence.rb +65 -0
  125. data/test/functional/ct_1_iterator.rb +67 -0
  126. data/test/functional/ct_2_cancel.rb +81 -0
  127. data/test/functional/eft_0_process_definition.rb +65 -0
  128. data/test/functional/eft_10_cancel_process.rb +46 -0
  129. data/test/functional/eft_11_wait.rb +109 -0
  130. data/test/functional/eft_12_listen.rb +500 -0
  131. data/test/functional/eft_13_iterator.rb +342 -0
  132. data/test/functional/eft_14_cursor.rb +456 -0
  133. data/test/functional/eft_15_loop.rb +69 -0
  134. data/test/functional/eft_16_if.rb +183 -0
  135. data/test/functional/eft_17_equals.rb +55 -0
  136. data/test/functional/eft_18_concurrent_iterator.rb +410 -0
  137. data/test/functional/eft_19_reserve.rb +136 -0
  138. data/test/functional/eft_1_echo.rb +68 -0
  139. data/test/functional/eft_20_save.rb +116 -0
  140. data/test/functional/eft_21_restore.rb +61 -0
  141. data/test/functional/eft_22_noop.rb +28 -0
  142. data/test/functional/eft_23_apply.rb +168 -0
  143. data/test/functional/eft_24_add_branches.rb +98 -0
  144. data/test/functional/eft_25_command.rb +28 -0
  145. data/test/functional/eft_26_error.rb +77 -0
  146. data/test/functional/eft_27_inc.rb +280 -0
  147. data/test/functional/eft_28_once.rb +135 -0
  148. data/test/functional/eft_29_cron.rb +64 -0
  149. data/test/functional/eft_2_sequence.rb +58 -0
  150. data/test/functional/eft_30_ref.rb +155 -0
  151. data/test/functional/eft_31_registerp.rb +130 -0
  152. data/test/functional/eft_32_lose.rb +93 -0
  153. data/test/functional/eft_33_let.rb +31 -0
  154. data/test/functional/eft_34_given.rb +123 -0
  155. data/test/functional/eft_35_filter.rb +375 -0
  156. data/test/functional/eft_36_read.rb +95 -0
  157. data/test/functional/eft_3_participant.rb +149 -0
  158. data/test/functional/eft_4_set.rb +296 -0
  159. data/test/functional/eft_5_subprocess.rb +163 -0
  160. data/test/functional/eft_6_concurrence.rb +304 -0
  161. data/test/functional/eft_7_forget.rb +61 -0
  162. data/test/functional/eft_8_undo.rb +114 -0
  163. data/test/functional/eft_9_redo.rb +138 -0
  164. data/test/functional/ft_0_worker.rb +65 -0
  165. data/test/functional/ft_10_dollar.rb +304 -0
  166. data/test/functional/ft_11_recursion.rb +109 -0
  167. data/test/functional/ft_12_launchitem.rb +43 -0
  168. data/test/functional/ft_13_variables.rb +151 -0
  169. data/test/functional/ft_14_re_apply.rb +324 -0
  170. data/test/functional/ft_15_timeout.rb +226 -0
  171. data/test/functional/ft_16_participant_params.rb +98 -0
  172. data/test/functional/ft_17_conditional.rb +102 -0
  173. data/test/functional/ft_18_kill.rb +138 -0
  174. data/test/functional/ft_19_participant_code.rb +67 -0
  175. data/test/functional/ft_1_process_status.rb +796 -0
  176. data/test/functional/ft_20_storage_participant.rb +543 -0
  177. data/test/functional/ft_21_forget.rb +153 -0
  178. data/test/functional/ft_22_process_definitions.rb +90 -0
  179. data/test/functional/ft_23_load_defs.rb +79 -0
  180. data/test/functional/ft_24_block_participant.rb +235 -0
  181. data/test/functional/ft_25_receiver.rb +207 -0
  182. data/test/functional/ft_26_participant_rtimeout.rb +179 -0
  183. data/test/functional/ft_27_var_indirection.rb +128 -0
  184. data/test/functional/ft_28_null_noop_participants.rb +51 -0
  185. data/test/functional/ft_29_part_template.rb +60 -0
  186. data/test/functional/ft_2_errors.rb +380 -0
  187. data/test/functional/ft_30_smtp_participant.rb +122 -0
  188. data/test/functional/ft_31_part_blocking.rb +72 -0
  189. data/test/functional/ft_33_participant_subprocess_priority.rb +32 -0
  190. data/test/functional/ft_34_cursor_rewind.rb +101 -0
  191. data/test/functional/ft_35_add_service.rb +56 -0
  192. data/test/functional/ft_36_storage_history.rb +150 -0
  193. data/test/functional/ft_37_default_history.rb +109 -0
  194. data/test/functional/ft_38_participant_more.rb +193 -0
  195. data/test/functional/ft_39_wait_for.rb +136 -0
  196. data/test/functional/ft_3_participant_registration.rb +574 -0
  197. data/test/functional/ft_40_wait_logger.rb +62 -0
  198. data/test/functional/ft_41_participants.rb +91 -0
  199. data/test/functional/ft_42_storage_copy.rb +71 -0
  200. data/test/functional/ft_43_participant_on_reply.rb +87 -0
  201. data/test/functional/ft_44_var_participant.rb +35 -0
  202. data/test/functional/ft_45_participant_accept.rb +64 -0
  203. data/test/functional/ft_46_launch_single.rb +83 -0
  204. data/test/functional/ft_47_wfid_generator.rb +54 -0
  205. data/test/functional/ft_48_lose.rb +112 -0
  206. data/test/functional/ft_49_engine_on_error.rb +201 -0
  207. data/test/functional/ft_4_cancel.rb +132 -0
  208. data/test/functional/ft_50_engine_config.rb +22 -0
  209. data/test/functional/ft_51_misc.rb +67 -0
  210. data/test/functional/ft_52_case.rb +134 -0
  211. data/test/functional/ft_53_engine_on_terminate.rb +95 -0
  212. data/test/functional/ft_54_patterns.rb +104 -0
  213. data/test/functional/ft_55_engine_participant.rb +303 -0
  214. data/test/functional/ft_56_filter_attribute.rb +259 -0
  215. data/test/functional/ft_57_rev_participant.rb +252 -0
  216. data/test/functional/ft_58_workitem.rb +69 -0
  217. data/test/functional/ft_59_pause.rb +343 -0
  218. data/test/functional/ft_5_on_error.rb +384 -0
  219. data/test/functional/ft_60_code_participant.rb +45 -0
  220. data/test/functional/ft_61_trailing_fields.rb +34 -0
  221. data/test/functional/ft_62_exp_name_and_dollar_substitution.rb +35 -0
  222. data/test/functional/ft_6_on_cancel.rb +221 -0
  223. data/test/functional/ft_7_tags.rb +177 -0
  224. data/test/functional/ft_8_participant_consumption.rb +124 -0
  225. data/test/functional/ft_9_subprocesses.rb +146 -0
  226. data/test/functional/restart_base.rb +34 -0
  227. data/test/functional/rt_0_wait.rb +55 -0
  228. data/test/functional/rt_1_listen.rb +56 -0
  229. data/test/functional/rt_2_errors.rb +56 -0
  230. data/test/functional/rt_3_once.rb +70 -0
  231. data/test/functional/rt_4_cron.rb +64 -0
  232. data/test/functional/rt_5_timeout.rb +60 -0
  233. data/test/functional/rtest.rb +8 -0
  234. data/test/functional/storage_helper.rb +93 -0
  235. data/test/functional/test.rb +44 -0
  236. data/test/functional/vertical.rb +46 -0
  237. data/test/path_helper.rb +15 -0
  238. data/test/test.rb +13 -0
  239. data/test/test_helper.rb +28 -0
  240. data/test/unit/storage.rb +428 -0
  241. data/test/unit/storages.rb +37 -0
  242. data/test/unit/test.rb +28 -0
  243. data/test/unit/ut_0_ruby_reader.rb +223 -0
  244. data/test/unit/ut_11_lookup.rb +122 -0
  245. data/test/unit/ut_13_serializer.rb +65 -0
  246. data/test/unit/ut_14_is_uri.rb +28 -0
  247. data/test/unit/ut_15_util.rb +57 -0
  248. data/test/unit/ut_16_reader.rb +225 -0
  249. data/test/unit/ut_18_engine.rb +47 -0
  250. data/test/unit/ut_19_part_template.rb +86 -0
  251. data/test/unit/ut_1_fei.rb +165 -0
  252. data/test/unit/ut_20_composite_storage.rb +74 -0
  253. data/test/unit/ut_21_svc_participant_list.rb +46 -0
  254. data/test/unit/ut_22_filter.rb +1094 -0
  255. data/test/unit/ut_23_svc_tracker.rb +48 -0
  256. data/test/unit/ut_24_radial_reader.rb +332 -0
  257. data/test/unit/ut_25_merge.rb +113 -0
  258. data/test/unit/ut_3_wait_logger.rb +39 -0
  259. data/test/unit/ut_4_expmap.rb +20 -0
  260. data/test/unit/ut_5_tree.rb +54 -0
  261. data/test/unit/ut_6_condition.rb +303 -0
  262. data/test/unit/ut_7_workitem.rb +99 -0
  263. data/test/unit/ut_8_tree_to_dot.rb +72 -0
  264. data/test/unit/ut_9_xml_reader.rb +61 -0
  265. metadata +504 -0
@@ -0,0 +1,342 @@
1
+
2
+ #
3
+ # testing ruote
4
+ #
5
+ # Mon Jun 29 09:35:48 JST 2009
6
+ #
7
+
8
+ require File.join(File.dirname(__FILE__), 'base')
9
+
10
+ require 'ruote/participant'
11
+
12
+
13
+ class EftIteratorTest < Test::Unit::TestCase
14
+ include FunctionalBase
15
+
16
+ def test_empty_iterator
17
+
18
+ pdef = Ruote.process_definition :name => 'test' do
19
+ sequence do
20
+ iterator :on_val => 'alice, bob, charly', :to_var => 'v' do
21
+ end
22
+ echo 'done.'
23
+ end
24
+ end
25
+
26
+ #noisy
27
+
28
+ assert_trace('done.', pdef)
29
+ end
30
+
31
+ class TraceParticipant
32
+ include Ruote::LocalParticipant
33
+ def consume(wi)
34
+ context.tracer << "#{wi.participant_name}/#{wi.fei.expid}\n"
35
+ reply(wi)
36
+ end
37
+ end
38
+
39
+ def test_on_val
40
+
41
+ pdef = Ruote.process_definition :name => 'test' do
42
+ iterator :on_val => 'alice, bob, charly', :to_var => 'v' do
43
+ participant '${v:v}'
44
+ end
45
+ end
46
+
47
+ @engine.register_participant '.*', TraceParticipant
48
+
49
+ #noisy
50
+
51
+ assert_trace(%w[ alice/0_0_0 bob/0_0_0 charly/0_0_0 ], pdef)
52
+ end
53
+
54
+ def test_on__list
55
+
56
+ pdef = Ruote.process_definition :name => 'test' do
57
+ iterator :on => 'alice, bob, charly', :to_var => 'v' do
58
+ participant '${v:v}'
59
+ end
60
+ end
61
+
62
+ @engine.register_participant '.*', TraceParticipant
63
+
64
+ assert_trace(%w[ alice/0_0_0 bob/0_0_0 charly/0_0_0 ], pdef)
65
+ end
66
+
67
+ def test_on_f
68
+
69
+ pdef = Ruote.process_definition :name => 'test' do
70
+ set :f => 'people', :val => %w[ alice bob charly ]
71
+ iterator :on_f => 'people', :to_var => 'v' do
72
+ participant '${v:v}'
73
+ end
74
+ end
75
+
76
+ @engine.register_participant '.*', TraceParticipant
77
+
78
+ assert_trace(%w[ alice/0_1_0 bob/0_1_0 charly/0_1_0 ], pdef)
79
+ end
80
+
81
+ def test_on_nested_f
82
+
83
+ pdef = Ruote.process_definition :name => 'test' do
84
+ set 'f:data' => {}
85
+ set 'f:data.people' => %w[ alice bob charly ]
86
+ iterator :on_f => 'data.people', :to_var => 'v' do
87
+ participant '${v:v}'
88
+ end
89
+ end
90
+
91
+ @engine.register_participant '.*', TraceParticipant
92
+
93
+ assert_trace(%w[ alice/0_2_0 bob/0_2_0 charly/0_2_0 ], pdef)
94
+ end
95
+
96
+ def test_to_f
97
+
98
+ pdef = Ruote.process_definition :name => 'test' do
99
+ iterator :on_val => 'alice, bob, charly', :to_field => 'f' do
100
+ participant '${f:f}'
101
+ end
102
+ end
103
+
104
+ @engine.register_participant '.*' do |workitem|
105
+ @tracer << "#{workitem.fields['f']}/#{workitem.fei.expid}\n"
106
+ end
107
+
108
+ #noisy
109
+
110
+ assert_trace(%w[ alice/0_0_0 bob/0_0_0 charly/0_0_0 ], pdef)
111
+ end
112
+
113
+ def test_to
114
+
115
+ pdef = Ruote.process_definition :name => 'test' do
116
+ iterator :on_val => 'a, b', :to => 'x' do
117
+ echo '${f:x}'
118
+ end
119
+ iterator :on_val => 'c, d', :to => 'f:y' do
120
+ echo '${f:y}'
121
+ end
122
+ iterator :on_val => 'e, f', :to => 'v:z' do
123
+ echo '${v:z}'
124
+ end
125
+ end
126
+
127
+ #@engine.noisy = true
128
+
129
+ wfid = @engine.launch(pdef)
130
+ @engine.wait_for(wfid)
131
+
132
+ assert_equal %w[ a b c d e f ], @tracer.to_a
133
+ end
134
+
135
+ PDEF0 = Ruote.process_definition :name => 'test' do
136
+ sequence do
137
+ iterator :on_val => 'alice, bob, charly', :to_var => 'v' do
138
+ participant '${v:v}'
139
+ end
140
+ echo 'done.'
141
+ end
142
+ end
143
+
144
+ def test_break
145
+
146
+ @engine.register_participant '.*' do |workitem|
147
+
148
+ @tracer << "#{workitem.participant_name}\n"
149
+
150
+ if workitem.participant_name == 'bob'
151
+ workitem.fields['__command__'] = [ 'break', nil ]
152
+ end
153
+ end
154
+
155
+ #noisy
156
+
157
+ assert_trace(%w[ alice bob done. ], PDEF0)
158
+ end
159
+
160
+ def test_rewind
161
+
162
+ stash[:rewound] = false
163
+
164
+ @engine.register_participant '.*' do |workitem|
165
+
166
+ @tracer << "#{workitem.participant_name}\n"
167
+
168
+ if (not stash[:rewound]) and workitem.participant_name == 'bob'
169
+ stash[:rewound] = true
170
+ workitem.fields['__command__'] = [ 'rewind', nil ]
171
+ end
172
+ end
173
+
174
+ #noisy
175
+
176
+ assert_trace(%w[ alice bob alice bob charly done. ], PDEF0)
177
+ end
178
+
179
+ def test_skip
180
+
181
+ @engine.register_participant '.*' do |workitem|
182
+
183
+ @tracer << "#{workitem.participant_name}\n"
184
+
185
+ if workitem.participant_name == 'alice'
186
+ workitem.fields['__command__'] = [ 'skip', 1 ]
187
+ end
188
+ end
189
+
190
+ #noisy
191
+
192
+ assert_trace(%w[ alice charly done.], PDEF0)
193
+ end
194
+
195
+ def test_jump
196
+
197
+ @engine.register_participant '.*' do |workitem|
198
+
199
+ @tracer << "#{workitem.participant_name}\n"
200
+
201
+ if workitem.participant_name == 'alice'
202
+ workitem.fields['__command__'] = [ 'jump', -1 ]
203
+ end
204
+ end
205
+
206
+ #noisy
207
+
208
+ assert_trace(%w[ alice charly done.], PDEF0)
209
+ end
210
+
211
+ def test_skip_command
212
+
213
+ pdef = Ruote.process_definition :name => 'test' do
214
+ iterator :on_val => 'alice, bob, charly', :to_var => 'v' do
215
+ sequence do
216
+ participant '${v:v}'
217
+ skip 1, :if => '${v:v} == alice'
218
+ end
219
+ end
220
+ end
221
+
222
+ @engine.register_participant '.*' do |workitem|
223
+ @tracer << "#{workitem.participant_name}/#{workitem.fei.expid}\n"
224
+ end
225
+
226
+ #noisy
227
+
228
+ assert_trace(%w[ alice/0_0_0_0 charly/0_0_0_0 ], pdef)
229
+ end
230
+
231
+ def test_break_if
232
+
233
+ pdef = Ruote.process_definition :name => 'test' do
234
+ iterator :on_val => 'a, b, c', :to_var => 'v', :break_if => '${v:v} == b' do
235
+ participant '${v:v}'
236
+ end
237
+ end
238
+
239
+ @engine.register_participant '.*' do |workitem|
240
+ @tracer << "#{workitem.participant_name}/#{workitem.fei.expid}\n"
241
+ end
242
+
243
+ #noisy
244
+
245
+ assert_trace(%w[ a/0_0_0 b/0_0_0 ], pdef)
246
+ end
247
+
248
+ def test_break_unless
249
+
250
+ pdef = Ruote.process_definition :name => 'test' do
251
+ set :var => 'v', :val => 'a'
252
+ iterator :on_val => 'a, b, c', :to_var => 'v', :break_unless => '${v:v} == a' do
253
+ participant '${v:v}'
254
+ end
255
+ end
256
+
257
+ @engine.register_participant '.*' do |workitem|
258
+ @tracer << "#{workitem.participant_name}/#{workitem.fei.expid}\n"
259
+ end
260
+
261
+ #noisy
262
+
263
+ assert_trace(%w[ a/0_1_0 b/0_1_0 ], pdef)
264
+ end
265
+
266
+ def test_iterator_with_hash_as_input
267
+
268
+ pdef = Ruote.process_definition :name => 'test' do
269
+ iterator :on_val => { 'a' => 'A', 'b' => 'B' }, :to_f => 'f' do
270
+ p1
271
+ end
272
+ end
273
+
274
+ @engine.register_participant :p1 do |wi|
275
+ @tracer << wi.fields['f'].join(':')
276
+ @tracer << "\n"
277
+ end
278
+
279
+ #noisy
280
+
281
+ assert_trace %w[ a:A b:B ], pdef
282
+ end
283
+
284
+ def test_implicit_i_variable
285
+
286
+ pdef = Ruote.process_definition :name => 'test' do
287
+ iterator :on_val => 'alice, bob, charly' do
288
+ participant '${v:i}:${v:ii}'
289
+ end
290
+ end
291
+
292
+ @engine.register_participant '.*' do |workitem|
293
+ @tracer << "#{workitem.participant_name}/#{workitem.fei.expid}\n"
294
+ end
295
+
296
+ #noisy
297
+
298
+ assert_trace(%w[ alice:0/0_0_0 bob:1/0_0_0 charly:2/0_0_0 ], pdef)
299
+ end
300
+
301
+ def test_nested_break
302
+
303
+ pdef = Ruote.process_definition :name => 'test' do
304
+ iterator :on => 'a, b, c', :tag => 'it' do
305
+ sequence do
306
+ echo '0_${v:i}'
307
+ cursor do
308
+ echo '1_${v:i}'
309
+ _break :ref => 'it'
310
+ echo '11_${v:i}'
311
+ end
312
+ echo '2_${v:i}'
313
+ end
314
+ end
315
+ end
316
+
317
+ #noisy
318
+
319
+ assert_trace %w[ 0_a 1_a ], pdef
320
+ end
321
+
322
+ def test_external_break
323
+
324
+ pdef = Ruote.process_definition :name => 'test' do
325
+ concurrence do
326
+ iterator :on => (1..1000).to_a, :tag => 'it' do
327
+ echo '${v:i}'
328
+ end
329
+ sequence do
330
+ sequence do
331
+ _break :ref => 'it'
332
+ end
333
+ end
334
+ end
335
+ end
336
+
337
+ #noisy
338
+
339
+ assert_trace %w[ 1 2 ], pdef
340
+ end
341
+ end
342
+
@@ -0,0 +1,456 @@
1
+
2
+ #
3
+ # testing ruote
4
+ #
5
+ # Mon Jun 29 18:34:02 JST 2009
6
+ #
7
+
8
+ require File.join(File.dirname(__FILE__), 'base')
9
+
10
+ require 'ruote/part/no_op_participant'
11
+
12
+
13
+ class EftCursorTest < Test::Unit::TestCase
14
+ include FunctionalBase
15
+
16
+ def test_empty_cursor
17
+
18
+ pdef = Ruote.process_definition :name => 'test' do
19
+ cursor do
20
+ end
21
+ end
22
+
23
+ #noisy
24
+
25
+ assert_trace('', pdef)
26
+ end
27
+
28
+ def test_cursor
29
+
30
+ pdef = Ruote.process_definition :name => 'test' do
31
+ cursor do
32
+ echo 'a'
33
+ echo 'b'
34
+ end
35
+ end
36
+
37
+ #noisy
38
+
39
+ assert_trace(%w[ a b ], pdef)
40
+ end
41
+
42
+ def test_skip
43
+
44
+ pdef = Ruote.process_definition :name => 'test' do
45
+ cursor do
46
+ echo 'a'
47
+ skip 1
48
+ echo 'b'
49
+ echo 'c'
50
+ end
51
+ end
52
+
53
+ #noisy
54
+
55
+ assert_trace(%w[ a c ], pdef)
56
+ end
57
+
58
+ def test_break
59
+
60
+ pdef = Ruote.process_definition :name => 'test' do
61
+ cursor do
62
+ echo 'a'
63
+ _break
64
+ echo 'b'
65
+ end
66
+ end
67
+
68
+ #noisy
69
+
70
+ assert_trace('a', pdef)
71
+ end
72
+
73
+ def test_stop
74
+
75
+ pdef = Ruote.process_definition :name => 'test' do
76
+ cursor do
77
+ echo 'a'
78
+ stop
79
+ echo 'b'
80
+ end
81
+ end
82
+
83
+ #noisy
84
+
85
+ assert_trace('a', pdef)
86
+ end
87
+
88
+ def test_over
89
+
90
+ pdef = Ruote.process_definition :name => 'test' do
91
+ cursor do
92
+ echo 'a'
93
+ over
94
+ echo 'b'
95
+ end
96
+ end
97
+
98
+ #noisy
99
+
100
+ assert_trace('a', pdef)
101
+ end
102
+
103
+ def test_jump_to_tag
104
+
105
+ pdef = Ruote.process_definition :name => 'test' do
106
+ cursor do
107
+ echo 'a'
108
+ jump :to => 'c'
109
+ echo 'b'
110
+ echo 'c', :tag => 'c'
111
+ end
112
+ end
113
+
114
+ #noisy
115
+
116
+ assert_trace(%w[ a c ], pdef)
117
+ end
118
+
119
+ def test_jump_to_variable_tag
120
+
121
+ pdef = Ruote.process_definition :name => 'test' do
122
+ cursor do
123
+ echo 'a'
124
+ jump :to => 'd'
125
+ echo 'b'
126
+ set :var => 'v0', :val => 'd'
127
+ jump :to => 'd'
128
+ echo 'c'
129
+ echo 'd', :tag => '${v:v0}'
130
+ end
131
+ end
132
+
133
+ #noisy
134
+
135
+ assert_trace(%w[ a b d ], pdef)
136
+ end
137
+
138
+ def test_rewind_if
139
+
140
+ pdef = Ruote.process_definition :name => 'test' do
141
+ sequence do
142
+ set :f => 'counter', :val => 0
143
+ set :f => 'rewind', :val => false
144
+ cursor :rewind_if => '${f:rewind}' do
145
+ alpha
146
+ end
147
+ end
148
+ end
149
+
150
+ @engine.register_participant :alpha do |workitem|
151
+ workitem.fields['counter'] += 1
152
+ workitem.fields['rewind'] = workitem.fields['counter'] < 5
153
+ @tracer << "a\n"
154
+ end
155
+
156
+ #noisy
157
+
158
+ assert_trace(%w[ a ] * 5, pdef)
159
+ end
160
+
161
+ def test_jump_to
162
+
163
+ pdef = Ruote.process_definition :name => 'test' do
164
+ cursor do
165
+ author
166
+ reviewer
167
+ jump :to => 'author', :if => '${not_ok}'
168
+ publisher
169
+ end
170
+ end
171
+
172
+ @engine.register_participant :author do |workitem|
173
+ @tracer << "a\n"
174
+ stash[:count] ||= 0
175
+ stash[:count] += 1
176
+ end
177
+ @engine.register_participant :reviewer do |workitem|
178
+ @tracer << "r\n"
179
+ workitem.fields['not_ok'] = (stash[:count] < 3)
180
+ end
181
+ @engine.register_participant :publisher do |workitem|
182
+ @tracer << "p\n"
183
+ end
184
+
185
+ #noisy
186
+
187
+ assert_trace %w[ a r a r a r p ], pdef
188
+ # ARP nostalgy....
189
+ end
190
+
191
+ def test_deep_rewind
192
+
193
+ pdef = Ruote.process_definition :name => 'test' do
194
+ cursor do
195
+ sequence do
196
+ echo 'a'
197
+ rewind
198
+ echo 'b'
199
+ end
200
+ end
201
+ end
202
+
203
+ #noisy
204
+
205
+ wfid = @engine.launch(pdef)
206
+
207
+ wait_for(14)
208
+
209
+ #p @tracer.to_s
210
+
211
+ assert_equal [ 'a', 'a' ], @tracer.to_a[0..1]
212
+ end
213
+
214
+ def test_external_break
215
+
216
+ pdef = Ruote.process_definition :name => 'test' do
217
+ concurrence do
218
+ repeat :tag => 'cu' do
219
+ echo 'a'
220
+ end
221
+ sequence do
222
+ wait '1.1'
223
+ stop :ref => 'cu'
224
+ alpha
225
+ end
226
+ end
227
+ end
228
+
229
+ @engine.register_participant :alpha, Ruote::NoOpParticipant
230
+
231
+ #noisy
232
+
233
+ wfid = @engine.launch(pdef)
234
+
235
+ wait_for(:alpha)
236
+ wait_for(wfid)
237
+
238
+ #p @tracer.to_s
239
+ assert_equal %w[ a a a ], @tracer.to_a[0, 3]
240
+
241
+ assert_nil @engine.process(wfid)
242
+ end
243
+
244
+ def test_nested_break
245
+
246
+ pdef = Ruote.process_definition :name => 'test' do
247
+ cursor :tag => 'cu' do
248
+ echo 'a'
249
+ cursor do
250
+ echo 'b'
251
+ _break :ref => 'cu'
252
+ echo 'c'
253
+ end
254
+ echo 'd'
255
+ end
256
+ end
257
+
258
+ #noisy
259
+
260
+ assert_trace %w[ a b ], pdef
261
+ end
262
+
263
+ def test_break_if
264
+
265
+ pdef = Ruote.process_definition :name => 'test' do
266
+ cursor :break_if => 'true' do
267
+ echo 'c'
268
+ end
269
+ echo 'done.'
270
+ end
271
+
272
+ #noisy
273
+
274
+ assert_trace 'done.', pdef
275
+ end
276
+
277
+ def test_over_unless
278
+
279
+ pdef = Ruote.process_definition :name => 'test' do
280
+ cursor :over_unless => 'false' do
281
+ echo 'c'
282
+ end
283
+ echo 'done.'
284
+ end
285
+
286
+ #noisy
287
+
288
+ assert_trace 'done.', pdef
289
+ end
290
+
291
+ class Alpha
292
+ include Ruote::LocalParticipant
293
+ def consume(workitem)
294
+ workitem.command = 'break'
295
+ reply_to_engine(workitem)
296
+ end
297
+ def cancel(fei, flavour)
298
+ end
299
+ end
300
+ class Bravo < Alpha
301
+ def consume(workitem)
302
+ workitem.command = 'skip 1'
303
+ reply_to_engine(workitem)
304
+ end
305
+ end
306
+
307
+ def test_cursor_and_workitem
308
+
309
+ pdef = Ruote.define do
310
+ cursor do
311
+ echo 'in'
312
+ bravo
313
+ echo 'mid'
314
+ alpha
315
+ echo 'out'
316
+ end
317
+ echo 'done.'
318
+ end
319
+
320
+ #noisy
321
+
322
+ @engine.register do
323
+ alpha EftCursorTest::Alpha
324
+ bravo EftCursorTest::Bravo
325
+ end
326
+
327
+ assert_trace "in\ndone.", pdef
328
+ end
329
+
330
+ def test_cursor_with_lonely_rewind
331
+
332
+ pdef = Ruote.define do
333
+ cursor do
334
+ rewind
335
+ end
336
+ end
337
+
338
+ #@engine.noisy = true
339
+
340
+ wfid = @engine.launch(pdef)
341
+
342
+ @engine.wait_for(9)
343
+
344
+ assert_not_nil @engine.process(wfid)
345
+ end
346
+
347
+ class Charly
348
+ include Ruote::LocalParticipant
349
+ def initialize(opts)
350
+ @opts = opts
351
+ end
352
+ def consume(workitem)
353
+ workitem.command = @opts['command']
354
+ reply_to_engine(workitem)
355
+ end
356
+ def cancel(fei, flavour)
357
+ end
358
+ end
359
+
360
+ JUMP_DEF = Ruote.process_definition do
361
+ cursor do
362
+ echo 'top'
363
+ charly
364
+ echo 'middle'
365
+ delta
366
+ echo 'bottom'
367
+ end
368
+ end
369
+
370
+ def test_workitem_command_and_jump_array
371
+
372
+ #noisy
373
+
374
+ @engine.register do
375
+ charly EftCursorTest::Charly, 'command' => [ 'jump', 'delta' ]
376
+ catchall Ruote::NoOpParticipant
377
+ end
378
+
379
+ assert_trace "top\nbottom", JUMP_DEF
380
+ end
381
+
382
+ def test_workitem_command_and_jump_string
383
+
384
+ #noisy
385
+
386
+ @engine.register do
387
+ charly EftCursorTest::Charly, 'command' => 'jump delta'
388
+ catchall Ruote::NoOpParticipant
389
+ end
390
+
391
+ assert_trace "top\nbottom", JUMP_DEF
392
+ end
393
+
394
+ def test_workitem_command_and_jump_to_string
395
+
396
+ #noisy
397
+
398
+ @engine.register do
399
+ charly EftCursorTest::Charly, 'command' => 'jump to delta'
400
+ catchall Ruote::NoOpParticipant
401
+ end
402
+
403
+ assert_trace "top\nbottom", JUMP_DEF
404
+ end
405
+
406
+ def test_reset
407
+
408
+ pdef = Ruote.define do
409
+ cursor do
410
+ alpha
411
+ set 'f:toto' => 'oops'
412
+ reset
413
+ end
414
+ end
415
+
416
+ @engine.register { catchall }
417
+
418
+ #@engine.noisy = true
419
+
420
+ wfid = @engine.launch(pdef)
421
+ @engine.wait_for(:alpha)
422
+
423
+ assert_nil @engine.storage_participant.first.fields['toto']
424
+
425
+ @engine.storage_participant.proceed(@engine.storage_participant.first)
426
+ @engine.wait_for(:alpha)
427
+
428
+ assert_nil @engine.storage_participant.first.fields['toto']
429
+ end
430
+
431
+ def test_reset_if
432
+
433
+ pdef = Ruote.define do
434
+ cursor :reset_if => '${f:reset} == true' do
435
+ alpha
436
+ set 'f:toto' => 'oops'
437
+ set 'f:reset' => true
438
+ end
439
+ end
440
+
441
+ @engine.register { catchall }
442
+
443
+ #@engine.noisy = true
444
+
445
+ wfid = @engine.launch(pdef)
446
+ @engine.wait_for(:alpha)
447
+
448
+ assert_nil @engine.storage_participant.first.fields['toto']
449
+
450
+ @engine.storage_participant.proceed(@engine.storage_participant.first)
451
+ @engine.wait_for(:alpha)
452
+
453
+ assert_nil @engine.storage_participant.first.fields['toto']
454
+ end
455
+ end
456
+