test/functional/ft_25_receiver.rb in ruote-2.1.11 vs test/functional/ft_25_receiver.rb in ruote-2.2.0

- old
+ new

@@ -22,22 +22,20 @@ alpha echo '.' 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) - def consume (workitem) + @context.stash[:wi] = workitem - @wi = workitem - # no reply to the engine end # do not let the dispatch happen in its own thread, this makes # wait_for(:alpha) synchronous. @@ -85,17 +83,17 @@ #noisy 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) assert_nil @engine.process(wfid) @@ -107,34 +105,32 @@ wfid = @engine.launch(@pdef) wait_for(:alpha) - @engine.receive(@alpha.wi) + @engine.receive(@engine.context.stash[:wi]) wait_for(wfid) assert_nil @engine.process(wfid) rcv = logger.log.select { |e| e['action'] == 'receive' }.first assert_equal 'Ruote::Engine', rcv['receiver'] end class MyOtherParticipant - def initialize (receiver) - @receiver = receiver + include Ruote::LocalParticipant + def consume(workitem) + @context.receiver.pass(workitem.to_h) end - def consume (workitem) - @receiver.pass(workitem.to_h) - end end class MyOtherReceiver < Ruote::Receiver - def initialize (context, opts={}) + def initialize(context, opts={}) super(context, opts) @count = 0 end - def pass (workitem) + def pass(workitem) if @count < 1 @context.error_handler.action_handle( 'dispatch', workitem['fei'], RuntimeError.new('something went wrong')) else reply(workitem) @@ -143,13 +139,17 @@ end end 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 end @@ -170,8 +170,38 @@ wait_for(wfid) ps = @engine.process(wfid) assert_nil ps + end + + def test_receiver_fexp_and_wi + + #@engine.register do + # catchall Ruote::StorageParticipant + #end + @engine.register_participant :alpha, Ruote::StorageParticipant + + #noisy + + wfid = @engine.launch(Ruote.define do + alpha + end) + + @engine.wait_for(:alpha) + @engine.wait_for(1) + + wi = @engine.storage_participant.first + + assert_equal wfid, wi.fei.wfid + + assert_equal wfid, @engine.fexp(wi).fei.wfid + assert_equal wfid, @engine.fexp(wi.fei).fei.wfid + assert_equal wfid, @engine.fexp(wi.fei.sid).fei.wfid + assert_equal wfid, @engine.fexp(wi.fei.sid).h.applied_workitem['fei']['wfid'] + + assert_equal wfid, @engine.workitem(wi).wfid + assert_equal wfid, @engine.workitem(wi.fei).wfid + assert_equal wfid, @engine.workitem(wi.fei.sid).wfid end end