Author: henrib
Date: Sun Jul 17 18:44:55 2011
New Revision: 1147698
URL: http://svn.apache.org/viewvc?rev=1147698&view=rev
Log:
JEXL-115:
* More tests around interruption handling
Modified:
commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/Script.java
commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/ScriptCallableTest.java
Modified:
commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/Script.java
URL:
http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/Script.java?rev=1147698&r1=1147697&r2=1147698&view=diff
==============================================================================
---
commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/Script.java
(original)
+++
commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/Script.java
Sun Jul 17 18:44:55 2011
@@ -23,7 +23,7 @@ import java.util.concurrent.Callable;
/**
* <p>A JEXL Script.</p>
* <p>A script is some valid JEXL syntax to be executed with
- * a given set of {@link JexlContext} variabless.</p>
+ * a given set of {@link JexlContext} variables.</p>
* <p>A script is a group of statements, separated by semicolons.</p>
* <p>The statements can be <code>blocks</code> (curly braces containing code),
* Control statements such as <code>if</code> and <code>while</code>
Modified:
commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/ScriptCallableTest.java
URL:
http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/ScriptCallableTest.java?rev=1147698&r1=1147697&r2=1147698&view=diff
==============================================================================
---
commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/ScriptCallableTest.java
(original)
+++
commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/ScriptCallableTest.java
Sun Jul 17 18:44:55 2011
@@ -73,6 +73,26 @@ public class ScriptCallableTest extends
Thread.sleep(1000 * s);
return s;
}
+
+ public int waitInterrupt(int s) {
+ try {
+ Thread.sleep(1000 * s);
+ return s;
+ } catch(InterruptedException xint) {
+ Thread.currentThread().interrupt();
+ }
+ return -1;
+ }
+
+ public int runForever() {
+ boolean x = false;
+ while(true) {
+ if (x) {
+ break;
+ }
+ }
+ return 1;
+ }
}
public void testWait() throws Exception {
@@ -101,6 +121,38 @@ public class ScriptCallableTest extends
assertTrue(future.isCancelled());
}
+ public void testCancelWaitInterrupt() throws Exception {
+ Script e = JEXL.createScript("waitInterrupt(42)");
+ Callable<Object> c = e.callable(new TestContext());
+
+ ExecutorService executor = Executors.newFixedThreadPool(1);
+ Future<?> future = executor.submit(c);
+ try {
+ future.get(100, TimeUnit.MILLISECONDS);
+ fail("should have timed out");
+ } catch (TimeoutException xtimeout) {
+ // ok, ignore
+ }
+ future.cancel(true);
+ assertTrue(future.isCancelled());
+ }
+
+ public void testCancelForever() throws Exception {
+ Script e = JEXL.createScript("runForever()");
+ Callable<Object> c = e.callable(new TestContext());
+
+ ExecutorService executor = Executors.newFixedThreadPool(1);
+ Future<?> future = executor.submit(c);
+ try {
+ future.get(100, TimeUnit.MILLISECONDS);
+ fail("should have timed out");
+ } catch (TimeoutException xtimeout) {
+ // ok, ignore
+ }
+ future.cancel(true);
+ assertTrue(future.isCancelled());
+ }
+
public void testCancelLoopWait() throws Exception {
Script e = JEXL.createScript("while (true) { wait(10) }");
Callable<Object> c = e.callable(new TestContext());