From 271f537cad78ac867f02b462759de7dabddde92d Mon Sep 17 00:00:00 2001 From: Peter Thomas Date: Thu, 4 Aug 2022 10:18:11 +0530 Subject: [PATCH] turn back on the async / listen tests #2009 #1883 --- .../java/com/intuit/karate/EventContext.java | 34 ------------------- .../intuit/karate/core/ScenarioBridge.java | 10 +++--- .../intuit/karate/core/ScenarioEngine.java | 9 ++--- karate-demo/pom.xml | 2 -- .../java/mock/contract/QueueConsumer.java | 14 +------- .../test/java/mock/contract/QueueUtils.java | 1 + 6 files changed, 12 insertions(+), 58 deletions(-) delete mode 100644 karate-core/src/main/java/com/intuit/karate/EventContext.java diff --git a/karate-core/src/main/java/com/intuit/karate/EventContext.java b/karate-core/src/main/java/com/intuit/karate/EventContext.java deleted file mode 100644 index beea682a9..000000000 --- a/karate-core/src/main/java/com/intuit/karate/EventContext.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * The MIT License - * - * Copyright 2021 Intuit Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ -package com.intuit.karate; - -/** - * - * @author pthomas3 - */ -public interface EventContext { - - void signal(Object arg); - -} diff --git a/karate-core/src/main/java/com/intuit/karate/core/ScenarioBridge.java b/karate-core/src/main/java/com/intuit/karate/core/ScenarioBridge.java index 68e0c1707..22b27baf3 100644 --- a/karate-core/src/main/java/com/intuit/karate/core/ScenarioBridge.java +++ b/karate-core/src/main/java/com/intuit/karate/core/ScenarioBridge.java @@ -23,7 +23,6 @@ */ package com.intuit.karate.core; -import com.intuit.karate.EventContext; import com.intuit.karate.FileUtils; import com.intuit.karate.Json; import com.intuit.karate.JsonUtils; @@ -68,7 +67,7 @@ * * @author pthomas3 */ -public class ScenarioBridge implements PerfContext, EventContext { +public class ScenarioBridge implements PerfContext { private final ScenarioEngine ENGINE; @@ -764,10 +763,11 @@ public void setXml(String name, String path, String xml) { getEngine().set(name, path, new Variable(XmlUtils.toXmlDoc(xml))); } - @Override public void signal(Object o) { - Value v = Value.asValue(o); - getEngine().signal(JsValue.toJava(v)); + synchronized (JsValue.LOCK) { + Value v = Value.asValue(o); + getEngine().signal(JsValue.toJava(v)); + } } public Object sizeOf(Value v) { diff --git a/karate-core/src/main/java/com/intuit/karate/core/ScenarioEngine.java b/karate-core/src/main/java/com/intuit/karate/core/ScenarioEngine.java index 4418fe516..54c8969f5 100644 --- a/karate-core/src/main/java/com/intuit/karate/core/ScenarioEngine.java +++ b/karate-core/src/main/java/com/intuit/karate/core/ScenarioEngine.java @@ -748,8 +748,8 @@ public WebSocketClient webSocket(WebSocketOptions options) { return webSocketClient; } - public synchronized void signal(Object result) { - SIGNAL.complete(result); + public void signal(Object result) { + SIGNAL.complete(result); } public void listen(String exp) { @@ -759,10 +759,11 @@ public void listen(String exp) { Object listenResult = null; try { listenResult = SIGNAL.get(timeout, TimeUnit.MILLISECONDS); + Thread.sleep(100); // IMPORTANT, else graal js complains } catch (Exception e) { logger.error("listen timed out: {}", e + ""); - } - synchronized (JS.context) { + } + synchronized (JsValue.LOCK) { setHiddenVariable(LISTEN_RESULT, listenResult); logger.debug("exit listen state with result: {}", listenResult); SIGNAL = new CompletableFuture(); diff --git a/karate-demo/pom.xml b/karate-demo/pom.xml index e36f938ba..2adaf0792 100644 --- a/karate-demo/pom.xml +++ b/karate-demo/pom.xml @@ -128,10 +128,8 @@ demo/DemoTestParallel.java - mock/micro/*Runner.java mock/proxy/*Runner.java ssl/*Test.java diff --git a/karate-demo/src/test/java/mock/contract/QueueConsumer.java b/karate-demo/src/test/java/mock/contract/QueueConsumer.java index fffea25d5..28bf8afde 100644 --- a/karate-demo/src/test/java/mock/contract/QueueConsumer.java +++ b/karate-demo/src/test/java/mock/contract/QueueConsumer.java @@ -1,6 +1,5 @@ package mock.contract; -import com.intuit.karate.EventContext; import javax.jms.Connection; import javax.jms.Destination; import javax.jms.JMSException; @@ -46,18 +45,7 @@ public void listen(java.util.function.Consumer handler) { throw new RuntimeException(e); } }); - } - - public void bind(EventContext context) { - setMessageListener(message -> { - TextMessage tm = (TextMessage) message; - try { - context.signal(tm.getText()); - } catch (Exception e) { - throw new RuntimeException(e); - } - }); - } + } public void setMessageListener(MessageListener ml) { try { diff --git a/karate-demo/src/test/java/mock/contract/QueueUtils.java b/karate-demo/src/test/java/mock/contract/QueueUtils.java index fa2916b0b..5e7b216b8 100644 --- a/karate-demo/src/test/java/mock/contract/QueueUtils.java +++ b/karate-demo/src/test/java/mock/contract/QueueUtils.java @@ -26,6 +26,7 @@ public static Connection getConnection() { static { try { + logger.debug("waiting for activemq connection ..."); ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("vm://localhost?broker.persistent=false&waitForStart=10000"); connection = connectionFactory.createConnection(); connection.start();