Sha256: a7cbf4847075328b1ffc41af86fe69860e20d68ab4b4eba6410d5b586da2c670

Contents?: true

Size: 1.56 KB

Versions: 9

Compression:

Stored size: 1.56 KB

Contents

#
# Testing ruote
#
# Fri Dec  4 17:15:10 JST 2009
#

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


class Ruote::Worker

  def step_by_one
    msg = @storage.get_msgs.first
    #p [ msg['action'], msg['fei'] ]
    if msg
      process(msg)
    else
      false
    end
  end

  public :process

  def step_until (&block)
    loop do
      msg = @storage.get_msgs.first
      return msg if block.call(msg)
      process(msg)
    end
  end
end

class Ruote::Engine
  def step (count=1)
    count.times { @context.worker.step_by_one }
  end
  def step!
    r = @context.worker.step_by_one
    step! if r == false
  end
  def walk
    while @context.worker.step_by_one do; end
  end
  def do_step (msg)
    @context.worker.process(msg)
  end
  def step_until (&block)
    @context.worker.step_until(&block)
  end
end


module ConcurrentBase

  def setup

    @storage = determine_storage(
      's_logger' => [ 'ruote/log/test_logger', 'Ruote::TestLogger' ])

    @engine0 = Ruote::Engine.new(Ruote::Worker.new(@storage), false)
    @engine1 = Ruote::Engine.new(Ruote::Worker.new(@storage), false)
      #
      # the 2 engines are set with run=false

    @tracer0 = Tracer.new
    @tracer1 = Tracer.new

    @engine0.context.add_service('s_tracer', @tracer0, nil)
    @engine1.context.add_service('s_tracer', @tracer1, nil)

    @engine1.context.logger.color = '32' # green
  end

  def teardown

    @storage.purge!

    @engine0.shutdown
    @engine1.shutdown
  end

  protected

  def noisy

    @engine0.context.logger.noisy = true
    @engine1.context.logger.noisy = true
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
ruote-2.1.9 test/functional/concurrent_base.rb
ruote-2.1.8 test/functional/concurrent_base.rb
ruote-2.1.7 test/functional/concurrent_base.rb
ruote-2.1.6 test/functional/concurrent_base.rb
ruote-2.1.5 test/functional/concurrent_base.rb
ruote-2.1.4 test/functional/concurrent_base.rb
ruote-2.1.3 test/functional/concurrent_base.rb
ruote-2.1.2 test/functional/concurrent_base.rb
ruote-2.1.1 test/functional/concurrent_base.rb