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,67 @@
1
+
2
+ #
3
+ # testing ruote
4
+ #
5
+ # Mon Dec 7 13:54:18 JST 2009
6
+ #
7
+
8
+ require File.join(File.dirname(__FILE__), 'concurrent_base')
9
+
10
+
11
+ class CtIteratorTest < Test::Unit::TestCase
12
+ include ConcurrentBase
13
+
14
+ # Test proper handling of collisions between an iterator and another worker
15
+ # passing a stop command.
16
+ #
17
+ def test_collision
18
+
19
+ pdef = Ruote.process_definition do
20
+ concurrence do
21
+ iterator :on => (1..10).to_a, :tag => 'it' do
22
+ echo '${v:i}'
23
+ end
24
+ sequence do
25
+ sequence do
26
+ stop :ref => 'it'
27
+ end
28
+ end
29
+ end
30
+ end
31
+
32
+ noisy if ARGV.include?('-N')
33
+
34
+ wfid = @engine0.launch(pdef)
35
+
36
+ stop_msg = nil
37
+
38
+ loop do
39
+ m = @engine0.next_msg
40
+ if m['command']
41
+ stop_msg = m
42
+ break
43
+ end
44
+ @engine0.do_process(m)
45
+ end
46
+
47
+ assert_equal 'stop', stop_msg['command'].first
48
+ assert_equal '0_0_0', stop_msg['fei']['expid']
49
+
50
+ msg = @engine0.next_msg
51
+
52
+ t0 = Thread.new { @engine1.do_process(stop_msg) }
53
+ t1 = Thread.new { @engine0.do_process(msg) }
54
+ t0.join
55
+ t1.join
56
+
57
+ loop do
58
+ m = @engine0.next_msg
59
+ break if m['action'] == 'terminated'
60
+ @engine0.do_process(m)
61
+ end
62
+
63
+ assert_equal "1\n2", @tracer0.to_s
64
+ assert_equal '', @tracer1.to_s
65
+ end
66
+ end
67
+
@@ -0,0 +1,81 @@
1
+
2
+ #
3
+ # testing ruote
4
+ #
5
+ # Mon Dec 28 19:13:02 JST 2009
6
+ #
7
+
8
+ require File.join(File.dirname(__FILE__), 'concurrent_base')
9
+
10
+
11
+ class CtCancelTest < Test::Unit::TestCase
12
+ include ConcurrentBase
13
+
14
+ # A collision between a reply and a cancel
15
+ #
16
+ # The first one to occur should neutralize the other (and the flow should
17
+ # not stall).
18
+ #
19
+ def test_collision
20
+
21
+ pdef = Ruote.process_definition do
22
+ sequence do
23
+ alpha
24
+ end
25
+ end
26
+
27
+ alpha = @engine0.register_participant :alpha do |workitem|
28
+ # let reply immediately
29
+ end
30
+
31
+ noisy if ARGV.include?('-N')
32
+
33
+ wfid = @engine0.launch(pdef)
34
+
35
+ @engine0.step 7
36
+
37
+ dispatched_seen = false
38
+ reply_msg = nil
39
+
40
+ loop do
41
+ m = @engine0.next_msg
42
+ ma = m['action']
43
+ if ma == 'dispatched'
44
+ dispatched_seen = true
45
+ @engine0.do_process(m)
46
+ break if reply_msg
47
+ elsif ma == 'reply'
48
+ reply_msg = m
49
+ break
50
+ else
51
+ @engine0.do_process(m)
52
+ end
53
+ end
54
+
55
+ #p dispatched_seen
56
+
57
+ @engine0.cancel_expression(
58
+ { 'engine_id' => 'engine', 'wfid' => wfid, 'expid' => '0_0' })
59
+
60
+ msgs = @engine0.gather_msgs
61
+
62
+ msgs = msgs - [ reply_msg ]
63
+
64
+ assert_equal 1, msgs.size
65
+ assert_equal 'cancel', msgs.first['action']
66
+
67
+ t1 = Thread.new { @engine1.do_process(msgs.first) }
68
+ t0 = Thread.new { @engine0.do_process(reply_msg) }
69
+ t1.join
70
+ t0.join
71
+
72
+ loop do
73
+ m = @engine0.next_msg
74
+ @engine0.do_process(m)
75
+ break if m['action'] == 'terminated'
76
+ end
77
+
78
+ assert_nil @engine0.process(wfid)
79
+ end
80
+ end
81
+
@@ -0,0 +1,65 @@
1
+
2
+ #
3
+ # testing ruote
4
+ #
5
+ # Sat Jan 24 22:40:35 JST 2009
6
+ #
7
+
8
+ require File.join(File.dirname(__FILE__), 'base')
9
+
10
+ require 'ruote/participant'
11
+
12
+
13
+ class EftProcessDefinitionTest < Test::Unit::TestCase
14
+ include FunctionalBase
15
+
16
+ def test_empty_procdef
17
+
18
+ assert_trace(
19
+ '',
20
+ Ruote.define(:name => 'test_1') { })
21
+ end
22
+
23
+ def test_sub_definition
24
+
25
+ pdef = Ruote.process_definition :name => 'main' do
26
+ define :name => 'sub0' do
27
+ end
28
+ participant :ref => :alpha
29
+ end
30
+
31
+ alpha = @engine.register_participant :alpha, Ruote::StorageParticipant
32
+
33
+ #noisy
34
+
35
+ wfid = @engine.launch(pdef)
36
+
37
+ wait_for(:alpha)
38
+
39
+ ps = @engine.process(wfid)
40
+
41
+ assert_equal(
42
+ {"sub0"=> ["0_0", ["define", {"name"=>"sub0"}, []]],
43
+ "main"=> ["0", ["define", {"name"=>"main"}, [["define", {"name"=>"sub0"}, []], ["participant", {"ref"=>"alpha"}, []]]]]},
44
+ ps.variables)
45
+ end
46
+
47
+ #def test_define_implicit_name
48
+ # pdef = Ruote.define 'accounting_process' do
49
+ # end
50
+ # assert_equal 'accounting_process', pdef[1]['name']
51
+ #end
52
+
53
+ def test_sub_define_implicit_name
54
+
55
+ pdef = Ruote.define 'accounting_process' do
56
+ define 'sub0' do
57
+ end
58
+ end
59
+
60
+ assert_equal(
61
+ ["define", {"accounting_process"=>nil}, [["define", {"sub0"=>nil}, []]]],
62
+ pdef)
63
+ end
64
+ end
65
+
@@ -0,0 +1,46 @@
1
+
2
+ #
3
+ # testing ruote
4
+ #
5
+ # Mon Jun 15 21:18:06 JST 2009
6
+ #
7
+
8
+ require File.join(File.dirname(__FILE__), 'base')
9
+
10
+
11
+ class EftCancelProcessTest < Test::Unit::TestCase
12
+ include FunctionalBase
13
+
14
+ def test_cancel_process
15
+
16
+ pdef = Ruote.process_definition do
17
+ sequence do
18
+ echo 'a'
19
+ cancel_process
20
+ echo 'b'
21
+ end
22
+ end
23
+
24
+ #noisy
25
+
26
+ assert_trace('a', pdef)
27
+
28
+ #assert_equal 3, logger.log.select { |e| e[1] == :entered_tag }.size
29
+ end
30
+
31
+ def test_unless
32
+
33
+ pdef = Ruote.process_definition do
34
+ sequence do
35
+ echo 'a'
36
+ terminate :unless => 'true == true'
37
+ echo 'b'
38
+ end
39
+ end
40
+
41
+ #noisy
42
+
43
+ assert_trace("a\nb", pdef)
44
+ end
45
+ end
46
+
@@ -0,0 +1,109 @@
1
+
2
+ #
3
+ # testing ruote
4
+ #
5
+ # Thu Jun 18 11:03:45 JST 2009
6
+ #
7
+
8
+ require File.join(File.dirname(__FILE__), 'base')
9
+
10
+
11
+ class EftWaitTest < Test::Unit::TestCase
12
+ include FunctionalBase
13
+
14
+ def test_wait_for
15
+
16
+ pdef = Ruote.process_definition do
17
+ sequence do
18
+ alpha
19
+ wait :for => '2s'
20
+ alpha
21
+ echo 'done.'
22
+ end
23
+ end
24
+
25
+ #noisy
26
+
27
+ @engine.context.stash[:ts] = []
28
+
29
+ @engine.register_participant(:alpha) { stash[:ts] << Time.now }
30
+
31
+ assert_trace 'done.', pdef
32
+
33
+ d = (
34
+ @engine.context.stash[:ts][1].sec - @engine.context.stash[:ts][0].sec
35
+ ) % 60
36
+
37
+ deltas = [ 2, 3 ]
38
+ deltas << 4 if @engine.storage.class.name.match(/^Ruote::Couch::/)
39
+
40
+ assert(
41
+ deltas.include?(d),
42
+ "delta is #{d}, which isn't in #{deltas.inspect}")
43
+ end
44
+
45
+ def test_cancel_wait
46
+
47
+ pdef = Ruote.process_definition do
48
+ sequence do
49
+ echo 'a'
50
+ wait :for => '3d'
51
+ echo 'b'
52
+ end
53
+ end
54
+
55
+ #noisy
56
+
57
+ wfid = @engine.launch(pdef)
58
+
59
+ wait_for(4)
60
+
61
+ @engine.cancel_process(wfid)
62
+
63
+ wait_for(wfid)
64
+
65
+ assert_equal 'a', @tracer.to_s
66
+ assert_equal 0, @engine.storage.get_many('schedules').size
67
+ end
68
+
69
+ def test_wait_until
70
+
71
+ @engine.context.stash[:ts] = []
72
+
73
+ @engine.register_participant(:alpha) { stash[:ts] << Time.now }
74
+
75
+ pdef = Ruote.process_definition do
76
+ sequence do
77
+ alpha
78
+ wait :until => (Time.now + 2.0).to_s
79
+ alpha
80
+ echo 'done.'
81
+ end
82
+ end
83
+
84
+ #noisy
85
+
86
+ assert_trace 'done.', pdef
87
+
88
+ ts0 = @engine.context.stash[:ts][0]
89
+ ts1 = @engine.context.stash[:ts][1]
90
+
91
+ assert(ts1 - ts0 > 1.0, "#{ts1 - ts0} should be > 1.0")
92
+ end
93
+
94
+ def test_wait_until_now
95
+
96
+ pdef = Ruote.process_definition do
97
+ sequence do
98
+ echo 'a'
99
+ wait Time.now
100
+ echo 'b'
101
+ end
102
+ end
103
+
104
+ #noisy
105
+
106
+ assert_trace %w[ a b ], pdef
107
+ end
108
+ end
109
+
@@ -0,0 +1,500 @@
1
+
2
+ #
3
+ # testing ruote
4
+ #
5
+ # Fri Jun 19 15:26:33 JST 2009
6
+ #
7
+
8
+ require File.join(File.dirname(__FILE__), 'base')
9
+
10
+
11
+ class EftListenTest < Test::Unit::TestCase
12
+ include FunctionalBase
13
+
14
+ def test_listen
15
+
16
+ pdef = Ruote.process_definition do
17
+ concurrence do
18
+ sequence do
19
+ listen :to => '/^al.*/'
20
+ echo '1'
21
+ end
22
+ sequence do
23
+ alpha
24
+ end
25
+ end
26
+ end
27
+
28
+ #noisy
29
+
30
+ @engine.register_participant :alpha do
31
+ @tracer << "alpha\n"
32
+ end
33
+
34
+ wfid = @engine.launch(pdef)
35
+ wait_for(wfid)
36
+
37
+ assert_equal %w[ 1 alpha ], @tracer.to_a.sort
38
+
39
+ assert_equal(
40
+ 0, @engine.context.storage.get('variables', 'trackers')['trackers'].size)
41
+ end
42
+
43
+ def test_listen_with_child
44
+
45
+ pdef = Ruote.process_definition do
46
+ concurrence do
47
+ listen :to => /^al.*/ do
48
+ bravo
49
+ end
50
+ sequence do
51
+ alpha
52
+ alpha
53
+ end
54
+ end
55
+ end
56
+
57
+ @engine.register_participant :alpha do
58
+ @tracer << "a\n"
59
+ end
60
+ @engine.register_participant :bravo do |workitem|
61
+ @tracer << "#{workitem.fei.wfid}|#{workitem.fei.subid}"
62
+ @tracer << "\n"
63
+ end
64
+
65
+ #noisy
66
+
67
+ wfid = @engine.launch(pdef)
68
+
69
+ wait_for(:bravo)
70
+ wait_for(:bravo)
71
+ wait_for(3)
72
+
73
+ #sleep 0.001
74
+ #p @tracer.to_s
75
+
76
+ a = @tracer.to_a
77
+ assert_equal 2, a.select { |e| e == 'a' }.size
78
+
79
+ a = (a - [ 'a', 'a' ]).sort
80
+ assert_equal 2, a.uniq.size
81
+
82
+ ps = @engine.process(wfid)
83
+
84
+ #assert_equal 3, ps.expressions.size
85
+ assert_equal 0, ps.errors.size
86
+
87
+ assert_equal(
88
+ 1, @engine.context.storage.get('variables', 'trackers')['trackers'].size)
89
+ end
90
+
91
+ def test_upon
92
+
93
+ pdef = Ruote.process_definition do
94
+ concurrence do
95
+ sequence do
96
+ listen :to => /^al.*/, :merge => false
97
+ bravo
98
+ end
99
+ sequence do
100
+ listen :to => '/^al.*/', :upon => 'reply'
101
+ bravo
102
+ end
103
+ sequence do
104
+ alpha
105
+ end
106
+ end
107
+ end
108
+
109
+ #noisy
110
+
111
+ @engine.register_participant :alpha do |workitem|
112
+ @tracer << "alpha\n"
113
+ workitem.fields['seen'] = 'yes'
114
+ end
115
+ @engine.register_participant :bravo do |workitem|
116
+ @tracer << "bravo:#{workitem.fields['seen']}\n"
117
+ end
118
+
119
+ wfid = @engine.launch(pdef)
120
+ @engine.wait_for(wfid)
121
+
122
+ assert_equal %w[ alpha bravo: bravo:yes ], @tracer.to_a.sort
123
+ end
124
+
125
+ def test_merge_override
126
+
127
+ pdef = Ruote.process_definition do
128
+ set :f => 'name', :val => 'Kilroy'
129
+ set :f => 'other', :val => 'nothing'
130
+ concurrence do
131
+ sequence do
132
+ listen :to => '/^al.*/', :merge => 'override', :upon => 'reply'
133
+ bravo
134
+ end
135
+ sequence do
136
+ alpha
137
+ end
138
+ end
139
+ end
140
+
141
+ #noisy
142
+
143
+ @engine.register_participant :alpha do |wi|
144
+ @tracer << "alpha\n"
145
+ wi.fields['name'] = 'William Mandella'
146
+ end
147
+ @engine.register_participant :bravo do |wi|
148
+ @tracer << "name:#{wi.fields['name']} "
149
+ @tracer << "other:#{wi.fields['other']}\n"
150
+ end
151
+
152
+ assert_trace("alpha\nname:William Mandella other:nothing", pdef)
153
+ end
154
+
155
+ def test_where
156
+
157
+ pdef = Ruote.process_definition do
158
+ concurrence do
159
+ listen :to => 'alpha', :where => '${f:who} == toto', :upon => 'reply' do
160
+ echo 'toto'
161
+ end
162
+ sequence do
163
+ alpha
164
+ end
165
+ sequence do
166
+ alpha
167
+ end
168
+ end
169
+ end
170
+
171
+ #noisy
172
+
173
+ stash[:count] = 0
174
+
175
+ @engine.register_participant :alpha do |wi|
176
+ @tracer << "alpha\n"
177
+ wi.fields['who'] = 'toto' if stash[:count] > 0
178
+ stash[:count] += 1
179
+ end
180
+
181
+ wfid = @engine.launch(pdef)
182
+
183
+ wait_for(wfid) # ceased
184
+
185
+ assert_equal %w[ alpha alpha toto ].join("\n"), @tracer.to_s
186
+ assert_equal 3, @engine.process(wfid).expressions.size
187
+
188
+ assert_not_nil(
189
+ @engine.context.logger.log.find { |l| l['action'] == 'ceased' })
190
+ end
191
+
192
+ def test_listen_cancel
193
+
194
+ pdef = Ruote.process_definition do
195
+ listen :to => 'alpha'
196
+ end
197
+
198
+ wfid = @engine.launch(pdef)
199
+
200
+ wait_for(2)
201
+
202
+ assert_equal(
203
+ 1, @engine.context.storage.get('variables', 'trackers')['trackers'].size)
204
+
205
+ @engine.cancel_process(wfid)
206
+
207
+ wait_for(wfid)
208
+
209
+ assert_equal(
210
+ 0, @engine.context.storage.get('variables', 'trackers')['trackers'].size)
211
+ end
212
+
213
+ def test_cross
214
+
215
+ listening = Ruote.process_definition do
216
+ sequence do
217
+ listen :to => 'alpha'
218
+ echo 'ldone.'
219
+ end
220
+ end
221
+ emitting = Ruote.process_definition do
222
+ sequence do
223
+ alpha
224
+ echo 'edone.'
225
+ end
226
+ end
227
+
228
+ @engine.register_participant :alpha do
229
+ # nothing
230
+ end
231
+
232
+ #noisy
233
+
234
+ lwfid = @engine.launch(listening)
235
+ ewfid = @engine.launch(emitting)
236
+
237
+ wait_for(lwfid, ewfid)
238
+
239
+ #assert_equal("edone.\nldone.", @tracer.to_s)
240
+ assert_equal %w[ edone. ldone. ], @tracer.to_a.sort
241
+ end
242
+
243
+ def test_not_cross
244
+
245
+ listening = Ruote.process_definition do
246
+ sequence do
247
+ listen :to => 'alpha', :wfid => :same
248
+ echo 'ldone.'
249
+ end
250
+ end
251
+ emitting = Ruote.process_definition do
252
+ sequence do
253
+ alpha
254
+ echo 'edone.'
255
+ end
256
+ end
257
+
258
+ @engine.register_participant :alpha do
259
+ # nothing
260
+ end
261
+
262
+ lwfid = @engine.launch(listening)
263
+ ewfid = @engine.launch(emitting)
264
+
265
+ wait_for(ewfid)
266
+
267
+ assert_equal("edone.", @tracer.to_s)
268
+
269
+ ps = @engine.process(lwfid)
270
+ assert_equal(3, ps.expressions.size)
271
+ end
272
+
273
+ def test_listen_to_tag
274
+
275
+ listening = Ruote.process_definition do
276
+ concurrence do
277
+ listen :to => :first_phase, :upon => :leaving do
278
+ echo 'left'
279
+ end
280
+ listen :to => :first_phase, :upon => :entering do
281
+ echo 'entered'
282
+ end
283
+ end
284
+ end
285
+ emitting = Ruote.process_definition do
286
+ sequence :tag => :first_phase do
287
+ echo 'in'
288
+ end
289
+ echo 'edone.'
290
+ end
291
+
292
+ #noisy
293
+
294
+ lwfid = @engine.launch(listening)
295
+ ewfid = @engine.launch(emitting)
296
+
297
+ wait_for(ewfid)
298
+
299
+ assert_equal(%w[ in entered edone. left ], @tracer.to_a)
300
+ end
301
+
302
+ def test_listen_and_doesnt_match
303
+
304
+ pdef = Ruote.define do
305
+ concurrence :count => 1 do
306
+ listen :to => 'stone', :upon => 'entering' do
307
+ echo 'stone'
308
+ end
309
+ sequence :tag => 'milestone' do
310
+ echo 'milestone'
311
+ end
312
+ end
313
+ end
314
+
315
+ assert_trace "milestone", pdef
316
+ end
317
+
318
+ def test_listen_and_do_match
319
+
320
+ pdef = Ruote.define do
321
+ concurrence :count => 1 do
322
+ listen :to => /stone/, :upon => 'entering' do
323
+ echo 'stone'
324
+ end
325
+ sequence :tag => 'milestone' do
326
+ echo 'milestone'
327
+ end
328
+ end
329
+ end
330
+
331
+ wfid = @engine.launch(pdef)
332
+
333
+ @engine.wait_for(wfid)
334
+
335
+ assert_equal %w[ milestone stone ], @tracer.to_a
336
+ end
337
+
338
+ # somewhere between Haneda and Changi (Thu Apr 21 00:56:19 JST 2011)
339
+
340
+ def test_listen_to_errors
341
+
342
+ @engine.context['ruby_eval_allowed'] = true
343
+
344
+ pdef = Ruote.define do
345
+ concurrence :count => 1 do
346
+ listen :to => :errors do
347
+ echo 'error:${f:__error__.message}'
348
+ end
349
+ sequence do
350
+ nemo
351
+ end
352
+ end
353
+ end
354
+
355
+ #@engine.noisy = true
356
+
357
+ wfid = @engine.launch(pdef)
358
+
359
+ @engine.wait_for(wfid)
360
+
361
+ @engine.wait_for(3)
362
+ # give it some time (steps) to launch the listen block
363
+
364
+ assert_equal "error:unknown participant or subprocess 'nemo'", @tracer.to_s
365
+ end
366
+
367
+ def test_listen_and_caught_errors
368
+
369
+ pdef = Ruote.define do
370
+ concurrence :count => 1 do
371
+ listen :to => :errors do
372
+ echo 'error intercepted'
373
+ end
374
+ sequence :on_error => :pass do
375
+ nemo
376
+ end
377
+ end
378
+ end
379
+
380
+ #@engine.noisy = true
381
+
382
+ wfid = @engine.launch(pdef)
383
+ @engine.wait_for(wfid)
384
+
385
+ assert_equal '', @tracer.to_s
386
+ end
387
+
388
+ def test_listen_does_not_work_for_errors_in_other_processes
389
+
390
+ #@engine.noisy = true
391
+
392
+ wfid0 = @engine.launch(Ruote.define do
393
+ listen :to => :errors do
394
+ echo 'error intercepted'
395
+ end
396
+ end)
397
+
398
+ sleep 0.700
399
+
400
+ wfid1 = @engine.launch(Ruote.define do
401
+ nemo
402
+ end)
403
+
404
+ @engine.wait_for(wfid1)
405
+
406
+ sleep 0.350
407
+ # just to be sure the 'listen' doesn't trigger
408
+
409
+ assert_equal '', @tracer.to_s
410
+ end
411
+
412
+ def test_listen_error_class
413
+
414
+ pdef = Ruote.define do
415
+ concurrence do
416
+ listen :to => :errors, :class => 'RuntimeError' do
417
+ echo 'runtime error'
418
+ end
419
+ listen :to => :errors, :class => 'ArgumentError' do
420
+ echo 'argument error'
421
+ end
422
+ sequence do
423
+ nemo
424
+ end
425
+ sequence do
426
+ echo '${r:nada}'
427
+ end
428
+ end
429
+ end
430
+
431
+ #@engine.noisy = true
432
+
433
+ wfid = @engine.launch(pdef)
434
+
435
+ #sleep 1.000
436
+ 4.times { @engine.wait_for(wfid) } # error, error, ceased, ceased
437
+
438
+ assert_equal(
439
+ true,
440
+ [ "runtime error\nargument error",
441
+ "argument error\nruntime error" ].include?(@tracer.to_s))
442
+ end
443
+
444
+ def test_listen_error_message
445
+
446
+ @engine.context['ruby_eval_allowed'] = true
447
+
448
+ pdef = Ruote.define do
449
+ concurrence do
450
+ listen :to => :errors, :msg => /nemo/ do
451
+ echo 'nemo error ${__error__.fei.expid}'
452
+ end
453
+ listen :to => :errors, :msg => 'nada' do
454
+ echo 'nada error ${__error__.fei.expid}'
455
+ end
456
+ sequence do
457
+ nemo
458
+ end
459
+ sequence do
460
+ error 'nada'
461
+ end
462
+ end
463
+ end
464
+
465
+ #@engine.noisy = true
466
+
467
+ wfid = @engine.launch(pdef)
468
+
469
+ 4.times { @engine.wait_for(wfid) } # error, error, ceased, ceased
470
+
471
+ assert_equal "nemo error 0_0_2_0\nnada error 0_0_3_0", @tracer.to_s
472
+ end
473
+
474
+ def test_listen_error_classes
475
+
476
+ pdef = Ruote.define do
477
+ concurrence do
478
+ listen :to => :errors, :class => 'RuntimeError, ArgumentError' do
479
+ echo 'that error ${__error__.fei.expid}'
480
+ end
481
+ sequence do
482
+ nemo
483
+ end
484
+ sequence do
485
+ echo '${r:nada}'
486
+ end
487
+ end
488
+ end
489
+
490
+ #@engine.noisy = true
491
+
492
+ wfid = @engine.launch(pdef)
493
+
494
+ #sleep 1.000
495
+ 4.times { @engine.wait_for(wfid) } # error, error, ceased, ceased
496
+
497
+ assert_equal "that error 0_0_1_0\nthat error 0_0_2_0", @tracer.to_s
498
+ end
499
+ end
500
+