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();
}
}
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());
}
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()));
}
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());
}
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;
}
}
Aggregations