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/09/28 08:57:18 UTC

[incubator-plc4x] branch master updated: [General] SingleItemToSingleRequestProtocol added one more test case and simplified code a bit.

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

sruehl 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 dbd84f4  [General] SingleItemToSingleRequestProtocol added one more test case and simplified code a bit.
dbd84f4 is described below

commit dbd84f47eeae70068591db56cb41ab457b0d8e89
Author: Sebastian Rühl <sr...@apache.org>
AuthorDate: Fri Sep 28 10:57:10 2018 +0200

    [General] SingleItemToSingleRequestProtocol added one more test case
    and simplified code a bit.
---
 .../SingleItemToSingleRequestProtocolTest.java     | 39 +++++++++++++++++++---
 1 file changed, 35 insertions(+), 4 deletions(-)

diff --git a/plc4j/protocols/driver-bases/base/src/test/java/org/apache/plc4x/java/base/protocol/SingleItemToSingleRequestProtocolTest.java b/plc4j/protocols/driver-bases/base/src/test/java/org/apache/plc4x/java/base/protocol/SingleItemToSingleRequestProtocolTest.java
index 1185ace..045cbff 100644
--- a/plc4j/protocols/driver-bases/base/src/test/java/org/apache/plc4x/java/base/protocol/SingleItemToSingleRequestProtocolTest.java
+++ b/plc4j/protocols/driver-bases/base/src/test/java/org/apache/plc4x/java/base/protocol/SingleItemToSingleRequestProtocolTest.java
@@ -136,7 +136,7 @@ class SingleItemToSingleRequestProtocolTest implements WithAssertions {
         void simpleRead() throws Exception {
             // Given
             // we have a simple read
-            PlcRequestContainer<TestDefaultPlcReadRequest, InternalPlcResponse> msg = new PlcRequestContainer<>(TestDefaultPlcReadRequest.build(), responseCompletableFuture);
+            PlcRequestContainer<?, ?> msg = new PlcRequestContainer<>(TestDefaultPlcReadRequest.build(), responseCompletableFuture);
             // When
             // we write this
             SUT.write(channelHandlerContext, msg, channelPromise);
@@ -167,7 +167,7 @@ class SingleItemToSingleRequestProtocolTest implements WithAssertions {
         void partialRead() throws Exception {
             // Given
             // we have a simple read
-            PlcRequestContainer<TestDefaultPlcReadRequest, InternalPlcResponse> msg = new PlcRequestContainer<>(TestDefaultPlcReadRequest.build(), responseCompletableFuture);
+            PlcRequestContainer<?, ?> msg = new PlcRequestContainer<>(TestDefaultPlcReadRequest.build(), responseCompletableFuture);
             // When
             // we write this
             SUT.write(channelHandlerContext, msg, channelPromise);
@@ -196,6 +196,37 @@ class SingleItemToSingleRequestProtocolTest implements WithAssertions {
             );
         }
 
+        @Test
+        void noRead() throws Exception {
+            // Given
+            // we have a simple read
+            PlcRequestContainer<?, ?> msg = new PlcRequestContainer<>(TestDefaultPlcReadRequest.build(), responseCompletableFuture);
+            // When
+            // we write this
+            SUT.write(channelHandlerContext, msg, channelPromise);
+            // And
+            // and we simulate that some one responded
+            verify(channelHandlerContext, times(5)).write(any(), any());
+            // Then
+            // We create SUT with 1 seconds timeout
+            TimeUnit.SECONDS.sleep(2);
+            // our complete container should complete normally
+            verify(responseCompletableFuture).completeExceptionally(any());
+            // And we should have no memory leak
+            assertThat(SUT.getStatistics()).containsOnly(
+                entry("queue", 0),
+                entry("sentButUnacknowledgedSubContainer", 0),
+                entry("correlationToParentContainer", 0),
+                entry("containerCorrelationIdMap", 0),
+                entry("responsesToBeDelivered", 0),
+                entry("correlationIdGenerator", 5),
+                entry("deliveredItems", 0L),
+                entry("erroredItems", 5L),
+                entry("deliveredContainers", 0L),
+                entry("erroredContainers", 1L)
+            );
+        }
+
         @SuppressWarnings("unchecked")
         private Void produceReadResponse(PlcRequestContainer plcRequestContainer) {
             InternalPlcReadRequest request = (InternalPlcReadRequest) plcRequestContainer.getRequest();
@@ -242,7 +273,7 @@ class SingleItemToSingleRequestProtocolTest implements WithAssertions {
         @Test
         void read() throws Exception {
             // Given
-            PlcRequestContainer<TestDefaultPlcReadRequest, InternalPlcResponse> msg = new PlcRequestContainer<>(TestDefaultPlcReadRequest.build(), responseCompletableFuture);
+            PlcRequestContainer<?, ?> msg = new PlcRequestContainer<>(TestDefaultPlcReadRequest.build(), responseCompletableFuture);
             // When
             SUT.write(channelHandlerContext, msg, channelPromise);
             // Then
@@ -273,7 +304,7 @@ class SingleItemToSingleRequestProtocolTest implements WithAssertions {
         @Test
         void write() throws Exception {
             // Given
-            PlcRequestContainer<TestDefaultPlcWriteRequest, InternalPlcResponse> msg = new PlcRequestContainer<>(TestDefaultPlcWriteRequest.build(), responseCompletableFuture);
+            PlcRequestContainer<?, ?> msg = new PlcRequestContainer<>(TestDefaultPlcWriteRequest.build(), responseCompletableFuture);
             // When
             SUT.write(channelHandlerContext, msg, channelPromise);
             // Then