This is an automated email from the ASF dual-hosted git repository.
henrib pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-jexl.git
The following commit(s) were added to refs/heads/master by this push:
new 6db56bf JEXL-255: separated script execution cancellation and
interruption
6db56bf is described below
commit 6db56bfc115e0fc9fc320b4ada5f5d231be62c2c
Author: Henri Biestro <[email protected]>
AuthorDate: Mon Mar 5 08:38:50 2018 +0100
JEXL-255: separated script execution cancellation and interruption
---
.../commons/jexl3/internal/InterpreterBase.java | 13 ++------
.../apache/commons/jexl3/ScriptCallableTest.java | 36 +++++++++++++++++++---
2 files changed, 35 insertions(+), 14 deletions(-)
diff --git
a/src/main/java/org/apache/commons/jexl3/internal/InterpreterBase.java
b/src/main/java/org/apache/commons/jexl3/internal/InterpreterBase.java
index 4afa2d4..9f77987 100644
--- a/src/main/java/org/apache/commons/jexl3/internal/InterpreterBase.java
+++ b/src/main/java/org/apache/commons/jexl3/internal/InterpreterBase.java
@@ -269,7 +269,6 @@ public abstract class InterpreterBase extends ParserVisitor
{
return (JexlException) cause;
}
if (cause instanceof InterruptedException) {
- cancelled = true;
return new JexlException.Cancel(node);
}
return new JexlException(node, methodName, xany);
@@ -280,21 +279,15 @@ public abstract class InterpreterBase extends
ParserVisitor {
* @return false if already cancelled, true otherwise
*/
protected boolean cancel() {
- if (cancelled) {
- return false;
- }
- synchronized(this) {
- cancelled = true;
- return true;
- }
+ return cancelled? false : (cancelled = true);
}
/**
* Checks whether this interpreter execution was cancelled due to thread
interruption.
* @return true if cancelled, false otherwise
*/
- protected synchronized boolean isCancelled() {
- return cancelled |= Thread.currentThread().isInterrupted();
+ protected boolean isCancelled() {
+ return cancelled | Thread.currentThread().isInterrupted();
}
/**
diff --git a/src/test/java/org/apache/commons/jexl3/ScriptCallableTest.java
b/src/test/java/org/apache/commons/jexl3/ScriptCallableTest.java
index 6728fd4..313562d 100644
--- a/src/test/java/org/apache/commons/jexl3/ScriptCallableTest.java
+++ b/src/test/java/org/apache/commons/jexl3/ScriptCallableTest.java
@@ -524,6 +524,10 @@ public class ScriptCallableTest extends JexlTestCase {
return statement.call();
}
+ public void sleep(long ms) throws InterruptedException {
+ Thread.sleep(ms);
+ }
+
}
@Test
@@ -533,20 +537,44 @@ public class ScriptCallableTest extends JexlTestCase {
Object result = null;
try {
result = script.execute(ctxt, true);
- Assert.assertEquals("cancelled", result);
} catch (Exception xany) {
- String msg = xany.toString();
+ Assert.fail(xany.toString());
}
+ Assert.assertEquals("cancelled", result);
+
result = script.execute(ctxt, false);
Assert.assertEquals(42, result);
script = JEXL.createScript("(flag)->{ @timeout(100, 'cancelled') {
while(flag); 42; } }");
try {
result = script.execute(ctxt, true);
- Assert.assertEquals("cancelled", result);
} catch (Exception xany) {
- String msg = xany.toString();
+ Assert.fail(xany.toString());
}
+ Assert.assertEquals("cancelled", result);
+
result = script.execute(ctxt, false);
Assert.assertEquals(42, result);
+ script = JEXL.createScript("@timeout(10) {sleep(1000); 42; } -42;");
+ try {
+ result = script.execute(ctxt);
+ } catch (Exception xany) {
+ Assert.fail(xany.toString());
+ }
+ Assert.assertEquals(-42, result);
+
+ script = JEXL.createScript("@timeout(10) {sleep(1000); return 42; }
return -42;");
+ try {
+ result = script.execute(ctxt);
+ } catch (Exception xany) {
+ Assert.fail(xany.toString());
+ }
+ Assert.assertEquals(-42, result);
+ script = JEXL.createScript("@timeout(1000) {sleep(10); return 42; }
return -42;");
+ try {
+ result = script.execute(ctxt);
+ } catch (Exception xany) {
+ Assert.fail(xany.toString());
+ }
+ Assert.assertEquals(42, result);
}
}
--
To stop receiving notification emails like this one, please contact
[email protected].