You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by at...@apache.org on 2017/12/09 23:44:32 UTC
commons-scxml git commit: SCXML-257 delay must support decimal
values
Repository: commons-scxml
Updated Branches:
refs/heads/master d3c4e83a3 -> 35e75829e
SCXML-257 <send> delay must support decimal values
This fixes 3 more W3C IRP tests
Project: http://git-wip-us.apache.org/repos/asf/commons-scxml/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-scxml/commit/35e75829
Tree: http://git-wip-us.apache.org/repos/asf/commons-scxml/tree/35e75829
Diff: http://git-wip-us.apache.org/repos/asf/commons-scxml/diff/35e75829
Branch: refs/heads/master
Commit: 35e75829ef4a2cb124718e9a01301621d82ede8b
Parents: d3c4e83
Author: Ate Douma <at...@apache.org>
Authored: Sun Dec 10 00:44:26 2017 +0100
Committer: Ate Douma <at...@apache.org>
Committed: Sun Dec 10 00:44:26 2017 +0100
----------------------------------------------------------------------
src/changes/changes.xml | 4 ++
.../org/apache/commons/scxml2/model/Send.java | 48 ++++++++++++--------
.../apache/commons/scxml2/model/SendTest.java | 27 +++++++++++
.../org/apache/commons/scxml2/w3c/tests.xml | 6 +--
4 files changed, 62 insertions(+), 23 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-scxml/blob/35e75829/src/changes/changes.xml
----------------------------------------------------------------------
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index ad8afb3..30111b6 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -35,6 +35,10 @@
<release version="2.0" date="In Git master"
description="Latest unreleased code">
+ <action dev="ate" type="update" issue="SCXML-257">
+ [12-10-2017] <send> delay must support decimal values
+ </action>
+
<action dev="ate" type="update" issue="SCXML-256">
[12-10-2017] Add SCXMLExecutor.run() ans SCXMLSemantics.initialize(...) methods and SCXML early/late binding
</action>
http://git-wip-us.apache.org/repos/asf/commons-scxml/blob/35e75829/src/main/java/org/apache/commons/scxml2/model/Send.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/scxml2/model/Send.java b/src/main/java/org/apache/commons/scxml2/model/Send.java
index 8a8dd2d..bae395a 100644
--- a/src/main/java/org/apache/commons/scxml2/model/Send.java
+++ b/src/main/java/org/apache/commons/scxml2/model/Send.java
@@ -408,7 +408,7 @@ public class Send extends NamelistHolder implements ContentContainer {
}
}
if (delayString != null) {
- wait = parseDelay(delayString, exctx.getAppLog());
+ wait = parseDelay(delayString, delayexpr != null, delayexpr != null ? delayexpr : delay);
}
String eventValue = event;
if (eventValue == null && eventexpr != null) {
@@ -434,11 +434,12 @@ public class Send extends NamelistHolder implements ContentContainer {
* Parse delay.
*
* @param delayString The String value of the delay, in CSS2 format
- * @param appLog The application log
+ * @param expression indicates if this is for a delayexpr or delay attribute
+ * @param delayStringSource the original delayString source (delayString might be different in case of a delayexpr)
* @return The parsed delay in milliseconds
* @throws SCXMLExpressionException If the delay cannot be parsed
*/
- private long parseDelay(final String delayString, final Log appLog)
+ static long parseDelay(final String delayString, final boolean expression, final String delayStringSource)
throws SCXMLExpressionException {
long wait = 0L;
@@ -446,26 +447,33 @@ public class Send extends NamelistHolder implements ContentContainer {
if (delayString != null && delayString.trim().length() > 0) {
- String trimDelay = delayString.trim();
- String numericDelay = trimDelay;
- if (trimDelay.endsWith(MILLIS)) {
- numericDelay = trimDelay.substring(0, trimDelay.length() - 2);
- } else if (trimDelay.endsWith(SECONDS)) {
- multiplier = MILLIS_IN_A_SECOND;
- numericDelay = trimDelay.substring(0, trimDelay.length() - 1);
- } else if (trimDelay.endsWith(MINUTES)) { // Not CSS2
- multiplier = MILLIS_IN_A_MINUTE;
- numericDelay = trimDelay.substring(0, trimDelay.length() - 1);
- }
-
try {
- wait = Long.parseLong(numericDelay);
+ String trimDelay = delayString.trim();
+ String numericDelay = trimDelay;
+ if (trimDelay.endsWith(MILLIS)) {
+ numericDelay = trimDelay.substring(0, trimDelay.length() - 2);
+ } else if (trimDelay.endsWith(SECONDS)) {
+ multiplier = multiplier*MILLIS_IN_A_SECOND;
+ numericDelay = trimDelay.substring(0, trimDelay.length() - 1);
+ } else if (trimDelay.endsWith(MINUTES)) { // Not CSS2
+ multiplier = multiplier*MILLIS_IN_A_MINUTE;
+ numericDelay = trimDelay.substring(0, trimDelay.length() - 1);
+ }
+ int fractionIndex = numericDelay.indexOf('.');
+ if (fractionIndex > -1) {
+ if (fractionIndex > 0) {
+ wait = Long.parseLong(numericDelay.substring(0, fractionIndex));
+ wait *= multiplier;
+ }
+ numericDelay = numericDelay.substring(fractionIndex+1);
+ multiplier /= Math.pow(10, numericDelay.length());
+ }
+ if (numericDelay.length() > 0) {
+ wait += Long.parseLong(numericDelay) * multiplier;
+ }
} catch (NumberFormatException nfe) {
- appLog.error(nfe.getMessage(), nfe);
- throw new SCXMLExpressionException(nfe.getMessage(), nfe);
+ throw new SCXMLExpressionException("<send>: invalid " + (expression ? "delayexpr=\"" : "delay=\"") + delayStringSource +"\"");
}
- wait *= multiplier;
-
}
return wait;
}
http://git-wip-us.apache.org/repos/asf/commons-scxml/blob/35e75829/src/test/java/org/apache/commons/scxml2/model/SendTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/scxml2/model/SendTest.java b/src/test/java/org/apache/commons/scxml2/model/SendTest.java
index 2c1e5b7..7424fe8 100644
--- a/src/test/java/org/apache/commons/scxml2/model/SendTest.java
+++ b/src/test/java/org/apache/commons/scxml2/model/SendTest.java
@@ -22,6 +22,7 @@ import java.util.List;
import java.util.Map;
import org.apache.commons.scxml2.SCXMLExecutor;
+import org.apache.commons.scxml2.SCXMLExpressionException;
import org.apache.commons.scxml2.SCXMLIOProcessor;
import org.apache.commons.scxml2.SCXMLTestHelper;
import org.apache.commons.scxml2.TriggerEvent;
@@ -61,4 +62,30 @@ public class SendTest {
Assert.assertEquals("The first one in the namelist must be 'one'.", "one", it.next());
Assert.assertEquals("The first one in the namelist must be 'two'.", "two", it.next());
}
+
+ private long parseDelay(String delayString) throws SCXMLExpressionException {
+ return Send.parseDelay(delayString, true, delayString);
+ }
+
+ @Test
+ public void testDelayExpression() throws Exception {
+ Assert.assertEquals(0L, parseDelay(".s"));
+ Assert.assertEquals(0L, parseDelay(".0s"));
+ Assert.assertEquals(1000L, parseDelay("1.s"));
+ Assert.assertEquals(1000L, parseDelay("1.0s"));
+ Assert.assertEquals(1500L, parseDelay("1.5s"));
+ Assert.assertEquals(500L, parseDelay(".5s"));
+ Assert.assertEquals(500L, parseDelay("0.5s"));
+ Assert.assertEquals(50L, parseDelay("0.05s"));
+ Assert.assertEquals(5L, parseDelay("0.005s"));
+ Assert.assertEquals(0L, parseDelay("0.0005s"));
+ Assert.assertEquals(0L, parseDelay(".9ms"));
+ Assert.assertEquals(1L, parseDelay("1.9ms"));
+ Assert.assertEquals(60000L, parseDelay("1m"));
+ Assert.assertEquals(60000L, parseDelay("1.0m"));
+ Assert.assertEquals(30000L, parseDelay(".5m"));
+ Assert.assertEquals(6000L, parseDelay(".1m"));
+ Assert.assertEquals(6000L, parseDelay(".10m"));
+ Assert.assertEquals(15000L, parseDelay(".25m"));
+ }
}
http://git-wip-us.apache.org/repos/asf/commons-scxml/blob/35e75829/src/test/java/org/apache/commons/scxml2/w3c/tests.xml
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/scxml2/w3c/tests.xml b/src/test/java/org/apache/commons/scxml2/w3c/tests.xml
index 8f32647..ad41e3f 100644
--- a/src/test/java/org/apache/commons/scxml2/w3c/tests.xml
+++ b/src/test/java/org/apache/commons/scxml2/w3c/tests.xml
@@ -103,7 +103,7 @@
<test id="172" mandatory="true" manual="false" jexl="true" ecma="true"/>
<test id="173" mandatory="true" manual="false" jexl="true" ecma="true"/>
<test id="174" mandatory="true" manual="false" jexl="true" ecma="true"/>
- <test id="175" mandatory="true" manual="false" jexl="false" ecma="false"/>
+ <test id="175" mandatory="true" manual="false" jexl="true" ecma="true"/>
<test id="176" mandatory="true" manual="false" jexl="true" ecma="true"/>
<test id="178" mandatory="true" manual="true" jexl="true" ecma="true" finalState="final"/>
<test id="179" mandatory="true" manual="false" jexl="true" ecma="true"/>
@@ -119,8 +119,8 @@
<test id="521" mandatory="true" manual="false" jexl="false" ecma="false"/>
<test id="553" mandatory="true" manual="false" jexl="true" ecma="true"/>
<test id="207" mandatory="true" manual="false" jexl="false" ecma="false" implemented="false"/>
- <test id="208" mandatory="true" manual="false" jexl="false" ecma="false"/>
- <test id="210" mandatory="true" manual="false" jexl="false" ecma="false"/>
+ <test id="208" mandatory="true" manual="false" jexl="true" ecma="true"/>
+ <test id="210" mandatory="true" manual="false" jexl="true" ecma="true"/>
<test id="215" mandatory="true" manual="false" jexl="false" ecma="false"/>
<test id="216" mandatory="true" manual="false" jexl="false" ecma="false"/>
<test id="220" mandatory="true" manual="false" jexl="false" ecma="false"/>