You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@plc4x.apache.org by sr...@apache.org on 2018/02/07 11:22:19 UTC
[incubator-plc4x] 01/02: added util methods for manual usage of
TcpHexDumper
This is an automated email from the ASF dual-hosted git repository.
sruehl pushed a commit to branch feature/Beckhoff_ADS_protocol
in repository https://gitbox.apache.org/repos/asf/incubator-plc4x.git
commit ff07d14c113fec25c3a96c832ceeca4afea2b4e3
Author: Sebastian Rühl <sr...@apache.org>
AuthorDate: Wed Feb 7 12:21:42 2018 +0100
added util methods for manual usage of TcpHexDumper
---
.../apache/plc4x/java/ads/util/TcpHexDumper.java | 22 +++++++++++++++++++++-
1 file changed, 21 insertions(+), 1 deletion(-)
diff --git a/plc4j/protocols/ads/src/test/java/org/apache/plc4x/java/ads/util/TcpHexDumper.java b/plc4j/protocols/ads/src/test/java/org/apache/plc4x/java/ads/util/TcpHexDumper.java
index 92aa16e..4eb726f 100644
--- a/plc4j/protocols/ads/src/test/java/org/apache/plc4x/java/ads/util/TcpHexDumper.java
+++ b/plc4j/protocols/ads/src/test/java/org/apache/plc4x/java/ads/util/TcpHexDumper.java
@@ -25,6 +25,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.ByteArrayOutputStream;
+import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.net.ServerSocket;
@@ -33,7 +34,7 @@ import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
-public class TcpHexDumper implements BeforeEachCallback, AfterEachCallback, ParameterResolver {
+public class TcpHexDumper implements BeforeEachCallback, AfterEachCallback, ParameterResolver, Closeable {
private static final Logger logger = LoggerFactory.getLogger(TcpHexDumper.class);
@@ -115,6 +116,16 @@ public class TcpHexDumper implements BeforeEachCallback, AfterEachCallback, Para
}
}
+ public static TcpHexDumper runOn(int port) throws IOException, InterruptedException {
+ TcpHexDumper tcpHexDumper = new TcpHexDumper();
+ tcpHexDumper.init(port);
+ return tcpHexDumper;
+ }
+
+ public Integer getPort() {
+ return serverSocket.getLocalPort();
+ }
+
private int initShutdownTimeout(ExtensionContext context) {
ExtendWithTcpHexDumper annotation = context.getRequiredTestClass().getAnnotation(ExtendWithTcpHexDumper.class);
return annotation.shutdownTimeout();
@@ -135,4 +146,13 @@ public class TcpHexDumper implements BeforeEachCallback, AfterEachCallback, Para
return socket.getLocalPort();
}
}
+
+ @Override
+ public void close() throws IOException {
+ try {
+ stop();
+ } catch (InterruptedException e) {
+ throw new IOException(e);
+ }
+ }
}
--
To stop receiving notification emails like this one, please contact
sruehl@apache.org.