* 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;
import org.opendaylight.netconf.util.test.XmlFileLoader;
public class MessageParserTest {
-
private NetconfMessage msg;
@Before
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();
testChunkChannel.writeInbound(recievedOutbound);
}
- assertTrue(messages.isEmpty());
+ assertEquals(0, messages.size());
NetconfMessage receivedMessage = testChunkChannel.readInbound();
assertNotNull(receivedMessage);
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) {
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;
/**
* 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);
}
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"
+ "</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());