- public void testChunkedFramingMechanismOnPipeline() throws Exception {
- EmbeddedChannel testChunkChannel = new EmbeddedChannel(
- FramingMechanismHandlerFactory.createHandler(FramingMechanism.CHUNK),
- new ProtocolMessageEncoder<NetconfMessage>(msgFactory),
-
- new NetconfMessageAggregator(FramingMechanism.CHUNK), new NetconfMessageChunkDecoder(),
- new ProtocolMessageDecoder<NetconfMessage>(msgFactory));
-
- testChunkChannel.writeOutbound(this.msg);
- Queue<Object> messages = testChunkChannel.outboundMessages();
- assertFalse(messages.isEmpty());
-
- int msgLength = msgFactory.put(this.msg).length;
- int chunkCount = msgLength / NetconfMessageFactory.MAX_CHUNK_SIZE;
- if ((msgLength % NetconfMessageFactory.MAX_CHUNK_SIZE) != 0) {
- chunkCount++;
- }
- for (int i = 1; i <= chunkCount; i++) {
- ByteBuf recievedOutbound = (ByteBuf) messages.poll();
- int exptHeaderLength = NetconfMessageFactory.MAX_CHUNK_SIZE;
- if (i == chunkCount) {
- exptHeaderLength = msgLength - (NetconfMessageFactory.MAX_CHUNK_SIZE * (i - 1));
- byte[] eom = new byte[NetconfMessageFactory.endOfChunk.length];
- recievedOutbound.getBytes(recievedOutbound.readableBytes() - NetconfMessageFactory.endOfChunk.length,
- eom);
- assertArrayEquals(NetconfMessageFactory.endOfChunk, eom);
- }
-
- byte[] header = new byte[String.valueOf(exptHeaderLength).length() + NetconfMessageHeader.MIN_HEADER_LENGTH
- - 1];
- recievedOutbound.getBytes(0, header);
- NetconfMessageHeader messageHeader = new NetconfMessageHeader();
- messageHeader.fromBytes(header);
- assertEquals(exptHeaderLength, messageHeader.getLength());
-
- testChunkChannel.writeInbound(recievedOutbound);
- }
- assertTrue(messages.isEmpty());
-
- NetconfMessage receivedMessage = (NetconfMessage) testChunkChannel.readInbound();
- assertNotNull(receivedMessage);
- assertTrue(this.msg.getDocument().isEqualNode(receivedMessage.getDocument()));
+ public void testPutEOM() throws IOException, SAXException, ParserConfigurationException {
+ final NetconfMessage msg = XmlFileLoader.xmlFileToNetconfMessage("netconfMessages/client_hello.xml");
+ final byte[] bytes = this.parser.put(msg);
+ assertArrayEquals(NetconfMessageFactory.endOfMessage, ByteArray.subByte(bytes, bytes.length
+ - NetconfMessageFactory.endOfMessage.length, NetconfMessageFactory.endOfMessage.length));