Search in sources :

Example 1 with EmptyByteBuf

use of io.netty.buffer.EmptyByteBuf in project netty by netty.

the class Http2FrameRoundtripTest method teardown.

@AfterEach
public void teardown() {
    try {
        // Release all of the buffers.
        for (ByteBuf buf : needReleasing) {
            buf.release();
        }
        // Now verify that all of the reference counts are zero.
        for (ByteBuf buf : needReleasing) {
            int expectedFinalRefCount = 0;
            if (buf.isReadOnly() || buf instanceof EmptyByteBuf) {
                // Special case for when we're writing slices of the padding buffer.
                expectedFinalRefCount = 1;
            }
            assertEquals(expectedFinalRefCount, buf.refCnt());
        }
    } finally {
        needReleasing.clear();
    }
}
Also used : EmptyByteBuf(io.netty.buffer.EmptyByteBuf) ByteBuf(io.netty.buffer.ByteBuf) CompositeByteBuf(io.netty.buffer.CompositeByteBuf) EmptyByteBuf(io.netty.buffer.EmptyByteBuf) AfterEach(org.junit.jupiter.api.AfterEach)

Example 2 with EmptyByteBuf

use of io.netty.buffer.EmptyByteBuf in project grpc-java by grpc.

the class NettyServerStreamTest method closeAfterClientHalfCloseShouldSucceed.

@Test
public void closeAfterClientHalfCloseShouldSucceed() throws Exception {
    ListMultimap<CharSequence, CharSequence> expectedHeaders = ImmutableListMultimap.copyOf(new DefaultHttp2Headers().status(new AsciiString("200")).set(new AsciiString("content-type"), new AsciiString("application/grpc")).set(new AsciiString("grpc-status"), new AsciiString("0")));
    // Client half-closes. Listener gets halfClosed()
    stream().transportState().inboundDataReceived(new EmptyByteBuf(UnpooledByteBufAllocator.DEFAULT), true);
    verify(serverListener).halfClosed();
    // Server closes. Status sent
    stream().close(Status.OK, trailers);
    assertNull("no message expected", listenerMessageQueue.poll());
    ArgumentCaptor<SendResponseHeadersCommand> cmdCap = ArgumentCaptor.forClass(SendResponseHeadersCommand.class);
    verify(writeQueue).enqueue(cmdCap.capture(), eq(true));
    SendResponseHeadersCommand cmd = cmdCap.getValue();
    assertThat(cmd.stream()).isSameInstanceAs(stream.transportState());
    assertThat(ImmutableListMultimap.copyOf(cmd.headers())).containsExactlyEntriesIn(expectedHeaders);
    assertThat(cmd.endOfStream()).isTrue();
    // Sending and receiving complete. Listener gets closed()
    stream().transportState().complete();
    verify(serverListener).closed(Status.OK);
    assertNull("no message expected", listenerMessageQueue.poll());
}
Also used : EmptyByteBuf(io.netty.buffer.EmptyByteBuf) DefaultHttp2Headers(io.netty.handler.codec.http2.DefaultHttp2Headers) AsciiString(io.netty.util.AsciiString) Test(org.junit.Test)

Example 3 with EmptyByteBuf

use of io.netty.buffer.EmptyByteBuf in project riposte by Nike-Inc.

the class HttpUtilsTest method convertContentChunksToRawString_and_convertContentChunksToRawBytes_works_with_EmptyByteBuf_chunks.

@Test
public void convertContentChunksToRawString_and_convertContentChunksToRawBytes_works_with_EmptyByteBuf_chunks() throws IOException {
    // given
    Charset contentCharset = CharsetUtil.UTF_8;
    String chunk1Content = UUID.randomUUID().toString();
    String chunk2Content = UUID.randomUUID().toString();
    byte[] chunk1Bytes = chunk1Content.getBytes(contentCharset);
    byte[] chunk2Bytes = chunk2Content.getBytes(contentCharset);
    ByteBuf chunk1ByteBuf = Unpooled.copiedBuffer(chunk1Bytes);
    ByteBuf chunk2ByteBuf = Unpooled.copiedBuffer(chunk2Bytes);
    Collection<HttpContent> chunkCollection = Arrays.asList(new DefaultHttpContent(chunk1ByteBuf), new DefaultHttpContent(new EmptyByteBuf(ByteBufAllocator.DEFAULT)), new DefaultHttpContent(chunk2ByteBuf), new DefaultHttpContent(new EmptyByteBuf(ByteBufAllocator.DEFAULT)));
    // when
    String resultString = HttpUtils.convertContentChunksToRawString(contentCharset, chunkCollection);
    byte[] resultBytes = HttpUtils.convertContentChunksToRawBytes(chunkCollection);
    // then
    String expectedResultString = chunk1Content + chunk2Content;
    assertThat(resultString, is(expectedResultString));
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    baos.write(chunk1Bytes);
    baos.write(chunk2Bytes);
    assertThat(resultBytes, is(baos.toByteArray()));
}
Also used : EmptyByteBuf(io.netty.buffer.EmptyByteBuf) DefaultHttpContent(io.netty.handler.codec.http.DefaultHttpContent) Charset(java.nio.charset.Charset) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ByteBuf(io.netty.buffer.ByteBuf) EmptyByteBuf(io.netty.buffer.EmptyByteBuf) HttpContent(io.netty.handler.codec.http.HttpContent) DefaultHttpContent(io.netty.handler.codec.http.DefaultHttpContent) Test(org.junit.Test)

Example 4 with EmptyByteBuf

use of io.netty.buffer.EmptyByteBuf in project riposte by Nike-Inc.

the class HttpUtilsTest method convertContentChunksToRawBytes_returns_null_if_total_bytes_is_zero.

@Test
public void convertContentChunksToRawBytes_returns_null_if_total_bytes_is_zero() {
    // given
    Collection<HttpContent> chunkCollection = Arrays.asList(new DefaultHttpContent(new EmptyByteBuf(ByteBufAllocator.DEFAULT)), new DefaultHttpContent(new EmptyByteBuf(ByteBufAllocator.DEFAULT)));
    // when
    byte[] resultBytes = HttpUtils.convertContentChunksToRawBytes(chunkCollection);
    // then
    assertThat(resultBytes, nullValue());
}
Also used : EmptyByteBuf(io.netty.buffer.EmptyByteBuf) DefaultHttpContent(io.netty.handler.codec.http.DefaultHttpContent) HttpContent(io.netty.handler.codec.http.HttpContent) DefaultHttpContent(io.netty.handler.codec.http.DefaultHttpContent) Test(org.junit.Test)

Example 5 with EmptyByteBuf

use of io.netty.buffer.EmptyByteBuf in project ProxProx by GoMint.

the class Decoder method decode.

@Override
protected void decode(ChannelHandlerContext channelHandlerContext, ByteBuf buf, List<Object> objects) throws Exception {
    if (buf instanceof EmptyByteBuf) {
        // The Channel has disconnected and this is the last message we got. R.I.P. connection
        return;
    }
    byte packetId = buf.readByte();
    switch(packetId) {
        case 1:
            WrappedMCPEPacket wrappedMCPEPacket = new WrappedMCPEPacket();
            wrappedMCPEPacket.read(buf);
            objects.add(wrappedMCPEPacket);
            break;
        case 2:
            UpdatePingPacket updatePingPacket = new UpdatePingPacket();
            updatePingPacket.read(buf);
            objects.add(updatePingPacket);
            break;
        case 3:
            SendPlayerToServerPacket sendPlayerToServerPacket = new SendPlayerToServerPacket();
            sendPlayerToServerPacket.read(buf);
            objects.add(sendPlayerToServerPacket);
            break;
        default:
            break;
    }
}
Also used : SendPlayerToServerPacket(io.gomint.proxprox.network.tcp.protocol.SendPlayerToServerPacket) UpdatePingPacket(io.gomint.proxprox.network.tcp.protocol.UpdatePingPacket) EmptyByteBuf(io.netty.buffer.EmptyByteBuf) WrappedMCPEPacket(io.gomint.proxprox.network.tcp.protocol.WrappedMCPEPacket)

Aggregations

EmptyByteBuf (io.netty.buffer.EmptyByteBuf)8 Test (org.junit.Test)4 ByteBuf (io.netty.buffer.ByteBuf)2 DefaultHttpContent (io.netty.handler.codec.http.DefaultHttpContent)2 HttpContent (io.netty.handler.codec.http.HttpContent)2 SendPlayerToServerPacket (io.gomint.proxprox.network.tcp.protocol.SendPlayerToServerPacket)1 UpdatePingPacket (io.gomint.proxprox.network.tcp.protocol.UpdatePingPacket)1 WrappedMCPEPacket (io.gomint.proxprox.network.tcp.protocol.WrappedMCPEPacket)1 Status (io.grpc.Status)1 ByteBufHolder (io.netty.buffer.ByteBufHolder)1 CompositeByteBuf (io.netty.buffer.CompositeByteBuf)1 DecoderResult (io.netty.handler.codec.DecoderResult)1 HttpResponse (io.netty.handler.codec.http.HttpResponse)1 DefaultHttp2Headers (io.netty.handler.codec.http2.DefaultHttp2Headers)1 AsciiString (io.netty.util.AsciiString)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 Charset (java.nio.charset.Charset)1 ICoreMessage (org.apache.activemq.artemis.api.core.ICoreMessage)1 Message (org.apache.activemq.artemis.api.core.Message)1 Transaction (org.apache.activemq.artemis.core.transaction.Transaction)1