Skip to content

Commit

Permalink
listen : merge and upon added
Browse files Browse the repository at this point in the history
  • Loading branch information
jmettraux committed Jun 21, 2009
1 parent 8cfa3d3 commit 887464b
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 8 deletions.
2 changes: 1 addition & 1 deletion TODO.txt
Expand Up @@ -77,7 +77,7 @@

[ ] define without name (__result__)

[ ] workitem.__result__
[x] workitem.__result__ / why, the workitem itself is the result
[ ] smart lookup ? (?)

[o] tracker
Expand Down
24 changes: 17 additions & 7 deletions lib/ruote/exp/fe_listen.rb
Expand Up @@ -28,17 +28,23 @@

module Ruote

#
# Listens for activity (incoming or outgoing workitems) on a (set of)
# participant(s).
#
class ListenExpression < FlowExpression

# TODO : implement where=
# TODO : implement merge=

names :listen, :receive

def apply

to = attribute(:to) || attribute(:on)
upon = attribute(:upon) || 'apply'
@merge = (attribute(:merge) || 'false').to_s

persist

tracker.register(
@fei,
Expand All @@ -51,15 +57,19 @@ def apply

def reply (workitem)

# TODO : merge !
wi = @applied_workitem.dup

if tree_children.size > 0
if @merge == 'true'
wi.fields.merge!(workitem.fields)
elsif @merge == 'override'
wi.fields = workitem.fields
#else don't touch
end

pool.launch_sub(
"#{@fei.expid}_0", tree_children[0], self, @applied_workitem.dup, true)
if tree_children.size > 0
pool.launch_sub("#{@fei.expid}_0", tree_children[0], self, wi, true)
else

reply_to_parent(@applied_workitem)
reply_to_parent(wi)
end
end

Expand Down
2 changes: 2 additions & 0 deletions test/functional/base.rb
Expand Up @@ -65,6 +65,8 @@ def assert_trace (launch_thing, expected_trace, opts={})

wfid = @engine.launch(launch_thing, opts[:launch_opts] || {})

if t = opts[:sleep]; sleep t; end

wait_for(wfid, opts)

yield(@engine) if block_given?
Expand Down
61 changes: 61 additions & 0 deletions test/functional/eft_12_listen.rb
Expand Up @@ -70,5 +70,66 @@ def test_listen_with_child
assert_equal 3, ps.expressions.size
assert_equal 0, ps.errors.size
end

def test_upon

pdef = Ruote.process_definition do
concurrence do
sequence do
listen :to => '^al.*'
bravo
end
sequence do
listen :to => '^al.*', :upon => 'reply', :merge => true
bravo
end
sequence do
alpha
end
end
end

#noisy

@engine.register_participant :alpha do |workitem|
@tracer << "alpha\n"
workitem.fields['seen'] = 'yes'
end
@engine.register_participant :bravo do |workitem|
@tracer << "bravo:#{workitem.fields['seen']}\n"
end

assert_trace(pdef, %w[ alpha bravo: bravo:yes ], :sleep => 1.0)
end

def test_merge_override

pdef = Ruote.process_definition do
set :f => 'name', :val => 'Kilroy'
set :f => 'other', :val => 'nothing'
concurrence do
sequence do
listen :to => '^al.*', :merge => 'override'
bravo
end
sequence do
alpha
end
end
end

#noisy

@engine.register_participant :alpha do |wi|
@tracer << "alpha\n"
wi.fields['name'] = 'William Mandella'
end
@engine.register_participant :bravo do |wi|
@tracer << "name:#{wi.fields['name']} "
@tracer << "other:#{wi.fields['other']}\n"
end

assert_trace(pdef, "alpha\nname:William Mandella other:nothing")
end
end

0 comments on commit 887464b

Please sign in to comment.