ruote 2.1.7 → 2.1.8

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 (74) hide show
  1. data/CHANGELOG.txt +13 -0
  2. data/CREDITS.txt +2 -1
  3. data/Rakefile +4 -3
  4. data/TODO.txt +11 -1
  5. data/lib/ruote/exp/fe_concurrence.rb +26 -2
  6. data/lib/ruote/exp/fe_participant.rb +1 -1
  7. data/lib/ruote/exp/merge.rb +16 -9
  8. data/lib/ruote/fei.rb +1 -1
  9. data/lib/ruote/parser.rb +2 -1
  10. data/lib/ruote/part/smtp_participant.rb +22 -41
  11. data/lib/ruote/part/storage_participant.rb +20 -1
  12. data/lib/ruote/part/template.rb +34 -18
  13. data/lib/ruote/storage/base.rb +2 -20
  14. data/lib/ruote/storage/composite_storage.rb +134 -0
  15. data/lib/ruote/storage/fs_storage.rb +15 -1
  16. data/lib/ruote/util/dollar.rb +1 -0
  17. data/lib/ruote/util/misc.rb +5 -1
  18. data/lib/ruote/util/time.rb +13 -3
  19. data/lib/ruote/version.rb +1 -1
  20. data/lib/ruote/worker.rb +2 -2
  21. data/ruote.gemspec +18 -12
  22. data/test/bm/seq_thousand.rb +1 -1
  23. data/test/functional/base.rb +6 -8
  24. data/test/functional/crunner.rb +2 -0
  25. data/test/functional/eft_0_process_definition.rb +2 -2
  26. data/test/functional/eft_10_cancel_process.rb +2 -2
  27. data/test/functional/eft_11_wait.rb +3 -3
  28. data/test/functional/eft_12_listen.rb +1 -1
  29. data/test/functional/eft_13_iterator.rb +14 -14
  30. data/test/functional/eft_14_cursor.rb +12 -12
  31. data/test/functional/eft_15_loop.rb +2 -2
  32. data/test/functional/eft_16_if.rb +11 -15
  33. data/test/functional/eft_17_equals.rb +2 -2
  34. data/test/functional/eft_18_concurrent_iterator.rb +35 -8
  35. data/test/functional/eft_1_echo.rb +1 -1
  36. data/test/functional/eft_21_restore.rb +3 -3
  37. data/test/functional/eft_22_noop.rb +1 -1
  38. data/test/functional/eft_23_apply.rb +9 -9
  39. data/test/functional/eft_25_command.rb +1 -1
  40. data/test/functional/eft_27_inc.rb +12 -12
  41. data/test/functional/eft_28_when.rb +4 -4
  42. data/test/functional/eft_2_sequence.rb +3 -3
  43. data/test/functional/eft_3_participant.rb +5 -5
  44. data/test/functional/eft_4_set.rb +12 -12
  45. data/test/functional/eft_5_subprocess.rb +8 -8
  46. data/test/functional/eft_6_concurrence.rb +17 -4
  47. data/test/functional/eft_7_forget.rb +1 -1
  48. data/test/functional/eft_8_undo.rb +3 -3
  49. data/test/functional/ft_0_worker.rb +17 -1
  50. data/test/functional/ft_10_dollar.rb +9 -9
  51. data/test/functional/ft_11_recursion.rb +2 -2
  52. data/test/functional/ft_13_variables.rb +4 -4
  53. data/test/functional/ft_17_conditional.rb +5 -5
  54. data/test/functional/ft_19_alias.rb +1 -1
  55. data/test/functional/ft_1_process_status.rb +1 -1
  56. data/test/functional/ft_20_storage_participant.rb +2 -0
  57. data/test/functional/ft_22_process_definitions.rb +11 -4
  58. data/test/functional/ft_24_block_participants.rb +13 -4
  59. data/test/functional/ft_27_var_indirection.rb +5 -5
  60. data/test/functional/ft_28_null_noop_participants.rb +1 -1
  61. data/test/functional/ft_29_part_template.rb +4 -23
  62. data/test/functional/ft_30_smtp_participant.rb +50 -4
  63. data/test/functional/ft_32_fs_history.rb +4 -8
  64. data/test/functional/ft_33_participant_subprocess_priority.rb +1 -1
  65. data/test/functional/ft_36_storage_history.rb +2 -2
  66. data/test/functional/ft_5_on_error.rb +5 -5
  67. data/test/functional/ft_8_participant_consumption.rb +2 -2
  68. data/test/path_helper.rb +1 -1
  69. data/test/test_helper.rb +17 -0
  70. data/test/unit/storage.rb +2 -17
  71. data/test/unit/ut_19_part_template.rb +76 -0
  72. data/test/unit/ut_1_fei.rb +13 -0
  73. data/test/unit/ut_20_composite_storage.rb +34 -0
  74. metadata +111 -55
@@ -45,7 +45,7 @@ class FtNullNoopParticipantsTest < Test::Unit::TestCase
45
45
 
46
46
  #noisy
47
47
 
48
- assert_trace pdef, "done."
48
+ assert_trace "done.", pdef
49
49
  end
50
50
  end
51
51
 
@@ -20,14 +20,15 @@ class FtPartTemplateTest < Test::Unit::TestCase
20
20
 
21
21
  def initialize (opts={}, &block)
22
22
 
23
- @block_template = block
24
23
  @template = opts[:template]
25
24
  end
26
25
 
27
26
  def consume (workitem)
28
27
 
29
28
  @context['s_tracer'] << render_template(
30
- Ruote::Exp::FlowExpression.fetch(@context, workitem.fei.to_h), workitem)
29
+ @template,
30
+ Ruote::Exp::FlowExpression.fetch(@context, workitem.fei.to_h),
31
+ workitem)
31
32
  @context['s_tracer'] << "\n"
32
33
 
33
34
  reply_to_engine(workitem)
@@ -52,27 +53,7 @@ class FtPartTemplateTest < Test::Unit::TestCase
52
53
  :alpha,
53
54
  MyParticipant.new(:template => "0:${v:var0}\n1:${f:field0}"))
54
55
 
55
- assert_trace pdef, %w[ 0:v_value 1:f_value done. ]
56
- end
57
-
58
- def test_block_template
59
-
60
- pdef = Ruote.process_definition :name => 'def0' do
61
- set 'v:var0' => 'v_value'
62
- set 'f:field0' => 'f_value'
63
- alpha
64
- echo 'done.'
65
- end
66
-
67
- #noisy
68
-
69
- @engine.register_participant(
70
- :alpha,
71
- MyParticipant.new {
72
- "0:${v:var0}\n1:${f:field0}"
73
- })
74
-
75
- assert_trace pdef, %w[ 0:v_value 1:f_value done. ]
56
+ assert_trace %w[ 0:v_value 1:f_value done. ], pdef
76
57
  end
77
58
  end
78
59
 
@@ -13,7 +13,7 @@ require 'ruote/part/smtp_participant'
13
13
  class NftSmtpParticipantTest < Test::Unit::TestCase
14
14
  include FunctionalBase
15
15
 
16
- if RUBY_PLATFORM != 'java'
16
+ unless Ruote::JAVA
17
17
 
18
18
  require 'mailtrap' # sudo gem install mailtrap
19
19
 
@@ -24,9 +24,9 @@ class NftSmtpParticipantTest < Test::Unit::TestCase
24
24
  end
25
25
  end
26
26
 
27
- def test_smtp
27
+ def _test_smtp
28
28
 
29
- return if RUBY_PLATFORM == 'java'
29
+ return if Ruote::JAVA
30
30
 
31
31
  pdef = Ruote.process_definition :name => 'test' do
32
32
  sequence do
@@ -38,7 +38,7 @@ class NftSmtpParticipantTest < Test::Unit::TestCase
38
38
  trapfile = Ruote::WIN ? 'ruote_mailtrap.txt' : '/tmp/ruote_mailtrap.txt'
39
39
  FileUtils.rm_f(trapfile)
40
40
 
41
- Thread.new do
41
+ t = Thread.new do
42
42
  Trap.new('127.0.0.1', 2525, true, trapfile)
43
43
  end
44
44
  sleep 0.040
@@ -64,6 +64,52 @@ class NftSmtpParticipantTest < Test::Unit::TestCase
64
64
 
65
65
  assert_match(/cat food/, File.read(trapfile))
66
66
  assert_nil @engine.process(wfid)
67
+
68
+ t.kill
69
+ end
70
+
71
+ def test_smtp_non_instance_participant
72
+
73
+ return if Ruote::JAVA
74
+
75
+ pdef = Ruote.process_definition :name => 'test' do
76
+ sequence do
77
+ set 'f:item' => 'cat food'
78
+ alpha
79
+ end
80
+ end
81
+
82
+ trapfile = Ruote::WIN ? 'ruote_mailtrap.txt' : '/tmp/ruote_mailtrap.txt'
83
+ FileUtils.rm_f(trapfile)
84
+
85
+ t = Thread.new do
86
+ Trap.new('127.0.0.1', 2525, true, trapfile)
87
+ end
88
+ sleep 0.040
89
+ # give it some time to start listening
90
+
91
+ @engine.register_participant(
92
+ :alpha,
93
+ Ruote::SmtpParticipant,
94
+ :server => '127.0.0.1',
95
+ :port => 2525,
96
+ :to => 'toto@cloudwhatever.ch',
97
+ :from => 'john@outoftheblue.ch',
98
+ :notification => true,
99
+ :template => %{
100
+ Hello, do you want ${f:item} ?
101
+ })
102
+
103
+ #noisy
104
+
105
+ wfid = @engine.launch(pdef)
106
+
107
+ sleep 0.450
108
+
109
+ assert_match(/cat food/, File.read(trapfile))
110
+ assert_nil @engine.process(wfid)
111
+
112
+ t.kill
67
113
  end
68
114
  end
69
115
 
@@ -7,11 +7,7 @@
7
7
 
8
8
  require File.join(File.dirname(__FILE__), 'base')
9
9
 
10
- begin
11
- require 'yajl'
12
- rescue LoadError
13
- require 'json'
14
- end
10
+ require_json
15
11
  Rufus::Json.detect_backend rescue nil
16
12
 
17
13
  require 'ruote/log/fs_history'
@@ -35,8 +31,8 @@ class FtFsHistoryTest < Test::Unit::TestCase
35
31
 
36
32
  #noisy
37
33
 
38
- wfid0 = assert_trace(pdef, "done.")
39
- wfid1 = assert_trace(pdef, "done.\ndone.")
34
+ wfid0 = assert_trace("done.", pdef)
35
+ wfid1 = assert_trace("done.\ndone.", pdef)
40
36
 
41
37
  sleep 0.100
42
38
 
@@ -81,7 +77,7 @@ class FtFsHistoryTest < Test::Unit::TestCase
81
77
 
82
78
  #noisy
83
79
 
84
- wfid0 = assert_trace(pdef, "done.")
80
+ wfid0 = assert_trace("done.", pdef)
85
81
 
86
82
  sleep 0.100
87
83
 
@@ -26,7 +26,7 @@ class FtParticipantSubprocessPriorityTest < Test::Unit::TestCase
26
26
 
27
27
  #noisy
28
28
 
29
- assert_trace pdef, 'sub0'
29
+ assert_trace 'sub0', pdef
30
30
  end
31
31
  end
32
32
 
@@ -28,8 +28,8 @@ class FtStorageHistoryTest < Test::Unit::TestCase
28
28
 
29
29
  #noisy
30
30
 
31
- wfid0 = assert_trace(pdef, "done.")
32
- wfid1 = assert_trace(pdef, "done.\ndone.")
31
+ wfid0 = assert_trace("done.", pdef)
32
+ wfid1 = assert_trace("done.\ndone.", pdef)
33
33
 
34
34
  sleep 0.100
35
35
 
@@ -25,7 +25,7 @@ class FtOnErrorTest < Test::Unit::TestCase
25
25
 
26
26
  #noisy
27
27
 
28
- assert_trace(pdef, 'caught')
28
+ assert_trace('caught', pdef)
29
29
 
30
30
  assert_equal 1, logger.log.select { |e| e['action'] == 'fail' }.size
31
31
  end
@@ -72,7 +72,7 @@ class FtOnErrorTest < Test::Unit::TestCase
72
72
 
73
73
  #noisy
74
74
 
75
- assert_trace(pdef, %w[ 1 2 done. ])
75
+ assert_trace(%w[ 1 2 done. ], pdef)
76
76
  end
77
77
 
78
78
  def test_on_error_undo
@@ -91,7 +91,7 @@ class FtOnErrorTest < Test::Unit::TestCase
91
91
 
92
92
  #noisy
93
93
 
94
- wfid = assert_trace(pdef, %w[ a b d ])
94
+ wfid = assert_trace(%w[ a b d ], pdef)
95
95
 
96
96
  assert_nil @engine.process(wfid)
97
97
  end
@@ -124,7 +124,7 @@ class FtOnErrorTest < Test::Unit::TestCase
124
124
 
125
125
  #noisy
126
126
 
127
- assert_trace(pdef, 'failed.')
127
+ assert_trace('failed.', pdef)
128
128
  end
129
129
 
130
130
  def test_with_concurrence
@@ -147,7 +147,7 @@ class FtOnErrorTest < Test::Unit::TestCase
147
147
 
148
148
  #noisy
149
149
 
150
- assert_trace pdef, 'done.'
150
+ assert_trace 'done.', pdef
151
151
  assert_equal 1, a_count
152
152
  assert_equal 1, e_count
153
153
  end
@@ -25,7 +25,7 @@ class FtParticipantConsumptionTest < Test::Unit::TestCase
25
25
 
26
26
  #noisy
27
27
 
28
- assert_trace(pdef, 'alpha')
28
+ assert_trace('alpha', pdef)
29
29
 
30
30
  Thread.pass
31
31
  # making sure the reply to the participant expression is intercepted
@@ -69,7 +69,7 @@ class FtParticipantConsumptionTest < Test::Unit::TestCase
69
69
  @tracer << "#{workitem.participant_name} #{workitem.fei.expid}\n"
70
70
  end
71
71
 
72
- assert_trace(pdef, 'alpha 0_0_0')
72
+ assert_trace('alpha 0_0_0', pdef)
73
73
  end
74
74
  end
75
75
 
data/test/path_helper.rb CHANGED
@@ -7,7 +7,7 @@
7
7
 
8
8
  # making sure the tests see ruote
9
9
 
10
- puts "ruby #{RUBY_VERSION} #{RUBY_PLATFORM}"
10
+ puts `ruby -v`
11
11
 
12
12
  ruotelib = File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
13
13
  $:.unshift(ruotelib) unless $:.include?(ruotelib)
data/test/test_helper.rb CHANGED
@@ -10,3 +10,20 @@ require File.join(File.dirname(__FILE__), 'path_helper')
10
10
  require 'test/unit'
11
11
  require 'rubygems'
12
12
 
13
+
14
+ def require_json
15
+ begin
16
+ require 'yajl'
17
+ rescue LoadError
18
+ require 'json'
19
+ end
20
+ end
21
+
22
+ def require_patron
23
+ begin
24
+ require 'patron'
25
+ rescue LoadError
26
+ # stick with net/http
27
+ end
28
+ end
29
+
data/test/unit/storage.rb CHANGED
@@ -7,16 +7,8 @@
7
7
 
8
8
  require File.join(File.dirname(__FILE__), %w[ .. test_helper.rb ])
9
9
 
10
- begin
11
- require 'yajl'
12
- rescue LoadError
13
- require 'json'
14
- end
15
- begin
16
- require 'patron'
17
- rescue LoadError
18
- # stick with net/http
19
- end
10
+ require_json
11
+ require_patron
20
12
 
21
13
  require File.join(File.dirname(__FILE__), %w[ .. functional storage_helper.rb ])
22
14
 
@@ -125,13 +117,6 @@ class UtStorage < Test::Unit::TestCase
125
117
 
126
118
  def test_keys_should_be_string
127
119
 
128
- #begin
129
- # require 'yajl'
130
- #rescue LoadError
131
- # require 'json'
132
- #end
133
- #Rufus::Json.detect_backend
134
-
135
120
  doc = { '_id' => 'h0', 'type' => 'dogfood', :m0 => :z, :m1 => [ :a, :b ] }
136
121
 
137
122
  @s.put(doc)
@@ -0,0 +1,76 @@
1
+
2
+ #
3
+ # testing ruote
4
+ #
5
+ # Thu Mar 4 10:24:30 JST 2010
6
+ #
7
+
8
+ require File.join(File.dirname(__FILE__), '..', 'test_helper.rb')
9
+
10
+ require_json
11
+ require 'ruote/part/template'
12
+
13
+
14
+ class UtPartTemplateTest < Test::Unit::TestCase
15
+
16
+ class MyParticipant
17
+ include ::Ruote::TemplateMixin
18
+ end
19
+
20
+ DEFAULT = %{
21
+ workitem for gonzalo
22
+
23
+ {"wfid":"20100304-bidehachina","expid":"0_0_1"}
24
+
25
+ - 'car' ==> "BMW"
26
+ - 'model' ==> "BMW 328 Mille Miglia"
27
+ }.strip
28
+
29
+ def setup
30
+
31
+ @workitem = {
32
+ 'fei'=> { 'wfid' => '20100304-bidehachina', 'expid' => '0_0_1' },
33
+ 'participant_name' => 'gonzalo',
34
+ 'fields' => {
35
+ 'car' => 'BMW',
36
+ 'model' => 'BMW 328 Mille Miglia'
37
+ }
38
+ }
39
+ end
40
+
41
+ def test_default_template
42
+
43
+ assert_equal(
44
+ DEFAULT,
45
+ MyParticipant.new.render_default_template(@workitem))
46
+
47
+ assert_equal(
48
+ DEFAULT,
49
+ MyParticipant.new.render_template(nil, nil, @workitem))
50
+ end
51
+
52
+ def test_file_template
53
+
54
+ fn = "#{__FILE__}.template"
55
+
56
+ File.open(fn, 'wb') { |f| f.write('the model is ${f:model}') }
57
+
58
+ assert_equal(
59
+ 'the model is BMW 328 Mille Miglia',
60
+ MyParticipant.new.render_template(fn, nil, @workitem))
61
+
62
+ FileUtils.rm_f(fn)
63
+ end
64
+
65
+ def test_string_template
66
+
67
+ template = %{
68
+ My car is a ${f:car}
69
+ }.strip
70
+
71
+ assert_equal(
72
+ 'My car is a BMW',
73
+ MyParticipant.new.render_template(template, nil, @workitem))
74
+ end
75
+ end
76
+
@@ -74,5 +74,18 @@ class UtFeiTest < Test::Unit::TestCase
74
74
  assert_equal f0.hash, f1.hash
75
75
  assert_not_equal f0.hash, f2.hash
76
76
  end
77
+
78
+ def test_from_id
79
+
80
+ assert_equal(
81
+ '0_0_1!!20100224-fake',
82
+ Ruote::FlowExpressionId.from_id('0_0_1!!20100224-fake').to_storage_id)
83
+ assert_equal(
84
+ '0_0_1!!20100224-fake',
85
+ Ruote::FlowExpressionId.from_id('wi!0_0_1!!20100224-fake').to_storage_id)
86
+ assert_equal(
87
+ '0_0_1!!20100224-fake',
88
+ Ruote::FlowExpressionId.from_id('wi!store!0_0_1!!20100224-fake').to_storage_id)
89
+ end
77
90
  end
78
91
 
@@ -0,0 +1,34 @@
1
+
2
+ #
3
+ # testing ruote
4
+ #
5
+ # Sun Mar 14 21:25:52 JST 2010
6
+ #
7
+
8
+ require File.join(File.dirname(__FILE__), '..', 'test_helper.rb')
9
+
10
+ require 'ruote'
11
+ require 'ruote/storage/composite_storage'
12
+
13
+
14
+ class UtCompositeStorageTest < Test::Unit::TestCase
15
+
16
+ def test_initial
17
+
18
+ msgs = Ruote::HashStorage.new({})
19
+ default = Ruote::HashStorage.new({})
20
+
21
+ cs = Ruote::CompositeStorage.new(default, 'msgs' => msgs)
22
+
23
+ cs.put('action' => 'terminate', 'type' => 'msgs', 'id' => 'xxx')
24
+ cs.put_msg('terminate', 'type' => 'msgs')
25
+ cs.put_schedule('at', {}, Time.now + 10, 'action' => 'reply')
26
+
27
+ assert_equal 0, default.h['msgs'].size
28
+ assert_equal 1, default.h['schedules'].size
29
+ assert_equal 2, cs.get_msgs.size
30
+ assert_equal 2, msgs.get_msgs.size
31
+ assert_equal 0, msgs.h['schedules'].size
32
+ end
33
+ end
34
+