openwferu 0.9.11 → 0.9.12

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. data/README.txt +0 -3
  2. data/examples/engine_template.rb +10 -4
  3. data/lib/openwfe/engine/engine.rb +336 -63
  4. data/lib/openwfe/engine/file_persisted_engine.rb +9 -1
  5. data/lib/openwfe/expool/errorjournal.rb +379 -0
  6. data/lib/openwfe/expool/expressionpool.rb +84 -55
  7. data/lib/openwfe/expool/expstorage.rb +54 -18
  8. data/lib/openwfe/expool/journal.rb +31 -22
  9. data/lib/openwfe/expool/yamlexpstorage.rb +57 -16
  10. data/lib/openwfe/expressions/fe_sequence.rb +1 -1
  11. data/lib/openwfe/expressions/flowexpression.rb +13 -1
  12. data/lib/openwfe/expressions/{fe_raw.rb → raw.rb} +5 -2
  13. data/lib/openwfe/expressions/raw_prog.rb +1 -1
  14. data/lib/openwfe/expressions/raw_xml.rb +1 -1
  15. data/lib/openwfe/expressions/time.rb +2 -0
  16. data/lib/openwfe/flowexpressionid.rb +21 -6
  17. data/lib/openwfe/omixins.rb +37 -14
  18. data/lib/openwfe/participants/atomparticipants.rb +6 -5
  19. data/lib/openwfe/participants/participantmap.rb +2 -0
  20. data/lib/openwfe/rest/controlclient.rb +1 -0
  21. data/lib/openwfe/rudefinitions.rb +5 -1
  22. data/lib/openwfe/storage/yamlfilestorage.rb +7 -3
  23. data/lib/openwfe/util/otime.rb +1 -1
  24. data/lib/openwfe/util/safe.rb +14 -0
  25. data/lib/openwfe/util/scheduler.rb +8 -5
  26. data/lib/openwfe/util/workqueue.rb +9 -2
  27. data/lib/openwfe/utils.rb +18 -0
  28. data/lib/openwfe/version.rb +1 -1
  29. data/test/atom_test.rb +27 -26
  30. data/test/fei_test.rb +3 -3
  31. data/test/file_persistence_test.rb +19 -2
  32. data/test/ft_0c_testname.rb +6 -3
  33. data/test/ft_26_load.rb +14 -7
  34. data/test/ft_26b_load.rb +87 -0
  35. data/test/ft_26c_load.rb +71 -0
  36. data/test/ft_27_getflowpos.rb +22 -3
  37. data/test/ft_34_cancelwfid.rb +3 -2
  38. data/test/ft_42_environments.rb +3 -1
  39. data/test/ft_58_ejournal.rb +119 -0
  40. data/test/ft_59_ps.rb +118 -0
  41. data/test/ft_60_ecancel.rb +87 -0
  42. data/test/ft_tests.rb +4 -0
  43. data/test/hparticipant_test.rb +1 -1
  44. data/test/orest_test.rb +27 -4
  45. data/test/param_test.rb +5 -1
  46. data/test/participant_test.rb +39 -0
  47. data/test/rake_qtest.rb +3 -5
  48. data/test/rest_test.rb +2 -2
  49. data/test/scheduler_test.rb +10 -15
  50. metadata +10 -3
@@ -50,15 +50,17 @@ require 'openwfe/service'
50
50
 
51
51
  require 'openwfe/expressions/flowexpression'
52
52
  require 'openwfe/expressions/raw_xml'
53
+
53
54
  #
54
55
  # making sure classes in those files are loaded
55
56
  # before their yaml persistence is tuned
56
57
  # (else the reopening of the class is interpreted as
57
58
  # a definition of the class...)
58
59
 
59
-
60
60
  module OpenWFE
61
-
61
+
62
+
63
+
62
64
  #
63
65
  # Stores OpenWFEru related objects into yaml encoded files.
64
66
  # This storage is meant to look and feel like a Hash.
@@ -144,6 +146,7 @@ module OpenWFE
144
146
 
145
147
  if not File.exist?(fei_path)
146
148
  ldebug { "[] didn't find file at #{fei_path}" }
149
+ #puts "[] didn't find file at #{fei_path}"
147
150
  return nil
148
151
  end
149
152
 
@@ -165,7 +168,7 @@ module OpenWFE
165
168
  def load_object (path)
166
169
 
167
170
  object = YAML.load_file(path)
168
-
171
+
169
172
  object.application_context = @application_context \
170
173
  if object.respond_to? :application_context=
171
174
 
@@ -213,6 +216,7 @@ module OpenWFE
213
216
  # Passes each object to the given block
214
217
  #
215
218
  def each_object (&block)
219
+
216
220
  each_object_path do |path|
217
221
  block.call load_object(path)
218
222
  end
@@ -64,7 +64,7 @@ module OpenWFE
64
64
  date = DateTime.parse(date)
65
65
  end
66
66
 
67
- s = date.to_s
67
+ s = date.to_s # this is costly
68
68
  s[10] = " "
69
69
 
70
70
  return s
@@ -86,6 +86,8 @@ module OpenWFE
86
86
  #
87
87
  def OpenWFE.instance_eval_safely (instance, code, safe_level)
88
88
 
89
+ return instance.instance_eval(code) if on_jruby?
90
+
89
91
  code.untaint
90
92
 
91
93
  r = nil
@@ -95,6 +97,8 @@ module OpenWFE
95
97
  r = instance.instance_eval(code)
96
98
  end.join
97
99
 
100
+ raise "cannot TAMPER with JRUBY_VERSION" if on_jruby?
101
+
98
102
  r
99
103
  end
100
104
 
@@ -103,6 +107,8 @@ module OpenWFE
103
107
  #
104
108
  def OpenWFE.eval_safely (code, safe_level, binding=nil)
105
109
 
110
+ return eval(code, binding) if on_jruby?
111
+
106
112
  code.untaint
107
113
 
108
114
  r = nil
@@ -112,6 +118,8 @@ module OpenWFE
112
118
  r = eval(code, binding)
113
119
  end.join
114
120
 
121
+ raise "cannot TAMPER with JRUBY_VERSION" if on_jruby?
122
+
115
123
  r
116
124
  end
117
125
 
@@ -138,6 +146,12 @@ module OpenWFE
138
146
 
139
147
  eval_safely(c, safe_level, binding)
140
148
  end
149
+
150
+ protected
151
+
152
+ def on_jruby?
153
+ defined?(JRUBY_VERSION) != nil
154
+ end
141
155
 
142
156
  end
143
157
 
@@ -40,7 +40,6 @@
40
40
  #
41
41
 
42
42
  require 'monitor'
43
-
44
43
  require 'openwfe/util/otime'
45
44
 
46
45
 
@@ -139,10 +138,16 @@ module OpenWFE
139
138
  def sstart
140
139
 
141
140
  @scheduler_thread = Thread.new do
141
+
142
+ if defined?(JRUBY_VERSION)
143
+ require 'java'
144
+ java.lang.Thread.current_thread.name = "openwferu scheduler (Ruby Thread)"
145
+ end
146
+
142
147
  while true
143
148
  break if @stopped
144
149
  step
145
- sleep(@precision)
150
+ sleep @precision
146
151
  end
147
152
  end
148
153
  end
@@ -297,7 +302,6 @@ module OpenWFE
297
302
  # be used to unschedule the job.
298
303
  #
299
304
  def schedule (cron_line, params={}, &block)
300
-
301
305
  synchronize do
302
306
 
303
307
  params = prepare_params(params)
@@ -398,7 +402,6 @@ module OpenWFE
398
402
  end
399
403
 
400
404
  def sschedule_at (at, params={}, &block)
401
-
402
405
  synchronize do
403
406
 
404
407
  #puts "0 at is '#{at.to_s}' (#{at.class})"
@@ -509,7 +512,7 @@ module OpenWFE
509
512
 
510
513
  #puts "push() at '#{Time.at(job.at)}'"
511
514
 
512
- return job.eid
515
+ job.eid
513
516
  end
514
517
 
515
518
  #
@@ -58,7 +58,7 @@ module OpenWFE
58
58
  @workqueue = []
59
59
  @workqueue_frequency = 0
60
60
 
61
- OpenWFE::call_in_thread "expression_pool", self do
61
+ OpenWFE::call_in_thread "workqueue", self do
62
62
  while true
63
63
  break if @workqueue_frequency == nil
64
64
  sleep @workqueue_frequency
@@ -81,6 +81,8 @@ module OpenWFE
81
81
  def stop_workqueue
82
82
  @workqueue_frequency = nil
83
83
  do_process_workqueue
84
+ #
85
+ # maybe could process the work queue until it's really empty
84
86
  end
85
87
 
86
88
  #
@@ -141,12 +143,17 @@ module OpenWFE
141
143
  #ldebug { "do_process_workqueue() #{q.size} items to process" }
142
144
 
143
145
  q.each do |elt|
144
-
146
+
145
147
  do_process_workelement elt
146
148
  #
147
149
  # exception management is now done in the
148
150
  # do_process_workelement method
149
151
  end
152
+
153
+ #
154
+ # TODO : have a pool of workers handle that
155
+
156
+ #q.size
150
157
  end
151
158
 
152
159
  protected
data/lib/openwfe/utils.rb CHANGED
@@ -116,6 +116,7 @@ module OpenWFE
116
116
  return object if object.kind_of?(Fixnum)
117
117
  return object if object.kind_of?(TrueClass)
118
118
  return object if object.kind_of?(FalseClass)
119
+ return object if object.kind_of?(Symbol)
119
120
 
120
121
  return object.dup if object.kind_of?(String)
121
122
 
@@ -250,6 +251,19 @@ module OpenWFE
250
251
  s
251
252
  end
252
253
 
254
+ #
255
+ # Sets the name of the current thread (the attribute :name if it is
256
+ # a ruby thread, the java thread name if we're in JRuby)
257
+ #
258
+ def set_current_thread_name (name)
259
+ if defined?(JRUBY_VERSION)
260
+ require 'java'
261
+ java.lang.Thread.current_thread.name = "#{name} (Ruby Thread)"
262
+ else
263
+ Thread.current[:name] = name
264
+ end
265
+ end
266
+
253
267
  #
254
268
  # Some code for writing thinks like :
255
269
  #
@@ -268,6 +282,10 @@ module OpenWFE
268
282
  return unless block
269
283
 
270
284
  Thread.new do
285
+
286
+ #set_current_thread_name "call_in_thread() for '#{caller_name}'"
287
+ set_current_thread_name caller_name
288
+
271
289
  begin
272
290
  #$SAFE = safe_level
273
291
  #
@@ -34,5 +34,5 @@
34
34
  #
35
35
 
36
36
  module OpenWFE
37
- OPENWFERU_VERSION = '0.9.11'
37
+ OPENWFERU_VERSION = '0.9.12'
38
38
  end
data/test/atom_test.rb CHANGED
@@ -30,28 +30,24 @@ class AtomTest < Test::Unit::TestCase
30
30
  #
31
31
  # test atom 0
32
32
 
33
- class Atom0Definition < ProcessDefinition
34
- def make
35
- process_definition :name => "atom0", :revision => "0" do
36
- sequence do
37
-
38
- set \
39
- :field => "atom_entry_title",
40
- :value => "#{$run_index}"
41
- set \
42
- :field => "colour",
43
- :value => "blue"
44
- participant :ref => "feed0-alpha"
45
-
46
- set \
47
- :field => "atom_entry_title",
48
- :value => "#{$run_index}"
49
- set \
50
- :field => "colour",
51
- :value => "red"
52
- participant :ref => "feed1-bravo"
53
- end
54
- end
33
+ class AtomDefinition0 < ProcessDefinition
34
+ sequence do
35
+
36
+ set \
37
+ :field => "atom_entry_title",
38
+ :value => "#{$run_index}"
39
+ set \
40
+ :field => "colour",
41
+ :value => "blue"
42
+ participant :ref => "feed0-alpha"
43
+
44
+ set \
45
+ :field => "atom_entry_title",
46
+ :value => "#{$run_index}"
47
+ set \
48
+ :field => "colour",
49
+ :value => "red"
50
+ participant :ref => "feed1-bravo"
55
51
  end
56
52
  end
57
53
 
@@ -67,7 +63,7 @@ class AtomTest < Test::Unit::TestCase
67
63
 
68
64
  feed1 = AtomParticipant.new(7) do |fe, participant, workitem|
69
65
 
70
- t = Time.new.to_s
66
+ t = Time.now.to_s
71
67
  """
72
68
  <p>
73
69
  <h1>${f:colour}</h1>
@@ -86,13 +82,18 @@ class AtomTest < Test::Unit::TestCase
86
82
  @engine.register_participant("feed1-.*", feed1)
87
83
 
88
84
  $run_index = "first run"
89
- @engine.launch(LaunchItem.new(Atom0Definition))
85
+ @engine.launch(LaunchItem.new(AtomDefinition0))
90
86
 
91
87
  $run_index = "second run"
92
- @engine.launch(LaunchItem.new(Atom0Definition))
88
+ @engine.launch(LaunchItem.new(AtomDefinition0))
93
89
 
94
90
  $run_index = "third and last run"
95
- @engine.launch(LaunchItem.new(Atom0Definition))
91
+ @engine.launch(LaunchItem.new(AtomDefinition0))
92
+
93
+ @engine.join_until_idle
94
+
95
+ assert File.exist?('work/atom_feed0-alpha.xml')
96
+ assert File.exist?('work/atom_feed1-bravo.xml')
96
97
  end
97
98
 
98
99
  end
data/test/fei_test.rb CHANGED
@@ -109,12 +109,12 @@ class FeiTest < Test::Unit::TestCase
109
109
  fei0 = new_fei()
110
110
  s = fei0.to_s
111
111
  fei1 = OpenWFE::FlowExpressionId.to_fei(s)
112
+ fei2 = OpenWFE::FlowExpressionId.from_s(s)
112
113
 
113
114
  puts "\n#{s}\n#{fei1.to_s}" if fei0 != fei1
114
115
 
115
- assert \
116
- fei0 == fei1,
117
- "fei .to_s() and .str_to_fei(s) are not working"
116
+ assert_equal fei0, fei1
117
+ assert_equal fei1, fei2
118
118
  end
119
119
 
120
120
  def test_parent_wfid
@@ -2,8 +2,6 @@
2
2
  require 'test/unit'
3
3
 
4
4
  require 'openwfe/engine/engine'
5
- #require 'openwfe/flowexpressionid'
6
- #require 'openwfe/expressions/expressionmap'
7
5
  require 'openwfe/expool/expstorage'
8
6
  require 'openwfe/expool/yamlexpstorage'
9
7
 
@@ -16,6 +14,10 @@ class FilePersistenceTest < Test::Unit::TestCase
16
14
  @engine = Engine.new
17
15
  end
18
16
 
17
+ def teardown
18
+ @engine.stop
19
+ end
20
+
19
21
  def ac
20
22
  return @engine.application_context
21
23
  end
@@ -35,6 +37,21 @@ class FilePersistenceTest < Test::Unit::TestCase
35
37
  fe = SequenceExpression.new(fei, nil, nil, nil, nil)
36
38
  test_persistence(fes,fe)
37
39
  end
40
+
41
+ def test_path_splitting
42
+
43
+ fei = new_fei
44
+ fes = YamlFileExpressionStorage.new("yaml", ac)
45
+ class << fes
46
+ public :compute_file_path
47
+ end
48
+ path = fes.compute_file_path fei
49
+ a = fes.class.split_file_path path
50
+
51
+ assert_equal a[0], fei.wfid
52
+ assert_equal a[1], fei.expression_id
53
+ assert_equal a[2], fei.expression_name
54
+ end
38
55
 
39
56
  #
40
57
  # test UTF-8 data persistence
@@ -20,10 +20,13 @@ class TestTestName < Test::Unit::TestCase
20
20
  #end
21
21
 
22
22
  def test_name_of_test
23
- dotest(\
24
- """<process-definition name='#{name_of_test}' revision='0'>
23
+ dotest(
24
+ """
25
+ <process-definition name='#{name_of_test}' revision='0'>
25
26
  <print>#{name_of_test}</print>
26
- </process-definition>""", "name_of_test")
27
+ </process-definition>
28
+ """.strip,
29
+ "name_of_test")
27
30
  end
28
31
 
29
32
  end
data/test/ft_26_load.rb CHANGED
@@ -27,15 +27,16 @@ class FlowTest26 < Test::Unit::TestCase
27
27
  #
28
28
 
29
29
  class TestDefinition0 < ProcessDefinition
30
- def make
31
- process_definition :name => "test0", :revision => "0" do
32
- sequence do
33
- count
34
- count
35
- end
30
+ process_definition :name => "test0", :revision => "0" do
31
+ sequence do
32
+ count
33
+ count
36
34
  end
37
35
  end
38
36
  end
37
+ #class TestDefinition0 < ProcessDefinition
38
+ # count
39
+ #end
39
40
 
40
41
  #def xxxx_load_0
41
42
  def test_load_0
@@ -52,7 +53,7 @@ class FlowTest26 < Test::Unit::TestCase
52
53
  map[workitem.flow_id] = count
53
54
  end
54
55
 
55
- n = 100
56
+ n = 1000
56
57
 
57
58
  n.times do |i|
58
59
  li = LaunchItem.new(TestDefinition0)
@@ -60,11 +61,17 @@ class FlowTest26 < Test::Unit::TestCase
60
61
  @engine.launch(li)
61
62
  end
62
63
 
64
+ #while @engine.get_expression_storage.size > 1
65
+ # sleep 0.001
66
+ #end
67
+ @engine.join_until_idle
68
+
63
69
  good = true
64
70
 
65
71
  n.times do |i|
66
72
  c = map[i]
67
73
  if c == 2
74
+ #if c == 1
68
75
  print "."
69
76
  else
70
77
  print c
@@ -0,0 +1,87 @@
1
+
2
+ #
3
+ # Testing OpenWFE
4
+ #
5
+ # John Mettraux at openwfe.org
6
+ #
7
+ # Tue Jan 2 13:14:37 JST 2007
8
+ #
9
+
10
+ #require 'profile'
11
+
12
+ require 'flowtestbase'
13
+ require 'openwfe/expressions/raw_prog'
14
+
15
+ include OpenWFE
16
+
17
+
18
+ class FlowTest26b < Test::Unit::TestCase
19
+ include FlowTestBase
20
+
21
+ #def setup
22
+ #end
23
+
24
+ #def teardown
25
+ #end
26
+
27
+ #
28
+ # Test 0
29
+ #
30
+
31
+ class TestDefinition0 < ProcessDefinition
32
+ count
33
+ end
34
+
35
+ #def xxxx_load_0
36
+ def test_load_0
37
+
38
+ #require 'openwfe/expool/journal'
39
+ #@engine.application_context[:keep_journals] = true
40
+ #@engine.init_service("journal", Journal)
41
+
42
+ $count = 0
43
+
44
+ @engine.register_participant("count") do |workitem|
45
+ $count += 1
46
+ #puts "count is #{$count}"
47
+ end
48
+
49
+
50
+ n = 1000
51
+ n.times do |i|
52
+ @engine.launch(LaunchItem.new(TestDefinition0))
53
+
54
+ end
55
+
56
+ puts "launched #{n} items"
57
+
58
+ #n.times do |i|
59
+ # Thread.new do
60
+ # @engine.launch(LaunchItem.new(TestDefinition0))
61
+ # end
62
+ #end
63
+
64
+ #5.times do
65
+ # Thread.new do
66
+ # (n / 5).times do
67
+ # @engine.launch(LaunchItem.new(TestDefinition0))
68
+ # end
69
+ # end
70
+ #end
71
+ #sleep 1
72
+
73
+ join_until_idle
74
+
75
+ assert_equal $count, n
76
+ end
77
+
78
+ def join_until_idle ()
79
+ storage = @engine.get_expression_storage
80
+ while storage.size > 1
81
+ sleep 1
82
+ puts "storage.size:#{storage.size}"
83
+ end
84
+ end
85
+
86
+ end
87
+
@@ -0,0 +1,71 @@
1
+
2
+ #
3
+ # Testing OpenWFE
4
+ #
5
+ # John Mettraux at openwfe.org
6
+ #
7
+ # Tue Jan 2 13:14:37 JST 2007
8
+ #
9
+
10
+ #require 'profile'
11
+
12
+ require 'flowtestbase'
13
+ require 'openwfe/expressions/raw_prog'
14
+
15
+ include OpenWFE
16
+
17
+
18
+ class FlowTest26c < Test::Unit::TestCase
19
+ include FlowTestBase
20
+
21
+ #def setup
22
+ #end
23
+
24
+ #def teardown
25
+ #end
26
+
27
+ #
28
+ # Test 0
29
+ #
30
+
31
+ N = 10000
32
+
33
+ class TestDefinition0 < ProcessDefinition
34
+ sequence do
35
+ N.times do
36
+ count
37
+ end
38
+ end
39
+ end
40
+
41
+ #def xxxx_load_0
42
+ def test_load_0
43
+
44
+ #require 'openwfe/expool/journal'
45
+ #@engine.application_context[:keep_journals] = true
46
+ #@engine.init_service("journal", Journal)
47
+ #
48
+ # very heavy
49
+
50
+ #require 'openwfe/expool/errorjournal'
51
+ #@engine.init_service("journal", ErrorJournal)
52
+ #
53
+ # light, almost inexistent (when there are no errors)
54
+
55
+ $count = 0
56
+
57
+ @engine.register_participant("count") do |workitem|
58
+ $count += 1
59
+ #print "."
60
+ end
61
+
62
+ fei = @engine.launch(LaunchItem.new(TestDefinition0))
63
+ puts "launched #{fei}"
64
+
65
+ @engine.wait_for fei
66
+
67
+ assert_equal $count, N
68
+ end
69
+
70
+ end
71
+
@@ -45,12 +45,30 @@ class FlowTest27 < Test::Unit::TestCase
45
45
 
46
46
  sleep 0.500
47
47
 
48
- l = @engine.get_expression_pool.get_flow_position(fei.wfid)
48
+ l = @engine.get_process_stack(fei.wfid)
49
49
 
50
50
  #print_exp_list(l)
51
51
 
52
52
  assert_equal \
53
- l.size, 3, "get_flow_position() returned #{l.size} elements"
53
+ l.size, 3, "get_process_stack() returned #{l.size} elements"
54
+
55
+ ps = @engine.get_process_status
56
+ #puts
57
+ #puts ps[fei.parent_wfid].to_s
58
+ #puts
59
+
60
+ assert_equal ps[fei.parent_wfid].errors.size, 0
61
+ assert_equal ps[fei.parent_wfid].expressions.size, 1
62
+ assert_kind_of ParticipantExpression, ps[fei.parent_wfid].expressions[0]
63
+
64
+ ps = @engine.get_process_status fei.wfid[0, 4]
65
+
66
+ assert_equal ps[fei.parent_wfid].errors.size, 0
67
+ assert_equal ps[fei.parent_wfid].expressions.size, 1
68
+ assert_kind_of ParticipantExpression, ps[fei.parent_wfid].expressions[0]
69
+
70
+ #
71
+ # resume process
54
72
 
55
73
  wi = sp.first_workitem
56
74
 
@@ -81,7 +99,8 @@ class FlowTest27 < Test::Unit::TestCase
81
99
 
82
100
  sleep 0.500
83
101
 
84
- l = @engine.get_flow_position(fei.wfid)
102
+ #l = @engine.get_process_stack(fei.wfid)
103
+ l = @engine.get_process_stack(fei)
85
104
  #
86
105
  # shortcut version
87
106
 
@@ -62,8 +62,9 @@ class FlowTest34 < Test::Unit::TestCase
62
62
 
63
63
  @engine.cancel_process(fei.wfid)
64
64
 
65
- #l = @engine.list_processes()
66
- #assert_equal l.size, 0
65
+ sleep 0.500
66
+
67
+ assert_equal @engine.get_process_stack(fei.wfid).size, 0
67
68
 
68
69
  assert_equal sp.size, 0
69
70
  # check that participant got cancelled as well
@@ -43,7 +43,7 @@ class FlowTest42 < Test::Unit::TestCase
43
43
  def test_0
44
44
  dotest(
45
45
  TestCase42a0,
46
- "v:c")
46
+ [ "v:b", "v:c" ])
47
47
  end
48
48
 
49
49
 
@@ -51,6 +51,8 @@ class FlowTest42 < Test::Unit::TestCase
51
51
  # Test 1
52
52
  #
53
53
 
54
+ # DISABLED
55
+
54
56
  class TestCase42a1 < ProcessDefinition
55
57
  sequence do
56
58
  set :variable => "v", :value => "a"