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 2008/11/14 03:03:45 UTC
svn commit: r713905 - in /commons/proper/scxml/trunk/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
Author: rahul
Date: Thu Nov 13 18:03:45 2008
New Revision: 713905
URL: http://svn.apache.org/viewvc?rev=713905&view=rev
Log:
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/trunk/src/test/java/org/apache/commons/scxml/env/jexl/eventdata-04.xml (with props)
Modified:
commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/env/SimpleScheduler.java
commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/EventDataTest.java
Modified: commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/env/SimpleScheduler.java
URL: http://svn.apache.org/viewvc/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/env/SimpleScheduler.java?rev=713905&r1=713904&r2=713905&view=diff
==============================================================================
--- commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/env/SimpleScheduler.java (original)
+++ commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/env/SimpleScheduler.java Thu Nov 13 18:03:45 2008
@@ -139,7 +139,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 "
@@ -197,15 +197,33 @@
private String event;
/**
+ * The event payload, if any.
+ */
+ private Map 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 payload) {
super();
this.sendId = sendId;
this.event = event;
+ this.payload = payload;
}
/**
@@ -214,7 +232,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/trunk/src/test/java/org/apache/commons/scxml/EventDataTest.java
URL: http://svn.apache.org/viewvc/commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/EventDataTest.java?rev=713905&r1=713904&r2=713905&view=diff
==============================================================================
--- commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/EventDataTest.java (original)
+++ commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/EventDataTest.java Thu Nov 13 18:03:45 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.State;
/**
* 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;
}
/**
@@ -147,6 +153,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/trunk/src/test/java/org/apache/commons/scxml/env/jexl/eventdata-04.xml
URL: http://svn.apache.org/viewvc/commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/env/jexl/eventdata-04.xml?rev=713905&view=auto
==============================================================================
--- commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/env/jexl/eventdata-04.xml (added)
+++ commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/env/jexl/eventdata-04.xml Thu Nov 13 18:03:45 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/trunk/src/test/java/org/apache/commons/scxml/env/jexl/eventdata-04.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/env/jexl/eventdata-04.xml
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL