commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ra...@apache.org
Subject svn commit: r713906 - in /commons/proper/scxml/branches/J6/src: main/java/org/apache/commons/scxml/env/SimpleScheduler.java test/java/org/apache/commons/scxml/EventDataTest.java test/java/org/apache/commons/scxml/env/jexl/eventdata-04.xml
Date Fri, 14 Nov 2008 02:05:11 GMT
Author: rahul
Date: Thu Nov 13 18:05:10 2008
New Revision: 713906

URL: http://svn.apache.org/viewvc?rev=713906&view=rev
Log:
Porting r713905 from trunk.
Delayed events not passing payload.
Test SCXML document provided by Roger Hoover <roger dot hoover at gmail dot com>
SCXML-87

Added:
    commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/env/jexl/eventdata-04.xml
  (with props)
Modified:
    commons/proper/scxml/branches/J6/src/main/java/org/apache/commons/scxml/env/SimpleScheduler.java
    commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/EventDataTest.java

Modified: commons/proper/scxml/branches/J6/src/main/java/org/apache/commons/scxml/env/SimpleScheduler.java
URL: http://svn.apache.org/viewvc/commons/proper/scxml/branches/J6/src/main/java/org/apache/commons/scxml/env/SimpleScheduler.java?rev=713906&r1=713905&r2=713906&view=diff
==============================================================================
--- commons/proper/scxml/branches/J6/src/main/java/org/apache/commons/scxml/env/SimpleScheduler.java
(original)
+++ commons/proper/scxml/branches/J6/src/main/java/org/apache/commons/scxml/env/SimpleScheduler.java
Thu Nov 13 18:05:10 2008
@@ -141,7 +141,7 @@
             if (delay > 0L) {
                 // Need to schedule this one
                 Timer timer = new Timer(true);
-                timer.schedule(new DelayedEventTask(sendId, event), delay);
+                timer.schedule(new DelayedEventTask(sendId, event, params), delay);
                 timers.put(sendId, timer);
                 if (log.isDebugEnabled()) {
                     log.debug("Scheduled event '" + event + "' with delay "
@@ -199,15 +199,33 @@
         private String event;
 
         /**
+         * The event payload, if any.
+         */
+        private Map<String, Object> payload;
+
+        /**
          * Constructor.
          *
          * @param sendId The ID of the send element.
          * @param event The name of the event to be triggered.
          */
         DelayedEventTask(final String sendId, final String event) {
+            this(sendId, event, null);
+        }
+
+        /**
+         * Constructor for events with payload.
+         *
+         * @param sendId The ID of the send element.
+         * @param event The name of the event to be triggered.
+         * @param payload The event payload, if any.
+         */
+        DelayedEventTask(final String sendId, final String event,
+                final Map<String, Object> payload) {
             super();
             this.sendId = sendId;
             this.event = event;
+            this.payload = payload;
         }
 
         /**
@@ -216,7 +234,7 @@
         public void run() {
             try {
                 executor.triggerEvent(new TriggerEvent(event,
-                    TriggerEvent.SIGNAL_EVENT));
+                    TriggerEvent.SIGNAL_EVENT, payload));
             } catch (ModelException me) {
                 log.error(me.getMessage(), me);
             }

Modified: commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/EventDataTest.java
URL: http://svn.apache.org/viewvc/commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/EventDataTest.java?rev=713906&r1=713905&r2=713906&view=diff
==============================================================================
--- commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/EventDataTest.java
(original)
+++ commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/EventDataTest.java
Thu Nov 13 18:05:10 2008
@@ -24,6 +24,10 @@
 import junit.framework.TestSuite;
 import junit.textui.TestRunner;
 
+import org.apache.commons.scxml.env.SimpleScheduler;
+import org.apache.commons.scxml.env.Tracer;
+import org.apache.commons.scxml.env.jexl.JexlEvaluator;
+import org.apache.commons.scxml.model.SCXML;
 import org.apache.commons.scxml.model.TransitionTarget;
 /**
  * Unit tests {@link org.apache.commons.scxml.SCXMLExecutor}.
@@ -45,7 +49,7 @@
     }
 
     // Test data
-    private URL eventdata01, eventdata02, eventdata03;
+    private URL eventdata01, eventdata02, eventdata03, eventdata04;
     private SCXMLExecutor exec;
 
     /**
@@ -58,13 +62,15 @@
             getResource("org/apache/commons/scxml/env/jexl/eventdata-02.xml");
         eventdata03 = this.getClass().getClassLoader().
             getResource("org/apache/commons/scxml/env/jexl/eventdata-03.xml");
+        eventdata04 = this.getClass().getClassLoader().
+            getResource("org/apache/commons/scxml/env/jexl/eventdata-04.xml");
     }
 
     /**
      * Tear down instance variables required by this test case.
      */
     public void tearDown() {
-        eventdata01 = eventdata02 = eventdata03 = null;
+        eventdata01 = eventdata02 = eventdata03 = eventdata04 = null;
     }
 
     /**
@@ -138,6 +144,22 @@
         }
     }
 
+    public void testEventdata04Sample() throws InterruptedException {
+        SCXML scxml = SCXMLTestHelper.parse(eventdata04);
+        Tracer trc = new Tracer();
+        try {
+            exec = new SCXMLExecutor(new JexlEvaluator(), null, trc);
+            exec.setEventdispatcher(new SimpleScheduler(exec));
+            exec.addListener(scxml, trc);
+            exec.setStateMachine(scxml);
+            exec.go();
+        } catch (Exception e) {
+            fail(e.getMessage());
+        }
+        assertNotNull(exec);
+        Thread.sleep(200); // let the 100 delay lapse
+    }
+
     public static class ConnectionAlertingPayload {
         private int line;
         public ConnectionAlertingPayload(int line) {

Added: commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/env/jexl/eventdata-04.xml
URL: http://svn.apache.org/viewvc/commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/env/jexl/eventdata-04.xml?rev=713906&view=auto
==============================================================================
--- commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/env/jexl/eventdata-04.xml
(added)
+++ commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/env/jexl/eventdata-04.xml
Thu Nov 13 18:05:10 2008
@@ -0,0 +1,57 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * 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="start">
+
+   <parallel id="start">
+
+       <state id="simulatedUser">
+           <datamodel>
+               <data name="one" expr="1" />
+               <data name="two" expr="2" />
+           </datamodel>
+
+           <onentry>
+               <send event="event.bar" namelist="one two" delay="'100ms'"/>
+           </onentry>
+           <transition event="event.bar">
+               <log label="'simulatedUser'" expr="_eventdatamap['event.bar'].one + ',
' + _eventdatamap['event.bar'].two"/>
+           </transition>
+       </state>
+
+       <state id="counter">
+           <initial>
+               <transition target="twenty"/>
+           </initial>
+
+           <state id="twenty">
+               <transition event="event.bar"
+                   cond="_eventdatamap['event.bar'].one + _eventdatamap['event.bar'].two
eq 3"
+                   target="thirty"/>
+               <transition event="event.bar">
+                   <log label="'event.bar in twenty state'" expr="_eventdatamap['event.bar'].one
+ ', ' + _eventdatamap['event.bar'].two"/>
+               </transition>
+           </state>
+
+           <state id="thirty" final="true"/>
+       </state>
+
+   </parallel>
+
+</scxml>

Propchange: commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/env/jexl/eventdata-04.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/proper/scxml/branches/J6/src/test/java/org/apache/commons/scxml/env/jexl/eventdata-04.xml
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL



Mime
View raw message