ruote 2.1.11 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -7,8 +7,6 @@
7
7
 
8
8
  require File.join(File.dirname(__FILE__), 'base')
9
9
 
10
- require 'ruote/part/hash_participant'
11
-
12
10
 
13
11
  class FtTimeoutTest < Test::Unit::TestCase
14
12
  include FunctionalBase
@@ -22,20 +20,21 @@ class FtTimeoutTest < Test::Unit::TestCase
22
20
  end
23
21
  end
24
22
 
25
- alpha = @engine.register_participant :alpha, Ruote::HashParticipant.new
26
- bravo = @engine.register_participant :bravo, Ruote::HashParticipant.new
23
+ @engine.register_participant :alpha, Ruote::StorageParticipant
24
+ sto = @engine.register_participant :bravo, Ruote::StorageParticipant
27
25
 
28
26
  #noisy
29
27
 
30
28
  wfid = @engine.launch(pdef)
31
29
  wait_for(:bravo)
32
30
 
33
- assert_equal 0, alpha.size
34
- assert_equal 1, bravo.size
31
+ assert_equal 1, sto.size
32
+ assert_equal 'bravo', sto.first.participant_name
33
+
35
34
  assert_equal 2, logger.log.select { |e| e['flavour'] == 'timeout' }.size
36
35
  assert_equal 0, @engine.storage.get_many('schedules').size
37
36
 
38
- assert_not_nil bravo.first.fields['__timed_out__']
37
+ assert_not_nil sto.first.fields['__timed_out__']
39
38
  end
40
39
 
41
40
  def test_cancel_timeout
@@ -47,22 +46,23 @@ class FtTimeoutTest < Test::Unit::TestCase
47
46
  end
48
47
  end
49
48
 
50
- alpha = @engine.register_participant :alpha, Ruote::HashParticipant.new
51
- bravo = @engine.register_participant :bravo, Ruote::HashParticipant.new
49
+ @engine.register_participant :alpha, Ruote::StorageParticipant
50
+ sto = @engine.register_participant :bravo, Ruote::StorageParticipant
52
51
 
53
52
  #noisy
54
53
 
55
54
  wfid = @engine.launch(pdef)
56
55
  wait_for(6)
57
56
 
58
- assert_equal 1, alpha.size
57
+ assert_equal 1, sto.size
58
+ assert_equal 'alpha', sto.first.participant_name
59
59
 
60
- @engine.cancel_expression(alpha.first.fei)
60
+ @engine.cancel_expression(sto.first.fei)
61
61
 
62
62
  wait_for(:bravo)
63
63
 
64
- assert_equal 0, alpha.size
65
- assert_equal 1, bravo.size
64
+ assert_equal 1, sto.size
65
+ assert_equal 'bravo', sto.first.participant_name
66
66
  assert_equal 0, @engine.storage.get_many('schedules').size
67
67
  end
68
68
 
@@ -82,7 +82,7 @@ class FtTimeoutTest < Test::Unit::TestCase
82
82
  alpha :timeout => '1.1', :on_timeout => 'redo'
83
83
  end
84
84
 
85
- alpha = @engine.register_participant :alpha, Ruote::HashParticipant.new
85
+ alpha = @engine.register_participant :alpha, Ruote::StorageParticipant
86
86
 
87
87
  #noisy
88
88
 
@@ -113,7 +113,7 @@ class FtTimeoutTest < Test::Unit::TestCase
113
113
  end
114
114
  end
115
115
 
116
- alpha = @engine.register_participant :alpha, Ruote::HashParticipant.new
116
+ alpha = @engine.register_participant :alpha, Ruote::StorageParticipant
117
117
 
118
118
  #noisy
119
119
 
@@ -132,7 +132,7 @@ class FtTimeoutTest < Test::Unit::TestCase
132
132
  alpha :timeout => '1.1', :on_timeout => 'error'
133
133
  end
134
134
 
135
- alpha = @engine.register_participant :alpha, Ruote::HashParticipant.new
135
+ alpha = @engine.register_participant :alpha, Ruote::StorageParticipant
136
136
 
137
137
  #noisy
138
138
 
@@ -161,7 +161,7 @@ class FtTimeoutTest < Test::Unit::TestCase
161
161
  end
162
162
  end
163
163
 
164
- alpha = @engine.register_participant :alpha, Ruote::HashParticipant.new
164
+ alpha = @engine.register_participant :alpha, Ruote::StorageParticipant
165
165
 
166
166
  wfid = @engine.launch(pdef)
167
167
  wait_for(wfid)
@@ -203,7 +203,7 @@ class FtTimeoutTest < Test::Unit::TestCase
203
203
  end
204
204
  end
205
205
 
206
- alpha = @engine.register_participant :alpha, Ruote::HashParticipant.new
206
+ alpha = @engine.register_participant :alpha, Ruote::StorageParticipant
207
207
 
208
208
  #noisy
209
209
 
@@ -7,8 +7,6 @@
7
7
 
8
8
  require File.join(File.dirname(__FILE__), 'base')
9
9
 
10
- require 'ruote/part/hash_participant'
11
-
12
10
 
13
11
  class FtParticipantParamsTest < Test::Unit::TestCase
14
12
  include FunctionalBase
@@ -23,7 +21,7 @@ class FtParticipantParamsTest < Test::Unit::TestCase
23
21
  end
24
22
  end
25
23
 
26
- alpha = @engine.register_participant :alpha, Ruote::HashParticipant.new
24
+ alpha = @engine.register_participant :alpha, Ruote::StorageParticipant
27
25
 
28
26
  #noisy
29
27
 
@@ -45,11 +45,12 @@ class FtConditionalTest < Test::Unit::TestCase
45
45
  echo 'a', :if => '${f:d}'
46
46
  echo 'b', :if => '${f:d} == some dude'
47
47
  echo 'c', :if => "${f:d} == 'some dude'"
48
- echo 'd', :if => '${f:d} is set'
48
+ echo 'd', :if => "${f:d} == ${'f:d}"
49
+ echo 'e', :if => '${f:d} is set'
49
50
  end
50
51
  end
51
52
 
52
- assert_trace("some dude\na\nb\nd", pdef)
53
+ assert_trace("some dude\na\nc\nd\ne", pdef)
53
54
  end
54
55
 
55
56
  def test_unless
@@ -72,5 +73,27 @@ class FtConditionalTest < Test::Unit::TestCase
72
73
 
73
74
  assert_trace(%w[ other u . ], { 'f' => 'other' }, pdef)
74
75
  end
76
+
77
+ def test_and_or
78
+
79
+ pdef = Ruote.process_definition do
80
+
81
+ set 'f:t' => true
82
+ set 'f:f' => false
83
+
84
+ sequence do
85
+
86
+ echo '${f:t}/${f:f}'
87
+
88
+ echo 'a', :if => '${f:t}'
89
+ echo 'b', :if => '${f:t} or ${f:f}'
90
+ echo 'c', :if => '${f:t} and ${f:f}'
91
+ echo 'd', :if => '${f:t} and (${f:t} or ${f:f})'
92
+ echo 'e', :if => '${f:t} and (${f:t} and ${f:f})'
93
+ end
94
+ end
95
+
96
+ assert_trace(%w[ true/false a b d ], pdef)
97
+ end
75
98
  end
76
99
 
@@ -7,8 +7,6 @@
7
7
 
8
8
  require File.join(File.dirname(__FILE__), 'base')
9
9
 
10
- require 'ruote/part/hash_participant'
11
-
12
10
 
13
11
  class FtKillTest < Test::Unit::TestCase
14
12
  include FunctionalBase
@@ -19,7 +17,7 @@ class FtKillTest < Test::Unit::TestCase
19
17
  alpha
20
18
  end
21
19
 
22
- alpha = @engine.register_participant :alpha, Ruote::HashParticipant.new
20
+ alpha = @engine.register_participant :alpha, Ruote::StorageParticipant
23
21
 
24
22
  #noisy
25
23
 
@@ -46,8 +44,8 @@ class FtKillTest < Test::Unit::TestCase
46
44
  end
47
45
  end
48
46
 
49
- alpha = @engine.register_participant :alpha, Ruote::HashParticipant.new
50
- catcher = @engine.register_participant :catcher, Ruote::HashParticipant.new
47
+ @engine.register_participant :alpha, Ruote::StorageParticipant
48
+ sto = @engine.register_participant :catcher, Ruote::StorageParticipant
51
49
 
52
50
  wfid = @engine.launch(pdef)
53
51
  wait_for(:alpha)
@@ -56,8 +54,7 @@ class FtKillTest < Test::Unit::TestCase
56
54
 
57
55
  wait_for(wfid)
58
56
 
59
- assert_equal 0, alpha.size
60
- assert_equal 0, catcher.size
57
+ assert_equal 0, sto.size
61
58
  end
62
59
 
63
60
  def test_kill_expression_does_not_trigger_on_cancel
@@ -68,18 +65,74 @@ class FtKillTest < Test::Unit::TestCase
68
65
  end
69
66
  end
70
67
 
71
- alpha = @engine.register_participant :alpha, Ruote::HashParticipant.new
72
- catcher = @engine.register_participant :catcher, Ruote::HashParticipant.new
68
+ @engine.register_participant :alpha, Ruote::StorageParticipant
69
+ sto = @engine.register_participant :catcher, Ruote::StorageParticipant
73
70
 
74
71
  wfid = @engine.launch(pdef)
75
72
  wait_for(:alpha)
76
73
 
77
- @engine.kill_expression(alpha.first.fei)
74
+ @engine.kill_expression(sto.first.fei)
78
75
 
79
76
  wait_for(wfid)
80
77
 
81
- assert_equal 0, alpha.size
82
- assert_equal 0, catcher.size
78
+ assert_equal 0, sto.size
79
+ end
80
+
81
+ def test_kill__expression
82
+
83
+ pdef = Ruote.process_definition do
84
+ alpha
85
+ end
86
+
87
+ @engine.register_participant :alpha, Ruote::NullParticipant
88
+
89
+ #noisy
90
+
91
+ wfid = @engine.launch(pdef)
92
+
93
+ @engine.wait_for(:alpha)
94
+
95
+ @engine.kill(wfid)
96
+
97
+ @engine.wait_for(wfid)
98
+
99
+ assert_nil @engine.process(wfid)
100
+
101
+ assert_equal 1, logger.log.select { |e| e['action'] == 'kill_process' }.size
102
+ end
103
+
104
+ def test_kill__process
105
+
106
+ pdef = Ruote.process_definition do
107
+ alpha
108
+ echo '0'
109
+ alpha
110
+ echo '1'
111
+ alpha
112
+ echo '2'
113
+ end
114
+
115
+ @engine.register_participant :alpha, Ruote::NullParticipant
116
+
117
+ wfid = @engine.launch(pdef)
118
+
119
+ r = @engine.wait_for(:alpha)
120
+
121
+ @engine.kill(r['fei']) # fei as a Hash
122
+
123
+ r = @engine.wait_for(:alpha)
124
+
125
+ @engine.kill(Ruote.sid(r['fei'])) # fei as a String
126
+
127
+ r = @engine.wait_for(:alpha)
128
+
129
+ @engine.kill(Ruote::Workitem.new(r['workitem'])) # fei as workitem
130
+
131
+ @engine.wait_for(wfid)
132
+
133
+ assert_equal %w[ 0 1 2 ], @tracer.to_a
134
+
135
+ assert_equal 6, logger.log.select { |e| e['flavour'] == 'kill' }.size
83
136
  end
84
137
  end
85
138
 
@@ -13,7 +13,7 @@ require 'ruote/participant'
13
13
  class FtProcessStatusTest < Test::Unit::TestCase
14
14
  include FunctionalBase
15
15
 
16
- def test_ps
16
+ def test_process
17
17
 
18
18
  pdef = Ruote.process_definition :name => 'my process' do
19
19
  participant :ref => 'alpha'
@@ -21,7 +21,7 @@ class FtProcessStatusTest < Test::Unit::TestCase
21
21
 
22
22
  #noisy
23
23
 
24
- alpha = @engine.register_participant :alpha, Ruote::HashParticipant.new
24
+ alpha = @engine.register_participant :alpha, Ruote::StorageParticipant
25
25
 
26
26
  wfid = @engine.launch(pdef, :workitem => { 'kilroy' => 'was here' })
27
27
 
@@ -47,7 +47,7 @@ class FtProcessStatusTest < Test::Unit::TestCase
47
47
  end
48
48
  end
49
49
 
50
- alpha = @engine.register_participant :alpha, Ruote::HashParticipant
50
+ alpha = @engine.register_participant :alpha, Ruote::StorageParticipant
51
51
  wfid = @engine.launch(pdef, :workitem => { 'kilroy' => 'was here' })
52
52
 
53
53
  wait_for(:alpha)
@@ -93,7 +93,7 @@ class FtProcessStatusTest < Test::Unit::TestCase
93
93
  end
94
94
  end
95
95
 
96
- alpha = @engine.register_participant :alpha, Ruote::HashParticipant
96
+ alpha = @engine.register_participant :alpha, Ruote::StorageParticipant
97
97
  wfid = @engine.launch(pdef)
98
98
 
99
99
  wait_for(:alpha)
@@ -145,7 +145,7 @@ class FtProcessStatusTest < Test::Unit::TestCase
145
145
  end
146
146
  end
147
147
 
148
- alpha = @engine.register_participant :alpha, Ruote::HashParticipant
148
+ alpha = @engine.register_participant :alpha, Ruote::StorageParticipant
149
149
  wfid = @engine.launch(pdef)
150
150
 
151
151
  wait_for(:alpha)
@@ -169,41 +169,6 @@ class FtProcessStatusTest < Test::Unit::TestCase
169
169
  ps.original_tree)
170
170
  end
171
171
 
172
- def test_sub_processes
173
-
174
- pdef = Ruote.process_definition do
175
- define 'sub0' do
176
- alpha
177
- end
178
- sequence do
179
- sub0
180
- end
181
- end
182
-
183
- alpha = @engine.register_participant :alpha, Ruote::HashParticipant.new
184
-
185
- #noisy
186
-
187
- wfid = @engine.launch(pdef)
188
-
189
- wait_for(:alpha)
190
-
191
- assert_equal wfid, alpha.first.fei.wfid
192
- assert_not_nil alpha.first.fei.sub_wfid
193
-
194
- ps = @engine.process(wfid)
195
-
196
- #ps.expressions.each { |e| puts e.fei.to_s }
197
-
198
- assert_equal 5, ps.expressions.size
199
-
200
- wfids = ps.expressions.collect { |e|
201
- [ e.fei.wfid, e.fei.sub_wfid ].join('|')
202
- }.sort.uniq
203
-
204
- assert_equal 2, wfids.size
205
- end
206
-
207
172
  def test_all_variables
208
173
 
209
174
  pdef = Ruote.process_definition do
@@ -219,7 +184,7 @@ class FtProcessStatusTest < Test::Unit::TestCase
219
184
  end
220
185
  end
221
186
 
222
- alpha = @engine.register_participant :alpha, Ruote::HashParticipant.new
187
+ alpha = @engine.register_participant :alpha, Ruote::StorageParticipant
223
188
 
224
189
  #noisy
225
190
 
@@ -249,7 +214,7 @@ class FtProcessStatusTest < Test::Unit::TestCase
249
214
  end
250
215
  end
251
216
 
252
- alpha = @engine.register_participant :alpha, Ruote::HashParticipant.new
217
+ alpha = @engine.register_participant :alpha, Ruote::StorageParticipant
253
218
 
254
219
  #noisy
255
220
 
@@ -258,7 +223,7 @@ class FtProcessStatusTest < Test::Unit::TestCase
258
223
 
259
224
  ps = @engine.process(wfid)
260
225
 
261
- assert_equal 2, ps.tags.size
226
+ assert_equal %w[ main part ], ps.tags.keys.sort
262
227
 
263
228
  assert_equal 2, ps.all_tags.size
264
229
  assert_kind_of Array, ps.all_tags['main']
@@ -278,7 +243,7 @@ class FtProcessStatusTest < Test::Unit::TestCase
278
243
  end
279
244
  end
280
245
 
281
- alpha = @engine.register_participant :alpha, Ruote::HashParticipant.new
246
+ alpha = @engine.register_participant :alpha, Ruote::StorageParticipant
282
247
 
283
248
  #noisy
284
249
 
@@ -299,7 +264,7 @@ class FtProcessStatusTest < Test::Unit::TestCase
299
264
 
300
265
  #noisy
301
266
 
302
- alpha = @engine.register_participant :alpha, Ruote::HashParticipant.new
267
+ alpha = @engine.register_participant :alpha, Ruote::StorageParticipant
303
268
 
304
269
  wfid0 = @engine.launch(pdef)
305
270
  wfid1 = @engine.launch(pdef)
@@ -315,6 +280,50 @@ class FtProcessStatusTest < Test::Unit::TestCase
315
280
  assert_equal 2, alpha.size
316
281
  end
317
282
 
283
+ def test_processes_and_leftovers
284
+
285
+ n = 3
286
+
287
+ @engine.register_participant :alpha, Ruote::StorageParticipant
288
+
289
+ n.times.collect { @engine.launch(Ruote.define { alpha }) }
290
+
291
+ while @engine.storage_participant.size < n; sleep 0.100; end
292
+ sleep 0.100
293
+
294
+ @engine.ps(@engine.storage_participant.first.wfid).expressions.each do |exp|
295
+ @engine.storage.delete(exp.h)
296
+ end
297
+ # nuking all the expressions of a process instance
298
+
299
+ assert_equal n - 1, @engine.processes.size
300
+ assert_equal n, @engine.storage_participant.size
301
+ # orphan workitem left in storage
302
+
303
+ assert_equal 1, @engine.leftovers.size
304
+ end
305
+
306
+ def test_left_overs
307
+
308
+ [
309
+ { '_id' => '0!f!x', 'type' => 'workitems', 'fei' => { 'wfid' => 'x' } },
310
+ { '_id' => '0!f!y', 'type' => 'errors', 'fei' => { 'wfid' => 'y' } },
311
+ { '_id' => '0!f!a', 'type' => 'workitems', 'fei' => { 'wfid' => 'a' } },
312
+ { '_id' => '0!f!a', 'type' => 'expressions', 'fei' => { 'wfid' => 'a' } },
313
+ { '_id' => '0!f!z', 'type' => 'schedules', 'fei' => { 'wfid' => 'z' },
314
+ 'at' => Ruote.time_to_utc_s(Time.now + 24 * 3600) }
315
+ ].each do |doc|
316
+ @engine.storage.put(doc)
317
+ end
318
+
319
+ assert_equal(
320
+ 3,
321
+ @engine.leftovers.size)
322
+ assert_equal(
323
+ %w[ workitems errors schedules ],
324
+ @engine.leftovers.collect { |lo| lo['type'] })
325
+ end
326
+
318
327
  def test_tree_rewrite
319
328
 
320
329
  pdef = Ruote.process_definition :name => 'test' do
@@ -326,9 +335,6 @@ class FtProcessStatusTest < Test::Unit::TestCase
326
335
  delta
327
336
  end
328
337
 
329
- tree0 = nil
330
- tree1 = nil
331
-
332
338
  @engine.register_participant :alpha do |wi, fexp|
333
339
 
334
340
  @tracer << "a\n"
@@ -344,11 +350,11 @@ class FtProcessStatusTest < Test::Unit::TestCase
344
350
  end
345
351
  @engine.register_participant :charly do |wi, fexp|
346
352
  @tracer << "c\n"
347
- tree0 = fexp.context.engine.process(fexp.fei.wfid).current_tree
353
+ stash[:tree0] = fexp.context.engine.process(fexp.fei.wfid).current_tree
348
354
  end
349
355
  @engine.register_participant :delta do |wi, fexp|
350
356
  @tracer << "d\n"
351
- tree1 = fexp.context.engine.process(fexp.fei.wfid).current_tree
357
+ stash[:tree1] = fexp.context.engine.process(fexp.fei.wfid).current_tree
352
358
  end
353
359
 
354
360
  #noisy
@@ -357,11 +363,11 @@ class FtProcessStatusTest < Test::Unit::TestCase
357
363
 
358
364
  assert_equal(
359
365
  ["define", {"name"=>"test"}, [["sequence", {}, [["alpha", {}, []], ["charly", {}, []], ["participant", {"ref"=>"charly"}, []]]], ["delta", {}, []]]],
360
- tree0)
366
+ @engine.context.stash[:tree0])
361
367
 
362
368
  assert_equal(
363
369
  ["define", {"name"=>"test"}, [["sequence", {}, [["alpha", {}, []], ["charly", {}, []], ["charly", {}, []]]], ["participant", {"ref"=>"delta"}, []]]],
364
- tree1)
370
+ @engine.context.stash[:tree1])
365
371
  end
366
372
 
367
373
  def test_when_on_cancel_subprocess
@@ -375,7 +381,7 @@ class FtProcessStatusTest < Test::Unit::TestCase
375
381
  end
376
382
  end
377
383
 
378
- alpha = @engine.register_participant :alpha, Ruote::HashParticipant.new
384
+ alpha = @engine.register_participant :alpha, Ruote::StorageParticipant
379
385
 
380
386
  #noisy
381
387
 
@@ -386,9 +392,10 @@ class FtProcessStatusTest < Test::Unit::TestCase
386
392
  @engine.cancel_process(wfid)
387
393
 
388
394
  wait_for(:alpha)
395
+ wait_for(1)
389
396
 
390
397
  assert_match wfid, alpha.first.fei.wfid
391
- assert_not_nil alpha.first.fei.sub_wfid
398
+ assert_not_nil alpha.first.fei.subid
392
399
 
393
400
  assert_equal 0, @engine.process(wfid).errors.size
394
401
  assert_equal 4, @engine.process(wfid).expressions.size
@@ -416,7 +423,7 @@ class FtProcessStatusTest < Test::Unit::TestCase
416
423
 
417
424
  #noisy
418
425
 
419
- alpha = @engine.register_participant :alpha, Ruote::HashParticipant.new
426
+ alpha = @engine.register_participant :alpha, Ruote::StorageParticipant
420
427
 
421
428
  wfid = @engine.launch(pdef)
422
429
 
@@ -442,7 +449,7 @@ class FtProcessStatusTest < Test::Unit::TestCase
442
449
  end
443
450
  end
444
451
 
445
- alpha = @engine.register_participant :alpha, Ruote::HashParticipant.new
452
+ alpha = @engine.register_participant :alpha, Ruote::StorageParticipant
446
453
 
447
454
  wfid = @engine.launch(pdef)
448
455
 
@@ -454,20 +461,24 @@ class FtProcessStatusTest < Test::Unit::TestCase
454
461
  #puts ps.to_dot
455
462
 
456
463
  dot = ps.to_dot
457
- dot = dot.gsub(wfid, 'wfid').strip
464
+
465
+ dot = dot.gsub(wfid, 'wfid')
466
+ dot = dot.gsub(/![^!]+!/, '!!')
467
+ dot = dot.gsub(/wfid [^ ]+ /, 'wfid ')
468
+ dot = dot.strip
458
469
 
459
470
  assert_equal(
460
471
  %{
461
- digraph "process wfid wfid" {
462
- "0!!wfid" [ label="wfid 0 define" ];
472
+ digraph "process wfid {
473
+ "0!!wfid" [ label="wfid 0 define" ];
463
474
  "0!!wfid" -> "0_0!!wfid";
464
- "0_0!!wfid" [ label="wfid 0_0 concurrence" ];
475
+ "0_0!!wfid" [ label="wfid 0_0 concurrence" ];
465
476
  "0_0!!wfid" -> "0!!wfid";
466
477
  "0_0!!wfid" -> "0_0_0!!wfid";
467
478
  "0_0!!wfid" -> "0_0_1!!wfid";
468
- "0_0_0!!wfid" [ label="wfid 0_0_0 participant" ];
479
+ "0_0_0!!wfid" [ label="wfid 0_0_0 participant" ];
469
480
  "0_0_0!!wfid" -> "0_0!!wfid";
470
- "0_0_1!!wfid" [ label="wfid 0_0_1 participant" ];
481
+ "0_0_1!!wfid" [ label="wfid 0_0_1 participant" ];
471
482
  "0_0_1!!wfid" -> "0_0!!wfid";
472
483
  "err_0_0_1!!wfid" [ label = "error : #<ArgumentError: no participant named 'bravo'>" ];
473
484
  "err_0_0_1!!wfid" -> "0_0_1!!wfid" [ style = "dotted" ];
@@ -513,14 +524,33 @@ digraph "process wfid wfid" {
513
524
  @engine.wait_for(:alpha)
514
525
 
515
526
  assert_equal(
516
- [ [ "0_0!!#{wfid}", 'alpha', { 'task' => 'clean car' } ] ],
517
- @engine.process(wfid).position)
527
+ [ [ 'alpha', { 'task' => 'clean car' } ] ],
528
+ @engine.process(wfid).position.collect { |pos| pos[1..-1] })
518
529
 
519
530
  # #position leverages #workitems
520
531
 
521
532
  assert_equal(
522
- [ 'alpha' ],
523
- @engine.process(wfid).workitems.collect { |wi| wi.participant_name })
533
+ [ [ wfid, 'alpha' ] ],
534
+ @engine.process(wfid).workitems.collect { |wi|
535
+ [ wi.fei.wfid, wi.participant_name ]
536
+ })
537
+ end
538
+
539
+ def test_position_when_error
540
+
541
+ pdef = Ruote.define do
542
+ participant
543
+ end
544
+
545
+ wfid = @engine.launch(pdef)
546
+ @engine.wait_for(wfid)
547
+
548
+ assert_equal 1, @engine.process(wfid).errors.size
549
+
550
+ assert_equal(
551
+ [ [ nil,
552
+ { 'error' => '#<ArgumentError: no participant name specified>' } ] ],
553
+ @engine.process(wfid).position.collect { |pos| pos[1..-1] })
524
554
  end
525
555
 
526
556
  def test_ps_with_stored_workitems
@@ -559,7 +589,7 @@ digraph "process wfid wfid" {
559
589
  assert_equal 1, @engine.schedules(:count => true)
560
590
  end
561
591
 
562
- def test_ps_and_schedules
592
+ def test_processes_and_schedules
563
593
 
564
594
  @engine.register_participant '.+', Ruote::NullParticipant
565
595
 
@@ -571,7 +601,7 @@ digraph "process wfid wfid" {
571
601
  ps = @engine.process(wfid)
572
602
 
573
603
  assert_equal 1, ps.schedules.size
574
- assert_equal "0_0!!#{wfid}", ps.schedules.first['target'].sid
604
+ assert_match /^0_0![a-f0-9]+!#{wfid}$/, ps.schedules.first['target'].sid
575
605
  end
576
606
 
577
607
  def test_ps_pagination
@@ -592,6 +622,12 @@ digraph "process wfid wfid" {
592
622
  wfids,
593
623
  @engine.processes.collect { |ps| ps.wfid })
594
624
 
625
+ assert_equal(
626
+ wfids,
627
+ @engine.processes(:test => :garbage).collect { |ps| ps.wfid })
628
+ # prompted by
629
+ # http://groups.google.com/group/openwferu-users/browse_thread/thread/ee493bdf8d8cdb37
630
+
595
631
  assert_equal(
596
632
  wfids[0, 3],
597
633
  @engine.processes(:limit => 3).collect { |ps| ps.wfid })
@@ -631,11 +667,51 @@ digraph "process wfid wfid" {
631
667
  end
632
668
  end
633
669
 
634
- @engine.launch(pdef)
670
+ #noisy
671
+
672
+ wfid = @engine.launch(pdef)
673
+
674
+ @engine.wait_for(4)
675
+
676
+ #assert_equal 1, @engine.processes.size
677
+ assert_equal [ wfid ], @engine.processes.collect { |ps| ps.wfid }
678
+ end
679
+
680
+ def test_ps
681
+
682
+ @engine.register 'alpha', Ruote::NullParticipant
683
+
684
+ wfid = nil
685
+
686
+ 2.times { wfid = @engine.launch(Ruote.define { alpha }) }
687
+
688
+ @engine.wait_for(4)
689
+
690
+ assert_equal 2, @engine.ps.size
691
+ assert_equal wfid, @engine.ps(wfid).wfid
692
+ end
693
+
694
+ def test_definition_name
695
+
696
+ pdef = Ruote.process_definition :name => 'invictus' do
697
+ alpha
698
+ end
699
+
700
+ #noisy
701
+
702
+ alpha = @engine.register_participant :alpha, Ruote::NullParticipant
703
+
704
+ wfid = @engine.launch(pdef)
705
+
706
+ wait_for(:alpha)
707
+
708
+ assert_equal 'invictus', @engine.process(wfid).definition_name
635
709
 
636
- sleep 0.400
710
+ exp = @engine.process(wfid).expressions.first
711
+ @engine.storage.delete(exp.h)
637
712
 
638
- assert_equal 1, @engine.processes.size
713
+ assert_nil @engine.process(wfid).definition_name
714
+ assert_nil @engine.process(wfid).definition_revision
639
715
  end
640
716
  end
641
717