You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ra...@apache.org on 2007/08/20 21:17:17 UTC
svn commit: r567791 - in /commons/proper/scxml/trunk/src:
main/java/org/apache/commons/scxml/semantics/SCXMLSemanticsImpl.java
test/java/org/apache/commons/scxml/TieBreakerTest.java
test/java/org/apache/commons/scxml/tie-breaker-05.xml
Author: rahul
Date: Mon Aug 20 12:17:16 2007
New Revision: 567791
URL: http://svn.apache.org/viewvc?rev=567791&view=rev
Log:
Apply per region document order filter for transition conflict resolution (identified in comments on SCXML-52).
Added:
commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/tie-breaker-05.xml (with props)
Modified:
commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/semantics/SCXMLSemanticsImpl.java
commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/TieBreakerTest.java
Modified: commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/semantics/SCXMLSemanticsImpl.java
URL: http://svn.apache.org/viewvc/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/semantics/SCXMLSemanticsImpl.java?rev=567791&r1=567790&r2=567791&view=diff
==============================================================================
--- commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/semantics/SCXMLSemanticsImpl.java (original)
+++ commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/semantics/SCXMLSemanticsImpl.java Mon Aug 20 12:17:16 2007
@@ -451,17 +451,22 @@
// check if all non-deterministic situations have been resolved
nonDeterm.removeAll(removeList);
if (nonDeterm.size() > 0) {
- // if not, first one wins (which is also first
- // in document order)
- Transition t = (Transition) nonDeterm.iterator().next();
- nonDeterm.remove(t);
+ // if not, first one in each state / region (which is also
+ // first in document order) wins
+ Set regions = new HashSet();
+ Iterator iter = nonDeterm.iterator();
+ while (iter.hasNext()) {
+ Transition t = (Transition) iter.next();
+ TransitionTarget parent = t.getParent();
+ if (regions.contains(parent)) {
+ removeList.add(t);
+ } else {
+ regions.add(parent);
+ }
+ }
}
- // apply global transition filter
+ // apply global and document order transition filter
step.getTransitList().removeAll(removeList);
- // apply document order priority
- step.getTransitList().removeAll(nonDeterm);
- removeList.clear();
- nonDeterm.clear();
}
}
Modified: commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/TieBreakerTest.java
URL: http://svn.apache.org/viewvc/commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/TieBreakerTest.java?rev=567791&r1=567790&r2=567791&view=diff
==============================================================================
--- commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/TieBreakerTest.java (original)
+++ commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/TieBreakerTest.java Mon Aug 20 12:17:16 2007
@@ -17,6 +17,7 @@
package org.apache.commons.scxml;
import java.net.URL;
+import java.util.Iterator;
import java.util.Set;
import junit.framework.Test;
@@ -53,7 +54,8 @@
}
// Test data
- private URL tiebreaker01, tiebreaker02, tiebreaker03, tiebreaker04;
+ private URL tiebreaker01, tiebreaker02, tiebreaker03, tiebreaker04,
+ tiebreaker05;
private SCXMLExecutor exec;
/**
@@ -68,13 +70,16 @@
getResource("org/apache/commons/scxml/tie-breaker-03.xml");
tiebreaker04 = this.getClass().getClassLoader().
getResource("org/apache/commons/scxml/tie-breaker-04.xml");
+ tiebreaker05 = this.getClass().getClassLoader().
+ getResource("org/apache/commons/scxml/tie-breaker-05.xml");
}
/**
* Tear down instance variables required by this test case.
*/
public void tearDown() {
- tiebreaker01 = tiebreaker02 = tiebreaker03 = tiebreaker04 = null;
+ tiebreaker01 = tiebreaker02 = tiebreaker03 = tiebreaker04 =
+ tiebreaker05 = null;
}
/**
@@ -126,6 +131,29 @@
assertEquals(1, currentStates.size());
currentStates = SCXMLTestHelper.fireEvent(exec, "event_1");
assertEquals(1, currentStates.size());
+ }
+
+ public void testTieBreaker05() {
+ exec = SCXMLTestHelper.getExecutor(tiebreaker05);
+ assertNotNull(exec);
+ Set currentStates = exec.getCurrentStatus().getStates();
+ assertEquals(3, currentStates.size());
+ String id = ((State) currentStates.iterator().next()).getId();
+ Iterator iter = currentStates.iterator();
+ while (iter.hasNext()) {
+ id = ((State) iter.next()).getId();
+ assertTrue(id.equals("s11") || id.equals("s212")
+ || id.equals("s2111"));
+ }
+ currentStates = SCXMLTestHelper.fireEvent(exec, "event1");
+ assertEquals(3, currentStates.size());
+ id = ((State) currentStates.iterator().next()).getId();
+ iter = currentStates.iterator();
+ while (iter.hasNext()) {
+ id = ((State) iter.next()).getId();
+ assertTrue(id.equals("s12") || id.equals("s212")
+ || id.equals("s2112"));
+ }
}
public static void main(String args[]) {
Added: commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/tie-breaker-05.xml
URL: http://svn.apache.org/viewvc/commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/tie-breaker-05.xml?rev=567791&view=auto
==============================================================================
--- commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/tie-breaker-05.xml (added)
+++ commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/tie-breaker-05.xml Mon Aug 20 12:17:16 2007
@@ -0,0 +1,68 @@
+<?xml version="1.0"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+-->
+<scxml xmlns="http://www.w3.org/2005/07/scxml" version="1.0" initialstate="main">
+
+<!--
+ Testing dispute resolution in regions
+ {s11,s2111,s212} -event1-> {s12,s2112,s212}
+-->
+
+ <state id="main">
+ <parallel id="para"> <!-- Outer parallel -->
+
+ <state id="s1">
+ <initial>
+ <transition target="s11"/>
+ </initial>
+ <state id="s11">
+ <transition event="event1" target="s12"/>
+ <transition event="event1" target="s13"/>
+ </state>
+ <state id="s12"/>
+ <state id="s13"/>
+ </state>
+
+ <state id="s2">
+ <initial>
+ <transition target="s21"/>
+ </initial>
+ <state id="s21">
+
+ <parallel id="para1"> <!-- Inner parallel -->
+ <state id="s211">
+ <initial>
+ <transition target="s2111"/>
+ </initial>
+ <state id="s2111">
+ <transition event="event1" target="s2112"/>
+ <transition event="event1" target="s2113"/>
+ </state>
+ <state id="s2112"/>
+ <state id="s2113"/>
+ </state>
+ <state id="s212"/>
+ </parallel>
+
+ </state>
+ <state id="s22"/>
+ </state>
+
+ </parallel>
+ </state>
+
+</scxml>
Propchange: commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/tie-breaker-05.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/tie-breaker-05.xml
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL