use of io.netty.channel.embedded.EmbeddedChannel in project netty by netty.
the class HttpRequestDecoderBenchmark method testDecodeWholeRequestInMultipleSteps.
private static void testDecodeWholeRequestInMultipleSteps(byte[] content, int fragmentSize) {
final EmbeddedChannel channel = new EmbeddedChannel(new HttpRequestDecoder());
final int headerLength = content.length - CONTENT_LENGTH;
// split up the header
for (int a = 0; a < headerLength; ) {
int amount = fragmentSize;
if (a + amount > headerLength) {
amount = headerLength - a;
}
// if header is done it should produce a HttpRequest
channel.writeInbound(Unpooled.wrappedBuffer(content, a, amount));
a += amount;
}
for (int i = CONTENT_LENGTH; i > 0; i--) {
// Should produce HttpContent
channel.writeInbound(Unpooled.wrappedBuffer(content, content.length - i, 1));
}
}
use of io.netty.channel.embedded.EmbeddedChannel in project netty by netty.
the class HttpClientCodecTest method testFailsOnMissingResponse.
@Test
public void testFailsOnMissingResponse() {
HttpClientCodec codec = new HttpClientCodec(4096, 8192, 8192, true);
EmbeddedChannel ch = new EmbeddedChannel(codec);
assertTrue(ch.writeOutbound(new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "http://localhost/")));
ByteBuf buffer = ch.readOutbound();
assertNotNull(buffer);
buffer.release();
try {
ch.finish();
fail();
} catch (CodecException e) {
assertTrue(e instanceof PrematureChannelClosureException);
}
}
use of io.netty.channel.embedded.EmbeddedChannel in project netty by netty.
the class HttpClientCodecTest method testFailsOnIncompleteChunkedResponse.
@Test
public void testFailsOnIncompleteChunkedResponse() {
HttpClientCodec codec = new HttpClientCodec(4096, 8192, 8192, true);
EmbeddedChannel ch = new EmbeddedChannel(codec);
ch.writeOutbound(new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "http://localhost/"));
ByteBuf buffer = ch.readOutbound();
assertNotNull(buffer);
buffer.release();
assertNull(ch.readInbound());
ch.writeInbound(Unpooled.copiedBuffer(INCOMPLETE_CHUNKED_RESPONSE, CharsetUtil.ISO_8859_1));
assertThat(ch.readInbound(), instanceOf(HttpResponse.class));
// Chunk 'first'
((HttpContent) ch.readInbound()).release();
// Chunk 'second'
((HttpContent) ch.readInbound()).release();
assertNull(ch.readInbound());
try {
ch.finish();
fail();
} catch (CodecException e) {
assertTrue(e instanceof PrematureChannelClosureException);
}
}
use of io.netty.channel.embedded.EmbeddedChannel in project netty by netty.
the class HttpClientCodecTest method testFailsNotOnRequestResponse.
@Test
public void testFailsNotOnRequestResponse() {
HttpClientCodec codec = new HttpClientCodec(4096, 8192, 8192, true);
EmbeddedChannel ch = new EmbeddedChannel(codec);
ch.writeOutbound(new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "http://localhost/"));
ch.writeInbound(Unpooled.copiedBuffer(RESPONSE, CharsetUtil.ISO_8859_1));
ch.finish();
for (; ; ) {
Object msg = ch.readOutbound();
if (msg == null) {
break;
}
release(msg);
}
for (; ; ) {
Object msg = ch.readInbound();
if (msg == null) {
break;
}
release(msg);
}
}
use of io.netty.channel.embedded.EmbeddedChannel in project netty by netty.
the class HttpContentCompressorTest method testFullContent.
@Test
public void testFullContent() throws Exception {
EmbeddedChannel ch = new EmbeddedChannel(new HttpContentCompressor());
ch.writeInbound(newRequest());
FullHttpResponse res = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK, Unpooled.copiedBuffer("Hello, World", CharsetUtil.US_ASCII));
res.headers().set(HttpHeaderNames.CONTENT_LENGTH, res.content().readableBytes());
ch.writeOutbound(res);
assertEncodedResponse(ch);
HttpContent c = ch.readOutbound();
assertThat(ByteBufUtil.hexDump(c.content()), is("1f8b0800000000000000f248cdc9c9d75108cf2fca4901000000ffff"));
c.release();
c = ch.readOutbound();
assertThat(ByteBufUtil.hexDump(c.content()), is("0300c6865b260c000000"));
c.release();
LastHttpContent last = ch.readOutbound();
assertThat(last.content().readableBytes(), is(0));
last.release();
assertThat(ch.readOutbound(), is(nullValue()));
}
Aggregations