Sha256: e348ed42773c00efb5c3c97800ef30fe76549a899aca49f79dd0764534bc0226

Contents?: true

Size: 1.92 KB

Versions: 6

Compression:

Stored size: 1.92 KB

Contents

#
# testing ruote
#
# Sat Jun 13 22:43:16 JST 2009
#

require File.join(File.dirname(__FILE__), 'base')

require 'ruote/part/local_participant'


class FtRecursionTest < Test::Unit::TestCase
  include FunctionalBase

  class CountingParticipant
    include Ruote::LocalParticipant

    attr_reader :wfids

    def initialize

      @wfids = []
    end

    def consume (workitem)

      @wfids << "#{workitem.fei.wfid}|#{workitem.fei.sub_wfid}"

      workitem.fields['count'] ||= 0
      workitem.fields['count'] = workitem.fields['count'] + 1

      @context.tracer << workitem.fields['count'].to_s + "\n"

      if workitem.fields['count'] > 5
        @context.engine.cancel_process(workitem.fei.wfid)
      else
        reply_to_engine(workitem)
      end
    end

    def cancel (fei, flavour)
    end
  end

  def test_main_recursion

    pdef = Ruote.process_definition :name => 'def0' do
      sequence do
        alpha
        def0
      end
    end

    alpha = @engine.register_participant :alpha, CountingParticipant.new

    #noisy

    assert_trace(pdef, %w[ 1 2 3 4 5 6 ])

    #p alpha.wfids.uniq

    assert_equal 6, alpha.wfids.uniq.size
  end

  def test_sub_recursion

    pdef = Ruote.process_definition do
      define 'sub0' do
        sequence do
          alpha
          sub0
        end
      end
      sub0
    end

    alpha = @engine.register_participant :alpha, CountingParticipant.new

    #noisy

    assert_trace pdef, %w[ 1 2 3 4 5 6 ]

    #p alpha.wfids.uniq

    assert_equal 6, alpha.wfids.uniq.size
  end

  def test_forgotten_main_recursion

    pdef = Ruote.process_definition :name => 'def0' do
      sequence do
        alpha
        forget do
          def0
        end
      end
    end

    alpha = @engine.register_participant :alpha, CountingParticipant.new

    #noisy

    wfid = @engine.launch(pdef)

    6.times { wait_for(:alpha) }

    Thread.pass

    assert_equal((1..6).to_a.join("\n"), @tracer.to_s)
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
ruote-2.1.7 test/functional/ft_11_recursion.rb
ruote-2.1.6 test/functional/ft_11_recursion.rb
ruote-2.1.5 test/functional/ft_11_recursion.rb
ruote-2.1.4 test/functional/ft_11_recursion.rb
ruote-2.1.3 test/functional/ft_11_recursion.rb
ruote-2.1.2 test/functional/ft_11_recursion.rb