List of usage examples for io.netty.buffer ByteBuf release
boolean release();
From source file:com.github.spapageo.jannel.channel.ChannelBufferUtilsTest.java
License:Open Source License
@Test public void testReadOctetStringToBytesWhenOctetStringSizeIsPositiveReadsByteBufferCorrectly() throws Exception { byte[] bytesToTransfer = { 0x14, 0x13 }; ByteBuf octetStringBytes = Unpooled.buffer(bytesToTransfer.length + 4); octetStringBytes.writeInt(bytesToTransfer.length); octetStringBytes.writeBytes(bytesToTransfer); ByteBuf readBytes = ChannelBufferUtils.readOctetStringToBytes(octetStringBytes); octetStringBytes.readerIndex(4);/*ww w .j a v a2 s .c o m*/ assertEquals("Read bytes and given bytes are not the same", octetStringBytes, readBytes); octetStringBytes.release(); readBytes.release(); }
From source file:com.github.spapageo.jannel.channel.ChannelBufferUtilsTest.java
License:Open Source License
@Test public void testWriteStringToOctetStringWhenStringIsNullWritesMinusOne() throws Exception { ByteBuf byteBuf = Unpooled.buffer(4); ChannelBufferUtils.writeStringToOctetString(null, byteBuf, StandardCharsets.UTF_8); assertEquals("Written length prefix in not -1 for null string", -1, byteBuf.readInt()); byteBuf.release(); }
From source file:com.github.spapageo.jannel.channel.ChannelBufferUtilsTest.java
License:Open Source License
@Test public void testWriteStringToOctetStringIsEncodedCorrectly() throws Exception { ByteBuf encodedString = Unpooled.copiedBuffer(STRING_TO_ENCODE.getBytes(StandardCharsets.UTF_8)); ByteBuf outputBuffer = Unpooled.buffer(4 + encodedString.capacity()); ChannelBufferUtils.writeStringToOctetString(STRING_TO_ENCODE, outputBuffer, StandardCharsets.UTF_8); assertEquals("Written length prefix in not the length of the encoded string byte array", encodedString.capacity(), outputBuffer.readInt()); assertEquals("Written bytes are not the same with those of the input string", encodedString, outputBuffer); outputBuffer.release(); encodedString.release();/*w w w .ja v a2 s . c o m*/ }
From source file:com.github.spapageo.jannel.channel.ChannelBufferUtilsTest.java
License:Open Source License
@Test public void testWriteBytesToOctetStringWhenBytesAreNullWritesMinusOne() throws Exception { ByteBuf byteBuf = Unpooled.buffer(4); ChannelBufferUtils.writeBytesToOctetString(null, byteBuf); assertEquals("Written length prefix in not -1 for null byte array", -1, byteBuf.readInt()); byteBuf.release(); }
From source file:com.github.spapageo.jannel.channel.ChannelBufferUtilsTest.java
License:Open Source License
@Test public void testWriteBytesToOctetStringIsWrittenCorrectly() throws Exception { byte[] payload = { 0x14, 0x16 }; ByteBuf input = Unpooled.copiedBuffer(payload); ByteBuf outputBuffer = Unpooled.buffer(4 + payload.length); ChannelBufferUtils.writeBytesToOctetString(input, outputBuffer); assertEquals("Written length prefix in not the length of the encoded byte array", payload.length, outputBuffer.readInt());// w w w. j a v a 2s. c om assertEquals("Written bytes are not the same with those of the input array", input.readerIndex(0), outputBuffer); outputBuffer.release(); input.release(); }
From source file:com.github.spapageo.jannel.channel.ChannelBufferUtilsTest.java
License:Open Source License
@Test public void testWriteUUIDToOctetStringWhenStringIsNullWritesMinusOne() throws Exception { ByteBuf byteBuf = Unpooled.buffer(4); ChannelBufferUtils.writeUUIDToOctetString(null, byteBuf, StandardCharsets.UTF_8); assertEquals("Written length prefix in not -1 for null string", -1, byteBuf.readInt()); byteBuf.release(); }
From source file:com.github.spapageo.jannel.channel.ChannelBufferUtilsTest.java
License:Open Source License
@Test public void testWriteUUIDToOctetStringIsEncodedCorrectly() throws Exception { UUID input = UUID.randomUUID(); String uuidString = input.toString(); ByteBuf encodedUUID = Unpooled.copiedBuffer(uuidString.getBytes(StandardCharsets.UTF_8)); ByteBuf outputBuffer = Unpooled.buffer(4 + encodedUUID.capacity()); ChannelBufferUtils.writeUUIDToOctetString(input, outputBuffer, StandardCharsets.UTF_8); assertEquals("Written length prefix in not the length of the encoded string byte array", encodedUUID.capacity(), outputBuffer.readInt()); assertEquals("Written bytes are not the same with those of the input string", encodedUUID, outputBuffer); outputBuffer.release(); encodedUUID.release();//from w w w .ja v a 2 s . co m }
From source file:com.github.spapageo.jannel.channel.MessageDecoderTest.java
License:Open Source License
@Test public void testDecodeReadsMessageTypeAndCallTranscoder() throws Exception { Transcoder transcoder = mock(DefaultTranscoder.class); MessageDecoder messageDecoder = new MessageDecoder(transcoder); Message msg = new Ack(); ByteBuf byteBuf = Unpooled.buffer(4); byteBuf.writeInt(msg.getType().value()); List<Object> output = new ArrayList<Object>(); messageDecoder.decode(null, byteBuf, output); verify(transcoder).decode(MessageType.ACK, byteBuf); byteBuf.release(); }
From source file:com.github.spapageo.jannel.channel.MessageDecoderTest.java
License:Open Source License
@Test public void testDecodeAddsDecodedMessageToOutputList() throws Exception { Transcoder transcoder = mock(DefaultTranscoder.class); MessageDecoder messageDecoder = new MessageDecoder(transcoder); Message msg = new Ack(); ByteBuf byteBuf = Unpooled.buffer(4); byteBuf.writeInt(msg.getType().value()); List<Object> output = new ArrayList<Object>(); when(transcoder.decode(any(MessageType.class), any(ByteBuf.class))).thenReturn(msg); messageDecoder.decode(null, byteBuf, output); assertTrue("List doesn't contain the decoded message", output.contains(msg)); byteBuf.release(); }
From source file:com.github.spapageo.jannel.channel.MessageEncoderTest.java
License:Open Source License
@Test public void testEncodeWritesMessageTypeAndCallsTranscoder() throws Exception { Transcoder transcoder = mock(DefaultTranscoder.class); MessageEncoder messageEncoder = new MessageEncoder(transcoder); Message msg = new Ack(); ByteBuf byteBuf = Unpooled.buffer(4); messageEncoder.encode(null, msg, byteBuf); assertEquals("The written message type doesn't match the given one", msg.getType().value(), byteBuf.readInt());/*from w w w . j av a 2 s . co m*/ verify(transcoder).encode(msg, byteBuf); byteBuf.release(); }