Deprecate DEFAULT_MAXIMUM_CHUNK_SIZE 19/101919/3
authorRobert Varga <robert.varga@pantheon.tech>
Fri, 29 Jul 2022 15:56:58 +0000 (17:56 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Fri, 29 Jul 2022 17:16:52 +0000 (19:16 +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>
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 88f4f1133726a3e8877fab7ccc3be161a5048b81..06b76a213dff55ba3753d508e834d1d01f7c2be5 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;
@@ -35,7 +32,6 @@ import org.opendaylight.netconf.util.messages.FramingMechanism;
 import org.opendaylight.netconf.util.test.XmlFileLoader;
 
 public class MessageParserTest {
-
     private NetconfMessage msg;
 
     @Before
@@ -48,13 +44,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(msg);
         Queue<Object> messages = testChunkChannel.outboundMessages();
-        assertFalse(messages.isEmpty());
+        assertEquals(1, messages.size());
 
         final NetconfMessageToXMLEncoder enc = new NetconfMessageToXMLEncoder();
         final ByteBuf out = Unpooled.buffer();
@@ -83,7 +78,7 @@ public class MessageParserTest {
 
             testChunkChannel.writeInbound(recievedOutbound);
         }
-        assertTrue(messages.isEmpty());
+        assertEquals(0, messages.size());
 
         NetconfMessage receivedMessage = testChunkChannel.readInbound();
         assertNotNull(receivedMessage);
index 6ee1c8b57cf4b9821d0280ca77e5826f9c39a0cd..3566bf4bb19fc39f69ab29e6dac2c86258c073bd 100644 (file)
@@ -194,7 +194,7 @@ public abstract class AbstractNetconfSessionNegotiator<S extends AbstractNetconf
         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());