From 80a45f64e77336c42c868e48c938828c50234ca2 Mon Sep 17 00:00:00 2001 From: John Mettraux Date: Sun, 30 Jan 2011 09:16:07 +0900 Subject: [PATCH] using sourcify for BlockParticipant - step 1 motivation : http://groups.google.com/group/openwferu-users/browse_thread/thread/5cb41f958d91308b step 2 is running a security check on the code befare evaluation. --- TODO.txt | 7 + lib/ruote/engine.rb | 14 +- lib/ruote/exp/fe_participant.rb | 3 +- lib/ruote/part/block_participant.rb | 27 ++-- lib/ruote/part/hash_participant.rb | 91 ------------- lib/ruote/part/storage_participant.rb | 20 +++ lib/ruote/participant.rb | 1 - lib/ruote/storage/hash_storage.rb | 11 +- lib/ruote/svc/participant_list.rb | 128 +++++++----------- lib/ruote/worker.rb | 13 -- ruote.gemspec | 2 +- test/functional/base.rb | 11 ++ test/functional/eft_0_process_definition.rb | 4 +- test/functional/eft_11_wait.rb | 21 +-- test/functional/eft_12_listen.rb | 6 +- test/functional/eft_13_iterator.rb | 21 +-- test/functional/eft_14_cursor.rb | 10 +- test/functional/eft_15_loop.rb | 10 +- test/functional/eft_18_concurrent_iterator.rb | 59 ++++---- test/functional/eft_19_reserve.rb | 8 +- test/functional/eft_20_save.rb | 8 +- test/functional/eft_3_participant.rb | 10 +- test/functional/eft_5_subprocess.rb | 6 +- test/functional/eft_6_concurrence.rb | 54 ++++---- test/functional/eft_8_undo.rb | 6 +- test/functional/eft_9_redo.rb | 2 +- test/functional/ft_11_recursion.rb | 26 ++-- test/functional/ft_12_launchitem.rb | 14 +- test/functional/ft_13_variables.rb | 16 +-- test/functional/ft_14_re_apply.rb | 15 +- test/functional/ft_15_timeout.rb | 36 ++--- test/functional/ft_16_participant_params.rb | 4 +- test/functional/ft_18_kill.rb | 20 ++- test/functional/ft_1_process_status.rb | 33 ++--- test/functional/ft_24_block_participants.rb | 20 +-- test/functional/ft_25_receiver.rb | 26 ++-- test/functional/ft_26_participant_rtimeout.rb | 24 ++-- test/functional/ft_29_part_template.rb | 7 +- test/functional/ft_2_errors.rb | 26 ++-- test/functional/ft_31_part_blocking.rb | 12 +- test/functional/ft_34_cursor_rewind.rb | 18 +-- .../ft_3_participant_registration.rb | 38 +++--- test/functional/ft_43_participant_on_reply.rb | 17 --- test/functional/ft_49_engine_on_error.rb | 16 +-- test/functional/ft_4_cancel.rb | 13 +- test/functional/ft_55_engine_participant.rb | 7 +- test/functional/ft_5_on_error.rb | 45 +++--- test/functional/ft_6_on_cancel.rb | 18 +-- test/functional/ft_7_tags.rb | 4 +- .../ft_8_participant_consumption.rb | 11 +- test/functional/ft_9_subprocesses.rb | 16 +-- test/functional/rt_1_listen.rb | 4 +- test/functional/test.rb | 4 +- test/unit/ut_3_wait_logger.rb | 7 +- 54 files changed, 468 insertions(+), 582 deletions(-) delete mode 100644 lib/ruote/part/hash_participant.rb diff --git a/TODO.txt b/TODO.txt index c85efd07..38ee0eb3 100644 --- a/TODO.txt +++ b/TODO.txt @@ -459,5 +459,12 @@ launch a process with a designed 'supervisor' ? [ ] ci : ruote-amqp +[ ] ci : ruote-mongodb [ ] ci : jruby +[ ] StorageParticipant#reply : raise if workitem not found ? +[ ] StorageParticipant#reply : accept fei ? + +[ ] eft_18 weak with jruby-1.5.1 + + diff --git a/lib/ruote/engine.rb b/lib/ruote/engine.rb index 90770b40..2adfb6d7 100644 --- a/lib/ruote/engine.rb +++ b/lib/ruote/engine.rb @@ -521,14 +521,18 @@ def load_definition (path) # containing the participant implementation. 'require' will load and eval # the ruby code only once, 'load' each time. # - def register_participant (regex, participant=nil, opts={}, &block) + def register_participant (regex, participant=nil, opts=nil, &block) + + if participant.is_a?(Hash) + opts = participant + participant = nil + end + + opts ||= {} pa = @context.plist.register(regex, participant, opts, block) - @context.storage.put_msg( - 'participant_registered', - 'regex' => regex.to_s, - 'engine_worker_only' => (pa != nil)) + @context.storage.put_msg('participant_registered', 'regex' => regex.to_s) pa end diff --git a/lib/ruote/exp/fe_participant.rb b/lib/ruote/exp/fe_participant.rb index ff450bfb..291ebeb5 100644 --- a/lib/ruote/exp/fe_participant.rb +++ b/lib/ruote/exp/fe_participant.rb @@ -167,8 +167,7 @@ def apply 'fei' => h.fei, 'participant_name' => h.participant_name, 'participant' => h.participant, - 'workitem' => h.applied_workitem, - 'for_engine_worker?' => (participant_info.class != Array)) + 'workitem' => h.applied_workitem) end def cancel (flavour) diff --git a/lib/ruote/part/block_participant.rb b/lib/ruote/part/block_participant.rb index 49216406..7c9cbe1c 100644 --- a/lib/ruote/part/block_participant.rb +++ b/lib/ruote/part/block_participant.rb @@ -67,28 +67,39 @@ class BlockParticipant include LocalParticipant attr_accessor :context - attr_accessor :do_not_thread - def initialize (block, opts) + def initialize (opts) @opts = opts - @block = block - @do_not_thread = false + end + + def do_not_thread + + @opts['do_not_thread'] end def consume (workitem) - r = if @block.arity == 1 + block = @opts['block'] + + #block = eval(block, @context.send(:binding)) + # doesn't work with ruby 1.9.2-p136 + + block = eval(block, @context.instance_eval { binding }) + # works OK with ruby 1.8.7-249 and 1.9.2-p136 + + # TODO : security !! + + r = if block.arity == 1 - @block.call(workitem) + block.call(workitem) else - @block.call( + block.call( workitem, Ruote::Exp::FlowExpression.fetch(@context, workitem.h.fei)) end if r != nil && r != workitem - #workitem.result = r workitem.result = (Rufus::Json.dup(r) rescue nil) end diff --git a/lib/ruote/part/hash_participant.rb b/lib/ruote/part/hash_participant.rb deleted file mode 100644 index 33198b6c..00000000 --- a/lib/ruote/part/hash_participant.rb +++ /dev/null @@ -1,91 +0,0 @@ -#-- -# Copyright (c) 2005-2011, John Mettraux, jmettraux@gmail.com -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in -# all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -# THE SOFTWARE. -# -# Made in Japan. -#++ - -require 'ruote/part/local_participant' - - -module Ruote - - # - # Storing workitems in-memory. Mainly used for testing purposes, but could - # prove useful for a transient ruote engine. - # - class HashParticipant - - include LocalParticipant - include Enumerable - - def initialize (opts=nil) - - @items = {} - end - - # No need for a separate thread when delivering to this participant. - # - def do_not_thread; true; end - - def consume (workitem) - - @items[workitem.fei.to_storage_id] = workitem - end - - # Makes sure to remove the workitem from the in-memory hash. - # - def cancel (fei, flavour) - - @items.delete(fei.to_storage_id) - end - - # Removes the workitem from the in-memory hash and replies to the engine. - # - def reply (workitem) - - @items.delete(workitem.fei.to_storage_id) - reply_to_engine(workitem) - end - - # Returns the count of workitems stored in this participant. - # - def size - - @items.size - end - - # Iterates over the workitems stored in here. - # - def each (&block) - - @items.each { |i| block.call(i) } - end - - # A convenience method (especially when testing), returns the first - # (only ?) workitem in the participant. - # - def first - - @items.values.first - end - end -end - diff --git a/lib/ruote/part/storage_participant.rb b/lib/ruote/part/storage_participant.rb index 4694391c..c707cac8 100644 --- a/lib/ruote/part/storage_participant.rb +++ b/lib/ruote/part/storage_participant.rb @@ -119,6 +119,9 @@ def fetch (fei) # Removes the workitem from the in-memory hash and replies to the engine. # + # TODO : should it raise if the workitem can't be found ? + # TODO : should it accept just the fei ? + # def reply (workitem) # TODO: change method name (receiver mess cleanup) @@ -287,6 +290,23 @@ def self.matches? (hwi, pname, criteria) true end + # Mostly a test method. Returns a Hash were keys are participant names + # and values are lists of workitems. + # + def per_participant + + inject({}) { |h, wi| (h[wi.participant_name] ||= []) << wi; h } + end + + # Mostly a test method. Returns a Hash were keys are participant names + # and values are integers, the count of workitems for a given participant + # name. + # + def per_participant_count + + per_participant.inject({}) { |h, (k, v)| h[k] = v.size; h } + end + protected # Fetches all the workitems. If there is a @store_name, will only fetch diff --git a/lib/ruote/participant.rb b/lib/ruote/participant.rb index ea3326a7..b5bb8cf2 100644 --- a/lib/ruote/participant.rb +++ b/lib/ruote/participant.rb @@ -1,5 +1,4 @@ -require 'ruote/part/hash_participant' require 'ruote/part/storage_participant' require 'ruote/part/no_op_participant' require 'ruote/part/null_participant' diff --git a/lib/ruote/storage/hash_storage.rb b/lib/ruote/storage/hash_storage.rb index bff02da6..ee1f2501 100644 --- a/lib/ruote/storage/hash_storage.rb +++ b/lib/ruote/storage/hash_storage.rb @@ -111,16 +111,11 @@ def delete (doc) doc['_rev'] ||= 0 - if prev['_rev'] == drev + return prev if prev['_rev'] != drev - @h[doc['type']].delete(doc['_id']) + @h[doc['type']].delete(doc['_id']) - nil - - else - - prev - end + nil # success end end diff --git a/lib/ruote/svc/participant_list.rb b/lib/ruote/svc/participant_list.rb index ff86fb23..a271a32e 100644 --- a/lib/ruote/svc/participant_list.rb +++ b/lib/ruote/svc/participant_list.rb @@ -23,6 +23,7 @@ #++ +require 'sourcify' require 'ruote/part/block_participant' @@ -37,12 +38,9 @@ module Ruote # class ParticipantList - attr_reader :instantiated_participants - def initialize (context) @context = context - @instantiated_participants = {} end # Registers a participant. Called by Engine#register_participant. @@ -53,17 +51,13 @@ def register (name, participant, options, block) h[k.to_s] = v.is_a?(Symbol) ? v.to_s : v h } - - entry = if participant.is_a?(Class) || participant.is_a?(String) - [ participant.to_s, options ] - else - "inpa_#{name.inspect}" - # INstantiated PArticipant - end + options['block'] = block.to_source if block key = (name.is_a?(Regexp) ? name : Regexp.new("^#{name}$")).source - entry = [ key, entry ] + klass = (participant || Ruote::BlockParticipant).to_s + + entry = [ key, [ klass, options ] ] list = get_list @@ -85,20 +79,9 @@ def register (name, participant, options, block) return register(name, participant, options, block) end - if entry.last.is_a?(String) - - participant = BlockParticipant.new(block, options) if block - - participant.context = @context if participant.respond_to?(:context=) - @instantiated_participants[entry.last] = participant - #participant - + if entry.last.first == 'Ruote::StorageParticipant' + Ruote::StorageParticipant.new(@context) else - - if entry.last.first == 'Ruote::StorageParticipant' - return Ruote::StorageParticipant.new(@context) - end - nil end end @@ -114,31 +97,13 @@ def unregister (name_or_participant) entry = nil list = get_list - if name_or_participant.is_a?(Symbol) - name_or_participant = name_or_participant.to_s - end - - if name_or_participant.is_a?(String) - - entry = list['list'].find { |re, pa| name_or_participant.match(re) } - - return nil unless entry - - code = entry.last if entry.last.is_a?(String) - - else # we've been given a participant instance - - code = @instantiated_participants.find { |k, v| - v == name_or_participant - } - - return nil unless code + name_or_participant = name_or_participant.to_s - code = code.first + entry = list['list'].find { |re, pa| name_or_participant.match(re) } - entry = list['list'].find { |re, pa| pa == code } + return nil unless entry - end + code = entry.last if entry.last.is_a?(String) list['list'].delete(entry) @@ -146,11 +111,9 @@ def unregister (name_or_participant) # # put failed, have to redo it # - return unregister(name_or_participant, r) + return unregister(name_or_participant) end - @instantiated_participants.delete(code) if code - entry.first end @@ -161,13 +124,11 @@ def unregister (name_or_participant) # def lookup (participant_name, workitem, opts={}) - pinfo = participant_name + pinfo = participant_name.is_a?(String) ? + lookup_info(participant_name, workitem) : participant_name - if participant_name.is_a?(String) && participant_name[0, 5] != 'inpa_' - pinfo = lookup_info(participant_name, workitem) - end - - pinfo ? instantiate(pinfo, opts) : nil + pinfo ? + instantiate(pinfo, opts) : nil end # Given a participant name, returns @@ -197,16 +158,12 @@ def lookup_info (pname, workitem) # def instantiate (pinfo, opts={}) - irt = opts[:if_respond_to?] - - pinfo = @instantiated_participants[pinfo] if pinfo.is_a?(String) - - if pinfo.respond_to?(:consume) - return (pinfo.respond_to?(irt) ? pinfo : nil) if irt - return pinfo - end - - return nil unless pinfo + #pinfo = @instantiated_participants[pinfo] if pinfo.is_a?(String) + #if pinfo.respond_to?(:consume) + # return (pinfo.respond_to?(irt) ? pinfo : nil) if irt + # return pinfo + #end + #return nil unless pinfo pa_class_name, options = pinfo @@ -220,18 +177,26 @@ def instantiate (pinfo, opts={}) pa_class = Ruote.constantize(pa_class_name) pa_m = pa_class.instance_methods + irt = opts[:if_respond_to?] + if irt && ! (pa_m.include?(irt.to_s) || pa_m.include?(irt.to_sym)) return nil end - pa = if pa_class.instance_method(:initialize).arity == 0 - pa_class.new + initialize_participant(pa_class, options) + end + + def initialize_participant (klass, options) + + participant = if klass.instance_method(:initialize).arity == 0 + klass.new else - pa_class.new(options) + klass.new(options) end - pa.context = @context if pa.respond_to?(:context=) - pa + participant.context = @context if participant.respond_to?(:context=) + + participant end # Return a list of names (regex) for the registered participants @@ -241,14 +206,18 @@ def names get_list['list'].collect { |re, pa| re } end - # Shuts down the 'instantiated participants' (engine worker participants) - # if they respond to #shutdown. + # Calls #shutdown on any participant that sports this method. # def shutdown - @instantiated_participants.each { |re, pa| - pa.shutdown if pa.respond_to?(:shutdown) - } + get_list['list'].each do |re, (kl, op)| + + kl = (Ruote.constantize(kl) rescue nil) + + if (kl.instance_method(:shutdown) rescue false) + initialize_participant(kl, op).shutdown + end + end end # Used by Engine#participant_list @@ -282,7 +251,7 @@ def list= (pl) # # put failed, have to redo it # - list= (pl) + list=(pl) end end @@ -333,9 +302,7 @@ def initialize (a) end def to_a - @classname[0, 5] == 'inpa_' ? - [ @regex, @classname ] : - [ @regex, [ @classname, @options ] ] + [ @regex, [ @classname, @options ] ] end def to_s @@ -373,8 +340,7 @@ def self.read (elt) klass = elt['classname'] || elt['class'] - return klass[0, 5] == 'inpa_' ? - [ regex, klass ] : [ regex, [ klass, options ] ] + return [ regex, [ klass, options ] ] end # else elt is a Array diff --git a/lib/ruote/worker.rb b/lib/ruote/worker.rb index b9e97c66..ed9bf7c9 100644 --- a/lib/ruote/worker.rb +++ b/lib/ruote/worker.rb @@ -204,8 +204,6 @@ def trigger (schedule) def process (msg) - return false if cannot_handle(msg) - return false unless @storage.reserve(msg) begin @@ -254,17 +252,6 @@ def notify (msg) end end - # Should always return false. Except when the message is a 'dispatch' - # and it's for a participant only available to an 'engine_worker' - # (block participants, stateful participants) - # - def cannot_handle (msg) - - return false if msg['action'] != 'dispatch' - - @context.engine.nil? && msg['for_engine_worker?'] - end - # Works for both the 'launch' and the 'apply' msgs. # def launch (msg) diff --git a/ruote.gemspec b/ruote.gemspec index c14e8299..1fe01d41 100644 --- a/ruote.gemspec +++ b/ruote.gemspec @@ -21,7 +21,7 @@ ruote is an open source Ruby workflow engine '*.gemspec', '*.txt', '*.rdoc', '*.md' ] - #s.add_runtime_dependency 'ruby2ruby', '>= 1.2.5' + s.add_runtime_dependency 'sourcify', '0.4.1' s.add_runtime_dependency 'rufus-json', '>= 0.2.5' s.add_runtime_dependency 'rufus-cloche', '>= 0.1.20' s.add_runtime_dependency 'rufus-dollar', '>= 1.0.4' diff --git a/test/functional/base.rb b/test/functional/base.rb index b48e5f06..b2729f8d 100644 --- a/test/functional/base.rb +++ b/test/functional/base.rb @@ -33,7 +33,13 @@ def setup @tracer = Tracer.new + tracer = @tracer + @engine.context.instance_eval do + @tracer = tracer + end + @engine.add_service('tracer', @tracer) + @engine.add_service('stash', {}) noisy if ARGV.include?('-N') @@ -47,6 +53,11 @@ def teardown @engine.context.storage.close if @engine.context.storage.respond_to?(:close) end + def stash + + @engine.context.stash + end + def assert_log_count (count, &block) c = @engine.context.logger.log.select(&block).size diff --git a/test/functional/eft_0_process_definition.rb b/test/functional/eft_0_process_definition.rb index bdb87809..c2a2a194 100644 --- a/test/functional/eft_0_process_definition.rb +++ b/test/functional/eft_0_process_definition.rb @@ -7,7 +7,7 @@ require File.join(File.dirname(__FILE__), 'base') -require 'ruote/part/hash_participant' +require 'ruote/participant' class EftProcessDefinitionTest < Test::Unit::TestCase @@ -28,7 +28,7 @@ def test_sub_definition participant :ref => :alpha end - alpha = @engine.register_participant :alpha, Ruote::HashParticipant + alpha = @engine.register_participant :alpha, Ruote::StorageParticipant #noisy diff --git a/test/functional/eft_11_wait.rb b/test/functional/eft_11_wait.rb index 90a4ca63..e53c5f62 100644 --- a/test/functional/eft_11_wait.rb +++ b/test/functional/eft_11_wait.rb @@ -24,13 +24,15 @@ def test_wait_for #noisy - ts = [] - @engine.register_participant(:alpha) { ts << Time.now } + @engine.context.stash[:ts] = [] + + @engine.register_participant(:alpha) { stash[:ts] << Time.now } assert_trace 'done.', pdef - #p [ ts[1].sec, ts[0].sec ] - d = (ts[1].sec - ts[0].sec) % 60 + d = ( + @engine.context.stash[:ts][1].sec - @engine.context.stash[:ts][0].sec + ) % 60 deltas = [ 2, 3 ] deltas << 4 if @engine.storage.class.name.match(/^Ruote::Couch::/) @@ -66,8 +68,9 @@ def test_cancel_wait def test_wait_until - ts = [] - @engine.register_participant(:alpha) { ts << Time.now } + @engine.context.stash[:ts] = [] + + @engine.register_participant(:alpha) { stash[:ts] << Time.now } pdef = Ruote.process_definition do sequence do @@ -82,8 +85,10 @@ def test_wait_until assert_trace 'done.', pdef - #p ts - assert ts[1] - ts[0] > 1.0, "#{ts[1] - ts[0]} should be > 1.0" + ts0 = @engine.context.stash[:ts][0] + ts1 = @engine.context.stash[:ts][1] + + assert(ts1 - ts0 > 1.0, "#{ts1 - ts0} should be > 1.0") end def test_wait_until_now diff --git a/test/functional/eft_12_listen.rb b/test/functional/eft_12_listen.rb index eb49e5bd..03b2d474 100644 --- a/test/functional/eft_12_listen.rb +++ b/test/functional/eft_12_listen.rb @@ -171,12 +171,12 @@ def test_where #noisy - count = 0 + stash[:count] = 0 @engine.register_participant :alpha do |wi| @tracer << "alpha\n" - wi.fields['who'] = 'toto' if count > 0 - count = count + 1 + wi.fields['who'] = 'toto' if stash[:count] > 0 + stash[:count] += 1 end wfid = @engine.launch(pdef) diff --git a/test/functional/eft_13_iterator.rb b/test/functional/eft_13_iterator.rb index 3e92a26a..4bfbb550 100644 --- a/test/functional/eft_13_iterator.rb +++ b/test/functional/eft_13_iterator.rb @@ -110,8 +110,9 @@ def test_break @tracer << "#{workitem.participant_name}\n" - workitem.fields['__command__'] = [ 'break', nil ] \ - if workitem.participant_name == 'bob' + if workitem.participant_name == 'bob' + workitem.fields['__command__'] = [ 'break', nil ] + end end #noisy @@ -121,14 +122,14 @@ def test_break def test_rewind - rewound = false + stash[:rewound] = false @engine.register_participant '.*' do |workitem| @tracer << "#{workitem.participant_name}\n" - if (not rewound) and workitem.participant_name == 'bob' - rewound = true + if (not stash[:rewound]) and workitem.participant_name == 'bob' + stash[:rewound] = true workitem.fields['__command__'] = [ 'rewind', nil ] end end @@ -144,8 +145,9 @@ def test_skip @tracer << "#{workitem.participant_name}\n" - workitem.fields['__command__'] = [ 'skip', 1 ] \ - if workitem.participant_name == 'alice' + if workitem.participant_name == 'alice' + workitem.fields['__command__'] = [ 'skip', 1 ] + end end #noisy @@ -159,8 +161,9 @@ def test_jump @tracer << "#{workitem.participant_name}\n" - workitem.fields['__command__'] = [ 'jump', -1 ] \ - if workitem.participant_name == 'alice' + if workitem.participant_name == 'alice' + workitem.fields['__command__'] = [ 'jump', -1 ] + end end #noisy diff --git a/test/functional/eft_14_cursor.rb b/test/functional/eft_14_cursor.rb index f1d95304..64aec132 100644 --- a/test/functional/eft_14_cursor.rb +++ b/test/functional/eft_14_cursor.rb @@ -169,16 +169,14 @@ def test_jump_to end end - count = 0 - # closures ftw - @engine.register_participant :author do |workitem| @tracer << "a\n" - count = count + 1 + stash[:count] ||= 0 + stash[:count] += 1 end @engine.register_participant :reviewer do |workitem| @tracer << "r\n" - workitem.fields['not_ok'] = (count < 3) + workitem.fields['not_ok'] = (stash[:count] < 3) end @engine.register_participant :publisher do |workitem| @tracer << "p\n" @@ -228,7 +226,7 @@ def test_external_break end end - @engine.register_participant :alpha, Ruote::NoOpParticipant.new + @engine.register_participant :alpha, Ruote::NoOpParticipant #noisy diff --git a/test/functional/eft_15_loop.rb b/test/functional/eft_15_loop.rb index 918914c9..28e2cb6f 100644 --- a/test/functional/eft_15_loop.rb +++ b/test/functional/eft_15_loop.rb @@ -34,8 +34,9 @@ def test_loop @tracer << "b\n" workitem.fields['count'] += 1 - workitem.fields['__command__'] = [ 'break', nil ] \ - if workitem.fields['count'] > 5 + if workitem.fields['count'] > 5 + workitem.fields['__command__'] = [ 'break', nil ] + end end assert_trace(%w[ a b a b a b ], pdef) @@ -57,8 +58,9 @@ def test_repeat (workitem.fields['count'] ||= 0) workitem.fields['count'] += 1 - workitem.fields['__command__'] = [ 'break', nil ] \ - if workitem.fields['count'] > 5 + if workitem.fields['count'] > 5 + workitem.fields['__command__'] = [ 'break', nil ] + end end assert_trace(%w[ a a a a a a ], pdef) diff --git a/test/functional/eft_18_concurrent_iterator.rb b/test/functional/eft_18_concurrent_iterator.rb index a49e5cd6..8950099a 100644 --- a/test/functional/eft_18_concurrent_iterator.rb +++ b/test/functional/eft_18_concurrent_iterator.rb @@ -7,9 +7,6 @@ require File.join(File.dirname(__FILE__), 'base') -require 'ruote/part/hash_participant' -require 'ruote/part/null_participant' - class EftConcurrentIteratorTest < Test::Unit::TestCase include FunctionalBase @@ -146,33 +143,36 @@ def test_iterator_with_branches_finishing_before_others end end - p1 = @engine.register_participant :participant_1, Ruote::HashParticipant.new - p2 = @engine.register_participant :participant_2, Ruote::HashParticipant.new - p3 = @engine.register_participant :participant_3, Ruote::HashParticipant.new + sto = @engine.register_participant '.+', Ruote::StorageParticipant + + assert_equal 0, sto.size # just to be sure #noisy wfid = @engine.launch(pdef) + wait_for(:participant_1) wait_for(:participant_1) - assert_equal 0, p2.size - assert_equal 0, p3.size + assert_equal( + { 'participant_1' => 2 }, + sto.per_participant_count) - p1.reply(p1.first) + sto.reply(sto.first) wait_for(:participant_2) + wait_for(1) - assert_equal 1, p2.size - assert_equal 0, p3.size + assert_equal( + { 'participant_1' => 1, 'participant_2' => 1 }, + sto.per_participant_count) - p2.reply(p2.first) + sto.reply(sto.per_participant['participant_2'].first) wait_for(3) - assert_equal 0, p3.size - assert_equal 1, p1.size - assert_equal 0, p2.size + assert_equal 1, sto.size + assert_equal 'participant_1', sto.first.participant_name end def test_passing_non_array_as_thing_to_iterate @@ -269,10 +269,8 @@ def test_merge_type_isolate bravo end - mf = nil - @engine.register_participant :bravo do |workitem| - mf = workitem.fields + stash[:mf] = workitem.fields nil end @@ -280,7 +278,7 @@ def test_merge_type_isolate assert_trace(%w[ . . . ], pdef) - mf = ('0'..'2').to_a.map { |k| mf[k]['f'] }.sort + mf = ('0'..'2').to_a.map { |k| @engine.context.stash[:mf][k]['f'] }.sort assert_equal %w[ a b c ], mf end @@ -293,10 +291,8 @@ def test_merge_type_stack bravo end - mf = nil - @engine.register_participant :bravo do |workitem| - mf = workitem.fields + stash[:mf] = workitem.fields nil end @@ -306,10 +302,10 @@ def test_merge_type_stack assert_equal( [["a"], ["b"]], - mf['stack'].collect { |f| f.values }.sort) + @engine.context.stash[:mf]['stack'].collect { |f| f.values }.sort) assert_equal( {"on"=>"a, b", "to_f"=>"f", "merge_type"=>"stack"}, - mf['stack_attributes']) + @engine.context.stash[:mf]['stack_attributes']) end def test_cancel @@ -326,8 +322,8 @@ def test_cancel end end - a_count = 0 - @engine.register_participant(:alpha) { |wi| a_count += 1 } + @engine.context.stash[:a_count] = 0 + @engine.register_participant(:alpha) { |wi| stash[:a_count] += 1 } @engine.register_participant(:bravo, Ruote::NullParticipant) #noisy @@ -337,7 +333,7 @@ def test_cancel wait_for(2 + n * 5) #p "=" * 80 - assert_equal n, a_count + assert_equal n, @engine.context.stash[:a_count] @engine.cancel_process(wfid) wait_for(wfid) @@ -356,12 +352,11 @@ def test_add_branch_command end end - @engine.register_participant 'alpha' do |workitem| + @engine.register_participant 'alpha' do |wi| @tracer << "#{workitem.fields['f']}\n" - workitem.fields['__add_branches__'] = %w[ a b ] \ - if workitem.fields['f'] == 2 + wi.fields['__add_branches__'] = %w[ a b ] if wi.fields['f'] == 2 end #noisy @@ -377,6 +372,10 @@ def test_add_branch_command def register_catchall_participant @subs = [] + subs = @subs + @engine.context.instance_eval do + @subs = subs + end @engine.register_participant '.*' do |workitem| diff --git a/test/functional/eft_19_reserve.rb b/test/functional/eft_19_reserve.rb index 3713af8f..ae9e080b 100644 --- a/test/functional/eft_19_reserve.rb +++ b/test/functional/eft_19_reserve.rb @@ -7,7 +7,7 @@ require File.join(File.dirname(__FILE__), 'base') -require 'ruote/part/hash_participant' +require 'ruote/participant' class EftReserveTest < Test::Unit::TestCase @@ -28,7 +28,7 @@ def test_reserve #noisy - alpha = @engine.register_participant :alpha, Ruote::HashParticipant.new + alpha = @engine.register_participant :alpha, Ruote::StorageParticipant wfid = @engine.launch(pdef) @@ -74,7 +74,7 @@ def test_cancel_reserve #noisy - alpha = @engine.register_participant :alpha, Ruote::HashParticipant.new + alpha = @engine.register_participant :alpha, Ruote::StorageParticipant wfid = @engine.launch(pdef) @@ -112,7 +112,7 @@ def test_reserve_but_no_name #noisy - alpha = @engine.register_participant :alpha, Ruote::HashParticipant.new + alpha = @engine.register_participant :alpha, Ruote::StorageParticipant wfid = @engine.launch(pdef) diff --git a/test/functional/eft_20_save.rb b/test/functional/eft_20_save.rb index 38885790..97447368 100644 --- a/test/functional/eft_20_save.rb +++ b/test/functional/eft_20_save.rb @@ -7,7 +7,7 @@ require File.join(File.dirname(__FILE__), 'base') -require 'ruote/part/hash_participant' +require 'ruote/participant' class EftSaveTest < Test::Unit::TestCase @@ -22,7 +22,7 @@ def test_save_to_variable #noisy - @engine.register_participant :alpha, Ruote::HashParticipant.new + @engine.register_participant :alpha, Ruote::StorageParticipant wfid = @engine.launch(pdef) @@ -43,7 +43,7 @@ def test_save_to_field #noisy - alpha = @engine.register_participant :alpha, Ruote::HashParticipant.new + alpha = @engine.register_participant :alpha, Ruote::StorageParticipant wfid = @engine.launch(pdef) @@ -63,7 +63,7 @@ def test_save_to_field_deep #noisy - alpha = @engine.register_participant :alpha, Ruote::HashParticipant.new + alpha = @engine.register_participant :alpha, Ruote::StorageParticipant wfid = @engine.launch(pdef) diff --git a/test/functional/eft_3_participant.rb b/test/functional/eft_3_participant.rb index 8c8e1bfd..b6a3af8e 100644 --- a/test/functional/eft_3_participant.rb +++ b/test/functional/eft_3_participant.rb @@ -68,7 +68,7 @@ def test_participant_exp_name_tree_rewriting delta :tag => 'whatever' end - delta = @engine.register_participant :delta, Ruote::HashParticipant.new + delta = @engine.register_participant :delta, Ruote::StorageParticipant @engine.launch(pdef) wait_for(:delta) @@ -88,7 +88,7 @@ def test_participant_if %w[ eecho fox gamma ].each do |pname| @engine.register_participant pname do |workitem| - @tracer << "#{pname}\n" + @tracer << "#{workitem.participant_name}\n" end end @@ -104,11 +104,9 @@ def test_participant_and_att_text echo 'done.' end - atts = nil - @engine.register_participant :notify do |wi, fe| #p fe.attribute_text - atts = fe.attributes + stash[:atts] = fe.attributes end #noisy @@ -117,7 +115,7 @@ def test_participant_and_att_text assert_equal( { "commander of the left guard"=>nil, "if"=>"true", "ref"=>"notify" }, - atts) + stash[:atts]) end def test_dispatched diff --git a/test/functional/eft_5_subprocess.rb b/test/functional/eft_5_subprocess.rb index 5ef1032b..c4994636 100644 --- a/test/functional/eft_5_subprocess.rb +++ b/test/functional/eft_5_subprocess.rb @@ -96,17 +96,15 @@ def test_subprocess_passing_tree end end - tree = nil - @engine.register_participant :alpha do |workitem, fexp| - tree = fexp.lookup_variable('tree') + stash[:tree] = fexp.lookup_variable('tree') end #noisy assert_trace '', pdef - assert_equal ["noop", {}, []], tree + assert_equal ["noop", {}, []], stash[:tree] end def test_subprocess_uri diff --git a/test/functional/eft_6_concurrence.rb b/test/functional/eft_6_concurrence.rb index a4476ebf..2fff33b4 100644 --- a/test/functional/eft_6_concurrence.rb +++ b/test/functional/eft_6_concurrence.rb @@ -7,7 +7,7 @@ require File.join(File.dirname(__FILE__), 'base') -require 'ruote/part/hash_participant' +#require 'ruote/part/hash_participant' class EftConcurrenceTest < Test::Unit::TestCase @@ -42,20 +42,20 @@ def test_over_if bravo end - count = 0 + @engine.context.instance_eval do + @count = 0 + end + # since block participants are evaluated in the context context - alpha = @engine.register_participant :alpha do |workitem| - workitem.fields['seen'] = 'indeed' if count == 1 + alpha = @engine.register_participant :alpha, 'do_not_thread' => true do |wi| + wi.fields['seen'] = 'indeed' if @count == 1 @tracer << "alpha\n" - count = count + 1 + @count = @count + 1 nil end - alpha.do_not_thread = true - - fields = nil @engine.register_participant :bravo do |workitem| - fields = workitem.fields + stash[:fields] = workitem.fields nil end @@ -67,10 +67,10 @@ def test_over_if # {'1'=>{"seen"=>"indeed"}, '0'=>{}, "params"=>{"ref"=>"bravo"}}, # fields) - params = fields.delete('params') + params = @engine.context.stash[:fields].delete('params') assert_equal({ 'ref' => 'bravo' }, params) - assert_match /seen/, fields.inspect + assert_match /seen/, @engine.context.stash[:fields].inspect end def test_over_unless @@ -85,17 +85,19 @@ def test_over_unless echo 'done.' end - count = 0 + @engine.context.instance_eval do + @count = 0 + end + # since block participants are evaluated in the context context - alpha = @engine.register_participant :alpha do |workitem| - if count > 1 - workitem.fields['ok'] = false + alpha = @engine.register_participant :alpha, 'do_not_thread' => true do |wi| + if @count > 1 + wi.fields['ok'] = false else @tracer << "a\n" - count = count + 1 + @count = @count + 1 end end - alpha.do_not_thread = true fields = nil @@ -137,7 +139,7 @@ def run_concurrence (concurrence_attributes, noise) alpha end - alpha = @engine.register_participant :alpha, Ruote::HashParticipant.new + alpha = @engine.register_participant :alpha, Ruote::StorageParticipant noisy if noise @@ -215,8 +217,7 @@ def run_test_count (remaining, noise) end end - @alpha = @engine.register_participant :alpha, Ruote::HashParticipant.new - @bravo = @engine.register_participant :bravo, Ruote::HashParticipant.new + @engine.register_participant '.+', Ruote::StorageParticipant noisy if noise @@ -224,7 +225,7 @@ def run_test_count (remaining, noise) wait_for(:alpha) - @alpha.reply(@alpha.first) + @engine.storage_participant.reply(@engine.storage_participant.first) wait_for(wfid) @@ -244,8 +245,7 @@ def test_count sleep 0.350 # since now dispatch_cancel occurs asynchronously... - assert_equal 0, @alpha.size - assert_equal 0, @bravo.size + assert_equal 0, @engine.storage_participant.size end def test_count_remaining_forget @@ -256,15 +256,15 @@ def test_count_remaining_forget #assert_equal 1, logger.log.select { |e| e['action'] == 'forget' }.size - assert_equal 0, @alpha.size - assert_equal 1, @bravo.size + assert_equal 1, @engine.storage_participant.size + assert_equal 'bravo', @engine.storage_participant.first.participant_name #@engine.context.storage.get_many('expressions').each { |e| p e['fei'] } #puts @engine.context.storage.dump('expressions') assert_equal 2, @engine.context.storage.get_many('expressions').size assert_not_nil @engine.process(wfid) - @bravo.reply(@bravo.first) + @engine.storage_participant.reply(@engine.storage_participant.first) wait_for(wfid) @@ -281,7 +281,7 @@ def test_cancel end end - alpha = @engine.register_participant :alpha, Ruote::HashParticipant.new + alpha = @engine.register_participant :alpha, Ruote::StorageParticipant #noisy diff --git a/test/functional/eft_8_undo.rb b/test/functional/eft_8_undo.rb index 528b3bb1..6153da5a 100644 --- a/test/functional/eft_8_undo.rb +++ b/test/functional/eft_8_undo.rb @@ -7,7 +7,7 @@ require File.join(File.dirname(__FILE__), 'base') -require 'ruote/part/hash_participant' +require 'ruote/participant' class EftUndoTest < Test::Unit::TestCase @@ -23,7 +23,7 @@ def test_undo_ref echo 'over' end - alpha = @engine.register_participant :alpha, Ruote::HashParticipant.new + alpha = @engine.register_participant :alpha, Ruote::StorageParticipant #noisy @@ -47,7 +47,7 @@ def test_undo echo 'over' end - alpha = @engine.register_participant :alpha, Ruote::HashParticipant.new + alpha = @engine.register_participant :alpha, Ruote::StorageParticipant #noisy diff --git a/test/functional/eft_9_redo.rb b/test/functional/eft_9_redo.rb index d7290a60..f79fb3fe 100644 --- a/test/functional/eft_9_redo.rb +++ b/test/functional/eft_9_redo.rb @@ -22,7 +22,7 @@ def test_redo end end - alpha = @engine.register_participant :alpha, Ruote::HashParticipant.new + alpha = @engine.register_participant :alpha, Ruote::StorageParticipant #noisy diff --git a/test/functional/ft_11_recursion.rb b/test/functional/ft_11_recursion.rb index cc655d9a..09ce2d61 100644 --- a/test/functional/ft_11_recursion.rb +++ b/test/functional/ft_11_recursion.rb @@ -16,16 +16,10 @@ class FtRecursionTest < Test::Unit::TestCase class CountingParticipant include Ruote::LocalParticipant - attr_reader :wfids - - def initialize - - @wfids = [] - end - def consume (workitem) - @wfids << "#{workitem.fei.wfid}|#{workitem.fei.subid}" + @context.stash[:wfids] ||= [] + @context.stash[:wfids] << "#{workitem.fei.wfid}|#{workitem.fei.subid}" workitem.fields['count'] ||= 0 workitem.fields['count'] = workitem.fields['count'] + 1 @@ -45,6 +39,8 @@ def cancel (fei, flavour) def test_main_recursion + @engine.context.stash[:wfids] = [] + pdef = Ruote.process_definition :name => 'def0' do sequence do alpha @@ -52,19 +48,19 @@ def test_main_recursion end end - alpha = @engine.register_participant :alpha, CountingParticipant.new + alpha = @engine.register_participant :alpha, CountingParticipant #noisy assert_trace(%w[ 1 2 3 4 5 6 ], pdef) - #p alpha.wfids.uniq - - assert_equal 6, alpha.wfids.uniq.size + assert_equal 6, @engine.context.stash[:wfids].uniq.size end def test_sub_recursion + @engine.context.stash[:wfids] = [] + pdef = Ruote.process_definition do define 'sub0' do sequence do @@ -75,7 +71,7 @@ def test_sub_recursion sub0 end - alpha = @engine.register_participant :alpha, CountingParticipant.new + alpha = @engine.register_participant :alpha, CountingParticipant #noisy @@ -83,7 +79,7 @@ def test_sub_recursion #p alpha.wfids.uniq - assert_equal 6, alpha.wfids.uniq.size + assert_equal 6, @engine.context.stash[:wfids].uniq.size end def test_forgotten_main_recursion @@ -97,7 +93,7 @@ def test_forgotten_main_recursion end end - alpha = @engine.register_participant :alpha, CountingParticipant.new + alpha = @engine.register_participant :alpha, CountingParticipant #noisy diff --git a/test/functional/ft_12_launchitem.rb b/test/functional/ft_12_launchitem.rb index 02493e27..a7405d86 100644 --- a/test/functional/ft_12_launchitem.rb +++ b/test/functional/ft_12_launchitem.rb @@ -17,10 +17,8 @@ def test_launch alpha end - fields = nil - @engine.register_participant :alpha do |workitem| - fields = workitem.fields + stash[:fields] = workitem.fields @tracer << 'a' nil end @@ -32,8 +30,14 @@ def test_launch assert_equal('a', @tracer.to_s) - assert_not_nil(fields.delete('dispatched_at')) - assert_equal({"a"=>0, "b"=>1, "params"=>{"ref"=>"alpha"}}, fields) + @engine.context.stash[:fields].delete('__result__') + + assert_not_nil( + @engine.context.stash[:fields].delete('dispatched_at')) + + assert_equal( + {"a"=>0, "b"=>1, "params"=>{"ref"=>"alpha"}}, + @engine.context.stash[:fields]) end end diff --git a/test/functional/ft_13_variables.rb b/test/functional/ft_13_variables.rb index 0bf9e966..7443cd58 100644 --- a/test/functional/ft_13_variables.rb +++ b/test/functional/ft_13_variables.rb @@ -104,7 +104,7 @@ def test_lookup_var_site end end - results = [] + @engine.context.stash[:results] = [] @engine.register_participant :alpha do |workitem, fexp| @@ -112,20 +112,18 @@ class << fexp public :locate_var end - results << fexp.locate_var('//a') - results << fexp.locate_var('/a').first.fei.to_storage_id - results << fexp.locate_var('a').first.fei.to_storage_id + stash[:results] << fexp.locate_var('//a') + stash[:results] << fexp.locate_var('/a').first.fei.to_storage_id + stash[:results] << fexp.locate_var('a').first.fei.to_storage_id end #noisy assert_trace 'done.', pdef - #p results - - assert_equal(nil, results[0]) - assert_match(/^0||\d+_\d+$/, results[1]) - assert_match(/^0\_0|\d+|\d+_\d+$/, results[2]) + assert_equal(nil, @engine.context.stash[:results][0]) + assert_match(/^0||\d+_\d+$/, @engine.context.stash[:results][1]) + assert_match(/^0\_0|\d+|\d+_\d+$/, @engine.context.stash[:results][2]) end def test_lookup_in_var diff --git a/test/functional/ft_14_re_apply.rb b/test/functional/ft_14_re_apply.rb index 8380239c..e15c3834 100644 --- a/test/functional/ft_14_re_apply.rb +++ b/test/functional/ft_14_re_apply.rb @@ -7,9 +7,6 @@ require File.join(File.dirname(__FILE__), 'base') -require 'ruote/part/hash_participant' -require 'ruote/part/storage_participant' - class FtReApplyTest < Test::Unit::TestCase include FunctionalBase @@ -23,7 +20,7 @@ class FtReApplyTest < Test::Unit::TestCase def test_re_apply - alpha = @engine.register_participant :alpha, Ruote::HashParticipant.new + alpha = @engine.register_participant :alpha, Ruote::StorageParticipant #noisy @@ -54,7 +51,7 @@ def test_re_apply def test_cancel_and_re_apply - alpha = @engine.register_participant :alpha, Ruote::HashParticipant.new + alpha = @engine.register_participant :alpha, Ruote::StorageParticipant #noisy @@ -85,7 +82,7 @@ def test_cancel_and_re_apply def test_update_expression_and_re_apply - alpha = @engine.register_participant :alpha, Ruote::HashParticipant.new + alpha = @engine.register_participant :alpha, Ruote::StorageParticipant #noisy @@ -129,7 +126,7 @@ def test_re_apply_with_new_workitem_fields end end - alpha = @engine.register_participant :alpha, Ruote::HashParticipant.new + alpha = @engine.register_participant :alpha, Ruote::StorageParticipant #noisy @@ -167,7 +164,7 @@ def test_re_apply_with_merged_workitem_fields end end - alpha = @engine.register_participant :alpha, Ruote::HashParticipant.new + alpha = @engine.register_participant :alpha, Ruote::StorageParticipant #noisy @@ -198,7 +195,7 @@ def test_re_apply_with_merged_workitem_fields def test_re_apply_with_new_tree - alpha = @engine.register_participant :alpha, Ruote::HashParticipant.new + alpha = @engine.register_participant :alpha, Ruote::StorageParticipant #noisy diff --git a/test/functional/ft_15_timeout.rb b/test/functional/ft_15_timeout.rb index 665d37b0..8f8f1fa9 100644 --- a/test/functional/ft_15_timeout.rb +++ b/test/functional/ft_15_timeout.rb @@ -7,8 +7,6 @@ require File.join(File.dirname(__FILE__), 'base') -require 'ruote/part/hash_participant' - class FtTimeoutTest < Test::Unit::TestCase include FunctionalBase @@ -22,20 +20,21 @@ def test_timeout end end - alpha = @engine.register_participant :alpha, Ruote::HashParticipant.new - bravo = @engine.register_participant :bravo, Ruote::HashParticipant.new + @engine.register_participant :alpha, Ruote::StorageParticipant + sto = @engine.register_participant :bravo, Ruote::StorageParticipant #noisy wfid = @engine.launch(pdef) wait_for(:bravo) - assert_equal 0, alpha.size - assert_equal 1, bravo.size + assert_equal 1, sto.size + assert_equal 'bravo', sto.first.participant_name + assert_equal 2, logger.log.select { |e| e['flavour'] == 'timeout' }.size assert_equal 0, @engine.storage.get_many('schedules').size - assert_not_nil bravo.first.fields['__timed_out__'] + assert_not_nil sto.first.fields['__timed_out__'] end def test_cancel_timeout @@ -47,22 +46,23 @@ def test_cancel_timeout end end - alpha = @engine.register_participant :alpha, Ruote::HashParticipant.new - bravo = @engine.register_participant :bravo, Ruote::HashParticipant.new + @engine.register_participant :alpha, Ruote::StorageParticipant + sto = @engine.register_participant :bravo, Ruote::StorageParticipant #noisy wfid = @engine.launch(pdef) wait_for(6) - assert_equal 1, alpha.size + assert_equal 1, sto.size + assert_equal 'alpha', sto.first.participant_name - @engine.cancel_expression(alpha.first.fei) + @engine.cancel_expression(sto.first.fei) wait_for(:bravo) - assert_equal 0, alpha.size - assert_equal 1, bravo.size + assert_equal 1, sto.size + assert_equal 'bravo', sto.first.participant_name assert_equal 0, @engine.storage.get_many('schedules').size end @@ -82,7 +82,7 @@ def test_on_timeout_redo alpha :timeout => '1.1', :on_timeout => 'redo' end - alpha = @engine.register_participant :alpha, Ruote::HashParticipant.new + alpha = @engine.register_participant :alpha, Ruote::StorageParticipant #noisy @@ -113,7 +113,7 @@ def test_on_timeout_cancel_nested end end - alpha = @engine.register_participant :alpha, Ruote::HashParticipant.new + alpha = @engine.register_participant :alpha, Ruote::StorageParticipant #noisy @@ -132,7 +132,7 @@ def test_on_timeout_error alpha :timeout => '1.1', :on_timeout => 'error' end - alpha = @engine.register_participant :alpha, Ruote::HashParticipant.new + alpha = @engine.register_participant :alpha, Ruote::StorageParticipant #noisy @@ -161,7 +161,7 @@ def test_deep_on_timeout_error end end - alpha = @engine.register_participant :alpha, Ruote::HashParticipant.new + alpha = @engine.register_participant :alpha, Ruote::StorageParticipant wfid = @engine.launch(pdef) wait_for(wfid) @@ -203,7 +203,7 @@ def test_timeout_at end end - alpha = @engine.register_participant :alpha, Ruote::HashParticipant.new + alpha = @engine.register_participant :alpha, Ruote::StorageParticipant #noisy diff --git a/test/functional/ft_16_participant_params.rb b/test/functional/ft_16_participant_params.rb index 6819ecb7..57e7d384 100644 --- a/test/functional/ft_16_participant_params.rb +++ b/test/functional/ft_16_participant_params.rb @@ -7,8 +7,6 @@ require File.join(File.dirname(__FILE__), 'base') -require 'ruote/part/hash_participant' - class FtParticipantParamsTest < Test::Unit::TestCase include FunctionalBase @@ -23,7 +21,7 @@ def test_params end end - alpha = @engine.register_participant :alpha, Ruote::HashParticipant.new + alpha = @engine.register_participant :alpha, Ruote::StorageParticipant #noisy diff --git a/test/functional/ft_18_kill.rb b/test/functional/ft_18_kill.rb index 26c4af10..119bf1b6 100644 --- a/test/functional/ft_18_kill.rb +++ b/test/functional/ft_18_kill.rb @@ -7,8 +7,6 @@ require File.join(File.dirname(__FILE__), 'base') -require 'ruote/participant' - class FtKillTest < Test::Unit::TestCase include FunctionalBase @@ -19,7 +17,7 @@ def test_kill_process alpha end - alpha = @engine.register_participant :alpha, Ruote::HashParticipant.new + alpha = @engine.register_participant :alpha, Ruote::StorageParticipant #noisy @@ -46,8 +44,8 @@ def test_kill_does_not_trigger_on_cancel end end - alpha = @engine.register_participant :alpha, Ruote::HashParticipant.new - catcher = @engine.register_participant :catcher, Ruote::HashParticipant.new + @engine.register_participant :alpha, Ruote::StorageParticipant + sto = @engine.register_participant :catcher, Ruote::StorageParticipant wfid = @engine.launch(pdef) wait_for(:alpha) @@ -56,8 +54,7 @@ def test_kill_does_not_trigger_on_cancel wait_for(wfid) - assert_equal 0, alpha.size - assert_equal 0, catcher.size + assert_equal 0, sto.size end def test_kill_expression_does_not_trigger_on_cancel @@ -68,18 +65,17 @@ def test_kill_expression_does_not_trigger_on_cancel end end - alpha = @engine.register_participant :alpha, Ruote::HashParticipant.new - catcher = @engine.register_participant :catcher, Ruote::HashParticipant.new + @engine.register_participant :alpha, Ruote::StorageParticipant + sto = @engine.register_participant :catcher, Ruote::StorageParticipant wfid = @engine.launch(pdef) wait_for(:alpha) - @engine.kill_expression(alpha.first.fei) + @engine.kill_expression(sto.first.fei) wait_for(wfid) - assert_equal 0, alpha.size - assert_equal 0, catcher.size + assert_equal 0, sto.size end def test_kill__expression diff --git a/test/functional/ft_1_process_status.rb b/test/functional/ft_1_process_status.rb index babb0e68..812d8a48 100644 --- a/test/functional/ft_1_process_status.rb +++ b/test/functional/ft_1_process_status.rb @@ -21,7 +21,7 @@ def test_ps #noisy - alpha = @engine.register_participant :alpha, Ruote::HashParticipant.new + alpha = @engine.register_participant :alpha, Ruote::StorageParticipant wfid = @engine.launch(pdef, :workitem => { 'kilroy' => 'was here' }) @@ -47,7 +47,7 @@ def test_variables end end - alpha = @engine.register_participant :alpha, Ruote::HashParticipant + alpha = @engine.register_participant :alpha, Ruote::StorageParticipant wfid = @engine.launch(pdef, :workitem => { 'kilroy' => 'was here' }) wait_for(:alpha) @@ -93,7 +93,7 @@ def test_tree end end - alpha = @engine.register_participant :alpha, Ruote::HashParticipant + alpha = @engine.register_participant :alpha, Ruote::StorageParticipant wfid = @engine.launch(pdef) wait_for(:alpha) @@ -145,7 +145,7 @@ def test_tree_when_define_rewrites_it end end - alpha = @engine.register_participant :alpha, Ruote::HashParticipant + alpha = @engine.register_participant :alpha, Ruote::StorageParticipant wfid = @engine.launch(pdef) wait_for(:alpha) @@ -184,7 +184,7 @@ def test_all_variables end end - alpha = @engine.register_participant :alpha, Ruote::HashParticipant.new + alpha = @engine.register_participant :alpha, Ruote::StorageParticipant #noisy @@ -214,7 +214,7 @@ def test_tags end end - alpha = @engine.register_participant :alpha, Ruote::HashParticipant.new + alpha = @engine.register_participant :alpha, Ruote::StorageParticipant #noisy @@ -243,7 +243,7 @@ def test_all_tags end end - alpha = @engine.register_participant :alpha, Ruote::HashParticipant.new + alpha = @engine.register_participant :alpha, Ruote::StorageParticipant #noisy @@ -264,7 +264,7 @@ def test_processes #noisy - alpha = @engine.register_participant :alpha, Ruote::HashParticipant.new + alpha = @engine.register_participant :alpha, Ruote::StorageParticipant wfid0 = @engine.launch(pdef) wfid1 = @engine.launch(pdef) @@ -291,9 +291,6 @@ def test_tree_rewrite delta end - tree0 = nil - tree1 = nil - @engine.register_participant :alpha do |wi, fexp| @tracer << "a\n" @@ -309,11 +306,11 @@ def test_tree_rewrite end @engine.register_participant :charly do |wi, fexp| @tracer << "c\n" - tree0 = fexp.context.engine.process(fexp.fei.wfid).current_tree + stash[:tree0] = fexp.context.engine.process(fexp.fei.wfid).current_tree end @engine.register_participant :delta do |wi, fexp| @tracer << "d\n" - tree1 = fexp.context.engine.process(fexp.fei.wfid).current_tree + stash[:tree1] = fexp.context.engine.process(fexp.fei.wfid).current_tree end #noisy @@ -322,11 +319,11 @@ def test_tree_rewrite assert_equal( ["define", {"name"=>"test"}, [["sequence", {}, [["alpha", {}, []], ["charly", {}, []], ["participant", {"ref"=>"charly"}, []]]], ["delta", {}, []]]], - tree0) + @engine.context.stash[:tree0]) assert_equal( ["define", {"name"=>"test"}, [["sequence", {}, [["alpha", {}, []], ["charly", {}, []], ["charly", {}, []]]], ["participant", {"ref"=>"delta"}, []]]], - tree1) + @engine.context.stash[:tree1]) end def test_when_on_cancel_subprocess @@ -340,7 +337,7 @@ def test_when_on_cancel_subprocess end end - alpha = @engine.register_participant :alpha, Ruote::HashParticipant.new + alpha = @engine.register_participant :alpha, Ruote::StorageParticipant #noisy @@ -382,7 +379,7 @@ def test_fexp_to_h #noisy - alpha = @engine.register_participant :alpha, Ruote::HashParticipant.new + alpha = @engine.register_participant :alpha, Ruote::StorageParticipant wfid = @engine.launch(pdef) @@ -408,7 +405,7 @@ def test_to_dot end end - alpha = @engine.register_participant :alpha, Ruote::HashParticipant.new + alpha = @engine.register_participant :alpha, Ruote::StorageParticipant wfid = @engine.launch(pdef) diff --git a/test/functional/ft_24_block_participants.rb b/test/functional/ft_24_block_participants.rb index d67a0ba1..c14d9021 100644 --- a/test/functional/ft_24_block_participants.rb +++ b/test/functional/ft_24_block_participants.rb @@ -64,25 +64,25 @@ def test_non_jsonfiable_result return if Ruote::WIN # defective 'json' lib on windows renders this test useless - t = Time.now - @engine.register_participant :alpha do |workitem| - t + Time.now end #noisy - #assert_trace TEST_BLOCK, Ruote.time_to_utc_s(t) - - expected = if defined?(DataMapper) - DataMapper::VERSION >= '1.0.0' ? t.to_s : '' + match = if defined?(DataMapper) && DataMapper::VERSION < '1.0.0' + /^$/ elsif Ruote::JAVA - '' + /^$/ else - t.to_s + /\b#{Time.now.year}\b/ end - assert_trace expected, TEST_BLOCK + wfid = @engine.launch(TEST_BLOCK) + + @engine.wait_for(wfid) + + assert_match match, @tracer.to_s end end diff --git a/test/functional/ft_25_receiver.rb b/test/functional/ft_25_receiver.rb index 4336a2b4..e67ad0b0 100644 --- a/test/functional/ft_25_receiver.rb +++ b/test/functional/ft_25_receiver.rb @@ -24,17 +24,15 @@ def setup end end - @alpha = @engine.register_participant 'alpha', MyParticipant.new + @engine.register_participant 'alpha', MyParticipant end class MyParticipant include Ruote::LocalParticipant - attr_accessor :wi - def consume (workitem) - @wi = workitem + @context.stash[:wi] = workitem # no reply to the engine end @@ -87,13 +85,13 @@ def test_my_receiver wfid = @engine.launch(@pdef) wait_for(:alpha) - while @alpha.wi.nil? do + while @engine.context.stash[:wi].nil? do Thread.pass end assert_equal 3, @engine.process(wfid).expressions.size - receiver.receive(@alpha.wi) + receiver.receive(@engine.context.stash[:wi]) wait_for(wfid) @@ -109,7 +107,7 @@ def test_engine_receive wait_for(:alpha) - @engine.receive(@alpha.wi) + @engine.receive(@engine.context.stash[:wi]) wait_for(wfid) @@ -120,11 +118,9 @@ def test_engine_receive end class MyOtherParticipant - def initialize (receiver) - @receiver = receiver - end + include Ruote::LocalParticipant def consume (workitem) - @receiver.pass(workitem.to_h) + @context.receiver.pass(workitem.to_h) end end class MyOtherReceiver < Ruote::Receiver @@ -145,9 +141,13 @@ def pass (workitem) def test_receiver_triggered_dispatch_error - receiver = MyOtherReceiver.new(@engine) + class << @engine.context + def receiver + @rcv ||= MyOtherReceiver.new(engine) + end + end - @engine.register_participant :alpha, MyOtherParticipant.new(receiver) + @engine.register_participant :alpha, MyOtherParticipant pdef = Ruote.process_definition do alpha diff --git a/test/functional/ft_26_participant_rtimeout.rb b/test/functional/ft_26_participant_rtimeout.rb index 80f6a693..76d91008 100644 --- a/test/functional/ft_26_participant_rtimeout.rb +++ b/test/functional/ft_26_participant_rtimeout.rb @@ -7,12 +7,18 @@ require File.join(File.dirname(__FILE__), 'base') -require 'ruote/part/hash_participant' +require 'ruote/participant' class FtParticipantTimeoutTest < Test::Unit::TestCase include FunctionalBase + class AlphaParticipant < Ruote::StorageParticipant + def rtimeout (workitem) + '1s' + end + end + def test_participant_defined_timeout pdef = Ruote.process_definition do @@ -22,28 +28,22 @@ def test_participant_defined_timeout end end - alpha = @engine.register_participant :alpha, Ruote::HashParticipant.new - bravo = @engine.register_participant :bravo, Ruote::HashParticipant.new - - class << alpha - def rtimeout (workitem) - '1s' - end - end + @engine.register_participant :alpha, AlphaParticipant + sto = @engine.register_participant :bravo, Ruote::StorageParticipant #noisy wfid = @engine.launch(pdef) wait_for(13) - assert_equal 0, alpha.size - assert_equal 1, bravo.size + assert_equal 1, sto.size + assert_equal 'bravo', sto.first.participant_name #logger.log.each { |l| p l } assert_equal 2, logger.log.select { |e| e['flavour'] == 'timeout' }.size assert_equal 0, @engine.storage.get_many('schedules').size - assert_not_nil bravo.first.fields['__timed_out__'] + assert_not_nil sto.first.fields['__timed_out__'] end class MyParticipant diff --git a/test/functional/ft_29_part_template.rb b/test/functional/ft_29_part_template.rb index dd29a6d5..7ce23ea3 100644 --- a/test/functional/ft_29_part_template.rb +++ b/test/functional/ft_29_part_template.rb @@ -18,9 +18,9 @@ class MyParticipant include Ruote::LocalParticipant include Ruote::TemplateMixin - def initialize (opts={}, &block) + def initialize (opts) - @template = opts[:template] + @template = opts['template'] end def consume (workitem) @@ -51,7 +51,8 @@ def test_template @engine.register_participant( :alpha, - MyParticipant.new(:template => "0:${v:var0}\n1:${f:field0}")) + MyParticipant, + :template => "0:${v:var0}\n1:${f:field0}") assert_trace %w[ 0:v_value 1:f_value done. ], pdef end diff --git a/test/functional/ft_2_errors.rb b/test/functional/ft_2_errors.rb index 21a73c6f..5949726b 100644 --- a/test/functional/ft_2_errors.rb +++ b/test/functional/ft_2_errors.rb @@ -7,7 +7,7 @@ require File.join(File.dirname(__FILE__), 'base') -require 'ruote/part/hash_participant' +require 'ruote/participant' class FtErrorsTest < Test::Unit::TestCase @@ -137,12 +137,12 @@ def test_error_in_participant end end - count = 0 + @engine.context.stash[:count] = 0 @engine.register_participant :alpha do - count += 1 + stash[:count] += 1 @tracer << "alpha\n" - raise "something went wrong" if count == 1 + raise "something went wrong" if stash[:count] == 1 end #noisy @@ -173,14 +173,13 @@ def test_error_in_do_no_thread_participant end end - count = 0 + @engine.context.stash[:count] = 0 - alpha = @engine.register_participant :alpha do - count += 1 + alpha = @engine.register_participant :alpha, 'do_not_thread' => true do + stash[:count] += 1 @tracer << "alpha\n" - raise "something went wrong" if count == 1 + raise "something went wrong" if stash[:count] == 1 end - alpha.do_not_thread = true wfid = @engine.launch(pdef) @@ -256,14 +255,13 @@ def test_errors_and_subprocesses end end - count = 0 + @engine.context.stash[:count] = 0 - alpha = @engine.register_participant :alpha do - count += 1 + alpha = @engine.register_participant :alpha, :do_not_thread => true do + stash[:count] += 1 @tracer << "alpha\n" - raise "something went wrong" if count == 1 + raise "something went wrong" if stash[:count] == 1 end - alpha.do_not_thread = true #noisy diff --git a/test/functional/ft_31_part_blocking.rb b/test/functional/ft_31_part_blocking.rb index 12516863..5c797501 100644 --- a/test/functional/ft_31_part_blocking.rb +++ b/test/functional/ft_31_part_blocking.rb @@ -32,10 +32,12 @@ def test_first_is_faster def run_engine (options={}) - first_time = options[:first_time] || 0.0 - second_time = options[:second_time] || 0.0 + @engine.context.stash[:first_time] = options[:first_time] || 0.0 + @engine.context.stash[:second_time] = options[:second_time] || 0.0 - second_time = first_time + 0.1 if first_time == second_time + if @engine.context.stash[:first_time] == @engine.context.stash[:second_time] + @engine.context.stash[:second_time] = @engine.context.stash[:first_time] + 0.1 + end pdef = Ruote.process_definition :name => 'simple' do sequence do @@ -48,12 +50,12 @@ def run_engine (options={}) end @engine.register_participant :first do |wi| - sleep first_time + sleep stash[:first_time] wi.fields['result'] = 'first' end @engine.register_participant :second do |wi| - sleep second_time + sleep stash[:second_time] wi.fields['result'] = 'second' end diff --git a/test/functional/ft_34_cursor_rewind.rb b/test/functional/ft_34_cursor_rewind.rb index 65339a04..d3c10dc5 100644 --- a/test/functional/ft_34_cursor_rewind.rb +++ b/test/functional/ft_34_cursor_rewind.rb @@ -7,7 +7,7 @@ require File.join(File.dirname(__FILE__), 'base') -require 'ruote/part/hash_participant' +require 'ruote/participant' # # testing forced rewinding @@ -25,9 +25,9 @@ def test_cursor_forced_back end end - alpha = @engine.register_participant :alpha, Ruote::HashParticipant.new - bravo = @engine.register_participant :bravo, Ruote::HashParticipant.new - charly = @engine.register_participant :charly, Ruote::HashParticipant.new + alpha = @engine.register_participant :alpha, Ruote::StorageParticipant + bravo = @engine.register_participant :bravo, Ruote::StorageParticipant + charly = @engine.register_participant :charly, Ruote::StorageParticipant #noisy @@ -64,9 +64,9 @@ def test_cursor_forced_jump end end - alpha = @engine.register_participant :alpha, Ruote::HashParticipant.new - bravo = @engine.register_participant :bravo, Ruote::HashParticipant.new - charly = @engine.register_participant :charly, Ruote::HashParticipant.new + @engine.register_participant :alpha, Ruote::StorageParticipant + @engine.register_participant :bravo, Ruote::StorageParticipant + sto = @engine.register_participant :charly, Ruote::StorageParticipant #noisy @@ -76,13 +76,13 @@ def test_cursor_forced_jump wfid = @engine.launch(pdef) wait_for(:alpha) - alpha.reply(alpha.first) + sto.reply(sto.first) wait_for(:bravo) # # rewinding... - wi = bravo.first + wi = sto.first exp = @engine.process(wfid).expressions.find { |e| e.name == 'cursor' } wi.h['fei'] = exp.h.fei diff --git a/test/functional/ft_3_participant_registration.rb b/test/functional/ft_3_participant_registration.rb index 7e970941..7479eadc 100644 --- a/test/functional/ft_3_participant_registration.rb +++ b/test/functional/ft_3_participant_registration.rb @@ -28,11 +28,9 @@ def test_participant_register assert_equal 'alpha', msg['regex'] assert_equal( - [ 'inpa_:alpha' ], - @engine.context.plist.instantiated_participants.collect { |e| e.first }) - - assert_equal( - [ [ '^alpha$', 'inpa_:alpha' ] ], + [ [ "^alpha$", + [ "Ruote::BlockParticipant", + { "block" => "proc { |workitem| (@tracer << \"alpha\") }" } ] ] ], @engine.participant_list.collect { |pe| pe.to_a }) end @@ -73,12 +71,14 @@ def test_double_registration assert_equal 1, @engine.context.plist.send(:get_list)['list'].size end - def test_register_and_return_participant + def test_register_and_return_something pa = @engine.register_participant :alpha do |workitem| end + pb = @engine.register_participant :bravo, Ruote::StorageParticipant - assert_kind_of Ruote::BlockParticipant, pa + assert_nil pa + assert_equal Ruote::StorageParticipant, pb.class end def test_participant_unregister_by_name @@ -88,7 +88,7 @@ def test_participant_unregister_by_name @engine.register_participant :alpha do |workitem| end - @engine.unregister_participant :alpha + @engine.unregister_participant(:alpha) wait_for(2) Thread.pass @@ -96,16 +96,14 @@ def test_participant_unregister_by_name msg = logger.log.last assert_equal 'participant_unregistered', msg['action'] assert_equal '^alpha$', msg['regex'] - - assert_equal 0, @engine.context.plist.instantiated_participants.size end def test_participant_unregister - pa = @engine.register_participant :alpha do |workitem| + @engine.register_participant :alpha do |workitem| end - @engine.unregister_participant pa + @engine.unregister_participant('alpha') wait_for(2) @@ -113,26 +111,28 @@ def test_participant_unregister assert_equal 'participant_unregistered', msg['action'] assert_equal '^alpha$', msg['regex'] - assert_equal 0, @engine.context.plist.instantiated_participants.size + assert_equal 0, @engine.context.plist.list.size end class MyParticipant - attr_reader :down + @@down = false + def self.down + @@down + end def initialize - @down = false end def shutdown - @down = true + @@down = true end end def test_participant_shutdown - alpha = @engine.register :alpha, MyParticipant.new + alpha = @engine.register :alpha, MyParticipant @engine.context.plist.shutdown - assert_equal true, alpha.down + assert_equal true, MyParticipant.down end def test_participant_list_of_names @@ -389,7 +389,7 @@ def test_register_block %w[ Participants::Alpha Participants::Bravo Participants::Charlie - inpa_"david" + Ruote::BlockParticipant Participants::Zebda ], @engine.participant_list.collect { |pe| pe.classname }) diff --git a/test/functional/ft_43_participant_on_reply.rb b/test/functional/ft_43_participant_on_reply.rb index 038c276c..98a5e4b8 100644 --- a/test/functional/ft_43_participant_on_reply.rb +++ b/test/functional/ft_43_participant_on_reply.rb @@ -41,23 +41,6 @@ def test_participant_on_reply assert_trace('hello', pdef) end - def test_instantiated_participant_on_reply - - pdef = Ruote.process_definition do - sequence do - alpha - echo '${f:message}' - end - end - - @engine.register_participant :alpha, MyParticipant.new(nil) - # instantiated participant :-( - - #noisy - - assert_trace('hello', pdef) - end - class AwkwardParticipant include Ruote::LocalParticipant def initialize (opts) diff --git a/test/functional/ft_49_engine_on_error.rb b/test/functional/ft_49_engine_on_error.rb index 26d4e527..86ab764d 100644 --- a/test/functional/ft_49_engine_on_error.rb +++ b/test/functional/ft_49_engine_on_error.rb @@ -15,7 +15,7 @@ class FtEngineOnErrorTest < Test::Unit::TestCase def setup super - $seen = [] + @engine.context.stash[:seen] = [] end def test_no_on_error @@ -39,7 +39,7 @@ def initialize (opts) end def consume (workitem) workitem.fields['flavour'] = @opts['flavour'] - $seen << workitem + @context.stash[:seen] << workitem reply(workitem) end end @@ -64,14 +64,14 @@ def test_on_error_participant # unfortunately waiting for a participant triggers right # before the consume - assert_equal 1, $seen.size - assert_equal 'yellow', $seen.first.fields['colour'] - assert_equal 'vanilla', $seen.first.fields['flavour'] - assert_not_nil $seen.first.fei.subid + assert_equal 1, @engine.context.stash[:seen].size + assert_equal 'yellow', @engine.context.stash[:seen].first.fields['colour'] + assert_equal 'vanilla', @engine.context.stash[:seen].first.fields['flavour'] + assert_not_nil @engine.context.stash[:seen].first.fei.subid # TODO : look for error message and such - @engine.wait_for($seen.first.wfid) + @engine.wait_for(@engine.context.stash[:seen].first.wfid) assert_equal 1, @engine.processes.size end @@ -154,7 +154,7 @@ def test_on_error_workitem # unfortunately waiting for a participant triggers right # before the consume - wi = $seen.first + wi = @engine.context.stash[:seen].first assert_not_nil wi.error end diff --git a/test/functional/ft_4_cancel.rb b/test/functional/ft_4_cancel.rb index 0ede278b..3db7136e 100644 --- a/test/functional/ft_4_cancel.rb +++ b/test/functional/ft_4_cancel.rb @@ -19,7 +19,7 @@ def test_cancel_process alpha end - alpha = @engine.register_participant :alpha, Ruote::HashParticipant.new + alpha = @engine.register_participant :alpha, Ruote::StorageParticipant #noisy @@ -53,20 +53,23 @@ def test_cancel_expression end end - alpha = @engine.register_participant :alpha, Ruote::HashParticipant.new - bravo = @engine.register_participant :bravo, Ruote::HashParticipant.new + @engine.register_participant :alpha, Ruote::StorageParticipant + sto = @engine.register_participant :bravo, Ruote::StorageParticipant #noisy wfid = @engine.launch(pdef) wait_for(:alpha) - wi = alpha.first + assert_equal 1, sto.size + + wi = sto.first @engine.cancel_expression(wi.fei) wait_for(:bravo) - assert_not_nil bravo.first + assert_equal 1, sto.size + assert_equal 'bravo', sto.first.participant_name end def test_cancel__process diff --git a/test/functional/ft_55_engine_participant.rb b/test/functional/ft_55_engine_participant.rb index 0ad8e4bb..d6d0b266 100644 --- a/test/functional/ft_55_engine_participant.rb +++ b/test/functional/ft_55_engine_participant.rb @@ -11,8 +11,7 @@ require 'ruote' require 'ruote/storage/fs_storage' -require 'ruote/part/hash_participant' -require 'ruote/part/engine_participant' +require 'ruote/participant' class FtEngineParticipantTest < Test::Unit::TestCase @@ -155,7 +154,7 @@ def test_cancel_process #noisy - alpha = @engine1.register_participant :alpha, Ruote::HashParticipant.new + alpha = @engine1.register_participant :alpha, Ruote::StorageParticipant wfid = @engine0.launch(pdef) @@ -236,7 +235,7 @@ def test_forget end end - bravo = @engine1.register_participant :bravo, Ruote::HashParticipant.new + bravo = @engine1.register_participant :bravo, Ruote::StorageParticipant #noisy diff --git a/test/functional/ft_5_on_error.rb b/test/functional/ft_5_on_error.rb index 1fd4dea3..9450b4ba 100644 --- a/test/functional/ft_5_on_error.rb +++ b/test/functional/ft_5_on_error.rb @@ -42,10 +42,10 @@ def test_on_error_unknown_participant_name participant :mark_finished end - @marks = [] + @engine.context.stash[:marks] = [] @engine.register_participant 'mark\_.+' do |workitem| - @marks << workitem.participant_name + stash[:marks] << workitem.participant_name end #noisy @@ -54,7 +54,9 @@ def test_on_error_unknown_participant_name wait_for(wfid) - assert_equal %w[ mark_started mark_failed mark_finished ], @marks + assert_equal( + %w[ mark_started mark_failed mark_finished ], + @engine.context.stash[:marks]) end def test_on_error_unknown_participant_name_2 @@ -65,10 +67,10 @@ def test_on_error_unknown_participant_name_2 participant :mark_finished end - @marks = [] + @engine.context.stash[:marks] = [] @engine.register_participant 'mark\_.+' do |workitem| - @marks << workitem.participant_name + stash[:marks] << workitem.participant_name end #noisy @@ -77,7 +79,9 @@ def test_on_error_unknown_participant_name_2 wait_for(wfid) - assert_equal %w[ mark_started mark_failed mark_finished ], @marks + assert_equal( + %w[ mark_started mark_failed mark_finished ], + @engine.context.stash[:marks]) end def test_on_error_neutralization @@ -250,16 +254,17 @@ def test_with_concurrence end end - a_count = 0 - e_count = 0 - @engine.register_participant(:alpha) { |wi| a_count += 1 } - @engine.register_participant(:emil) { |wi| e_count += 1 } + @engine.context.stash[:a_count] = 0 + @engine.context.stash[:e_count] = 0 + + @engine.register_participant(:alpha) { |wi| stash[:a_count] += 1 } + @engine.register_participant(:emil) { |wi| stash[:e_count] += 1 } #noisy assert_trace 'done.', pdef - assert_equal 1, a_count - assert_equal 1, e_count + assert_equal 1, @engine.context.stash[:a_count] + assert_equal 1, @engine.context.stash[:e_count] end def test_participant_on_error @@ -271,14 +276,12 @@ def test_participant_on_error end end - workitem = nil - @engine.register_participant :troublemaker do |wi| wi.fields['seen'] = true raise 'Beijing, we have a problem !' end @engine.register_participant :troublespotter do |wi| - workitem = wi + stash[:workitem] = wi @tracer << 'err...' end @@ -291,12 +294,14 @@ def test_participant_on_error #puts er.message #puts er.trace + wi = @engine.context.stash[:workitem] + assert_equal 'err...', @tracer.to_s - assert_equal 5, workitem.error.size - assert_equal 'RuntimeError', workitem.error['class'] - assert_equal 'Beijing, we have a problem !', workitem.error['message'] - assert_equal Array, workitem.error['trace'].class - assert_equal true, workitem.fields['seen'] + assert_equal 5, wi.error.size + assert_equal 'RuntimeError', wi.error['class'] + assert_equal 'Beijing, we have a problem !', wi.error['message'] + assert_equal Array, wi.error['trace'].class + assert_equal true, wi.fields['seen'] end class Murphy diff --git a/test/functional/ft_6_on_cancel.rb b/test/functional/ft_6_on_cancel.rb index aec4bb25..cbdf900e 100644 --- a/test/functional/ft_6_on_cancel.rb +++ b/test/functional/ft_6_on_cancel.rb @@ -7,7 +7,7 @@ require File.join(File.dirname(__FILE__), 'base') -require 'ruote/part/hash_participant' +require 'ruote/participant' class FtOnCancelTest < Test::Unit::TestCase @@ -21,7 +21,7 @@ def test_on_cancel end end - nemo = @engine.register_participant :nemo, Ruote::HashParticipant + nemo = @engine.register_participant :nemo, Ruote::StorageParticipant @engine.register_participant :catcher do @tracer << "caught\n" @@ -46,7 +46,7 @@ def test_on_cancel_missing_handler end end - nemo = @engine.register_participant :nemo, Ruote::HashParticipant + nemo = @engine.register_participant :nemo, Ruote::StorageParticipant #noisy @@ -78,7 +78,7 @@ def test_on_cancel_trigger_subprocess end end - alpha = @engine.register_participant :alpha, Ruote::HashParticipant + alpha = @engine.register_participant :alpha, Ruote::StorageParticipant #noisy @@ -108,8 +108,8 @@ def test_on_cancel_expression end end - alpha = @engine.register_participant :alpha, Ruote::HashParticipant.new - bravo = @engine.register_participant :bravo, Ruote::HashParticipant.new + @engine.register_participant :alpha, Ruote::StorageParticipant + sto = @engine.register_participant :bravo, Ruote::StorageParticipant #noisy @@ -125,7 +125,7 @@ def test_on_cancel_expression wait_for(:bravo) - assert_equal 1, bravo.size + assert_equal 1, sto.size end def test_on_cancel_subprocess @@ -139,8 +139,8 @@ def test_on_cancel_subprocess end end - alpha = @engine.register_participant :alpha, Ruote::HashParticipant - bravo = @engine.register_participant :bravo, Ruote::HashParticipant + @engine.register_participant :alpha, Ruote::StorageParticipant + @engine.register_participant :bravo, Ruote::StorageParticipant #noisy diff --git a/test/functional/ft_7_tags.rb b/test/functional/ft_7_tags.rb index 6c499dd6..f73a9a26 100644 --- a/test/functional/ft_7_tags.rb +++ b/test/functional/ft_7_tags.rb @@ -21,7 +21,7 @@ def test_tag end end - alpha = @engine.register_participant :alpha, Ruote::HashParticipant.new + alpha = @engine.register_participant :alpha, Ruote::StorageParticipant #noisy @@ -60,7 +60,7 @@ def test_on_cancel end end - alpha = @engine.register_participant :alpha, Ruote::HashParticipant.new + alpha = @engine.register_participant :alpha, Ruote::StorageParticipant #noisy diff --git a/test/functional/ft_8_participant_consumption.rb b/test/functional/ft_8_participant_consumption.rb index 85947103..6aaebdc0 100644 --- a/test/functional/ft_8_participant_consumption.rb +++ b/test/functional/ft_8_participant_consumption.rb @@ -74,20 +74,23 @@ def test_dot_star def test_dispatch_time - wis = [] + @engine.context.stash[:wis] = [] pdef = Ruote.process_definition { alpha; alpha } @engine.register_participant 'alpha' do |workitem| - wis << workitem.to_h.dup + stash[:wis] << workitem.to_h.dup end assert_trace('', pdef) assert_equal( - String, wis.first['fields']['dispatched_at'].class) + String, + @engine.context.stash[:wis].first['fields']['dispatched_at'].class) + assert_not_equal( - wis.first['fields']['dispathed_at'], wis.last['fields']['dispatched_at']) + @engine.context.stash[:wis].first['fields']['dispathed_at'], + @engine.context.stash[:wis].last['fields']['dispatched_at']) end end diff --git a/test/functional/ft_9_subprocesses.rb b/test/functional/ft_9_subprocesses.rb index 9fa21d7c..7114d251 100644 --- a/test/functional/ft_9_subprocesses.rb +++ b/test/functional/ft_9_subprocesses.rb @@ -7,7 +7,7 @@ require File.join(File.dirname(__FILE__), 'base') -require 'ruote/part/hash_participant' +require 'ruote/participant' class FtSubprocessesTest < Test::Unit::TestCase @@ -26,7 +26,7 @@ def test_subprocess_tree_lookup end end - bravo = @engine.register_participant :bravo, Ruote::HashParticipant.new + bravo = @engine.register_participant :bravo, Ruote::StorageParticipant #noisy @@ -70,10 +70,10 @@ def test_subid end end - wfids = [] + @engine.context.stash[:wfids] = [] @engine.register_participant :alpha do |workitem| - wfids << workitem.fei.subid + stash[:wfids] << workitem.fei.subid end #noisy @@ -84,8 +84,8 @@ def test_subid wait_for(:alpha) wait_for(3) - assert_equal 2, wfids.size - assert_equal 2, wfids.sort.uniq.size + assert_equal 2, @engine.context.stash[:wfids].size + assert_equal 2, @engine.context.stash[:wfids].sort.uniq.size end def test_cancel_and_subprocess @@ -99,7 +99,7 @@ def test_cancel_and_subprocess end end - alpha = @engine.register_participant :alpha, Ruote::HashParticipant.new + alpha = @engine.register_participant :alpha, Ruote::StorageParticipant wfid = @engine.launch(pdef) @@ -126,7 +126,7 @@ def test_cancel_and_engine_variable_subprocess alpha end - alpha = @engine.register_participant :alpha, Ruote::HashParticipant.new + alpha = @engine.register_participant :alpha, Ruote::StorageParticipant #noisy diff --git a/test/functional/rt_1_listen.rb b/test/functional/rt_1_listen.rb index 504547c8..8e791412 100644 --- a/test/functional/rt_1_listen.rb +++ b/test/functional/rt_1_listen.rb @@ -9,7 +9,7 @@ require File.join(File.dirname(__FILE__), 'restart_base') -require 'ruote/part/hash_participant' +require 'ruote/participant' class RtListenTest < Test::Unit::TestCase @@ -32,7 +32,7 @@ def test_listen_and_restart #puts; noisy - alpha = @engine.register_participant :alpha, Ruote::HashParticipant.new + alpha = @engine.register_participant :alpha, Ruote::StorageParticipant wfid = @engine.launch(pdef) diff --git a/test/functional/test.rb b/test/functional/test.rb index 0081d604..813619bb 100644 --- a/test/functional/test.rb +++ b/test/functional/test.rb @@ -9,11 +9,9 @@ def l (t) if ARGV.include?('--split') - _v = ARGV.include?('-v') ? ' -v' : ' ' - puts puts "=== #{t} :" - puts `ruby#{_v} #{t} #{ARGV.join(' ')}` + puts `ruby -I. #{t} #{ARGV.join(' ')}` es = $?.exitstatus es = es.nil? ? 66 : es.to_s.to_i diff --git a/test/unit/ut_3_wait_logger.rb b/test/unit/ut_3_wait_logger.rb index fe67b9ee..6c1666fe 100644 --- a/test/unit/ut_3_wait_logger.rb +++ b/test/unit/ut_3_wait_logger.rb @@ -7,10 +7,7 @@ require File.join(File.dirname(__FILE__), '..', 'test_helper.rb') -require 'ruote/engine' -require 'ruote/worker' -require 'ruote/storage/hash_storage' -require 'ruote/part/hash_participant' +require 'ruote' class UtWaitLoggerTest < Test::Unit::TestCase @@ -28,7 +25,7 @@ def test_wait_for_participant #engine.context.logger.noisy = true - alpha = engine.register_participant :alpha, Ruote::HashParticipant.new + alpha = engine.register_participant :alpha, Ruote::StorageParticipant engine.launch(pdef) msg = engine.wait_for(:alpha)