Deprecate DEFAULT_MAXIMUM_CHUNK_SIZE 97/102197/1
authorRobert Varga <robert.varga@pantheon.tech>
Fri, 29 Jul 2022 15:56:58 +0000 (17:56 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Mon, 22 Aug 2022 08:19:02 +0000 (10:19 +0200)
This is an artificial global limit. We provide the ability to specify
this limit on a per-instance basis and callers should be taking
advantage of that instead.

Change-Id: I3abbed74c37b4f9a9e820adf0c38fba160a8dc88
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
(cherry picked from commit 14adff2aa1c1a88371693ee9ecd0ce27b227f24e)

netconf/netconf-impl/src/test/java/org/opendaylight/netconf/impl/MessageParserTest.java
netconf/netconf-netty-util/src/main/java/org/opendaylight/netconf/nettyutil/AbstractNetconfSessionNegotiator.java
netconf/netconf-netty-util/src/main/java/org/opendaylight/netconf/nettyutil/handler/NetconfChunkAggregator.java
netconf/netconf-netty-util/src/test/java/org/opendaylight/netconf/nettyutil/handler/NetconfChunkAggregatorTest.java

index 82c42dcb29fa59c0c9022737f087f92878a9b185..ace216f866a47953e70c20b34eccaab8581fe981 100644 (file)
@@ -5,15 +5,12 @@
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
-
 package org.opendaylight.netconf.impl;
 
 import static org.custommonkey.xmlunit.XMLAssert.assertXMLEqual;
 import static org.junit.Assert.assertArrayEquals;
 import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
 
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
@@ -36,7 +33,6 @@ import org.opendaylight.netconf.util.messages.NetconfMessageConstants;
 import org.opendaylight.netconf.util.test.XmlFileLoader;
 
 public class MessageParserTest {
-
     private NetconfMessage msg;
 
     @Before
@@ -49,13 +45,12 @@ public class MessageParserTest {
         EmbeddedChannel testChunkChannel = new EmbeddedChannel(
                 FramingMechanismHandlerFactory.createHandler(FramingMechanism.CHUNK),
                 new NetconfMessageToXMLEncoder(),
-
-                new NetconfChunkAggregator(),
+                new NetconfChunkAggregator(ChunkedFramingMechanismEncoder.MAX_CHUNK_SIZE),
                 new NetconfXMLToMessageDecoder());
 
         testChunkChannel.writeOutbound(this.msg);
         Queue<Object> messages = testChunkChannel.outboundMessages();
-        assertFalse(messages.isEmpty());
+        assertEquals(1, messages.size());
 
         final NetconfMessageToXMLEncoder enc = new NetconfMessageToXMLEncoder();
         final ByteBuf out = Unpooled.buffer();
@@ -85,7 +80,7 @@ public class MessageParserTest {
 
             testChunkChannel.writeInbound(recievedOutbound);
         }
-        assertTrue(messages.isEmpty());
+        assertEquals(0, messages.size());
 
         NetconfMessage receivedMessage = testChunkChannel.readInbound();
         assertNotNull(receivedMessage);
index 79c440105892aff663a313e3e7b84e7afe85b98c..d7f97aa4cc9197d9d84f3af88132a588c27b34e0 100644 (file)
@@ -194,7 +194,7 @@ public abstract class AbstractNetconfSessionNegotiator<P extends NetconfSessionP
         replaceChannelHandler(channel, AbstractChannelInitializer.NETCONF_MESSAGE_FRAME_ENCODER,
                 FramingMechanismHandlerFactory.createHandler(FramingMechanism.CHUNK));
         replaceChannelHandler(channel, AbstractChannelInitializer.NETCONF_MESSAGE_AGGREGATOR,
-                new NetconfChunkAggregator());
+                new NetconfChunkAggregator(DEFAULT_MAXIMUM_INCOMING_CHUNK_SIZE));
     }
 
     private boolean shouldUseChunkFraming(final Document doc) {
index cab1d741b15b7ab6d6971924691b598664d75a51..49e6a89dfd71c867f59da0087c782983d23b98f8 100644 (file)
@@ -27,6 +27,7 @@ public class NetconfChunkAggregator extends ByteToMessageDecoder {
     private static final String GOT_PARAM_WHILE_WAITING_FOR_PARAM_PARAM_PARAM =
         "Got byte {} while waiting for {}-{}-{}";
 
+    @Deprecated(since = "4.0.1", forRemoval = true)
     public static final @NonNegative int DEFAULT_MAXIMUM_CHUNK_SIZE =
         AbstractNetconfSessionNegotiator.DEFAULT_MAXIMUM_INCOMING_CHUNK_SIZE;
 
@@ -49,7 +50,10 @@ public class NetconfChunkAggregator extends ByteToMessageDecoder {
 
     /**
      * Construct an instance with maximum chunk size set to {@link #DEFAULT_MAXIMUM_CHUNK_SIZE}.
+     *
+     * @deprecated Prefer {@link #NetconfChunkAggregator(int)} for fine-grained control.
      */
+    @Deprecated(since = "4.0.1", forRemoval = true)
     public NetconfChunkAggregator() {
         this(DEFAULT_MAXIMUM_CHUNK_SIZE);
     }
index 5d692b2fcf35274c2c2899ecc9db7268dc3621e0..9c5a83e625919a64f15dbd7ebf903fc7c5e67435 100644 (file)
@@ -13,12 +13,9 @@ import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
 import java.nio.charset.StandardCharsets;
 import java.util.ArrayList;
-import java.util.List;
-import org.junit.BeforeClass;
 import org.junit.Test;
 
 public class NetconfChunkAggregatorTest {
-
     private static final String CHUNKED_MESSAGE = "\n#4\n"
             + "<rpc"
             + "\n#18\n"
@@ -29,36 +26,31 @@ public class NetconfChunkAggregatorTest {
             + "</rpc>"
             + "\n##\n";
 
-    public static final String EXPECTED_MESSAGE = "<rpc message-id=\"102\"\n"
+    private static final String EXPECTED_MESSAGE = "<rpc message-id=\"102\"\n"
             + "     xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n"
             + "  <close-session/>\n"
             + "</rpc>";
 
     private static final String CHUNKED_MESSAGE_ONE = "\n#101\n" + EXPECTED_MESSAGE + "\n##\n";
 
-    private static NetconfChunkAggregator agr;
-
-    @BeforeClass
-    public static void setUp() throws Exception {
-        agr = new NetconfChunkAggregator();
-    }
+    private final NetconfChunkAggregator agr = new NetconfChunkAggregator(4096);
 
     @Test
     public void testMultipleChunks() throws Exception {
-        final List<Object> output = new ArrayList<>();
-        final ByteBuf input = Unpooled.copiedBuffer(CHUNKED_MESSAGE.getBytes(StandardCharsets.UTF_8));
+        final var output = new ArrayList<>();
+        final var input = Unpooled.copiedBuffer(CHUNKED_MESSAGE.getBytes(StandardCharsets.UTF_8));
         agr.decode(null, input, output);
 
         assertEquals(1, output.size());
-        final ByteBuf chunk = (ByteBuf) output.get(0);
+        final var chunk = (ByteBuf) output.get(0);
 
         assertEquals(EXPECTED_MESSAGE, chunk.toString(StandardCharsets.UTF_8));
     }
 
     @Test
     public void testOneChunks() throws Exception {
-        final List<Object> output = new ArrayList<>();
-        final ByteBuf input = Unpooled.copiedBuffer(CHUNKED_MESSAGE_ONE.getBytes(StandardCharsets.UTF_8));
+        final var output = new ArrayList<>();
+        final var input = Unpooled.copiedBuffer(CHUNKED_MESSAGE_ONE.getBytes(StandardCharsets.UTF_8));
         agr.decode(null, input, output);
 
         assertEquals(1, output.size());