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

cdutz pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-plc4x.git


The following commit(s) were added to refs/heads/master by this push:
     new a69e14e  PLC4X-29 - [S7] Implement PDU Fragmentation
a69e14e is described below

commit a69e14e383449a291b81126cea6ef84b1c7ea6c9
Author: Christofer Dutz <christofer.d...@c-ware.de>
AuthorDate: Thu Feb 8 09:22:12 2018 +0100

    PLC4X-29 - [S7] Implement PDU Fragmentation
    
    - Fixed the logic for calculating the pdu size box
    - Fixed the tests where some were failing but not causing the build to fail 
(Have to investigate that)
---
 .../plc4x/java/isotp/netty/model/types/TpduSize.java    |  5 ++++-
 .../plc4x/java/s7/connection/S7PlcConnection.java       |  2 +-
 .../java/isotp/netty/model/types/IsotpTypeTests.java    | 17 ++++++++++-------
 3 files changed, 15 insertions(+), 9 deletions(-)

diff --git 
a/plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/isotp/netty/model/types/TpduSize.java
 
b/plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/isotp/netty/model/types/TpduSize.java
index 2e662bf..836da8b 100644
--- 
a/plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/isotp/netty/model/types/TpduSize.java
+++ 
b/plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/isotp/netty/model/types/TpduSize.java
@@ -49,9 +49,12 @@ public enum TpduSize {
     }
 
     public static TpduSize valueForGivenSize(int pduSize) {
+        if(pduSize < 0) {
+            throw new IllegalArgumentException("PduSize has to be greater than 
0");
+        }
         assert pduSize > 0;
         for (TpduSize tpduSize : values()) {
-            if(tpduSize.getValue() <= pduSize) {
+            if(tpduSize.getValue() >= pduSize) {
                 return tpduSize;
             }
         }
diff --git 
a/plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/s7/connection/S7PlcConnection.java
 
b/plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/s7/connection/S7PlcConnection.java
index c0f4793..2913585 100644
--- 
a/plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/s7/connection/S7PlcConnection.java
+++ 
b/plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/s7/connection/S7PlcConnection.java
@@ -102,7 +102,7 @@ public class S7PlcConnection extends AbstractPlcConnection 
implements PlcReader,
                             paramMaxAmqCallee = Short.parseShort(paramValue);
                             break;
                         default:
-                            logger.debug("Unknown parameter {}={}", paramName, 
paramValue);
+                            logger.debug("Unknown parameter {} with value {}", 
paramName, paramValue);
                     }
                 } else {
                     logger.debug("Unknown no-value parameter {}", paramName);
diff --git 
a/plc4j/protocols/s7/src/test/java/org/apache/plc4x/java/isotp/netty/model/types/IsotpTypeTests.java
 
b/plc4j/protocols/s7/src/test/java/org/apache/plc4x/java/isotp/netty/model/types/IsotpTypeTests.java
index f85ee4a..ac629a5 100644
--- 
a/plc4j/protocols/s7/src/test/java/org/apache/plc4x/java/isotp/netty/model/types/IsotpTypeTests.java
+++ 
b/plc4j/protocols/s7/src/test/java/org/apache/plc4x/java/isotp/netty/model/types/IsotpTypeTests.java
@@ -19,8 +19,10 @@ under the License.
 
 package org.apache.plc4x.java.isotp.netty.model.types;
 
+import org.apache.plc4x.java.api.exceptions.PlcProtocolException;
 import org.junit.jupiter.api.Tag;
 import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.function.Executable;
 
 import static org.junit.jupiter.api.Assertions.*;
 
@@ -172,8 +174,7 @@ class IsotpTypeTests {
     void tpduValueForGivenExactFit() {
         TpduSize tpduSize = TpduSize.valueForGivenSize(256);
 
-        assertEquals(tpduSize, TpduSize.SIZE_256, "expected tpdu size of 256");
-        assertEquals(tpduSize.getValue(), 128, "the value is not 128");
+        assertEquals(TpduSize.SIZE_256, tpduSize, "expected tpdu size of 256");
     }
 
     /**
@@ -183,9 +184,10 @@ class IsotpTypeTests {
     @Test
     @Tag("fast")
     void tpduValueForGivenIntermediateSize() {
-        TpduSize tpduSize = TpduSize.valueForGivenSize(123);
+        TpduSize tpduSize = TpduSize.valueForGivenSize(222);
 
-        assertEquals(tpduSize, TpduSize.SIZE_256, "expected tpdu size of 256");
+        assertEquals(TpduSize.SIZE_256, tpduSize, "expected tpdu size of 256");
+        assertNotEquals(222, tpduSize.getValue(), "the value is not 222");
     }
 
     /**
@@ -195,9 +197,10 @@ class IsotpTypeTests {
     @Test
     @Tag("fast")
     void tpduValueForGivenTooSmallSize() {
-        TpduSize tpduSize = TpduSize.valueForGivenSize(-1);
+        Executable closureContainingCodeToTest = () -> 
TpduSize.valueForGivenSize(-1);
 
-        assertEquals(tpduSize, TpduSize.SIZE_256, "expected tpdu size of 256");
+        assertThrows(IllegalArgumentException.class, 
closureContainingCodeToTest,
+            "An exception should have been thrown.");
     }
 
     /**
@@ -209,7 +212,7 @@ class IsotpTypeTests {
     void tpduValueForGivenTooGreatSize() {
         TpduSize tpduSize = TpduSize.valueForGivenSize(10000);
 
-        assertEquals(tpduSize, TpduSize.SIZE_8192, "expected tpdu size of 
8192");
+        assertEquals(TpduSize.SIZE_8192, tpduSize, "expected tpdu size of 
8192");
     }
 
 }
\ No newline at end of file

-- 
To stop receiving notification emails like this one, please contact
cd...@apache.org.

Reply via email to