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,7 +7,7 @@
7
7
 
8
8
  require File.join(File.dirname(__FILE__), 'base')
9
9
 
10
- require 'ruote/part/hash_participant'
10
+ require 'ruote/participant'
11
11
 
12
12
 
13
13
  class FtErrorsTest < Test::Unit::TestCase
@@ -137,12 +137,12 @@ class FtErrorsTest < Test::Unit::TestCase
137
137
  end
138
138
  end
139
139
 
140
- count = 0
140
+ @engine.context.stash[:count] = 0
141
141
 
142
142
  @engine.register_participant :alpha do
143
- count += 1
143
+ stash[:count] += 1
144
144
  @tracer << "alpha\n"
145
- raise "something went wrong" if count == 1
145
+ raise "something went wrong" if stash[:count] == 1
146
146
  end
147
147
 
148
148
  #noisy
@@ -173,14 +173,15 @@ class FtErrorsTest < Test::Unit::TestCase
173
173
  end
174
174
  end
175
175
 
176
- count = 0
176
+ @engine.context.stash[:count] = 0
177
177
 
178
- alpha = @engine.register_participant :alpha do
179
- count += 1
178
+ alpha = @engine.register_participant :alpha, 'do_not_thread' => true do
179
+ stash[:count] += 1
180
180
  @tracer << "alpha\n"
181
- raise "something went wrong" if count == 1
181
+ raise "something went wrong" if stash[:count] == 1
182
182
  end
183
- alpha.do_not_thread = true
183
+
184
+ #noisy
184
185
 
185
186
  wfid = @engine.launch(pdef)
186
187
 
@@ -200,15 +201,15 @@ class FtErrorsTest < Test::Unit::TestCase
200
201
  class WeakCancelParticipant
201
202
  include Ruote::LocalParticipant
202
203
 
203
- def initialize (opts)
204
+ def initialize(opts)
204
205
  end
205
- def consume (workitem)
206
+ def consume(workitem)
206
207
  # losing it
207
208
  end
208
209
  def do_not_thread
209
210
  true
210
211
  end
211
- def cancel (fei, flavour)
212
+ def cancel(fei, flavour)
212
213
  raise "failure in #cancel"
213
214
  end
214
215
  end
@@ -256,14 +257,13 @@ class FtErrorsTest < Test::Unit::TestCase
256
257
  end
257
258
  end
258
259
 
259
- count = 0
260
+ @engine.context.stash[:count] = 0
260
261
 
261
- alpha = @engine.register_participant :alpha do
262
- count += 1
262
+ alpha = @engine.register_participant :alpha, :do_not_thread => true do
263
+ stash[:count] += 1
263
264
  @tracer << "alpha\n"
264
- raise "something went wrong" if count == 1
265
+ raise "something went wrong" if stash[:count] == 1
265
266
  end
266
- alpha.do_not_thread = true
267
267
 
268
268
  #noisy
269
269
 
@@ -278,7 +278,7 @@ class FtErrorsTest < Test::Unit::TestCase
278
278
  err = ps.errors.first
279
279
 
280
280
  assert_equal wfid, err.fei.wfid
281
- assert_not_nil err.fei.sub_wfid
281
+ assert_not_nil err.fei.subid
282
282
 
283
283
  @engine.replay_at_error(err)
284
284
 
@@ -337,22 +337,6 @@ class FtErrorsTest < Test::Unit::TestCase
337
337
  assert_nil @engine.process(wfid)
338
338
  end
339
339
 
340
- #def test_ps_to_h
341
- # pdef = Ruote.process_definition do
342
- # error 'nada'
343
- # end
344
- # #noisy
345
- # wfid = @engine.launch(pdef)
346
- # wait_for(wfid)
347
- # ps = @engine.process(wfid)
348
- # es = ps.to_h['errors']
349
- # e = es.first
350
- # assert_equal 1, es.size
351
- # assert_equal 'reply', e['msg']['action']
352
- # assert_equal wfid, e['msg']['fei']['wfid']
353
- # assert_equal 8, e.size
354
- #end
355
-
356
340
  def test_error_intercepted
357
341
 
358
342
  pdef = Ruote.process_definition do
@@ -363,9 +347,9 @@ class FtErrorsTest < Test::Unit::TestCase
363
347
 
364
348
  r = @engine.wait_for(wfid)
365
349
 
366
- assert_equal 'RuntimeError', r['error_class']
367
- assert_equal "unknown participant or subprocess 'nada'", r['error_message']
368
- assert_equal Array, r['error_backtrace'].class
350
+ assert_equal 'RuntimeError', r['error']['class']
351
+ assert_equal "unknown participant or subprocess 'nada'", r['error']['message']
352
+ assert_equal Array, r['error']['trace'].class
369
353
  end
370
354
  end
371
355
 
@@ -18,7 +18,7 @@ class NftSmtpParticipantTest < Test::Unit::TestCase
18
18
  require 'mailtrap' # sudo gem install mailtrap
19
19
 
20
20
  class Trap < ::Mailtrap
21
- def puts (s)
21
+ def puts(s)
22
22
  # silent night...
23
23
  end
24
24
  end
@@ -30,12 +30,14 @@ class FtPartBlockingTest < Test::Unit::TestCase
30
30
 
31
31
  protected
32
32
 
33
- def run_engine (options={})
33
+ def run_engine(options={})
34
34
 
35
- first_time = options[:first_time] || 0.0
36
- second_time = options[:second_time] || 0.0
35
+ @engine.context.stash[:first_time] = options[:first_time] || 0.0
36
+ @engine.context.stash[:second_time] = options[:second_time] || 0.0
37
37
 
38
- second_time = first_time + 0.1 if first_time == second_time
38
+ if @engine.context.stash[:first_time] == @engine.context.stash[:second_time]
39
+ @engine.context.stash[:second_time] = @engine.context.stash[:first_time] + 0.1
40
+ end
39
41
 
40
42
  pdef = Ruote.process_definition :name => 'simple' do
41
43
  sequence do
@@ -48,12 +50,12 @@ class FtPartBlockingTest < Test::Unit::TestCase
48
50
  end
49
51
 
50
52
  @engine.register_participant :first do |wi|
51
- sleep first_time
53
+ sleep stash[:first_time]
52
54
  wi.fields['result'] = 'first'
53
55
  end
54
56
 
55
57
  @engine.register_participant :second do |wi|
56
- sleep second_time
58
+ sleep stash[:second_time]
57
59
  wi.fields['result'] = 'second'
58
60
  end
59
61
 
@@ -7,7 +7,7 @@
7
7
 
8
8
  require File.join(File.dirname(__FILE__), 'base')
9
9
 
10
- require 'ruote/part/hash_participant'
10
+ require 'ruote/participant'
11
11
 
12
12
  #
13
13
  # testing forced rewinding
@@ -25,9 +25,9 @@ class FtCursorRewindTest < Test::Unit::TestCase
25
25
  end
26
26
  end
27
27
 
28
- alpha = @engine.register_participant :alpha, Ruote::HashParticipant.new
29
- bravo = @engine.register_participant :bravo, Ruote::HashParticipant.new
30
- charly = @engine.register_participant :charly, Ruote::HashParticipant.new
28
+ alpha = @engine.register_participant :alpha, Ruote::StorageParticipant
29
+ bravo = @engine.register_participant :bravo, Ruote::StorageParticipant
30
+ charly = @engine.register_participant :charly, Ruote::StorageParticipant
31
31
 
32
32
  #noisy
33
33
 
@@ -64,9 +64,9 @@ class FtCursorRewindTest < Test::Unit::TestCase
64
64
  end
65
65
  end
66
66
 
67
- alpha = @engine.register_participant :alpha, Ruote::HashParticipant.new
68
- bravo = @engine.register_participant :bravo, Ruote::HashParticipant.new
69
- charly = @engine.register_participant :charly, Ruote::HashParticipant.new
67
+ @engine.register_participant :alpha, Ruote::StorageParticipant
68
+ @engine.register_participant :bravo, Ruote::StorageParticipant
69
+ sto = @engine.register_participant :charly, Ruote::StorageParticipant
70
70
 
71
71
  #noisy
72
72
 
@@ -76,16 +76,19 @@ class FtCursorRewindTest < Test::Unit::TestCase
76
76
  wfid = @engine.launch(pdef)
77
77
  wait_for(:alpha)
78
78
 
79
- alpha.reply(alpha.first)
79
+ sto.reply(sto.first)
80
80
  wait_for(:bravo)
81
81
 
82
82
  #
83
83
  # rewinding...
84
84
 
85
- wi = bravo.first
85
+ wi = sto.first
86
86
 
87
- wi.h['fei']['expid'] = wi.h['fei']['expid'][0..-3] # parent wfid
87
+ exp = @engine.process(wfid).expressions.find { |e| e.name == 'cursor' }
88
+ wi.h['fei'] = exp.h.fei
88
89
  wi.fields['__command__'] = [ 'jump', 'alpha' ]
90
+ #
91
+ # passing the "jump alpha" command to the cursor directly
89
92
 
90
93
  @engine.reply(wi)
91
94
 
@@ -15,7 +15,7 @@ class FtAddServiceTest < Test::Unit::TestCase
15
15
 
16
16
  attr_reader :context, :options
17
17
 
18
- def initialize (context, options={})
18
+ def initialize(context, options={})
19
19
 
20
20
  @context = context
21
21
  @options = options
@@ -28,7 +28,7 @@ class FtStorageHistoryTest < Test::Unit::TestCase
28
28
 
29
29
  #noisy
30
30
 
31
- wfid0 = assert_trace("done.", pdef)
31
+ wfid0 = assert_trace('done.', pdef)
32
32
  wfid1 = assert_trace("done.\ndone.", pdef)
33
33
 
34
34
  sleep 0.100
@@ -87,5 +87,28 @@ class FtStorageHistoryTest < Test::Unit::TestCase
87
87
  Time.parse('2010-01-08 00:00:00 UTC') ],
88
88
  @engine.context.history.range)
89
89
  end
90
+
91
+ def test_engine_dot_history
92
+
93
+ @engine.add_service(
94
+ 'history', 'ruote/log/storage_history', 'Ruote::StorageHistory')
95
+
96
+ assert_equal Ruote::StorageHistory, @engine.history.class
97
+ end
98
+
99
+ def test_wfids
100
+
101
+ @engine.add_service(
102
+ 'history', 'ruote/log/storage_history', 'Ruote::StorageHistory')
103
+
104
+ @engine.register_participant 'alpha', Ruote::NullParticipant
105
+
106
+ 3.times do
107
+ @engine.launch(Ruote.define { alpha })
108
+ @engine.wait_for(:alpha)
109
+ end
110
+
111
+ assert_equal 3, @engine.history.wfids.size
112
+ end
90
113
  end
91
114
 
@@ -0,0 +1,109 @@
1
+
2
+ #
3
+ # testing ruote
4
+ #
5
+ # Mon Jan 24 11:11:43 JST 2011
6
+ #
7
+
8
+ require File.join(File.dirname(__FILE__), 'base')
9
+
10
+
11
+ class FtDefaultHistoryTest < Test::Unit::TestCase
12
+ include FunctionalBase
13
+
14
+ def test_engine_has_history
15
+
16
+ assert_not_nil @engine.context.history
17
+ assert_not_nil @engine.history
18
+ end
19
+
20
+ def launch_processes(clear=true)
21
+
22
+ @engine.history.clear! if clear
23
+
24
+ @engine.register_participant 'alpha', Ruote::NullParticipant
25
+
26
+ pdef = Ruote.define do
27
+ alpha
28
+ end
29
+
30
+ wfids = 2.times.collect { @engine.launch(pdef) }
31
+
32
+ @engine.wait_for(:alpha)
33
+ @engine.wait_for(:alpha)
34
+ sleep 0.700
35
+
36
+ wfids
37
+ end
38
+
39
+ def test_all
40
+
41
+ #noisy
42
+
43
+ wfids = launch_processes
44
+
45
+ assert_equal 9, @engine.history.all.size
46
+ end
47
+
48
+ def test_by_wfid
49
+
50
+ wfids = launch_processes
51
+
52
+ assert_equal 4, @engine.history.by_wfid(wfids[0]).size
53
+ assert_not_nil @engine.history.by_wfid(wfids[0]).first['seen_at']
54
+
55
+ assert_equal 4, @engine.history.by_wfid(wfids[1]).size
56
+ end
57
+
58
+ def test_clear!
59
+
60
+ launch_processes
61
+
62
+ assert_equal 9, @engine.history.all.size
63
+
64
+ @engine.history.clear!
65
+
66
+ assert_equal 0, @engine.history.all.size
67
+ end
68
+
69
+ def test_default_range
70
+
71
+ range = @engine.history.range
72
+
73
+ assert_equal Time, range[0].class
74
+ assert_equal range[0], range[1]
75
+ end
76
+
77
+ def test_range
78
+
79
+ launch_processes
80
+ sleep 1
81
+ launch_processes(false)
82
+
83
+ range = @engine.history.range
84
+
85
+ assert_not_equal range[0], range[1]
86
+ assert range[0] < range[1]
87
+ end
88
+
89
+ def test_by_date
90
+
91
+ launch_processes
92
+
93
+ @engine.history.all.each { |msg| msg['seen_at'] = '1970-12-25' }
94
+
95
+ launch_processes(false)
96
+
97
+ assert_equal 18, @engine.history.all.size
98
+
99
+ assert_equal 9, @engine.history.by_date(Time.now).size
100
+ end
101
+
102
+ def test_wfids
103
+
104
+ wfids = launch_processes
105
+
106
+ assert_equal wfids.sort, @engine.history.wfids
107
+ end
108
+ end
109
+
@@ -17,9 +17,9 @@ class FtParticipantMoreTest < Test::Unit::TestCase
17
17
 
18
18
  class DifficultParticipant
19
19
  include Ruote::LocalParticipant
20
- def initialize (opts)
20
+ def initialize(opts)
21
21
  end
22
- def consume (workitem)
22
+ def consume(workitem)
23
23
  context.tracer << "diff\n"
24
24
  if workitem.fields['rejected'].nil?
25
25
  workitem.fields['rejected'] = true
@@ -47,9 +47,9 @@ class FtParticipantMoreTest < Test::Unit::TestCase
47
47
 
48
48
  class FightingParticipant
49
49
  include Ruote::LocalParticipant
50
- def initialize (opts)
50
+ def initialize(opts)
51
51
  end
52
- def consume (workitem)
52
+ def consume(workitem)
53
53
  try = workitem.fields['try'] || 0
54
54
  context.tracer << "try#{try}\n"
55
55
  workitem.fields['try'] = try + 1
@@ -78,10 +78,10 @@ class FtParticipantMoreTest < Test::Unit::TestCase
78
78
 
79
79
  class RetryParticipant
80
80
  include Ruote::LocalParticipant
81
- def initialize (opts)
81
+ def initialize(opts)
82
82
  @opts = opts
83
83
  end
84
- def consume (workitem)
84
+ def consume(workitem)
85
85
  try = workitem.fields['try'] || 0
86
86
  context.tracer << "#{Time.now.to_f}\n"
87
87
  workitem.fields['try'] = try + 1
@@ -91,7 +91,7 @@ class FtParticipantMoreTest < Test::Unit::TestCase
91
91
  reply(workitem)
92
92
  end
93
93
  end
94
- def cancel (fei, flavour)
94
+ def cancel(fei, flavour)
95
95
  unschedule_re_dispatch(fei)
96
96
  end
97
97
  end
@@ -147,12 +147,12 @@ class FtParticipantMoreTest < Test::Unit::TestCase
147
147
 
148
148
  class StashingParticipant
149
149
  include Ruote::LocalParticipant
150
- def initialize (opts)
150
+ def initialize(opts)
151
151
  end
152
- def consume (workitem)
152
+ def consume(workitem)
153
153
  put(workitem.fei, 'token' => workitem.params['token'])
154
154
  end
155
- def cancel (fei, flavour)
155
+ def cancel(fei, flavour)
156
156
  BLACKBOARD['token'] = get(fei, 'token')
157
157
  BLACKBOARD['all'] = get(fei)
158
158
  end
@@ -25,16 +25,18 @@ class FtWaitForTest < Test::Unit::TestCase
25
25
 
26
26
  wfid = @engine.launch(pdef)
27
27
 
28
- wait_for(:alpha)
28
+ r = wait_for(:alpha)
29
29
 
30
- assert_equal Ruote::Workitem, @engine.workitem("0_0!!#{wfid}").class
30
+ assert_equal(
31
+ Ruote::Workitem,
32
+ @engine.workitem(Ruote.sid(r['fei'])).class)
31
33
  end
32
34
 
33
35
  class MyParticipant
34
36
  include Ruote::LocalParticipant
35
- def initialize (opts)
37
+ def initialize(opts)
36
38
  end
37
- def consume (workitem)
39
+ def consume(workitem)
38
40
  sleep rand * 2
39
41
  reply_to_engine(workitem)
40
42
  end
@@ -108,12 +110,13 @@ class FtWaitForTest < Test::Unit::TestCase
108
110
  wfid = @engine.launch(pdef)
109
111
 
110
112
  seen = []
113
+ threads = []
111
114
 
112
- Thread.new do
115
+ threads << Thread.new do
113
116
  @engine.wait_for(wfid)
114
117
  seen << 'this'
115
118
  end
116
- Thread.new do
119
+ threads << Thread.new do
117
120
  @engine.wait_for(wfid)
118
121
  seen << 'that'
119
122
  end
@@ -122,9 +125,9 @@ class FtWaitForTest < Test::Unit::TestCase
122
125
 
123
126
  sp.reply(sp.first)
124
127
 
125
- @engine.wait_for(wfid)
126
-
127
- sleep 0.100
128
+ threads.each do |t|
129
+ t.join
130
+ end
128
131
 
129
132
  assert_equal %w[ that this ], seen.sort
130
133
  assert_equal [], @engine.context.logger.instance_variable_get(:@waiting)