commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ra...@apache.org
Subject svn commit: r601100 - in /commons/proper/scxml/trunk/src: main/java/org/apache/commons/scxml/ main/java/org/apache/commons/scxml/model/ main/java/org/apache/commons/scxml/semantics/ test/java/org/apache/commons/scxml/model/
Date Tue, 04 Dec 2007 21:58:36 GMT
Author: rahul
Date: Tue Dec  4 13:58:33 2007
New Revision: 601100

URL: http://svn.apache.org/viewvc?rev=601100&view=rev
Log:
SCXML-58 Object model not stateless
Tests (now pass) contributed by Mike Tillberg <mtillberg at comcast dot net>

Added:
    commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/model/stateless-parallel-01.xml
  (with props)
Modified:
    commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/SCInstance.java
    commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/model/State.java
    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/model/StatelessModelTest.java

Modified: commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/SCInstance.java
URL: http://svn.apache.org/viewvc/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/SCInstance.java?rev=601100&r1=601099&r2=601100&view=diff
==============================================================================
--- commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/SCInstance.java (original)
+++ commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/SCInstance.java Tue
Dec  4 13:58:33 2007
@@ -59,6 +59,12 @@
     private Map histories;
 
     /**
+     * <code>Map</code> for recording the run to completion status of
+     * composite states.
+     */
+    private Map completions;
+
+    /**
      * The <code>Invoker</code> classes <code>Map</code>, keyed by
      * &lt;invoke&gt; target types (specified using "targettype" attribute).
      */
@@ -96,6 +102,7 @@
         this.histories = Collections.synchronizedMap(new HashMap());
         this.invokerClasses = Collections.synchronizedMap(new HashMap());
         this.invokers = Collections.synchronizedMap(new HashMap());
+        this.completions = Collections.synchronizedMap(new HashMap());
         this.evaluator = null;
         this.rootContext = null;
         this.executor = executor;
@@ -354,6 +361,34 @@
      */
     public Map getInvokers() {
         return invokers;
+    }
+
+    /**
+     * Get the completion status for this composite
+     * {@link TransitionTarget}.
+     *
+     * @param transitionTarget The <code>TransitionTarget</code>.
+     * @return The completion status.
+     */
+    public boolean isDone(final TransitionTarget transitionTarget) {
+        Boolean done = (Boolean) completions.get(transitionTarget);
+        if (done == null) {
+            return false;
+        } else {
+            return done.booleanValue();
+        }
+    }
+
+    /**
+     * Set the completion status for this composite
+     * {@link TransitionTarget}.
+     *
+     * @param transitionTarget The TransitionTarget.
+     * @param done The completion status.
+     */
+    public void setDone(final TransitionTarget transitionTarget,
+            final boolean done) {
+        completions.put(transitionTarget, done ? Boolean.TRUE : Boolean.FALSE);
     }
 
 }

Modified: commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/model/State.java
URL: http://svn.apache.org/viewvc/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/model/State.java?rev=601100&r1=601099&r2=601100&view=diff
==============================================================================
--- commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/model/State.java (original)
+++ commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/model/State.java Tue
Dec  4 13:58:33 2007
@@ -78,6 +78,8 @@
      * Applies to composite states only. If one of its final children is
      * active, its parent is marked done. This property is reset upon
      * re-entry.
+     *
+     * @deprecated Will be removed in v1.0
      */
     private boolean done = false;
 
@@ -350,6 +352,8 @@
      * is active.
      *
      * @return Returns the done.
+     * @deprecated Will be removed in v1.0, in favor of
+     *             <code>SCInstance#isDone(TransitionTarget)</code>
      */
     public final boolean isDone() {
         return done;
@@ -360,6 +364,8 @@
      * and one its final states is active.
      *
      * @param done The done to set.
+     * @deprecated Will be removed in v1.0, in favor of
+     *             <code>SCInstance#setDone(TransitionTarget)</code>
      */
     public final void setDone(final boolean done) {
         this.done = done;

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=601100&r1=601099&r2=601100&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
Tue Dec  4 13:58:33 2007
@@ -254,7 +254,7 @@
                             TriggerEvent.CHANGE_EVENT);
                     internalEvents.add(te);
                     if (parent != null) {
-                        parent.setDone(true);
+                        scInstance.setDone(parent, true);
                     }
                     if (parent != null && parent.isRegion()) {
                         //3.4 we got a region, which is finalized
@@ -265,7 +265,7 @@
                         for (Iterator regions = p.getChildren().iterator();
                                 regions.hasNext();) {
                             State reg = (State) regions.next();
-                            if (reg.isDone()) {
+                            if (scInstance.isDone(reg)) {
                                 finCount++;
                             }
                         }
@@ -277,7 +277,7 @@
                                 + ".done", TriggerEvent.CHANGE_EVENT);
                             internalEvents.add(te);
                             //this is not in the specs, but is makes sense
-                            p.getParentState().setDone(true);
+                            scInstance.setDone(p.getParentState(), true);
                         }
                     }
                 }
@@ -704,7 +704,7 @@
         for (Iterator reset = entering.iterator(); reset.hasNext();) {
             Object o = reset.next();
             if (o instanceof State) {
-                ((State) o).setDone(false);
+                scInstance.setDone((State) o, false);
             }
         }
     }

Modified: commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/model/StatelessModelTest.java
URL: http://svn.apache.org/viewvc/commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/model/StatelessModelTest.java?rev=601100&r1=601099&r2=601100&view=diff
==============================================================================
--- commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/model/StatelessModelTest.java
(original)
+++ commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/model/StatelessModelTest.java
Tue Dec  4 13:58:33 2007
@@ -17,6 +17,7 @@
 package org.apache.commons.scxml.model;
 
 import java.net.URL;
+import java.util.Iterator;
 import java.util.Set;
 
 import junit.framework.Test;
@@ -48,9 +49,9 @@
     }
 
     // Test data
-    private URL stateless01jexl, stateless01jsp;
-    private SCXML scxml01jexl, scxml01jsp;
-    private SCXMLExecutor exec01, exec02;
+    private URL stateless01jexl, stateless01jsp, stateless01par;
+    private SCXML scxml01jexl, scxml01jsp, scxml01par, scxml02par;
+    private SCXMLExecutor exec01, exec02, exec03;
 
     /**
      * Set up instance variables required by this test case.
@@ -60,8 +61,12 @@
             getResource("org/apache/commons/scxml/env/jexl/stateless-01.xml");
         stateless01jsp = this.getClass().getClassLoader().
             getResource("org/apache/commons/scxml/env/jsp/stateless-01.xml");
+        stateless01par = this.getClass().getClassLoader().
+            getResource("org/apache/commons/scxml/model/stateless-parallel-01.xml");
         scxml01jexl = SCXMLTestHelper.digest(stateless01jexl);
         scxml01jsp = SCXMLTestHelper.digest(stateless01jsp);
+        scxml01par = SCXMLTestHelper.digest(stateless01par);
+        scxml02par = SCXMLTestHelper.digest(stateless01par);
     }
 
     /**
@@ -122,6 +127,83 @@
             assertNotNull(exec01);
             runSequentialTest();
         }
+    }
+
+    /**
+     * Test sharing a single SCXML object between two executors
+     */
+    public void testStatelessModelParallelSharedSCXML() {
+        exec01 = SCXMLTestHelper.getExecutor(scxml01par);
+        assertNotNull(exec01);
+        exec02 = SCXMLTestHelper.getExecutor(scxml01par);
+        assertNotNull(exec02);
+        assertFalse(exec01 == exec02);
+
+        Set currentStates = exec01.getCurrentStatus().getStates();
+        checkParallelStates(currentStates, "state1.init", "state2.init", "exec01");
+
+        currentStates = exec02.getCurrentStatus().getStates();
+        checkParallelStates(currentStates, "state1.init", "state2.init", "exec02");
+
+        currentStates = fireEvent("state1.event", exec01);
+        checkParallelStates(currentStates, "state1.final", "state2.init", "exec01");
+
+        currentStates = fireEvent("state2.event", exec02);
+        checkParallelStates(currentStates, "state1.init", "state2.final", "exec02");
+
+        currentStates = fireEvent("state2.event", exec01);
+        checkParallelStates(currentStates, "next", null, "exec01");
+
+        currentStates = fireEvent("state1.event", exec02);
+        checkParallelStates(currentStates, "next", null, "exec02");
+    }
+
+    /**
+     * Test sharing two SCXML objects between one executor (not recommended)
+     */
+    public void testStatelessModelParallelSwapSCXML() {
+        exec01 = SCXMLTestHelper.getExecutor(scxml01par);
+        assertNotNull(exec01);
+        assertTrue(scxml01par != scxml02par);
+
+        Set currentStates = exec01.getCurrentStatus().getStates();
+        checkParallelStates(currentStates, "state1.init", "state2.init", "exec01");
+
+        currentStates = fireEvent("state1.event", exec01);
+        checkParallelStates(currentStates, "state1.final", "state2.init", "exec01");
+        exec01.setStateMachine(scxml02par);
+
+        currentStates = fireEvent("state2.event", exec01);
+        checkParallelStates(currentStates, "next", null, "exec01");
+    }
+
+    private void checkParallelStates(Set currentStates, String s1, String s2,
+            String label) {
+        Iterator i = currentStates.iterator();
+        assertTrue("Not enough states", i.hasNext());
+        String cs1 = ((State) i.next()).getId();
+        String cs2 = null;
+        if (s2 != null) {
+            assertTrue("Not enough states, found one state: " + cs1, i.hasNext());
+            cs2 = ((State) i.next()).getId();
+            assertFalse("Too many states", i.hasNext());
+            if (s2.equals(cs2)) {
+                cs2 = null;
+            } else if (s1.equals(cs2)) {
+                cs2 = null;
+            } else {
+                fail(label + " in unexpected state " + cs2);
+            }
+        } else {
+            assertFalse("Too many states", i.hasNext());
+        }
+        if (s1 != null && s1.equals(cs1)) {
+            return;
+        }
+        if (s2 != null && s2.equals(cs1)) {
+            return;
+        }
+        fail(label + " in unexpected state " + cs1);
     }
 
     private void runSimultaneousTest() {

Added: commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/model/stateless-parallel-01.xml
URL: http://svn.apache.org/viewvc/commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/model/stateless-parallel-01.xml?rev=601100&view=auto
==============================================================================
--- commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/model/stateless-parallel-01.xml
(added)
+++ commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/model/stateless-parallel-01.xml
Tue Dec  4 13:58:33 2007
@@ -0,0 +1,54 @@
+<?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">
+
+    <state id="main">
+
+        <parallel id="main.parallel">
+
+            <state id="state1">
+                <initial>
+                    <transition target="state1.init"/>
+                </initial>
+                <state id="state1.init">
+                    <transition event="state1.event" target="state1.final" />
+                </state>
+                <state id="state1.final" final="true" />
+            </state>
+
+            <state id="state2">
+                <initial>
+                    <transition target="state2.init"/>
+                </initial>
+                <state id="state2.init">
+                    <transition event="state2.event" target="state2.final" />
+                </state>
+                <state id="state2.final" final="true" />
+            </state>
+
+        </parallel>
+
+        <transition event="main.parallel.done" target="next" />
+
+    </state>
+
+    <state id="next" final="true"/>
+
+</scxml>

Propchange: commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/model/stateless-parallel-01.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/model/stateless-parallel-01.xml
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL



Mime
View raw message