You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@plc4x.apache.org by cd...@apache.org on 2023/06/15 13:56:52 UTC

[plc4x] 02/02: bug(plc4j/opc-ua): Trying to fix the blocking test issue on Windows.

This is an automated email from the ASF dual-hosted git repository.

cdutz pushed a commit to branch chore/profinet-phase-3
in repository https://gitbox.apache.org/repos/asf/plc4x.git

commit edd7b4fb5aa8bc30bb7d9d23d6b1d2c0b6b226cf
Author: Christofer Dutz <cd...@apache.org>
AuthorDate: Thu Jun 15 15:56:37 2023 +0200

    bug(plc4j/opc-ua): Trying to fix the blocking test issue on Windows.
---
 .../plc4x/java/opcua/context/SecureChannel.java    |  2 +-
 .../protocol/OpcuaSubscriptionHandleTest.java      | 35 +++++++++++-----------
 .../opcua/src/test/resources/logback-test.xml      |  2 +-
 .../org/apache/plc4x/java/spi/TimeoutManager.java  |  2 +-
 .../spi/netty/NettyHashTimerTimeoutManager.java    | 16 +++++-----
 .../s7/src/main/resources/protocols/s7/s7.mspec    |  2 +-
 6 files changed, 30 insertions(+), 29 deletions(-)

diff --git a/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/context/SecureChannel.java b/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/context/SecureChannel.java
index af2bd152f9..f5bc0ccc78 100644
--- a/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/context/SecureChannel.java
+++ b/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/context/SecureChannel.java
@@ -63,7 +63,7 @@ public class SecureChannel {
     private static final int DEFAULT_MAX_MESSAGE_SIZE = 2097152;
     private static final int DEFAULT_RECEIVE_BUFFER_SIZE = 65535;
     private static final int DEFAULT_SEND_BUFFER_SIZE = 65535;
-    public static final Duration REQUEST_TIMEOUT = Duration.ofMillis(1000000);
+    public static final Duration REQUEST_TIMEOUT = Duration.ofMillis(10000);
     public static final long REQUEST_TIMEOUT_LONG = 10000L;
     private static final String PASSWORD_ENCRYPTION_ALGORITHM = "http://www.w3.org/2001/04/xmlenc#rsa-oaep";
     private static final PascalString SECURITY_POLICY_NONE = new PascalString("http://opcfoundation.org/UA/SecurityPolicy#None");
diff --git a/plc4j/drivers/opcua/src/test/java/org/apache/plc4x/java/opcua/protocol/OpcuaSubscriptionHandleTest.java b/plc4j/drivers/opcua/src/test/java/org/apache/plc4x/java/opcua/protocol/OpcuaSubscriptionHandleTest.java
index 5821bf3779..a63f2c9fa0 100644
--- a/plc4j/drivers/opcua/src/test/java/org/apache/plc4x/java/opcua/protocol/OpcuaSubscriptionHandleTest.java
+++ b/plc4j/drivers/opcua/src/test/java/org/apache/plc4x/java/opcua/protocol/OpcuaSubscriptionHandleTest.java
@@ -33,8 +33,7 @@ import org.slf4j.LoggerFactory;
 import java.nio.file.Files;
 import java.nio.file.Path;
 import java.nio.file.Paths;
-
-import static org.junit.jupiter.api.Assumptions.assumeTrue;
+import java.util.concurrent.TimeUnit;
 
 @DisableOnParallelsVmFlag
 public class OpcuaSubscriptionHandleTest {
@@ -134,7 +133,7 @@ public class OpcuaSubscriptionHandleTest {
         PlcSubscriptionRequest request = builder.build();
 
         // Get result of creating subscription
-        PlcSubscriptionResponse response = request.execute().get();
+        PlcSubscriptionResponse response = request.execute().get(1000, TimeUnit.MILLISECONDS);
         final OpcuaSubscriptionHandle subscriptionHandle = (OpcuaSubscriptionHandle) response.getSubscriptionHandle(tag);
 
         // Create handler for returned value
@@ -161,7 +160,7 @@ public class OpcuaSubscriptionHandleTest {
         PlcSubscriptionRequest request = builder.build();
 
         // Get result of creating subscription
-        PlcSubscriptionResponse response = request.execute().get();
+        PlcSubscriptionResponse response = request.execute().get(1000, TimeUnit.MILLISECONDS);
         final OpcuaSubscriptionHandle subscriptionHandle = (OpcuaSubscriptionHandle) response.getSubscriptionHandle(tag);
 
         // Create handler for returned value
@@ -188,7 +187,7 @@ public class OpcuaSubscriptionHandleTest {
         PlcSubscriptionRequest request = builder.build();
 
         // Get result of creating subscription
-        PlcSubscriptionResponse response = request.execute().get();
+        PlcSubscriptionResponse response = request.execute().get(10000, TimeUnit.MILLISECONDS);
         final OpcuaSubscriptionHandle subscriptionHandle = (OpcuaSubscriptionHandle) response.getSubscriptionHandle(tag);
 
         // Create handler for returned value
@@ -215,7 +214,7 @@ public class OpcuaSubscriptionHandleTest {
         PlcSubscriptionRequest request = builder.build();
 
         // Get result of creating subscription
-        PlcSubscriptionResponse response = request.execute().get();
+        PlcSubscriptionResponse response = request.execute().get(1000, TimeUnit.MILLISECONDS);
         final OpcuaSubscriptionHandle subscriptionHandle = (OpcuaSubscriptionHandle) response.getSubscriptionHandle(tag);
 
         // Create handler for returned value
@@ -242,7 +241,7 @@ public class OpcuaSubscriptionHandleTest {
         PlcSubscriptionRequest request = builder.build();
 
         // Get result of creating subscription
-        PlcSubscriptionResponse response = request.execute().get();
+        PlcSubscriptionResponse response = request.execute().get(1000, TimeUnit.MILLISECONDS);
         final OpcuaSubscriptionHandle subscriptionHandle = (OpcuaSubscriptionHandle) response.getSubscriptionHandle(tag);
 
         // Create handler for returned value
@@ -269,7 +268,7 @@ public class OpcuaSubscriptionHandleTest {
         PlcSubscriptionRequest request = builder.build();
 
         // Get result of creating subscription
-        PlcSubscriptionResponse response = request.execute().get();
+        PlcSubscriptionResponse response = request.execute().get(1000, TimeUnit.MILLISECONDS);
         final OpcuaSubscriptionHandle subscriptionHandle = (OpcuaSubscriptionHandle) response.getSubscriptionHandle(tag);
 
         // Create handler for returned value
@@ -296,7 +295,7 @@ public class OpcuaSubscriptionHandleTest {
         PlcSubscriptionRequest request = builder.build();
 
         // Get result of creating subscription
-        PlcSubscriptionResponse response = request.execute().get();
+        PlcSubscriptionResponse response = request.execute().get(1000, TimeUnit.MILLISECONDS);
         final OpcuaSubscriptionHandle subscriptionHandle = (OpcuaSubscriptionHandle) response.getSubscriptionHandle(tag);
 
         // Create handler for returned value
@@ -323,7 +322,7 @@ public class OpcuaSubscriptionHandleTest {
         PlcSubscriptionRequest request = builder.build();
 
         // Get result of creating subscription
-        PlcSubscriptionResponse response = request.execute().get();
+        PlcSubscriptionResponse response = request.execute().get(1000, TimeUnit.MILLISECONDS);
         final OpcuaSubscriptionHandle subscriptionHandle = (OpcuaSubscriptionHandle) response.getSubscriptionHandle(tag);
 
         // Create handler for returned value
@@ -350,7 +349,7 @@ public class OpcuaSubscriptionHandleTest {
         PlcSubscriptionRequest request = builder.build();
 
         // Get result of creating subscription
-        PlcSubscriptionResponse response = request.execute().get();
+        PlcSubscriptionResponse response = request.execute().get(1000, TimeUnit.MILLISECONDS);
         final OpcuaSubscriptionHandle subscriptionHandle = (OpcuaSubscriptionHandle) response.getSubscriptionHandle(tag);
 
         // Create handler for returned value
@@ -377,7 +376,7 @@ public class OpcuaSubscriptionHandleTest {
         PlcSubscriptionRequest request = builder.build();
 
         // Get result of creating subscription
-        PlcSubscriptionResponse response = request.execute().get();
+        PlcSubscriptionResponse response = request.execute().get(1000, TimeUnit.MILLISECONDS);
         final OpcuaSubscriptionHandle subscriptionHandle = (OpcuaSubscriptionHandle) response.getSubscriptionHandle(tag);
 
         // Create handler for returned value
@@ -404,7 +403,7 @@ public class OpcuaSubscriptionHandleTest {
         PlcSubscriptionRequest request = builder.build();
 
         // Get result of creating subscription
-        PlcSubscriptionResponse response = request.execute().get();
+        PlcSubscriptionResponse response = request.execute().get(1000, TimeUnit.MILLISECONDS);
         final OpcuaSubscriptionHandle subscriptionHandle = (OpcuaSubscriptionHandle) response.getSubscriptionHandle(tag);
 
         // Create handler for returned value
@@ -431,7 +430,7 @@ public class OpcuaSubscriptionHandleTest {
         PlcSubscriptionRequest request = builder.build();
 
         // Get result of creating subscription
-        PlcSubscriptionResponse response = request.execute().get();
+        PlcSubscriptionResponse response = request.execute().get(1000, TimeUnit.MILLISECONDS);
         final OpcuaSubscriptionHandle subscriptionHandle = (OpcuaSubscriptionHandle) response.getSubscriptionHandle(tag);
 
         // Create handler for returned value
@@ -458,7 +457,7 @@ public class OpcuaSubscriptionHandleTest {
         PlcSubscriptionRequest request = builder.build();
 
         // Get result of creating subscription
-        PlcSubscriptionResponse response = request.execute().get();
+        PlcSubscriptionResponse response = request.execute().get(1000, TimeUnit.MILLISECONDS);
         final OpcuaSubscriptionHandle subscriptionHandle = (OpcuaSubscriptionHandle) response.getSubscriptionHandle(tag);
 
         // Create handler for returned value
@@ -485,7 +484,7 @@ public class OpcuaSubscriptionHandleTest {
         PlcSubscriptionRequest request = builder.build();
 
         // Get result of creating subscription
-        PlcSubscriptionResponse response = request.execute().get();
+        PlcSubscriptionResponse response = request.execute().get(1000, TimeUnit.MILLISECONDS);
         final OpcuaSubscriptionHandle subscriptionHandle = (OpcuaSubscriptionHandle) response.getSubscriptionHandle(tag);
 
         // Create handler for returned value
@@ -512,7 +511,7 @@ public class OpcuaSubscriptionHandleTest {
         PlcSubscriptionRequest request = builder.build();
 
         // Get result of creating subscription
-        PlcSubscriptionResponse response = request.execute().get();
+        PlcSubscriptionResponse response = request.execute().get(1000, TimeUnit.MILLISECONDS);
         final OpcuaSubscriptionHandle subscriptionHandle = (OpcuaSubscriptionHandle) response.getSubscriptionHandle(tag);
 
         // Create handler for returned value
@@ -543,7 +542,7 @@ public class OpcuaSubscriptionHandleTest {
         PlcSubscriptionRequest request = builder.build();
 
         // Get result of creating subscription
-        PlcSubscriptionResponse response = request.execute().get();
+        PlcSubscriptionResponse response = request.execute().get(1000, TimeUnit.MILLISECONDS);
         final OpcuaSubscriptionHandle subscriptionHandle = (OpcuaSubscriptionHandle) response.getSubscriptionHandle(tag1);
 
         // Create handler for returned value
diff --git a/plc4j/drivers/opcua/src/test/resources/logback-test.xml b/plc4j/drivers/opcua/src/test/resources/logback-test.xml
index 1d9de10bd8..4833ef946e 100644
--- a/plc4j/drivers/opcua/src/test/resources/logback-test.xml
+++ b/plc4j/drivers/opcua/src/test/resources/logback-test.xml
@@ -27,7 +27,7 @@
     </encoder>
   </appender>
 
-  <root level="error">
+  <root level="debug">
     <appender-ref ref="STDOUT" />
   </root>
 </configuration>
\ No newline at end of file
diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/TimeoutManager.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/TimeoutManager.java
index 5ea253240f..7d293f78f3 100644
--- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/TimeoutManager.java
+++ b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/TimeoutManager.java
@@ -22,7 +22,7 @@ import java.util.function.Consumer;
 
 public interface TimeoutManager {
 
-    CompletionCallback register(TimedOperation operation);
+    CompletionCallback<?> register(TimedOperation operation);
 
     void stop();
 
diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/netty/NettyHashTimerTimeoutManager.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/netty/NettyHashTimerTimeoutManager.java
index 823baedee7..78b3be576a 100644
--- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/netty/NettyHashTimerTimeoutManager.java
+++ b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/netty/NettyHashTimerTimeoutManager.java
@@ -24,7 +24,6 @@ import io.netty.util.Timer;
 import java.util.Set;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.TimeoutException;
-import java.util.function.Consumer;
 import org.apache.plc4x.java.spi.TimedOperation;
 import org.apache.plc4x.java.spi.TimeoutManager;
 
@@ -36,14 +35,18 @@ public class NettyHashTimerTimeoutManager implements TimeoutManager {
         this(100L);
     }
 
-    public NettyHashTimerTimeoutManager(long tick) {
-        HashedWheelTimer wheelTimer = new HashedWheelTimer(tick, TimeUnit.MILLISECONDS);
+    /**
+     * Creates a new NettyHashTimerTimeoutManager that checks for timeouts every `tickInMilliseconds` milliseconds.
+     * @param tickInMilliseconds milliseconds between timeout checks.
+     */
+    public NettyHashTimerTimeoutManager(long tickInMilliseconds) {
+        HashedWheelTimer wheelTimer = new HashedWheelTimer(tickInMilliseconds, TimeUnit.MILLISECONDS);
         timer = wheelTimer;
         wheelTimer.start();
     }
 
     @Override
-    public CompletionCallback register(TimedOperation operation) {
+    public CompletionCallback<?> register(TimedOperation operation) {
         Timeout newTimeout = timer.newTimeout(timeout -> {
             if (timeout.isCancelled()) {
                 return;
@@ -52,7 +55,7 @@ public class NettyHashTimerTimeoutManager implements TimeoutManager {
             operation.getOnTimeoutConsumer().accept(exception);
         }, operation.getTimeout().toMillis(), TimeUnit.MILLISECONDS);
 
-        return new TimeoutCompletionCallback(newTimeout);
+        return new TimeoutCompletionCallback<>(newTimeout);
     }
 
     @Override
@@ -61,10 +64,9 @@ public class NettyHashTimerTimeoutManager implements TimeoutManager {
         timeouts.forEach(Timeout::cancel);
     }
 
-    static class TimeoutCompletionCallback implements CompletionCallback {
+    static class TimeoutCompletionCallback<T> implements CompletionCallback<T> {
 
         private final Timeout timeout;
-        private Consumer<TimeoutException> onTimeout;
 
         TimeoutCompletionCallback(Timeout timeout) {
             this.timeout = timeout;
diff --git a/protocols/s7/src/main/resources/protocols/s7/s7.mspec b/protocols/s7/src/main/resources/protocols/s7/s7.mspec
index 55df42afef..3a5e34e1b3 100644
--- a/protocols/s7/src/main/resources/protocols/s7/s7.mspec
+++ b/protocols/s7/src/main/resources/protocols/s7/s7.mspec
@@ -999,7 +999,7 @@
     ['0x12' UPDATE]
 ]
 
-[enum uint 8 'TimeBase'
+[enum uint 8 TimeBase
     ['0x00' B01SEC]
     ['0x01' B1SEC]
     ['0X02' B10SEC]