You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@royale.apache.org by jo...@apache.org on 2019/05/21 22:19:38 UTC
[royale-compiler] branch develop updated: royaleunit-ant-tasks:
added support for WebSocket with new player='html' option
This is an automated email from the ASF dual-hosted git repository.
joshtynjala pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/royale-compiler.git
The following commit(s) were added to refs/heads/develop by this push:
new fe561a6 royaleunit-ant-tasks: added support for WebSocket with new player='html' option
fe561a6 is described below
commit fe561a6770959077fd5061336c6daa75de3c8276
Author: Josh Tynjala <jo...@apache.org>
AuthorDate: Tue May 21 15:10:53 2019 -0700
royaleunit-ant-tasks: added support for WebSocket with new player='html' option
---
royaleunit-ant-tasks/build.xml | 2 +-
royaleunit-ant-tasks/pom.xml | 10 ++
.../apache/royale/test/ant/IRoyaleUnitServer.java | 28 ++++
.../royale/test/ant/RoyaleUnitSocketServer.java | 20 +--
.../royale/test/ant/RoyaleUnitSocketThread.java | 39 +++++-
.../royale/test/ant/RoyaleUnitWebSocketServer.java | 153 +++++++++++++++++++++
.../commands/player/PlayerCommandFactory.java | 2 +-
.../org/apache/royale/test/ant/tasks/TestRun.java | 19 ++-
.../ant/tasks/configuration/TaskConfiguration.java | 2 +-
.../src/main/resources/downloads.xml | 32 +++++
10 files changed, 285 insertions(+), 22 deletions(-)
diff --git a/royaleunit-ant-tasks/build.xml b/royaleunit-ant-tasks/build.xml
index 41805b2..d7a7105 100644
--- a/royaleunit-ant-tasks/build.xml
+++ b/royaleunit-ant-tasks/build.xml
@@ -112,7 +112,7 @@
<attribute name="Implementation-Title" value="${manifest.Implementation-Title}"/>
<attribute name="Implementation-Version" value="${manifest.Implementation-Version}.${build.number}"/>
<attribute name="Implementation-Vendor" value="${manifest.Implementation-Vendor}"/>
- <attribute name="Class-Path" value="dom4j.jar"/>
+ <attribute name="Class-Path" value="dom4j.jar java-websocket.jar slf4j-api.jar"/>
</manifest>
<fileset dir="${royaleunittasks}/src/main/resources" includes="royaleUnitTasks.tasks"/>
<fileset dir="${royaleunittasks}/src/main/resources" includes="TestRunner.template"/>
diff --git a/royaleunit-ant-tasks/pom.xml b/royaleunit-ant-tasks/pom.xml
index 6244fa9..24b1984 100644
--- a/royaleunit-ant-tasks/pom.xml
+++ b/royaleunit-ant-tasks/pom.xml
@@ -52,6 +52,16 @@
<artifactId>dom4j</artifactId>
<version>1.6.1</version>
</dependency>
+ <dependency>
+ <groupId>org.java-websocket</groupId>
+ <artifactId>Java-WebSocket</artifactId>
+ <version>1.4.0</version>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-simple</artifactId>
+ <version>1.7.25</version>
+ </dependency>
</dependencies>
</project>
diff --git a/royaleunit-ant-tasks/src/main/java/org/apache/royale/test/ant/IRoyaleUnitServer.java b/royaleunit-ant-tasks/src/main/java/org/apache/royale/test/ant/IRoyaleUnitServer.java
new file mode 100644
index 0000000..1dff70b
--- /dev/null
+++ b/royaleunit-ant-tasks/src/main/java/org/apache/royale/test/ant/IRoyaleUnitServer.java
@@ -0,0 +1,28 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.royale.test.ant;
+
+import java.io.IOException;
+
+public interface IRoyaleUnitServer
+{
+ public void start() throws IOException;
+ public void stop() throws IOException, InterruptedException;
+ public boolean isPending();
+ public String readNextTokenFromSocket() throws IOException;
+ public Exception getException();
+}
\ No newline at end of file
diff --git a/royaleunit-ant-tasks/src/main/java/org/apache/royale/test/ant/RoyaleUnitSocketServer.java b/royaleunit-ant-tasks/src/main/java/org/apache/royale/test/ant/RoyaleUnitSocketServer.java
index 5bfdd77..841eada 100644
--- a/royaleunit-ant-tasks/src/main/java/org/apache/royale/test/ant/RoyaleUnitSocketServer.java
+++ b/royaleunit-ant-tasks/src/main/java/org/apache/royale/test/ant/RoyaleUnitSocketServer.java
@@ -31,7 +31,7 @@ import org.apache.tools.ant.BuildException;
/**
* Class responsible for managing the connections to the test runner and any boiler plate in the network interactivity.
*/
-public class RoyaleUnitSocketServer
+public class RoyaleUnitSocketServer implements IRoyaleUnitServer
{
private static final char NULL_BYTE = '\u0000';
@@ -47,7 +47,6 @@ public class RoyaleUnitSocketServer
+ "</cross-domain-policy>";
private static final String START_OF_TEST_RUN_ACK = "<startOfTestRunAck/>";
- private static final String END_OF_TEST_RUN = "<endOfTestRun/>";
private static final String END_OF_TEST_RUN_ACK = "<endOfTestRunAck/>";
private int port;
@@ -86,6 +85,16 @@ public class RoyaleUnitSocketServer
throw new BuildException("Socket timeout waiting for royaleunit report", e);
}
}
+
+ public boolean isPending()
+ {
+ return false;
+ }
+
+ public Exception getException()
+ {
+ return null;
+ }
/**
* Resets the client connection.
@@ -197,11 +206,6 @@ public class RoyaleUnitSocketServer
//Did we recieve a message that the test run is over? Tell the user we have nothing more.
String token = buffer.toString();
- if(token.equals(END_OF_TEST_RUN))
- {
- return null;
- }
-
return token;
}
@@ -218,7 +222,7 @@ public class RoyaleUnitSocketServer
/**
* Stops the socket server, notifying the test runner, and closing the appropriate connections.
*/
- public void stop() throws IOException
+ public void stop() throws IOException, InterruptedException
{
LoggingUtil.log("\nStopping server ...");
diff --git a/royaleunit-ant-tasks/src/main/java/org/apache/royale/test/ant/RoyaleUnitSocketThread.java b/royaleunit-ant-tasks/src/main/java/org/apache/royale/test/ant/RoyaleUnitSocketThread.java
index eef119d..05d2445 100644
--- a/royaleunit-ant-tasks/src/main/java/org/apache/royale/test/ant/RoyaleUnitSocketThread.java
+++ b/royaleunit-ant-tasks/src/main/java/org/apache/royale/test/ant/RoyaleUnitSocketThread.java
@@ -37,16 +37,17 @@ public class RoyaleUnitSocketThread implements Callable<Object>
private static final String END_OF_SUCCESS = "status=\"success\" />";
private static final String END_OF_FAILURE = "</testcase>";
private static final String END_OF_IGNORE = "<skipped /></testcase>";
+ private static final String END_OF_TEST_RUN = "<endOfTestRun/>";
// XML attribute labels
private static final String SUITE_ATTRIBUTE = "classname";
private File reportDir;
- private RoyaleUnitSocketServer server;
+ private IRoyaleUnitServer server;
private Map<String, Report> reports;
- public RoyaleUnitSocketThread(RoyaleUnitSocketServer server, File reportDir, Map<String, Report> reports)
+ public RoyaleUnitSocketThread(IRoyaleUnitServer server, File reportDir, Map<String, Report> reports)
{
this.server = server;
this.reportDir = reportDir;
@@ -89,13 +90,37 @@ public class RoyaleUnitSocketThread implements Callable<Object>
*/
private void parseInboundMessages() throws IOException
{
- String request = null;
-
- while ((request = server.readNextTokenFromSocket()) != null)
+ while (true)
{
- // If the string is a failure, process the report
- if (request.endsWith(END_OF_FAILURE) || request.endsWith(END_OF_SUCCESS) || request.endsWith(END_OF_IGNORE))
+ if (server.isPending())
+ {
+ //try again later
+ try
+ {
+ Thread.sleep(100);
+ }
+ catch(Exception e) {}
+ continue;
+ }
+
+ if (server.getException() != null)
+ {
+ throw new BuildException(server.getException());
+ }
+
+ String request = server.readNextTokenFromSocket();
+ if (request == null)
+ {
+ break;
+ }
+ else if (request.equals(END_OF_TEST_RUN))
+ {
+ // The client has declared that the test run is complete
+ break;
+ }
+ else if (request.endsWith(END_OF_FAILURE) || request.endsWith(END_OF_SUCCESS) || request.endsWith(END_OF_IGNORE))
{
+ // Process all other known requests
processTestReport(request);
}
else
diff --git a/royaleunit-ant-tasks/src/main/java/org/apache/royale/test/ant/RoyaleUnitWebSocketServer.java b/royaleunit-ant-tasks/src/main/java/org/apache/royale/test/ant/RoyaleUnitWebSocketServer.java
new file mode 100644
index 0000000..09f4e0e
--- /dev/null
+++ b/royaleunit-ant-tasks/src/main/java/org/apache/royale/test/ant/RoyaleUnitWebSocketServer.java
@@ -0,0 +1,153 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.royale.test.ant;
+
+import java.io.IOException;
+import java.net.InetSocketAddress;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Timer;
+import java.util.TimerTask;
+import java.util.concurrent.Callable;
+
+import org.apache.tools.ant.BuildException;
+import org.java_websocket.WebSocket;
+import org.java_websocket.handshake.ClientHandshake;
+import org.java_websocket.server.WebSocketServer;
+
+public class RoyaleUnitWebSocketServer extends WebSocketServer implements IRoyaleUnitServer
+{
+ private static final String START_OF_TEST_RUN_ACK = "<startOfTestRunAck/>";
+ private static final String END_OF_TEST_RUN_ACK = "<endOfTestRunAck/>";
+
+ public RoyaleUnitWebSocketServer(int port, int timeout)
+ {
+ super(new InetSocketAddress(port));
+ this.timeout = timeout;
+ }
+
+ private int timeout;
+ private Timer timeoutTimer;
+ private List<String> queue = new ArrayList<String>();
+ private Exception resultException;
+
+ public Exception getException()
+ {
+ return resultException;
+ }
+
+ @Override
+ public void stop() throws IOException, InterruptedException
+ {
+ LoggingUtil.log("\nStopping server ...");
+
+ for(WebSocket socket : getConnections())
+ {
+ sendTestRunEndAcknowledgement(socket);
+ }
+ super.stop();
+ }
+
+ @Override
+ public void onOpen(WebSocket connection, ClientHandshake handshake)
+ {
+ if(timeoutTimer != null)
+ {
+ timeoutTimer.cancel();
+ timeoutTimer = null;
+ }
+
+ LoggingUtil.log("Client connected.");
+ LoggingUtil.log("Receiving data ...");
+
+ sendTestRunStartAcknowledgement(connection);
+ }
+
+ @Override
+ public void onClose(WebSocket connection, int code, String reason, boolean remote)
+ {
+ Thread.currentThread().interrupt();
+ }
+
+ @Override
+ public void onMessage(WebSocket connection, String message)
+ {
+ System.out.println("received message from " + connection.getRemoteSocketAddress() + ": " + message);
+ queue.add(message);
+ }
+
+ @Override
+ public void onError(WebSocket connection, Exception ex)
+ {
+ LoggingUtil.log("an error occured on connection " + connection.getRemoteSocketAddress() + ":" + ex);
+ resultException = ex;
+ }
+
+ @Override
+ public void onStart()
+ {
+ LoggingUtil.log("Starting server ...");
+ LoggingUtil.log("Waiting for client connection ...");
+
+ timeoutTimer = new Timer();
+ timeoutTimer.schedule(new TimerTask()
+ {
+ public void run()
+ {
+ resultException = new BuildException("Socket timeout waiting for royaleunit report");
+ }
+ }, timeout);
+ }
+
+ public boolean isPending()
+ {
+ return resultException == null && queue.size() == 0;
+ }
+
+ /**
+ * Reads tokens from the web socket
+ */
+ public String readNextTokenFromSocket() throws IOException
+ {
+ return queue.remove(0);
+ }
+
+ private void sendOutboundMessage(WebSocket connection, String message)
+ {
+ connection.send(message);
+ }
+
+ /**
+ * Generate and send message to inform test runner to begin sending test data
+ */
+ private void sendTestRunStartAcknowledgement(WebSocket connection)
+ {
+ LoggingUtil.log("Sending acknowledgement to player to start sending test data ...\n");
+
+ sendOutboundMessage(connection, START_OF_TEST_RUN_ACK);
+ }
+
+ /**
+ * Sends the end of test run to the listener to close the connection
+ */
+ private void sendTestRunEndAcknowledgement(WebSocket connection)
+ {
+ LoggingUtil.log("End of test data reached, sending acknowledgement to player ...");
+
+ sendOutboundMessage(connection, END_OF_TEST_RUN_ACK);
+ }
+}
\ No newline at end of file
diff --git a/royaleunit-ant-tasks/src/main/java/org/apache/royale/test/ant/launcher/commands/player/PlayerCommandFactory.java b/royaleunit-ant-tasks/src/main/java/org/apache/royale/test/ant/launcher/commands/player/PlayerCommandFactory.java
index c3d01a7..ddefd21 100644
--- a/royaleunit-ant-tasks/src/main/java/org/apache/royale/test/ant/launcher/commands/player/PlayerCommandFactory.java
+++ b/royaleunit-ant-tasks/src/main/java/org/apache/royale/test/ant/launcher/commands/player/PlayerCommandFactory.java
@@ -42,7 +42,7 @@ public class PlayerCommandFactory
DefaultPlayerCommand defaultInstance = null;
//choose player
- if (player.equals("flash"))
+ if (player.equals("flash") || player.equals("html"))
{
FlashPlayerCommand fpCommand = new FlashPlayerCommand();
fpCommand.setLocalTrusted(localTrusted);
diff --git a/royaleunit-ant-tasks/src/main/java/org/apache/royale/test/ant/tasks/TestRun.java b/royaleunit-ant-tasks/src/main/java/org/apache/royale/test/ant/tasks/TestRun.java
index 1b72284..feaefe6 100644
--- a/royaleunit-ant-tasks/src/main/java/org/apache/royale/test/ant/tasks/TestRun.java
+++ b/royaleunit-ant-tasks/src/main/java/org/apache/royale/test/ant/tasks/TestRun.java
@@ -25,6 +25,8 @@ import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project;
import org.apache.royale.test.ant.RoyaleUnitSocketServer;
import org.apache.royale.test.ant.RoyaleUnitSocketThread;
+import org.apache.royale.test.ant.RoyaleUnitWebSocketServer;
+import org.apache.royale.test.ant.IRoyaleUnitServer;
import org.apache.royale.test.ant.LoggingUtil;
import org.apache.royale.test.ant.launcher.commands.player.AdlCommand;
import org.apache.royale.test.ant.launcher.commands.player.PlayerCommand;
@@ -65,7 +67,7 @@ public class TestRun
//start the execution context
context.start();
-
+
//launch the player
Process process = player.launch();
@@ -138,9 +140,18 @@ public class TestRun
LoggingUtil.log("Setting up server process ...");
// Create server for use by thread
- RoyaleUnitSocketServer server = new RoyaleUnitSocketServer(configuration.getPort(),
- configuration.getSocketTimeout(), configuration.getServerBufferSize(),
- configuration.usePolicyFile());
+ IRoyaleUnitServer server = null;
+ if(configuration.getPlayer().equals("html"))
+ {
+ server = new RoyaleUnitWebSocketServer(
+ configuration.getPort(), configuration.getSocketTimeout());
+ }
+ else
+ {
+ server = new RoyaleUnitSocketServer(configuration.getPort(),
+ configuration.getSocketTimeout(), configuration.getServerBufferSize(),
+ configuration.usePolicyFile());
+ }
// Get handle to specialized object to run in separate thread.
Callable<Object> operation = new RoyaleUnitSocketThread(server,
diff --git a/royaleunit-ant-tasks/src/main/java/org/apache/royale/test/ant/tasks/configuration/TaskConfiguration.java b/royaleunit-ant-tasks/src/main/java/org/apache/royale/test/ant/tasks/configuration/TaskConfiguration.java
index 04c70a1..ef23bed 100644
--- a/royaleunit-ant-tasks/src/main/java/org/apache/royale/test/ant/tasks/configuration/TaskConfiguration.java
+++ b/royaleunit-ant-tasks/src/main/java/org/apache/royale/test/ant/tasks/configuration/TaskConfiguration.java
@@ -32,7 +32,7 @@ public class TaskConfiguration
{
private final String DEFAULT_WORKING_PATH = ".";
private final String DEFAULT_REPORT_PATH = ".";
- private final List<String> VALID_PLAYERS = Arrays.asList(new String[]{"flash", "air"});
+ private final List<String> VALID_PLAYERS = Arrays.asList(new String[]{"flash", "air", "html"});
private String player = "flash";
private File reportDir = null;
diff --git a/royaleunit-ant-tasks/src/main/resources/downloads.xml b/royaleunit-ant-tasks/src/main/resources/downloads.xml
index 4b070e4..73e8451 100644
--- a/royaleunit-ant-tasks/src/main/resources/downloads.xml
+++ b/royaleunit-ant-tasks/src/main/resources/downloads.xml
@@ -27,6 +27,8 @@
Licenses:
dom4j (1.6.1) - BSD
+ Java-WebSocket (1.4.0) - MIT
+ slf4j-api (1.7.25) - MIT
-->
<!-- this script supports the usingDownloadCache property and
@@ -83,6 +85,36 @@
<param name="license.use.url" value="https://raw.githubusercontent.com/dom4j/dom4j/master/LICENSE"/>
<param name="license.cacheName" value="dom4j-LICENSE.txt"/>
</antcall>
+
+ <!-- Java-WebSocket -->
+ <property name="javawebsocket.name" value="java-websocket"/>
+ <property name="javawebsocket.version" value="1.4.0"/>
+ <antcall target="download-dependency">
+ <param name="name" value="${javawebsocket.name}"/>
+ <param name="src.server" value="${maven.search.url}"/>
+ <param name="src.folder" value="org/java-websocket/Java-WebSocket/${javawebsocket.version}"/>
+ <param name="src.filename" value="Java-WebSocket-${javawebsocket.version}.jar"/>
+ <param name="src.checksum" value="59c1134b8c50ace9e074e9f1d5da4aaa"/>
+ <param name="dest.folder" value=""/>
+ <param name="dest.filename" value="${javawebsocket.name}.jar"/>
+ <param name="license.use.url" value="https://raw.githubusercontent.com/TooTallNate/Java-WebSocket/master/LICENSE"/>
+ <param name="license.cacheName" value="${javawebsocket.name}-LICENSE.txt"/>
+ </antcall>
+
+ <!-- slf4j-api -->
+ <property name="slf4j.name" value="slf4j-api"/>
+ <property name="slf4j.version" value="1.7.25"/>
+ <antcall target="download-dependency">
+ <param name="name" value="${slf4j.name}"/>
+ <param name="src.server" value="${maven.search.url}"/>
+ <param name="src.folder" value="org/slf4j/slf4j-api/${slf4j.version}"/>
+ <param name="src.filename" value="slf4j-api-${slf4j.version}.jar"/>
+ <param name="src.checksum" value="caafe376afb7086dcbee79f780394ca3"/>
+ <param name="dest.folder" value=""/>
+ <param name="dest.filename" value="${slf4j.name}.jar"/>
+ <param name="license.use.url" value="https://raw.githubusercontent.com/qos-ch/slf4j/master/LICENSE.txt"/>
+ <param name="license.cacheName" value="${slf4j.name}-LICENSE.txt"/>
+ </antcall>
</target>