Java Code Examples for io.netty.handler.codec.http.websocketx.BinaryWebSocketFrame#release()

The following examples show how to use io.netty.handler.codec.http.websocketx.BinaryWebSocketFrame#release() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PerFrameDeflateDecoderTest.java    From netty-4.1.22 with Apache License 2.0 6 votes vote down vote up
@Test
public void testCompressedEmptyFrame() {
    EmbeddedChannel encoderChannel = new EmbeddedChannel(
            ZlibCodecFactory.newZlibEncoder(ZlibWrapper.NONE, 9, 15, 8));
    EmbeddedChannel decoderChannel = new EmbeddedChannel(new PerFrameDeflateDecoder(false));

    encoderChannel.writeOutbound(Unpooled.EMPTY_BUFFER);
    ByteBuf compressedPayload = encoderChannel.readOutbound();
    BinaryWebSocketFrame compressedFrame =
            new BinaryWebSocketFrame(true, WebSocketExtension.RSV1 | WebSocketExtension.RSV3, compressedPayload);

    // execute
    decoderChannel.writeInbound(compressedFrame);
    BinaryWebSocketFrame uncompressedFrame = decoderChannel.readInbound();

    // test
    assertNotNull(uncompressedFrame);
    assertNotNull(uncompressedFrame.content());
    assertTrue(uncompressedFrame instanceof BinaryWebSocketFrame);
    assertEquals(WebSocketExtension.RSV3, uncompressedFrame.rsv());
    assertEquals(0, uncompressedFrame.content().readableBytes());
    uncompressedFrame.release();
}
 
Example 2
Source File: PerMessageDeflateEncoderTest.java    From netty-4.1.22 with Apache License 2.0 5 votes vote down vote up
@Test
public void testAlreadyCompressedFrame() {
    EmbeddedChannel encoderChannel = new EmbeddedChannel(new PerMessageDeflateEncoder(9, 15, false));

    // initialize
    byte[] payload = new byte[300];
    random.nextBytes(payload);

    BinaryWebSocketFrame frame = new BinaryWebSocketFrame(true,
            WebSocketExtension.RSV3 | WebSocketExtension.RSV1, Unpooled.wrappedBuffer(payload));

    // execute
    encoderChannel.writeOutbound(frame);
    BinaryWebSocketFrame newFrame = encoderChannel.readOutbound();

    // test
    assertNotNull(newFrame);
    assertNotNull(newFrame.content());
    assertTrue(newFrame instanceof BinaryWebSocketFrame);
    assertEquals(WebSocketExtension.RSV3 | WebSocketExtension.RSV1, newFrame.rsv());
    assertEquals(300, newFrame.content().readableBytes());

    byte[] finalPayload = new byte[300];
    newFrame.content().readBytes(finalPayload);
    assertTrue(Arrays.equals(finalPayload, payload));
    newFrame.release();
}
 
Example 3
Source File: PerFrameDeflateDecoderTest.java    From netty-4.1.22 with Apache License 2.0 5 votes vote down vote up
@Test
public void testCompressedFrame() {
    EmbeddedChannel encoderChannel = new EmbeddedChannel(
            ZlibCodecFactory.newZlibEncoder(ZlibWrapper.NONE, 9, 15, 8));
    EmbeddedChannel decoderChannel = new EmbeddedChannel(new PerFrameDeflateDecoder(false));

    // initialize
    byte[] payload = new byte[300];
    random.nextBytes(payload);

    encoderChannel.writeOutbound(Unpooled.wrappedBuffer(payload));
    ByteBuf compressedPayload = encoderChannel.readOutbound();

    BinaryWebSocketFrame compressedFrame = new BinaryWebSocketFrame(true,
            WebSocketExtension.RSV1 | WebSocketExtension.RSV3,
            compressedPayload.slice(0, compressedPayload.readableBytes() - 4));

    // execute
    decoderChannel.writeInbound(compressedFrame);
    BinaryWebSocketFrame uncompressedFrame = decoderChannel.readInbound();

    // test
    assertNotNull(uncompressedFrame);
    assertNotNull(uncompressedFrame.content());
    assertTrue(uncompressedFrame instanceof BinaryWebSocketFrame);
    assertEquals(WebSocketExtension.RSV3, uncompressedFrame.rsv());
    assertEquals(300, uncompressedFrame.content().readableBytes());

    byte[] finalPayload = new byte[300];
    uncompressedFrame.content().readBytes(finalPayload);
    assertTrue(Arrays.equals(finalPayload, payload));
    uncompressedFrame.release();
}
 
Example 4
Source File: PerFrameDeflateDecoderTest.java    From netty-4.1.22 with Apache License 2.0 5 votes vote down vote up
@Test
public void testNormalFrame() {
    EmbeddedChannel decoderChannel = new EmbeddedChannel(new PerFrameDeflateDecoder(false));

    // initialize
    byte[] payload = new byte[300];
    random.nextBytes(payload);

    BinaryWebSocketFrame frame = new BinaryWebSocketFrame(true,
            WebSocketExtension.RSV3, Unpooled.wrappedBuffer(payload));

    // execute
    decoderChannel.writeInbound(frame);
    BinaryWebSocketFrame newFrame = decoderChannel.readInbound();

    // test
    assertNotNull(newFrame);
    assertNotNull(newFrame.content());
    assertTrue(newFrame instanceof BinaryWebSocketFrame);
    assertEquals(WebSocketExtension.RSV3, newFrame.rsv());
    assertEquals(300, newFrame.content().readableBytes());

    byte[] finalPayload = new byte[300];
    newFrame.content().readBytes(finalPayload);
    assertTrue(Arrays.equals(finalPayload, payload));
    newFrame.release();
}
 
Example 5
Source File: PerMessageDeflateDecoderTest.java    From netty-4.1.22 with Apache License 2.0 5 votes vote down vote up
@Test
public void testCompressedFrame() {
    EmbeddedChannel encoderChannel = new EmbeddedChannel(
            ZlibCodecFactory.newZlibEncoder(ZlibWrapper.NONE, 9, 15, 8));
    EmbeddedChannel decoderChannel = new EmbeddedChannel(new PerMessageDeflateDecoder(false));

    // initialize
    byte[] payload = new byte[300];
    random.nextBytes(payload);

    encoderChannel.writeOutbound(Unpooled.wrappedBuffer(payload));
    ByteBuf compressedPayload = encoderChannel.readOutbound();

    BinaryWebSocketFrame compressedFrame = new BinaryWebSocketFrame(true,
            WebSocketExtension.RSV1 | WebSocketExtension.RSV3,
            compressedPayload.slice(0, compressedPayload.readableBytes() - 4));

    // execute
    decoderChannel.writeInbound(compressedFrame);
    BinaryWebSocketFrame uncompressedFrame = decoderChannel.readInbound();

    // test
    assertNotNull(uncompressedFrame);
    assertNotNull(uncompressedFrame.content());
    assertTrue(uncompressedFrame instanceof BinaryWebSocketFrame);
    assertEquals(WebSocketExtension.RSV3, uncompressedFrame.rsv());
    assertEquals(300, uncompressedFrame.content().readableBytes());

    byte[] finalPayload = new byte[300];
    uncompressedFrame.content().readBytes(finalPayload);
    assertTrue(Arrays.equals(finalPayload, payload));
    uncompressedFrame.release();
}
 
Example 6
Source File: PerMessageDeflateDecoderTest.java    From netty-4.1.22 with Apache License 2.0 5 votes vote down vote up
@Test
public void testNormalFrame() {
    EmbeddedChannel decoderChannel = new EmbeddedChannel(new PerMessageDeflateDecoder(false));

    // initialize
    byte[] payload = new byte[300];
    random.nextBytes(payload);

    BinaryWebSocketFrame frame = new BinaryWebSocketFrame(true,
            WebSocketExtension.RSV3, Unpooled.wrappedBuffer(payload));

    // execute
    decoderChannel.writeInbound(frame);
    BinaryWebSocketFrame newFrame = decoderChannel.readInbound();

    // test
    assertNotNull(newFrame);
    assertNotNull(newFrame.content());
    assertTrue(newFrame instanceof BinaryWebSocketFrame);
    assertEquals(WebSocketExtension.RSV3, newFrame.rsv());
    assertEquals(300, newFrame.content().readableBytes());

    byte[] finalPayload = new byte[300];
    newFrame.content().readBytes(finalPayload);
    assertTrue(Arrays.equals(finalPayload, payload));
    newFrame.release();
}
 
Example 7
Source File: PerFrameDeflateEncoderTest.java    From netty-4.1.22 with Apache License 2.0 5 votes vote down vote up
@Test
public void testAlreadyCompressedFrame() {
    EmbeddedChannel encoderChannel = new EmbeddedChannel(new PerFrameDeflateEncoder(9, 15, false));

    // initialize
    byte[] payload = new byte[300];
    random.nextBytes(payload);

    BinaryWebSocketFrame frame = new BinaryWebSocketFrame(true,
            WebSocketExtension.RSV3 | WebSocketExtension.RSV1, Unpooled.wrappedBuffer(payload));

    // execute
    encoderChannel.writeOutbound(frame);
    BinaryWebSocketFrame newFrame = encoderChannel.readOutbound();

    // test
    assertNotNull(newFrame);
    assertNotNull(newFrame.content());
    assertTrue(newFrame instanceof BinaryWebSocketFrame);
    assertEquals(WebSocketExtension.RSV3 | WebSocketExtension.RSV1, newFrame.rsv());
    assertEquals(300, newFrame.content().readableBytes());

    byte[] finalPayload = new byte[300];
    newFrame.content().readBytes(finalPayload);
    assertTrue(Arrays.equals(finalPayload, payload));
    newFrame.release();
}
 
Example 8
Source File: PerMessageDeflateDecoderTest.java    From netty-4.1.22 with Apache License 2.0 4 votes vote down vote up
@Test
public void testMultiCompressedPayloadWithinFrame() {
    EmbeddedChannel encoderChannel = new EmbeddedChannel(
            ZlibCodecFactory.newZlibEncoder(ZlibWrapper.NONE, 9, 15, 8));
    EmbeddedChannel decoderChannel = new EmbeddedChannel(new PerMessageDeflateDecoder(false));

    // initialize
    byte[] payload1 = new byte[100];
    random.nextBytes(payload1);
    byte[] payload2 = new byte[100];
    random.nextBytes(payload2);

    encoderChannel.writeOutbound(Unpooled.wrappedBuffer(payload1));
    ByteBuf compressedPayload1 = encoderChannel.readOutbound();
    encoderChannel.writeOutbound(Unpooled.wrappedBuffer(payload2));
    ByteBuf compressedPayload2 = encoderChannel.readOutbound();

    BinaryWebSocketFrame compressedFrame = new BinaryWebSocketFrame(true,
            WebSocketExtension.RSV1 | WebSocketExtension.RSV3,
            Unpooled.wrappedBuffer(
                    compressedPayload1,
                    compressedPayload2.slice(0, compressedPayload2.readableBytes() - 4)));

    // execute
    decoderChannel.writeInbound(compressedFrame);
    BinaryWebSocketFrame uncompressedFrame = decoderChannel.readInbound();

    // test
    assertNotNull(uncompressedFrame);
    assertNotNull(uncompressedFrame.content());
    assertTrue(uncompressedFrame instanceof BinaryWebSocketFrame);
    assertEquals(WebSocketExtension.RSV3, uncompressedFrame.rsv());
    assertEquals(200, uncompressedFrame.content().readableBytes());

    byte[] finalPayload1 = new byte[100];
    uncompressedFrame.content().readBytes(finalPayload1);
    assertTrue(Arrays.equals(finalPayload1, payload1));
    byte[] finalPayload2 = new byte[100];
    uncompressedFrame.content().readBytes(finalPayload2);
    assertTrue(Arrays.equals(finalPayload2, payload2));
    uncompressedFrame.release();
}