commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hen...@apache.org
Subject svn commit: r1752595 - /commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/ScriptCallableTest.java
Date Thu, 14 Jul 2016 07:31:10 GMT
Author: henrib
Date: Thu Jul 14 07:31:10 2016
New Revision: 1752595

URL: http://svn.apache.org/viewvc?rev=1752595&view=rev
Log:
JEXL: 
JEXL-205 / JEXL-206 - clean up tests

Modified:
    commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/ScriptCallableTest.java

Modified: commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/ScriptCallableTest.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/ScriptCallableTest.java?rev=1752595&r1=1752594&r2=1752595&view=diff
==============================================================================
--- commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/ScriptCallableTest.java
(original)
+++ commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/ScriptCallableTest.java
Thu Jul 14 07:31:10 2016
@@ -68,13 +68,13 @@ public class ScriptCallableTest extends
         JexlContext ctxt = new MapContext();
         ctxt.set("latch", latch);
 
-        JexlScript e = JEXL.createScript("latch.acquire(1); while(true);");
+        JexlScript e = JEXL.createScript("latch.release(); while(true);");
         final Script.Callable c = (Script.Callable) e.callable(ctxt);
         Object t = 42;
         Callable<Object> kc = new Callable<Object>() {
             @Override
             public Object call() throws Exception {
-                latch.release();
+                latch.acquire();
                 return c.cancel();
             }
         };
@@ -96,13 +96,18 @@ public class ScriptCallableTest extends
 
     @Test
     public void testCallableTimeout() throws Exception {
-        JexlScript e = JEXL.createScript("while(true);");
-        Callable<Object> c = e.callable(null);
+        final Semaphore latch = new Semaphore(0);
+        JexlContext ctxt = new MapContext();
+        ctxt.set("latch", latch);
+
+        JexlScript e = JEXL.createScript("latch.release(); while(true);");
+        Callable<Object> c = e.callable(ctxt);
         Object t = 42;
 
         ExecutorService executor = Executors.newFixedThreadPool(1);
         Future<?> future = executor.submit(c);
         try {
+            latch.acquire();
             t = future.get(100, TimeUnit.MILLISECONDS);
             Assert.fail("should have timed out");
         } catch (TimeoutException xtimeout) {
@@ -266,7 +271,7 @@ public class ScriptCallableTest extends
         JexlContext ctxt = new TestContext();
         ctxt.set("latch", latch);
 
-        JexlScript e = JEXL.createScript("runForever()");
+        JexlScript e = JEXL.createScript("latch.release(); runForever()");
         Callable<Object> c = e.callable(ctxt);
 
         ExecutorService executor = Executors.newFixedThreadPool(1);
@@ -274,7 +279,7 @@ public class ScriptCallableTest extends
         Object t = 42;
 
         try {
-            latch.release();
+            latch.acquire();
             t = future.get(100, TimeUnit.MILLISECONDS);
             Assert.fail("should have timed out");
         } catch (TimeoutException xtimeout) {



Mime
View raw message