Change the return type of EmbeddedChannel.read*() from Object to an ad-hoc type parameter
.. so that there's no need to explicitly down-cast. Fixes #2067
This commit is contained in:
parent
61ed9476ae
commit
94d6e44bba
@ -206,7 +206,7 @@ public abstract class HttpContentDecoder extends MessageToMessageDecoder<HttpObj
|
|||||||
// Clean-up the previous encoder if not cleaned up correctly.
|
// Clean-up the previous encoder if not cleaned up correctly.
|
||||||
if (decoder.finish()) {
|
if (decoder.finish()) {
|
||||||
for (;;) {
|
for (;;) {
|
||||||
ByteBuf buf = (ByteBuf) decoder.readOutbound();
|
ByteBuf buf = decoder.readOutbound();
|
||||||
if (buf == null) {
|
if (buf == null) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -234,7 +234,7 @@ public abstract class HttpContentDecoder extends MessageToMessageDecoder<HttpObj
|
|||||||
|
|
||||||
private void fetchDecoderOutput(List<Object> out) {
|
private void fetchDecoderOutput(List<Object> out) {
|
||||||
for (;;) {
|
for (;;) {
|
||||||
ByteBuf buf = (ByteBuf) decoder.readInbound();
|
ByteBuf buf = decoder.readInbound();
|
||||||
if (buf == null) {
|
if (buf == null) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -247,7 +247,7 @@ public abstract class HttpContentEncoder extends MessageToMessageCodec<HttpReque
|
|||||||
// Clean-up the previous encoder if not cleaned up correctly.
|
// Clean-up the previous encoder if not cleaned up correctly.
|
||||||
if (encoder.finish()) {
|
if (encoder.finish()) {
|
||||||
for (;;) {
|
for (;;) {
|
||||||
ByteBuf buf = (ByteBuf) encoder.readOutbound();
|
ByteBuf buf = encoder.readOutbound();
|
||||||
if (buf == null) {
|
if (buf == null) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -275,7 +275,7 @@ public abstract class HttpContentEncoder extends MessageToMessageCodec<HttpReque
|
|||||||
|
|
||||||
private void fetchEncoderOutput(List<Object> out) {
|
private void fetchEncoderOutput(List<Object> out) {
|
||||||
for (;;) {
|
for (;;) {
|
||||||
ByteBuf buf = (ByteBuf) encoder.readOutbound();
|
ByteBuf buf = encoder.readOutbound();
|
||||||
if (buf == null) {
|
if (buf == null) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -70,7 +70,7 @@ public class HttpContentCompressorTest {
|
|||||||
|
|
||||||
ch.writeOutbound(new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK));
|
ch.writeOutbound(new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK));
|
||||||
|
|
||||||
HttpResponse res = (HttpResponse) ch.readOutbound();
|
HttpResponse res = ch.readOutbound();
|
||||||
assertThat(res, is(not(instanceOf(FullHttpResponse.class))));
|
assertThat(res, is(not(instanceOf(FullHttpResponse.class))));
|
||||||
assertThat(res.headers().get(Names.TRANSFER_ENCODING), is("chunked"));
|
assertThat(res.headers().get(Names.TRANSFER_ENCODING), is("chunked"));
|
||||||
assertThat(res.headers().get(Names.CONTENT_LENGTH), is(nullValue()));
|
assertThat(res.headers().get(Names.CONTENT_LENGTH), is(nullValue()));
|
||||||
@ -79,12 +79,12 @@ public class HttpContentCompressorTest {
|
|||||||
ch.writeOutbound(LastHttpContent.EMPTY_LAST_CONTENT);
|
ch.writeOutbound(LastHttpContent.EMPTY_LAST_CONTENT);
|
||||||
|
|
||||||
HttpContent chunk;
|
HttpContent chunk;
|
||||||
chunk = (HttpContent) ch.readOutbound();
|
chunk = ch.readOutbound();
|
||||||
assertThat(chunk, is(instanceOf(HttpContent.class)));
|
assertThat(chunk, is(instanceOf(HttpContent.class)));
|
||||||
assertThat(chunk.content().isReadable(), is(true));
|
assertThat(chunk.content().isReadable(), is(true));
|
||||||
chunk.release();
|
chunk.release();
|
||||||
|
|
||||||
chunk = (HttpContent) ch.readOutbound();
|
chunk = ch.readOutbound();
|
||||||
assertThat(chunk, is(instanceOf(LastHttpContent.class)));
|
assertThat(chunk, is(instanceOf(LastHttpContent.class)));
|
||||||
assertThat(chunk.content().isReadable(), is(false));
|
assertThat(chunk.content().isReadable(), is(false));
|
||||||
chunk.release();
|
chunk.release();
|
||||||
|
@ -35,7 +35,7 @@ public class HttpInvalidMessageTest {
|
|||||||
public void testRequestWithBadInitialLine() throws Exception {
|
public void testRequestWithBadInitialLine() throws Exception {
|
||||||
EmbeddedChannel ch = new EmbeddedChannel(new HttpRequestDecoder());
|
EmbeddedChannel ch = new EmbeddedChannel(new HttpRequestDecoder());
|
||||||
ch.writeInbound(Unpooled.copiedBuffer("GET / HTTP/1.0 with extra\r\n", CharsetUtil.UTF_8));
|
ch.writeInbound(Unpooled.copiedBuffer("GET / HTTP/1.0 with extra\r\n", CharsetUtil.UTF_8));
|
||||||
HttpRequest req = (HttpRequest) ch.readInbound();
|
HttpRequest req = ch.readInbound();
|
||||||
DecoderResult dr = req.getDecoderResult();
|
DecoderResult dr = req.getDecoderResult();
|
||||||
assertFalse(dr.isSuccess());
|
assertFalse(dr.isSuccess());
|
||||||
assertTrue(dr.isFailure());
|
assertTrue(dr.isFailure());
|
||||||
@ -50,7 +50,7 @@ public class HttpInvalidMessageTest {
|
|||||||
ch.writeInbound(Unpooled.copiedBuffer("Good_Name: Good Value\r\n", CharsetUtil.UTF_8));
|
ch.writeInbound(Unpooled.copiedBuffer("Good_Name: Good Value\r\n", CharsetUtil.UTF_8));
|
||||||
ch.writeInbound(Unpooled.copiedBuffer("Bad=Name: Bad Value\r\n", CharsetUtil.UTF_8));
|
ch.writeInbound(Unpooled.copiedBuffer("Bad=Name: Bad Value\r\n", CharsetUtil.UTF_8));
|
||||||
ch.writeInbound(Unpooled.copiedBuffer("\r\n", CharsetUtil.UTF_8));
|
ch.writeInbound(Unpooled.copiedBuffer("\r\n", CharsetUtil.UTF_8));
|
||||||
HttpRequest req = (HttpRequest) ch.readInbound();
|
HttpRequest req = ch.readInbound();
|
||||||
DecoderResult dr = req.getDecoderResult();
|
DecoderResult dr = req.getDecoderResult();
|
||||||
assertFalse(dr.isSuccess());
|
assertFalse(dr.isSuccess());
|
||||||
assertTrue(dr.isFailure());
|
assertTrue(dr.isFailure());
|
||||||
@ -63,7 +63,7 @@ public class HttpInvalidMessageTest {
|
|||||||
public void testResponseWithBadInitialLine() throws Exception {
|
public void testResponseWithBadInitialLine() throws Exception {
|
||||||
EmbeddedChannel ch = new EmbeddedChannel(new HttpResponseDecoder());
|
EmbeddedChannel ch = new EmbeddedChannel(new HttpResponseDecoder());
|
||||||
ch.writeInbound(Unpooled.copiedBuffer("HTTP/1.0 BAD_CODE Bad Server\r\n", CharsetUtil.UTF_8));
|
ch.writeInbound(Unpooled.copiedBuffer("HTTP/1.0 BAD_CODE Bad Server\r\n", CharsetUtil.UTF_8));
|
||||||
HttpResponse res = (HttpResponse) ch.readInbound();
|
HttpResponse res = ch.readInbound();
|
||||||
DecoderResult dr = res.getDecoderResult();
|
DecoderResult dr = res.getDecoderResult();
|
||||||
assertFalse(dr.isSuccess());
|
assertFalse(dr.isSuccess());
|
||||||
assertTrue(dr.isFailure());
|
assertTrue(dr.isFailure());
|
||||||
@ -78,7 +78,7 @@ public class HttpInvalidMessageTest {
|
|||||||
ch.writeInbound(Unpooled.copiedBuffer("Good_Name: Good Value\r\n", CharsetUtil.UTF_8));
|
ch.writeInbound(Unpooled.copiedBuffer("Good_Name: Good Value\r\n", CharsetUtil.UTF_8));
|
||||||
ch.writeInbound(Unpooled.copiedBuffer("Bad=Name: Bad Value\r\n", CharsetUtil.UTF_8));
|
ch.writeInbound(Unpooled.copiedBuffer("Bad=Name: Bad Value\r\n", CharsetUtil.UTF_8));
|
||||||
ch.writeInbound(Unpooled.copiedBuffer("\r\n", CharsetUtil.UTF_8));
|
ch.writeInbound(Unpooled.copiedBuffer("\r\n", CharsetUtil.UTF_8));
|
||||||
HttpResponse res = (HttpResponse) ch.readInbound();
|
HttpResponse res = ch.readInbound();
|
||||||
DecoderResult dr = res.getDecoderResult();
|
DecoderResult dr = res.getDecoderResult();
|
||||||
assertFalse(dr.isSuccess());
|
assertFalse(dr.isSuccess());
|
||||||
assertTrue(dr.isFailure());
|
assertTrue(dr.isFailure());
|
||||||
@ -94,10 +94,10 @@ public class HttpInvalidMessageTest {
|
|||||||
ch.writeInbound(Unpooled.copiedBuffer("Transfer-Encoding: chunked\r\n\r\n", CharsetUtil.UTF_8));
|
ch.writeInbound(Unpooled.copiedBuffer("Transfer-Encoding: chunked\r\n\r\n", CharsetUtil.UTF_8));
|
||||||
ch.writeInbound(Unpooled.copiedBuffer("BAD_LENGTH\r\n", CharsetUtil.UTF_8));
|
ch.writeInbound(Unpooled.copiedBuffer("BAD_LENGTH\r\n", CharsetUtil.UTF_8));
|
||||||
|
|
||||||
HttpRequest req = (HttpRequest) ch.readInbound();
|
HttpRequest req = ch.readInbound();
|
||||||
assertTrue(req.getDecoderResult().isSuccess());
|
assertTrue(req.getDecoderResult().isSuccess());
|
||||||
|
|
||||||
HttpContent chunk = (HttpContent) ch.readInbound();
|
HttpContent chunk = ch.readInbound();
|
||||||
DecoderResult dr = chunk.getDecoderResult();
|
DecoderResult dr = chunk.getDecoderResult();
|
||||||
assertFalse(dr.isSuccess());
|
assertFalse(dr.isSuccess());
|
||||||
assertTrue(dr.isFailure());
|
assertTrue(dr.isFailure());
|
||||||
|
@ -27,7 +27,7 @@ import org.junit.Test;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static io.netty.util.ReferenceCountUtil.releaseLater;
|
import static io.netty.util.ReferenceCountUtil.*;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
public class HttpObjectAggregatorTest {
|
public class HttpObjectAggregatorTest {
|
||||||
@ -50,7 +50,7 @@ public class HttpObjectAggregatorTest {
|
|||||||
// this should trigger a channelRead event so return true
|
// this should trigger a channelRead event so return true
|
||||||
assertTrue(embedder.writeInbound(chunk3));
|
assertTrue(embedder.writeInbound(chunk3));
|
||||||
assertTrue(embedder.finish());
|
assertTrue(embedder.finish());
|
||||||
DefaultFullHttpRequest aggratedMessage = (DefaultFullHttpRequest) embedder.readInbound();
|
FullHttpRequest aggratedMessage = embedder.readInbound();
|
||||||
assertNotNull(aggratedMessage);
|
assertNotNull(aggratedMessage);
|
||||||
|
|
||||||
assertEquals(chunk1.content().readableBytes() + chunk2.content().readableBytes(),
|
assertEquals(chunk1.content().readableBytes() + chunk2.content().readableBytes(),
|
||||||
@ -92,7 +92,7 @@ public class HttpObjectAggregatorTest {
|
|||||||
// this should trigger a channelRead event so return true
|
// this should trigger a channelRead event so return true
|
||||||
assertTrue(embedder.writeInbound(trailer));
|
assertTrue(embedder.writeInbound(trailer));
|
||||||
assertTrue(embedder.finish());
|
assertTrue(embedder.finish());
|
||||||
DefaultFullHttpRequest aggratedMessage = (DefaultFullHttpRequest) embedder.readInbound();
|
FullHttpRequest aggratedMessage = embedder.readInbound();
|
||||||
assertNotNull(aggratedMessage);
|
assertNotNull(aggratedMessage);
|
||||||
|
|
||||||
assertEquals(chunk1.content().readableBytes() + chunk2.content().readableBytes(),
|
assertEquals(chunk1.content().readableBytes() + chunk2.content().readableBytes(),
|
||||||
@ -177,7 +177,7 @@ public class HttpObjectAggregatorTest {
|
|||||||
// this should trigger a channelRead event so return true
|
// this should trigger a channelRead event so return true
|
||||||
assertTrue(embedder.writeInbound(chunk3));
|
assertTrue(embedder.writeInbound(chunk3));
|
||||||
assertTrue(embedder.finish());
|
assertTrue(embedder.finish());
|
||||||
FullHttpRequest aggratedMessage = (FullHttpRequest) embedder.readInbound();
|
FullHttpRequest aggratedMessage = embedder.readInbound();
|
||||||
assertNotNull(aggratedMessage);
|
assertNotNull(aggratedMessage);
|
||||||
|
|
||||||
assertEquals(chunk1.content().readableBytes() + chunk2.content().readableBytes(),
|
assertEquals(chunk1.content().readableBytes() + chunk2.content().readableBytes(),
|
||||||
|
@ -19,7 +19,6 @@ package io.netty.handler.codec.http;
|
|||||||
import io.netty.buffer.Unpooled;
|
import io.netty.buffer.Unpooled;
|
||||||
import io.netty.channel.embedded.EmbeddedChannel;
|
import io.netty.channel.embedded.EmbeddedChannel;
|
||||||
import io.netty.util.CharsetUtil;
|
import io.netty.util.CharsetUtil;
|
||||||
|
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
@ -70,10 +69,10 @@ public class HttpRequestDecoderTest {
|
|||||||
private static void testDecodeWholeRequestAtOnce(byte[] content) {
|
private static void testDecodeWholeRequestAtOnce(byte[] content) {
|
||||||
EmbeddedChannel channel = new EmbeddedChannel(new HttpRequestDecoder());
|
EmbeddedChannel channel = new EmbeddedChannel(new HttpRequestDecoder());
|
||||||
Assert.assertTrue(channel.writeInbound(Unpooled.wrappedBuffer(content)));
|
Assert.assertTrue(channel.writeInbound(Unpooled.wrappedBuffer(content)));
|
||||||
HttpRequest req = (HttpRequest) channel.readInbound();
|
HttpRequest req = channel.readInbound();
|
||||||
Assert.assertNotNull(req);
|
Assert.assertNotNull(req);
|
||||||
checkHeaders(req.headers());
|
checkHeaders(req.headers());
|
||||||
LastHttpContent c = (LastHttpContent) channel.readInbound();
|
LastHttpContent c = channel.readInbound();
|
||||||
Assert.assertEquals(8, c.content().readableBytes());
|
Assert.assertEquals(8, c.content().readableBytes());
|
||||||
Assert.assertEquals(Unpooled.wrappedBuffer(content, content.length - 8, 8), c.content().readBytes(8));
|
Assert.assertEquals(Unpooled.wrappedBuffer(content, content.length - 8, 8), c.content().readBytes(8));
|
||||||
c.release();
|
c.release();
|
||||||
@ -142,11 +141,11 @@ public class HttpRequestDecoderTest {
|
|||||||
channel.writeInbound(Unpooled.wrappedBuffer(content, content.length - i, 1));
|
channel.writeInbound(Unpooled.wrappedBuffer(content, content.length - i, 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
HttpRequest req = (HttpRequest) channel.readInbound();
|
HttpRequest req = channel.readInbound();
|
||||||
Assert.assertNotNull(req);
|
Assert.assertNotNull(req);
|
||||||
checkHeaders(req.headers());
|
checkHeaders(req.headers());
|
||||||
|
|
||||||
LastHttpContent c = (LastHttpContent) channel.readInbound();
|
LastHttpContent c = channel.readInbound();
|
||||||
Assert.assertEquals(8, c.content().readableBytes());
|
Assert.assertEquals(8, c.content().readableBytes());
|
||||||
for (int i = 8; i > 1; i--) {
|
for (int i = 8; i > 1; i--) {
|
||||||
Assert.assertEquals(content[content.length - i], c.content().readByte());
|
Assert.assertEquals(content[content.length - i], c.content().readByte());
|
||||||
@ -165,7 +164,7 @@ public class HttpRequestDecoderTest {
|
|||||||
"Host: localhost" + crlf +
|
"Host: localhost" + crlf +
|
||||||
"EmptyHeader:" + crlf + crlf;
|
"EmptyHeader:" + crlf + crlf;
|
||||||
channel.writeInbound(Unpooled.wrappedBuffer(request.getBytes(CharsetUtil.US_ASCII)));
|
channel.writeInbound(Unpooled.wrappedBuffer(request.getBytes(CharsetUtil.US_ASCII)));
|
||||||
HttpRequest req = (HttpRequest) channel.readInbound();
|
HttpRequest req = channel.readInbound();
|
||||||
Assert.assertEquals("", req.headers().get("EmptyHeader"));
|
Assert.assertEquals("", req.headers().get("EmptyHeader"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,6 @@ import java.util.List;
|
|||||||
|
|
||||||
import static org.hamcrest.CoreMatchers.*;
|
import static org.hamcrest.CoreMatchers.*;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
|
|
||||||
public class HttpResponseDecoderTest {
|
public class HttpResponseDecoderTest {
|
||||||
|
|
||||||
@ -117,14 +116,14 @@ public class HttpResponseDecoderTest {
|
|||||||
EmbeddedChannel ch = new EmbeddedChannel(new HttpResponseDecoder());
|
EmbeddedChannel ch = new EmbeddedChannel(new HttpResponseDecoder());
|
||||||
ch.writeInbound(Unpooled.copiedBuffer("HTTP/1.1 200 OK\r\n\r\n", CharsetUtil.US_ASCII));
|
ch.writeInbound(Unpooled.copiedBuffer("HTTP/1.1 200 OK\r\n\r\n", CharsetUtil.US_ASCII));
|
||||||
|
|
||||||
HttpResponse res = (HttpResponse) ch.readInbound();
|
HttpResponse res = ch.readInbound();
|
||||||
assertThat(res.getProtocolVersion(), sameInstance(HttpVersion.HTTP_1_1));
|
assertThat(res.getProtocolVersion(), sameInstance(HttpVersion.HTTP_1_1));
|
||||||
assertThat(res.getStatus(), is(HttpResponseStatus.OK));
|
assertThat(res.getStatus(), is(HttpResponseStatus.OK));
|
||||||
assertThat(ch.readInbound(), is(nullValue()));
|
assertThat(ch.readInbound(), is(nullValue()));
|
||||||
|
|
||||||
assertThat(ch.finish(), is(true));
|
assertThat(ch.finish(), is(true));
|
||||||
|
|
||||||
LastHttpContent content = (LastHttpContent) ch.readInbound();
|
LastHttpContent content = ch.readInbound();
|
||||||
assertThat(content.content().isReadable(), is(false));
|
assertThat(content.content().isReadable(), is(false));
|
||||||
content.release();
|
content.release();
|
||||||
|
|
||||||
@ -136,19 +135,19 @@ public class HttpResponseDecoderTest {
|
|||||||
EmbeddedChannel ch = new EmbeddedChannel(new HttpResponseDecoder());
|
EmbeddedChannel ch = new EmbeddedChannel(new HttpResponseDecoder());
|
||||||
ch.writeInbound(Unpooled.copiedBuffer("HTTP/1.1 200 OK\r\n\r\n", CharsetUtil.US_ASCII));
|
ch.writeInbound(Unpooled.copiedBuffer("HTTP/1.1 200 OK\r\n\r\n", CharsetUtil.US_ASCII));
|
||||||
|
|
||||||
HttpResponse res = (HttpResponse) ch.readInbound();
|
HttpResponse res = ch.readInbound();
|
||||||
assertThat(res.getProtocolVersion(), sameInstance(HttpVersion.HTTP_1_1));
|
assertThat(res.getProtocolVersion(), sameInstance(HttpVersion.HTTP_1_1));
|
||||||
assertThat(res.getStatus(), is(HttpResponseStatus.OK));
|
assertThat(res.getStatus(), is(HttpResponseStatus.OK));
|
||||||
assertThat(ch.readInbound(), is(nullValue()));
|
assertThat(ch.readInbound(), is(nullValue()));
|
||||||
|
|
||||||
ch.writeInbound(Unpooled.wrappedBuffer(new byte[1024]));
|
ch.writeInbound(Unpooled.wrappedBuffer(new byte[1024]));
|
||||||
HttpContent content = (HttpContent) ch.readInbound();
|
HttpContent content = ch.readInbound();
|
||||||
assertThat(content.content().readableBytes(), is(1024));
|
assertThat(content.content().readableBytes(), is(1024));
|
||||||
content.release();
|
content.release();
|
||||||
|
|
||||||
assertThat(ch.finish(), is(true));
|
assertThat(ch.finish(), is(true));
|
||||||
|
|
||||||
LastHttpContent lastContent = (LastHttpContent) ch.readInbound();
|
LastHttpContent lastContent = ch.readInbound();
|
||||||
assertThat(lastContent.content().isReadable(), is(false));
|
assertThat(lastContent.content().isReadable(), is(false));
|
||||||
lastContent.release();
|
lastContent.release();
|
||||||
|
|
||||||
@ -162,20 +161,20 @@ public class HttpResponseDecoderTest {
|
|||||||
"HTTP/1.1 200 OK\r\nX-Header: h2=h2v2; Expires=Wed, 09-Jun-2021 10:18:14 GMT \r\n\r\n",
|
"HTTP/1.1 200 OK\r\nX-Header: h2=h2v2; Expires=Wed, 09-Jun-2021 10:18:14 GMT \r\n\r\n",
|
||||||
CharsetUtil.US_ASCII));
|
CharsetUtil.US_ASCII));
|
||||||
|
|
||||||
HttpResponse res = (HttpResponse) ch.readInbound();
|
HttpResponse res = ch.readInbound();
|
||||||
assertThat(res.getProtocolVersion(), sameInstance(HttpVersion.HTTP_1_1));
|
assertThat(res.getProtocolVersion(), sameInstance(HttpVersion.HTTP_1_1));
|
||||||
assertThat(res.getStatus(), is(HttpResponseStatus.OK));
|
assertThat(res.getStatus(), is(HttpResponseStatus.OK));
|
||||||
assertThat(res.headers().get("X-Header"), is("h2=h2v2; Expires=Wed, 09-Jun-2021 10:18:14 GMT"));
|
assertThat(res.headers().get("X-Header"), is("h2=h2v2; Expires=Wed, 09-Jun-2021 10:18:14 GMT"));
|
||||||
assertThat(ch.readInbound(), is(nullValue()));
|
assertThat(ch.readInbound(), is(nullValue()));
|
||||||
|
|
||||||
ch.writeInbound(Unpooled.wrappedBuffer(new byte[1024]));
|
ch.writeInbound(Unpooled.wrappedBuffer(new byte[1024]));
|
||||||
HttpContent content = (HttpContent) ch.readInbound();
|
HttpContent content = ch.readInbound();
|
||||||
assertThat(content.content().readableBytes(), is(1024));
|
assertThat(content.content().readableBytes(), is(1024));
|
||||||
content.release();
|
content.release();
|
||||||
|
|
||||||
assertThat(ch.finish(), is(true));
|
assertThat(ch.finish(), is(true));
|
||||||
|
|
||||||
LastHttpContent lastContent = (LastHttpContent) ch.readInbound();
|
LastHttpContent lastContent = ch.readInbound();
|
||||||
assertThat(lastContent.content().isReadable(), is(false));
|
assertThat(lastContent.content().isReadable(), is(false));
|
||||||
lastContent.release();
|
lastContent.release();
|
||||||
|
|
||||||
@ -195,11 +194,11 @@ public class HttpResponseDecoderTest {
|
|||||||
"\r\n",
|
"\r\n",
|
||||||
CharsetUtil.US_ASCII));
|
CharsetUtil.US_ASCII));
|
||||||
|
|
||||||
HttpResponse res = (HttpResponse) ch.readInbound();
|
HttpResponse res = ch.readInbound();
|
||||||
assertThat(res.getProtocolVersion(), sameInstance(HttpVersion.HTTP_1_1));
|
assertThat(res.getProtocolVersion(), sameInstance(HttpVersion.HTTP_1_1));
|
||||||
assertThat(res.getStatus(), is(HttpResponseStatus.OK));
|
assertThat(res.getStatus(), is(HttpResponseStatus.OK));
|
||||||
|
|
||||||
LastHttpContent lastContent = (LastHttpContent) ch.readInbound();
|
LastHttpContent lastContent = ch.readInbound();
|
||||||
assertThat(lastContent.content().isReadable(), is(false));
|
assertThat(lastContent.content().isReadable(), is(false));
|
||||||
HttpHeaders headers = lastContent.trailingHeaders();
|
HttpHeaders headers = lastContent.trailingHeaders();
|
||||||
assertEquals(1, headers.names().size());
|
assertEquals(1, headers.names().size());
|
||||||
@ -245,11 +244,11 @@ public class HttpResponseDecoderTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ch.writeInbound(Unpooled.wrappedBuffer(content, headerLength, content.length - headerLength));
|
ch.writeInbound(Unpooled.wrappedBuffer(content, headerLength, content.length - headerLength));
|
||||||
HttpResponse res = (HttpResponse) ch.readInbound();
|
HttpResponse res = ch.readInbound();
|
||||||
assertThat(res.getProtocolVersion(), sameInstance(HttpVersion.HTTP_1_1));
|
assertThat(res.getProtocolVersion(), sameInstance(HttpVersion.HTTP_1_1));
|
||||||
assertThat(res.getStatus(), is(HttpResponseStatus.OK));
|
assertThat(res.getStatus(), is(HttpResponseStatus.OK));
|
||||||
|
|
||||||
LastHttpContent lastContent = (LastHttpContent) ch.readInbound();
|
LastHttpContent lastContent = ch.readInbound();
|
||||||
assertThat(lastContent.content().isReadable(), is(false));
|
assertThat(lastContent.content().isReadable(), is(false));
|
||||||
HttpHeaders headers = lastContent.trailingHeaders();
|
HttpHeaders headers = lastContent.trailingHeaders();
|
||||||
assertEquals(1, headers.names().size());
|
assertEquals(1, headers.names().size());
|
||||||
@ -278,11 +277,11 @@ public class HttpResponseDecoderTest {
|
|||||||
ch.writeInbound(Unpooled.wrappedBuffer(data, 0, data.length / 2));
|
ch.writeInbound(Unpooled.wrappedBuffer(data, 0, data.length / 2));
|
||||||
ch.writeInbound(Unpooled.wrappedBuffer(data, 5, data.length / 2));
|
ch.writeInbound(Unpooled.wrappedBuffer(data, 5, data.length / 2));
|
||||||
|
|
||||||
HttpResponse res = (HttpResponse) ch.readInbound();
|
HttpResponse res = ch.readInbound();
|
||||||
assertThat(res.getProtocolVersion(), sameInstance(HttpVersion.HTTP_1_1));
|
assertThat(res.getProtocolVersion(), sameInstance(HttpVersion.HTTP_1_1));
|
||||||
assertThat(res.getStatus(), is(HttpResponseStatus.OK));
|
assertThat(res.getStatus(), is(HttpResponseStatus.OK));
|
||||||
|
|
||||||
LastHttpContent content = (LastHttpContent) ch.readInbound();
|
LastHttpContent content = ch.readInbound();
|
||||||
assertEquals(10, content.content().readableBytes());
|
assertEquals(10, content.content().readableBytes());
|
||||||
assertEquals(Unpooled.wrappedBuffer(data), content.content());
|
assertEquals(Unpooled.wrappedBuffer(data), content.content());
|
||||||
content.release();
|
content.release();
|
||||||
@ -321,11 +320,11 @@ public class HttpResponseDecoderTest {
|
|||||||
ch.writeInbound(Unpooled.wrappedBuffer(data, 0, data.length / 2));
|
ch.writeInbound(Unpooled.wrappedBuffer(data, 0, data.length / 2));
|
||||||
ch.writeInbound(Unpooled.wrappedBuffer(data, 5, data.length / 2));
|
ch.writeInbound(Unpooled.wrappedBuffer(data, 5, data.length / 2));
|
||||||
|
|
||||||
HttpResponse res = (HttpResponse) ch.readInbound();
|
HttpResponse res = ch.readInbound();
|
||||||
assertThat(res.getProtocolVersion(), sameInstance(HttpVersion.HTTP_1_1));
|
assertThat(res.getProtocolVersion(), sameInstance(HttpVersion.HTTP_1_1));
|
||||||
assertThat(res.getStatus(), is(HttpResponseStatus.OK));
|
assertThat(res.getStatus(), is(HttpResponseStatus.OK));
|
||||||
|
|
||||||
LastHttpContent lastContent = (LastHttpContent) ch.readInbound();
|
LastHttpContent lastContent = ch.readInbound();
|
||||||
assertEquals(10, lastContent.content().readableBytes());
|
assertEquals(10, lastContent.content().readableBytes());
|
||||||
assertEquals(Unpooled.wrappedBuffer(data), lastContent.content());
|
assertEquals(Unpooled.wrappedBuffer(data), lastContent.content());
|
||||||
lastContent.release();
|
lastContent.release();
|
||||||
@ -346,10 +345,10 @@ public class HttpResponseDecoderTest {
|
|||||||
EmbeddedChannel ch = new EmbeddedChannel(new HttpResponseDecoder());
|
EmbeddedChannel ch = new EmbeddedChannel(new HttpResponseDecoder());
|
||||||
ch.writeInbound(Unpooled.wrappedBuffer(data));
|
ch.writeInbound(Unpooled.wrappedBuffer(data));
|
||||||
|
|
||||||
HttpResponse res = (HttpResponse) ch.readInbound();
|
HttpResponse res = ch.readInbound();
|
||||||
assertThat(res.getProtocolVersion(), sameInstance(HttpVersion.HTTP_1_1));
|
assertThat(res.getProtocolVersion(), sameInstance(HttpVersion.HTTP_1_1));
|
||||||
assertThat(res.getStatus(), is(HttpResponseStatus.SWITCHING_PROTOCOLS));
|
assertThat(res.getStatus(), is(HttpResponseStatus.SWITCHING_PROTOCOLS));
|
||||||
HttpContent content = (HttpContent) ch.readInbound();
|
HttpContent content = ch.readInbound();
|
||||||
assertThat(content.content().readableBytes(), is(16));
|
assertThat(content.content().readableBytes(), is(16));
|
||||||
content.release();
|
content.release();
|
||||||
|
|
||||||
|
@ -47,13 +47,13 @@ public class HttpServerCodecTest {
|
|||||||
decoderEmbedder.writeInbound(prepareDataChunk(offeredContentLength));
|
decoderEmbedder.writeInbound(prepareDataChunk(offeredContentLength));
|
||||||
decoderEmbedder.finish();
|
decoderEmbedder.finish();
|
||||||
|
|
||||||
HttpMessage httpMessage = (HttpMessage) decoderEmbedder.readInbound();
|
HttpMessage httpMessage = decoderEmbedder.readInbound();
|
||||||
assertNotNull(httpMessage);
|
assertNotNull(httpMessage);
|
||||||
|
|
||||||
boolean empty = true;
|
boolean empty = true;
|
||||||
int totalBytesPolled = 0;
|
int totalBytesPolled = 0;
|
||||||
for (;;) {
|
for (;;) {
|
||||||
HttpContent httpChunk = (HttpContent) decoderEmbedder.readInbound();
|
HttpContent httpChunk = decoderEmbedder.readInbound();
|
||||||
if (httpChunk == null) {
|
if (httpChunk == null) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -80,7 +80,7 @@ public class HttpServerCodecTest {
|
|||||||
assertThat(ch.readInbound(), is(nullValue()));
|
assertThat(ch.readInbound(), is(nullValue()));
|
||||||
|
|
||||||
// Ensure the aggregator writes a 100 Continue response.
|
// Ensure the aggregator writes a 100 Continue response.
|
||||||
ByteBuf continueResponse = (ByteBuf) ch.readOutbound();
|
ByteBuf continueResponse = ch.readOutbound();
|
||||||
assertThat(continueResponse.toString(CharsetUtil.UTF_8), is("HTTP/1.1 100 Continue\r\n\r\n"));
|
assertThat(continueResponse.toString(CharsetUtil.UTF_8), is("HTTP/1.1 100 Continue\r\n\r\n"));
|
||||||
continueResponse.release();
|
continueResponse.release();
|
||||||
|
|
||||||
@ -91,7 +91,7 @@ public class HttpServerCodecTest {
|
|||||||
ch.writeInbound(Unpooled.wrappedBuffer(new byte[] { 42 }));
|
ch.writeInbound(Unpooled.wrappedBuffer(new byte[] { 42 }));
|
||||||
|
|
||||||
// Ensure the aggregator generates a full request.
|
// Ensure the aggregator generates a full request.
|
||||||
FullHttpRequest req = (FullHttpRequest) ch.readInbound();
|
FullHttpRequest req = ch.readInbound();
|
||||||
assertThat(req.headers().get(CONTENT_LENGTH), is("1"));
|
assertThat(req.headers().get(CONTENT_LENGTH), is("1"));
|
||||||
assertThat(req.content().readableBytes(), is(1));
|
assertThat(req.content().readableBytes(), is(1));
|
||||||
assertThat(req.content().readByte(), is((byte) 42));
|
assertThat(req.content().readByte(), is((byte) 42));
|
||||||
@ -107,7 +107,7 @@ public class HttpServerCodecTest {
|
|||||||
ch.writeOutbound(res);
|
ch.writeOutbound(res);
|
||||||
|
|
||||||
// Ensure the encoder handles the response after handling 100 Continue.
|
// Ensure the encoder handles the response after handling 100 Continue.
|
||||||
ByteBuf encodedRes = (ByteBuf) ch.readOutbound();
|
ByteBuf encodedRes = ch.readOutbound();
|
||||||
assertThat(encodedRes.toString(CharsetUtil.UTF_8), is("HTTP/1.1 201 Created\r\nContent-Length: 2\r\n\r\nOK"));
|
assertThat(encodedRes.toString(CharsetUtil.UTF_8), is("HTTP/1.1 201 Created\r\nContent-Length: 2\r\n\r\nOK"));
|
||||||
encodedRes.release();
|
encodedRes.release();
|
||||||
|
|
||||||
|
@ -47,25 +47,25 @@ public class WebSocketFrameAggregatorTest {
|
|||||||
|
|
||||||
Assert.assertTrue(channel.finish());
|
Assert.assertTrue(channel.finish());
|
||||||
|
|
||||||
BinaryWebSocketFrame frame = (BinaryWebSocketFrame) channel.readInbound();
|
BinaryWebSocketFrame frame = channel.readInbound();
|
||||||
Assert.assertTrue(frame.isFinalFragment());
|
Assert.assertTrue(frame.isFinalFragment());
|
||||||
Assert.assertEquals(1, frame.rsv());
|
Assert.assertEquals(1, frame.rsv());
|
||||||
Assert.assertEquals(content1, frame.content());
|
Assert.assertEquals(content1, frame.content());
|
||||||
frame.release();
|
frame.release();
|
||||||
|
|
||||||
PingWebSocketFrame frame2 = (PingWebSocketFrame) channel.readInbound();
|
PingWebSocketFrame frame2 = channel.readInbound();
|
||||||
Assert.assertTrue(frame2.isFinalFragment());
|
Assert.assertTrue(frame2.isFinalFragment());
|
||||||
Assert.assertEquals(0, frame2.rsv());
|
Assert.assertEquals(0, frame2.rsv());
|
||||||
Assert.assertEquals(content1, frame2.content());
|
Assert.assertEquals(content1, frame2.content());
|
||||||
frame2.release();
|
frame2.release();
|
||||||
|
|
||||||
PongWebSocketFrame frame3 = (PongWebSocketFrame) channel.readInbound();
|
PongWebSocketFrame frame3 = channel.readInbound();
|
||||||
Assert.assertTrue(frame3.isFinalFragment());
|
Assert.assertTrue(frame3.isFinalFragment());
|
||||||
Assert.assertEquals(0, frame3.rsv());
|
Assert.assertEquals(0, frame3.rsv());
|
||||||
Assert.assertEquals(content1, frame3.content());
|
Assert.assertEquals(content1, frame3.content());
|
||||||
frame3.release();
|
frame3.release();
|
||||||
|
|
||||||
BinaryWebSocketFrame frame4 = (BinaryWebSocketFrame) channel.readInbound();
|
BinaryWebSocketFrame frame4 = channel.readInbound();
|
||||||
Assert.assertTrue(frame4.isFinalFragment());
|
Assert.assertTrue(frame4.isFinalFragment());
|
||||||
Assert.assertEquals(0, frame4.rsv());
|
Assert.assertEquals(0, frame4.rsv());
|
||||||
Assert.assertEquals(aggregatedContent, frame4.content());
|
Assert.assertEquals(aggregatedContent, frame4.content());
|
||||||
@ -86,25 +86,25 @@ public class WebSocketFrameAggregatorTest {
|
|||||||
|
|
||||||
Assert.assertTrue(channel.finish());
|
Assert.assertTrue(channel.finish());
|
||||||
|
|
||||||
TextWebSocketFrame frame = (TextWebSocketFrame) channel.readInbound();
|
TextWebSocketFrame frame = channel.readInbound();
|
||||||
Assert.assertTrue(frame.isFinalFragment());
|
Assert.assertTrue(frame.isFinalFragment());
|
||||||
Assert.assertEquals(1, frame.rsv());
|
Assert.assertEquals(1, frame.rsv());
|
||||||
Assert.assertEquals(content1, frame.content());
|
Assert.assertEquals(content1, frame.content());
|
||||||
frame.release();
|
frame.release();
|
||||||
|
|
||||||
PingWebSocketFrame frame2 = (PingWebSocketFrame) channel.readInbound();
|
PingWebSocketFrame frame2 = channel.readInbound();
|
||||||
Assert.assertTrue(frame2.isFinalFragment());
|
Assert.assertTrue(frame2.isFinalFragment());
|
||||||
Assert.assertEquals(0, frame2.rsv());
|
Assert.assertEquals(0, frame2.rsv());
|
||||||
Assert.assertEquals(content1, frame2.content());
|
Assert.assertEquals(content1, frame2.content());
|
||||||
frame2.release();
|
frame2.release();
|
||||||
|
|
||||||
PongWebSocketFrame frame3 = (PongWebSocketFrame) channel.readInbound();
|
PongWebSocketFrame frame3 = channel.readInbound();
|
||||||
Assert.assertTrue(frame3.isFinalFragment());
|
Assert.assertTrue(frame3.isFinalFragment());
|
||||||
Assert.assertEquals(0, frame3.rsv());
|
Assert.assertEquals(0, frame3.rsv());
|
||||||
Assert.assertEquals(content1, frame3.content());
|
Assert.assertEquals(content1, frame3.content());
|
||||||
frame3.release();
|
frame3.release();
|
||||||
|
|
||||||
TextWebSocketFrame frame4 = (TextWebSocketFrame) channel.readInbound();
|
TextWebSocketFrame frame4 = channel.readInbound();
|
||||||
Assert.assertTrue(frame4.isFinalFragment());
|
Assert.assertTrue(frame4.isFinalFragment());
|
||||||
Assert.assertEquals(0, frame4.rsv());
|
Assert.assertEquals(0, frame4.rsv());
|
||||||
Assert.assertEquals(aggregatedContent, frame4.content());
|
Assert.assertEquals(aggregatedContent, frame4.content());
|
||||||
|
@ -58,11 +58,11 @@ public class WebSocketServerHandshaker00Test {
|
|||||||
|
|
||||||
EmbeddedChannel ch2 = new EmbeddedChannel(new HttpResponseDecoder());
|
EmbeddedChannel ch2 = new EmbeddedChannel(new HttpResponseDecoder());
|
||||||
ch2.writeInbound(ch.readOutbound());
|
ch2.writeInbound(ch.readOutbound());
|
||||||
HttpResponse res = (HttpResponse) ch2.readInbound();
|
HttpResponse res = ch2.readInbound();
|
||||||
|
|
||||||
Assert.assertEquals("ws://example.com/chat", res.headers().get(Names.SEC_WEBSOCKET_LOCATION));
|
Assert.assertEquals("ws://example.com/chat", res.headers().get(Names.SEC_WEBSOCKET_LOCATION));
|
||||||
Assert.assertEquals("chat", res.headers().get(Names.SEC_WEBSOCKET_PROTOCOL));
|
Assert.assertEquals("chat", res.headers().get(Names.SEC_WEBSOCKET_PROTOCOL));
|
||||||
LastHttpContent content = (LastHttpContent) ch2.readInbound();
|
LastHttpContent content = ch2.readInbound();
|
||||||
|
|
||||||
Assert.assertEquals("8jKS'y:G*Co,Wxa-", content.content().toString(CharsetUtil.US_ASCII));
|
Assert.assertEquals("8jKS'y:G*Co,Wxa-", content.content().toString(CharsetUtil.US_ASCII));
|
||||||
content.release();
|
content.release();
|
||||||
|
@ -53,11 +53,11 @@ public class WebSocketServerHandshaker08Test {
|
|||||||
new WebSocketServerHandshaker08(
|
new WebSocketServerHandshaker08(
|
||||||
"ws://example.com/chat", "chat", false, Integer.MAX_VALUE).handshake(ch, req);
|
"ws://example.com/chat", "chat", false, Integer.MAX_VALUE).handshake(ch, req);
|
||||||
|
|
||||||
ByteBuf resBuf = (ByteBuf) ch.readOutbound();
|
ByteBuf resBuf = ch.readOutbound();
|
||||||
|
|
||||||
EmbeddedChannel ch2 = new EmbeddedChannel(new HttpResponseDecoder());
|
EmbeddedChannel ch2 = new EmbeddedChannel(new HttpResponseDecoder());
|
||||||
ch2.writeInbound(resBuf);
|
ch2.writeInbound(resBuf);
|
||||||
HttpResponse res = (HttpResponse) ch2.readInbound();
|
HttpResponse res = ch2.readInbound();
|
||||||
|
|
||||||
Assert.assertEquals(
|
Assert.assertEquals(
|
||||||
"s3pPLMBiTxaQ9kYGzzhZRbK+xOo=", res.headers().get(Names.SEC_WEBSOCKET_ACCEPT));
|
"s3pPLMBiTxaQ9kYGzzhZRbK+xOo=", res.headers().get(Names.SEC_WEBSOCKET_ACCEPT));
|
||||||
|
@ -53,11 +53,11 @@ public class WebSocketServerHandshaker13Test {
|
|||||||
new WebSocketServerHandshaker13(
|
new WebSocketServerHandshaker13(
|
||||||
"ws://example.com/chat", "chat", false, Integer.MAX_VALUE).handshake(ch, req);
|
"ws://example.com/chat", "chat", false, Integer.MAX_VALUE).handshake(ch, req);
|
||||||
|
|
||||||
ByteBuf resBuf = (ByteBuf) ch.readOutbound();
|
ByteBuf resBuf = ch.readOutbound();
|
||||||
|
|
||||||
EmbeddedChannel ch2 = new EmbeddedChannel(new HttpResponseDecoder());
|
EmbeddedChannel ch2 = new EmbeddedChannel(new HttpResponseDecoder());
|
||||||
ch2.writeInbound(resBuf);
|
ch2.writeInbound(resBuf);
|
||||||
HttpResponse res = (HttpResponse) ch2.readInbound();
|
HttpResponse res = ch2.readInbound();
|
||||||
|
|
||||||
Assert.assertEquals(
|
Assert.assertEquals(
|
||||||
"s3pPLMBiTxaQ9kYGzzhZRbK+xOo=", res.headers().get(Names.SEC_WEBSOCKET_ACCEPT));
|
"s3pPLMBiTxaQ9kYGzzhZRbK+xOo=", res.headers().get(Names.SEC_WEBSOCKET_ACCEPT));
|
||||||
|
@ -87,7 +87,7 @@ public class BinaryMemcacheDecoderTest {
|
|||||||
incoming.writeBytes(GET_REQUEST);
|
incoming.writeBytes(GET_REQUEST);
|
||||||
channel.writeInbound(incoming);
|
channel.writeInbound(incoming);
|
||||||
|
|
||||||
BinaryMemcacheRequest request = (BinaryMemcacheRequest) channel.readInbound();
|
BinaryMemcacheRequest request = channel.readInbound();
|
||||||
|
|
||||||
assertThat(request, notNullValue());
|
assertThat(request, notNullValue());
|
||||||
assertThat(request.getHeader(), notNullValue());
|
assertThat(request.getHeader(), notNullValue());
|
||||||
@ -115,7 +115,7 @@ public class BinaryMemcacheDecoderTest {
|
|||||||
incoming.writeBytes(SET_REQUEST_WITH_CONTENT);
|
incoming.writeBytes(SET_REQUEST_WITH_CONTENT);
|
||||||
channel.writeInbound(incoming);
|
channel.writeInbound(incoming);
|
||||||
|
|
||||||
BinaryMemcacheRequest request = (BinaryMemcacheRequest) channel.readInbound();
|
BinaryMemcacheRequest request = channel.readInbound();
|
||||||
|
|
||||||
assertThat(request, notNullValue());
|
assertThat(request, notNullValue());
|
||||||
assertThat(request.getHeader(), notNullValue());
|
assertThat(request.getHeader(), notNullValue());
|
||||||
@ -131,7 +131,7 @@ public class BinaryMemcacheDecoderTest {
|
|||||||
|
|
||||||
int expectedContentChunks = 4;
|
int expectedContentChunks = 4;
|
||||||
for (int i = 1; i <= expectedContentChunks; i++) {
|
for (int i = 1; i <= expectedContentChunks; i++) {
|
||||||
MemcacheContent content = (MemcacheContent) channel.readInbound();
|
MemcacheContent content = channel.readInbound();
|
||||||
if (i < expectedContentChunks) {
|
if (i < expectedContentChunks) {
|
||||||
assertThat(content, instanceOf(MemcacheContent.class));
|
assertThat(content, instanceOf(MemcacheContent.class));
|
||||||
} else {
|
} else {
|
||||||
@ -154,7 +154,7 @@ public class BinaryMemcacheDecoderTest {
|
|||||||
channel.writeInbound(incoming.readBytes(5));
|
channel.writeInbound(incoming.readBytes(5));
|
||||||
}
|
}
|
||||||
|
|
||||||
BinaryMemcacheRequest request = (BinaryMemcacheRequest) channel.readInbound();
|
BinaryMemcacheRequest request = channel.readInbound();
|
||||||
|
|
||||||
assertThat(request, notNullValue());
|
assertThat(request, notNullValue());
|
||||||
assertThat(request.getHeader(), notNullValue());
|
assertThat(request.getHeader(), notNullValue());
|
||||||
@ -163,8 +163,8 @@ public class BinaryMemcacheDecoderTest {
|
|||||||
|
|
||||||
request.release();
|
request.release();
|
||||||
|
|
||||||
MemcacheContent content1 = (MemcacheContent) channel.readInbound();
|
MemcacheContent content1 = channel.readInbound();
|
||||||
MemcacheContent content2 = (MemcacheContent) channel.readInbound();
|
MemcacheContent content2 = channel.readInbound();
|
||||||
|
|
||||||
assertThat(content1, instanceOf(MemcacheContent.class));
|
assertThat(content1, instanceOf(MemcacheContent.class));
|
||||||
assertThat(content2, instanceOf(LastMemcacheContent.class));
|
assertThat(content2, instanceOf(LastMemcacheContent.class));
|
||||||
@ -184,7 +184,7 @@ public class BinaryMemcacheDecoderTest {
|
|||||||
public void shouldHandleTwoMessagesInOneBatch() {
|
public void shouldHandleTwoMessagesInOneBatch() {
|
||||||
channel.writeInbound(Unpooled.buffer().writeBytes(GET_REQUEST).writeBytes(GET_REQUEST));
|
channel.writeInbound(Unpooled.buffer().writeBytes(GET_REQUEST).writeBytes(GET_REQUEST));
|
||||||
|
|
||||||
BinaryMemcacheRequest request = (BinaryMemcacheRequest) channel.readInbound();
|
BinaryMemcacheRequest request = channel.readInbound();
|
||||||
assertThat(request, instanceOf(BinaryMemcacheRequest.class));
|
assertThat(request, instanceOf(BinaryMemcacheRequest.class));
|
||||||
assertThat(request, notNullValue());
|
assertThat(request, notNullValue());
|
||||||
request.release();
|
request.release();
|
||||||
@ -193,7 +193,7 @@ public class BinaryMemcacheDecoderTest {
|
|||||||
assertThat(lastContent, instanceOf(LastMemcacheContent.class));
|
assertThat(lastContent, instanceOf(LastMemcacheContent.class));
|
||||||
((ReferenceCounted) lastContent).release();
|
((ReferenceCounted) lastContent).release();
|
||||||
|
|
||||||
request = (BinaryMemcacheRequest) channel.readInbound();
|
request = channel.readInbound();
|
||||||
assertThat(request, instanceOf(BinaryMemcacheRequest.class));
|
assertThat(request, instanceOf(BinaryMemcacheRequest.class));
|
||||||
assertThat(request, notNullValue());
|
assertThat(request, notNullValue());
|
||||||
request.release();
|
request.release();
|
||||||
@ -212,43 +212,43 @@ public class BinaryMemcacheDecoderTest {
|
|||||||
channel.writeInbound(Unpooled.buffer().writeBytes(GET_RESPONSE_CHUNK_2));
|
channel.writeInbound(Unpooled.buffer().writeBytes(GET_RESPONSE_CHUNK_2));
|
||||||
|
|
||||||
// First message
|
// First message
|
||||||
BinaryMemcacheResponse response = (BinaryMemcacheResponse) channel.readInbound();
|
BinaryMemcacheResponse response = channel.readInbound();
|
||||||
assertThat(response.getHeader().getStatus(), is(BinaryMemcacheResponseStatus.KEY_ENOENT));
|
assertThat(response.getHeader().getStatus(), is(BinaryMemcacheResponseStatus.KEY_ENOENT));
|
||||||
assertThat(response.getHeader().getTotalBodyLength(), is(msgBody.length()));
|
assertThat(response.getHeader().getTotalBodyLength(), is(msgBody.length()));
|
||||||
response.release();
|
response.release();
|
||||||
|
|
||||||
// First message first content chunk
|
// First message first content chunk
|
||||||
MemcacheContent content = (MemcacheContent) channel.readInbound();
|
MemcacheContent content = channel.readInbound();
|
||||||
assertThat(content, instanceOf(LastMemcacheContent.class));
|
assertThat(content, instanceOf(LastMemcacheContent.class));
|
||||||
assertThat(content.content().toString(CharsetUtil.UTF_8), is(msgBody));
|
assertThat(content.content().toString(CharsetUtil.UTF_8), is(msgBody));
|
||||||
content.release();
|
content.release();
|
||||||
|
|
||||||
// Second message
|
// Second message
|
||||||
response = (BinaryMemcacheResponse) channel.readInbound();
|
response = channel.readInbound();
|
||||||
assertThat(response.getHeader().getStatus(), is(BinaryMemcacheResponseStatus.KEY_ENOENT));
|
assertThat(response.getHeader().getStatus(), is(BinaryMemcacheResponseStatus.KEY_ENOENT));
|
||||||
assertThat(response.getHeader().getTotalBodyLength(), is(msgBody.length()));
|
assertThat(response.getHeader().getTotalBodyLength(), is(msgBody.length()));
|
||||||
response.release();
|
response.release();
|
||||||
|
|
||||||
// Second message first content chunk
|
// Second message first content chunk
|
||||||
content = (MemcacheContent) channel.readInbound();
|
content = channel.readInbound();
|
||||||
assertThat(content, instanceOf(MemcacheContent.class));
|
assertThat(content, instanceOf(MemcacheContent.class));
|
||||||
assertThat(content.content().toString(CharsetUtil.UTF_8), is(msgBody.substring(0, 7)));
|
assertThat(content.content().toString(CharsetUtil.UTF_8), is(msgBody.substring(0, 7)));
|
||||||
content.release();
|
content.release();
|
||||||
|
|
||||||
// Second message second content chunk
|
// Second message second content chunk
|
||||||
content = (MemcacheContent) channel.readInbound();
|
content = channel.readInbound();
|
||||||
assertThat(content, instanceOf(LastMemcacheContent.class));
|
assertThat(content, instanceOf(LastMemcacheContent.class));
|
||||||
assertThat(content.content().toString(CharsetUtil.UTF_8), is(msgBody.substring(7, 9)));
|
assertThat(content.content().toString(CharsetUtil.UTF_8), is(msgBody.substring(7, 9)));
|
||||||
content.release();
|
content.release();
|
||||||
|
|
||||||
// Third message
|
// Third message
|
||||||
response = (BinaryMemcacheResponse) channel.readInbound();
|
response = channel.readInbound();
|
||||||
assertThat(response.getHeader().getStatus(), is(BinaryMemcacheResponseStatus.KEY_ENOENT));
|
assertThat(response.getHeader().getStatus(), is(BinaryMemcacheResponseStatus.KEY_ENOENT));
|
||||||
assertThat(response.getHeader().getTotalBodyLength(), is(msgBody.length()));
|
assertThat(response.getHeader().getTotalBodyLength(), is(msgBody.length()));
|
||||||
response.release();
|
response.release();
|
||||||
|
|
||||||
// Third message first content chunk
|
// Third message first content chunk
|
||||||
content = (MemcacheContent) channel.readInbound();
|
content = channel.readInbound();
|
||||||
assertThat(content, instanceOf(LastMemcacheContent.class));
|
assertThat(content, instanceOf(LastMemcacheContent.class));
|
||||||
assertThat(content.content().toString(CharsetUtil.UTF_8), is(msgBody));
|
assertThat(content.content().toString(CharsetUtil.UTF_8), is(msgBody));
|
||||||
content.release();
|
content.release();
|
||||||
|
@ -57,7 +57,7 @@ public class BinaryMemcacheEncoderTest {
|
|||||||
boolean result = channel.writeOutbound(request);
|
boolean result = channel.writeOutbound(request);
|
||||||
assertThat(result, is(true));
|
assertThat(result, is(true));
|
||||||
|
|
||||||
ByteBuf written = (ByteBuf) channel.readOutbound();
|
ByteBuf written = channel.readOutbound();
|
||||||
assertThat(written.readableBytes(), is(DEFAULT_HEADER_SIZE));
|
assertThat(written.readableBytes(), is(DEFAULT_HEADER_SIZE));
|
||||||
assertThat(written.readByte(), is((byte) 0x80));
|
assertThat(written.readByte(), is((byte) 0x80));
|
||||||
assertThat(written.readByte(), is((byte) 0x00));
|
assertThat(written.readByte(), is((byte) 0x00));
|
||||||
@ -74,7 +74,7 @@ public class BinaryMemcacheEncoderTest {
|
|||||||
boolean result = channel.writeOutbound(request);
|
boolean result = channel.writeOutbound(request);
|
||||||
assertThat(result, is(true));
|
assertThat(result, is(true));
|
||||||
|
|
||||||
ByteBuf written = (ByteBuf) channel.readOutbound();
|
ByteBuf written = channel.readOutbound();
|
||||||
assertThat(written.readableBytes(), is(DEFAULT_HEADER_SIZE));
|
assertThat(written.readableBytes(), is(DEFAULT_HEADER_SIZE));
|
||||||
assertThat(written.readByte(), is((byte) 0xAA));
|
assertThat(written.readByte(), is((byte) 0xAA));
|
||||||
assertThat(written.readByte(), is(BinaryMemcacheOpcodes.GET));
|
assertThat(written.readByte(), is(BinaryMemcacheOpcodes.GET));
|
||||||
@ -93,7 +93,7 @@ public class BinaryMemcacheEncoderTest {
|
|||||||
boolean result = channel.writeOutbound(request);
|
boolean result = channel.writeOutbound(request);
|
||||||
assertThat(result, is(true));
|
assertThat(result, is(true));
|
||||||
|
|
||||||
ByteBuf written = (ByteBuf) channel.readOutbound();
|
ByteBuf written = channel.readOutbound();
|
||||||
assertThat(written.readableBytes(), is(DEFAULT_HEADER_SIZE + extrasLength));
|
assertThat(written.readableBytes(), is(DEFAULT_HEADER_SIZE + extrasLength));
|
||||||
written.readBytes(DEFAULT_HEADER_SIZE);
|
written.readBytes(DEFAULT_HEADER_SIZE);
|
||||||
assertThat(written.readBytes(extrasLength).toString(CharsetUtil.UTF_8), equalTo(extrasContent));
|
assertThat(written.readBytes(extrasLength).toString(CharsetUtil.UTF_8), equalTo(extrasContent));
|
||||||
@ -111,7 +111,7 @@ public class BinaryMemcacheEncoderTest {
|
|||||||
boolean result = channel.writeOutbound(request);
|
boolean result = channel.writeOutbound(request);
|
||||||
assertThat(result, is(true));
|
assertThat(result, is(true));
|
||||||
|
|
||||||
ByteBuf written = (ByteBuf) channel.readOutbound();
|
ByteBuf written = channel.readOutbound();
|
||||||
assertThat(written.readableBytes(), is(DEFAULT_HEADER_SIZE + keyLength));
|
assertThat(written.readableBytes(), is(DEFAULT_HEADER_SIZE + keyLength));
|
||||||
written.readBytes(DEFAULT_HEADER_SIZE);
|
written.readBytes(DEFAULT_HEADER_SIZE);
|
||||||
assertThat(written.readBytes(keyLength).toString(CharsetUtil.UTF_8), equalTo(key));
|
assertThat(written.readBytes(keyLength).toString(CharsetUtil.UTF_8), equalTo(key));
|
||||||
@ -137,9 +137,9 @@ public class BinaryMemcacheEncoderTest {
|
|||||||
result = channel.writeOutbound(content2);
|
result = channel.writeOutbound(content2);
|
||||||
assertThat(result, is(true));
|
assertThat(result, is(true));
|
||||||
|
|
||||||
ByteBuf written = (ByteBuf) channel.readOutbound();
|
ByteBuf written = channel.readOutbound();
|
||||||
assertThat(written.readableBytes(), is(DEFAULT_HEADER_SIZE));
|
assertThat(written.readableBytes(), is(DEFAULT_HEADER_SIZE));
|
||||||
written = (ByteBuf) channel.readOutbound();
|
written = channel.readOutbound();
|
||||||
assertThat(written.readableBytes(), is(content1.content().readableBytes()));
|
assertThat(written.readableBytes(), is(content1.content().readableBytes()));
|
||||||
assertThat(
|
assertThat(
|
||||||
written.readBytes(content1.content().readableBytes()).toString(CharsetUtil.UTF_8),
|
written.readBytes(content1.content().readableBytes()).toString(CharsetUtil.UTF_8),
|
||||||
@ -147,7 +147,7 @@ public class BinaryMemcacheEncoderTest {
|
|||||||
);
|
);
|
||||||
written.release();
|
written.release();
|
||||||
|
|
||||||
written = (ByteBuf) channel.readOutbound();
|
written = channel.readOutbound();
|
||||||
assertThat(written.readableBytes(), is(content2.content().readableBytes()));
|
assertThat(written.readableBytes(), is(content2.content().readableBytes()));
|
||||||
assertThat(
|
assertThat(
|
||||||
written.readBytes(content2.content().readableBytes()).toString(CharsetUtil.UTF_8),
|
written.readBytes(content2.content().readableBytes()).toString(CharsetUtil.UTF_8),
|
||||||
|
@ -57,7 +57,7 @@ public class BinaryMemcacheObjectAggregatorTest {
|
|||||||
incoming.writeBytes(SET_REQUEST_WITH_CONTENT);
|
incoming.writeBytes(SET_REQUEST_WITH_CONTENT);
|
||||||
channel.writeInbound(incoming);
|
channel.writeInbound(incoming);
|
||||||
|
|
||||||
FullBinaryMemcacheRequest request = (FullBinaryMemcacheRequest) channel.readInbound();
|
FullBinaryMemcacheRequest request = channel.readInbound();
|
||||||
|
|
||||||
assertThat(request, instanceOf(FullBinaryMemcacheRequest.class));
|
assertThat(request, instanceOf(FullBinaryMemcacheRequest.class));
|
||||||
assertThat(request, notNullValue());
|
assertThat(request, notNullValue());
|
||||||
|
@ -30,7 +30,7 @@ public class SocksAuthRequestDecoderTest {
|
|||||||
SocksAuthRequestDecoder decoder = new SocksAuthRequestDecoder();
|
SocksAuthRequestDecoder decoder = new SocksAuthRequestDecoder();
|
||||||
EmbeddedChannel embedder = new EmbeddedChannel(decoder);
|
EmbeddedChannel embedder = new EmbeddedChannel(decoder);
|
||||||
SocksCommonTestUtils.writeMessageIntoEmbedder(embedder, msg);
|
SocksCommonTestUtils.writeMessageIntoEmbedder(embedder, msg);
|
||||||
msg = (SocksAuthRequest) embedder.readInbound();
|
msg = embedder.readInbound();
|
||||||
assertEquals(msg.username(), username);
|
assertEquals(msg.username(), username);
|
||||||
assertEquals(msg.username(), password);
|
assertEquals(msg.username(), password);
|
||||||
assertNull(embedder.readInbound());
|
assertNull(embedder.readInbound());
|
||||||
|
@ -31,7 +31,7 @@ public class SocksAuthResponseDecoderTest {
|
|||||||
SocksAuthResponseDecoder decoder = new SocksAuthResponseDecoder();
|
SocksAuthResponseDecoder decoder = new SocksAuthResponseDecoder();
|
||||||
EmbeddedChannel embedder = new EmbeddedChannel(decoder);
|
EmbeddedChannel embedder = new EmbeddedChannel(decoder);
|
||||||
SocksCommonTestUtils.writeMessageIntoEmbedder(embedder, msg);
|
SocksCommonTestUtils.writeMessageIntoEmbedder(embedder, msg);
|
||||||
msg = (SocksAuthResponse) embedder.readInbound();
|
msg = embedder.readInbound();
|
||||||
assertSame(msg.authStatus(), authStatus);
|
assertSame(msg.authStatus(), authStatus);
|
||||||
assertNull(embedder.readInbound());
|
assertNull(embedder.readInbound());
|
||||||
}
|
}
|
||||||
|
@ -39,7 +39,7 @@ public class SocksCmdRequestDecoderTest {
|
|||||||
if (msg.addressType() == SocksAddressType.UNKNOWN) {
|
if (msg.addressType() == SocksAddressType.UNKNOWN) {
|
||||||
assertTrue(embedder.readInbound() instanceof UnknownSocksRequest);
|
assertTrue(embedder.readInbound() instanceof UnknownSocksRequest);
|
||||||
} else {
|
} else {
|
||||||
msg = (SocksCmdRequest) embedder.readInbound();
|
msg = embedder.readInbound();
|
||||||
assertSame(msg.cmdType(), cmdType);
|
assertSame(msg.cmdType(), cmdType);
|
||||||
assertSame(msg.addressType(), addressType);
|
assertSame(msg.addressType(), addressType);
|
||||||
assertEquals(msg.host(), host);
|
assertEquals(msg.host(), host);
|
||||||
|
@ -35,7 +35,7 @@ public class SocksCmdResponseDecoderTest {
|
|||||||
if (addressType == SocksAddressType.UNKNOWN) {
|
if (addressType == SocksAddressType.UNKNOWN) {
|
||||||
assertTrue(embedder.readInbound() instanceof UnknownSocksResponse);
|
assertTrue(embedder.readInbound() instanceof UnknownSocksResponse);
|
||||||
} else {
|
} else {
|
||||||
msg = (SocksResponse) embedder.readInbound();
|
msg = embedder.readInbound();
|
||||||
assertEquals(((SocksCmdResponse) msg).cmdStatus(), cmdStatus);
|
assertEquals(((SocksCmdResponse) msg).cmdStatus(), cmdStatus);
|
||||||
}
|
}
|
||||||
assertNull(embedder.readInbound());
|
assertNull(embedder.readInbound());
|
||||||
|
@ -42,7 +42,7 @@ public class ByteToMessageDecoderTest {
|
|||||||
|
|
||||||
ByteBuf buf = Unpooled.wrappedBuffer(new byte[] {'a', 'b', 'c'});
|
ByteBuf buf = Unpooled.wrappedBuffer(new byte[] {'a', 'b', 'c'});
|
||||||
channel.writeInbound(buf.copy());
|
channel.writeInbound(buf.copy());
|
||||||
ByteBuf b = (ByteBuf) channel.readInbound();
|
ByteBuf b = channel.readInbound();
|
||||||
Assert.assertEquals(b, buf.skipBytes(1));
|
Assert.assertEquals(b, buf.skipBytes(1));
|
||||||
b.release();
|
b.release();
|
||||||
buf.release();
|
buf.release();
|
||||||
@ -67,7 +67,7 @@ public class ByteToMessageDecoderTest {
|
|||||||
});
|
});
|
||||||
|
|
||||||
channel.writeInbound(buf.copy());
|
channel.writeInbound(buf.copy());
|
||||||
ByteBuf b = (ByteBuf) channel.readInbound();
|
ByteBuf b = channel.readInbound();
|
||||||
Assert.assertEquals(b, Unpooled.wrappedBuffer(new byte[] { 'b', 'c'}));
|
Assert.assertEquals(b, Unpooled.wrappedBuffer(new byte[] { 'b', 'c'}));
|
||||||
buf.release();
|
buf.release();
|
||||||
b.release();
|
b.release();
|
||||||
|
@ -21,7 +21,7 @@ import io.netty.channel.embedded.EmbeddedChannel;
|
|||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import static io.netty.util.ReferenceCountUtil.releaseLater;
|
import static io.netty.util.ReferenceCountUtil.*;
|
||||||
|
|
||||||
public class LengthFieldBasedFrameDecoderTest {
|
public class LengthFieldBasedFrameDecoderTest {
|
||||||
|
|
||||||
@ -43,7 +43,7 @@ public class LengthFieldBasedFrameDecoderTest {
|
|||||||
}
|
}
|
||||||
Assert.assertTrue(channel.finish());
|
Assert.assertTrue(channel.finish());
|
||||||
|
|
||||||
ByteBuf b = (ByteBuf) channel.readInbound();
|
ByteBuf b = channel.readInbound();
|
||||||
Assert.assertEquals(5, b.readableBytes());
|
Assert.assertEquals(5, b.readableBytes());
|
||||||
Assert.assertEquals(1, b.readInt());
|
Assert.assertEquals(1, b.readInt());
|
||||||
Assert.assertEquals('a', b.readByte());
|
Assert.assertEquals('a', b.readByte());
|
||||||
@ -73,7 +73,7 @@ public class LengthFieldBasedFrameDecoderTest {
|
|||||||
|
|
||||||
Assert.assertTrue(channel.finish());
|
Assert.assertTrue(channel.finish());
|
||||||
|
|
||||||
ByteBuf b = (ByteBuf) channel.readInbound();
|
ByteBuf b = channel.readInbound();
|
||||||
Assert.assertEquals(5, b.readableBytes());
|
Assert.assertEquals(5, b.readableBytes());
|
||||||
Assert.assertEquals(1, b.readInt());
|
Assert.assertEquals(1, b.readInt());
|
||||||
Assert.assertEquals('a', b.readByte());
|
Assert.assertEquals('a', b.readByte());
|
||||||
|
@ -24,7 +24,7 @@ import org.junit.Test;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static io.netty.util.ReferenceCountUtil.releaseLater;
|
import static io.netty.util.ReferenceCountUtil.*;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
public class ReplayingDecoderTest {
|
public class ReplayingDecoderTest {
|
||||||
@ -122,7 +122,7 @@ public class ReplayingDecoderTest {
|
|||||||
|
|
||||||
ByteBuf buf = Unpooled.wrappedBuffer(new byte[] {'a', 'b', 'c'});
|
ByteBuf buf = Unpooled.wrappedBuffer(new byte[] {'a', 'b', 'c'});
|
||||||
channel.writeInbound(buf.copy());
|
channel.writeInbound(buf.copy());
|
||||||
ByteBuf b = (ByteBuf) channel.readInbound();
|
ByteBuf b = channel.readInbound();
|
||||||
assertEquals(b, buf.skipBytes(1));
|
assertEquals(b, buf.skipBytes(1));
|
||||||
b.release();
|
b.release();
|
||||||
buf.release();
|
buf.release();
|
||||||
@ -146,7 +146,7 @@ public class ReplayingDecoderTest {
|
|||||||
|
|
||||||
ByteBuf buf = Unpooled.wrappedBuffer(new byte[] {'a', 'b', 'c'});
|
ByteBuf buf = Unpooled.wrappedBuffer(new byte[] {'a', 'b', 'c'});
|
||||||
channel.writeInbound(buf.copy());
|
channel.writeInbound(buf.copy());
|
||||||
ByteBuf b = (ByteBuf) channel.readInbound();
|
ByteBuf b = channel.readInbound();
|
||||||
|
|
||||||
assertEquals("Expect to have still all bytes in the buffer", b, buf);
|
assertEquals("Expect to have still all bytes in the buffer", b, buf);
|
||||||
b.release();
|
b.release();
|
||||||
@ -172,7 +172,7 @@ public class ReplayingDecoderTest {
|
|||||||
});
|
});
|
||||||
|
|
||||||
channel.writeInbound(buf.copy());
|
channel.writeInbound(buf.copy());
|
||||||
ByteBuf b = (ByteBuf) channel.readInbound();
|
ByteBuf b = channel.readInbound();
|
||||||
assertEquals(b, Unpooled.wrappedBuffer(new byte[] { 'b', 'c'}));
|
assertEquals(b, Unpooled.wrappedBuffer(new byte[] { 'b', 'c'}));
|
||||||
b.release();
|
b.release();
|
||||||
buf.release();
|
buf.release();
|
||||||
|
@ -16,7 +16,6 @@
|
|||||||
package io.netty.handler.codec.bytes;
|
package io.netty.handler.codec.bytes;
|
||||||
|
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import io.netty.buffer.Unpooled;
|
|
||||||
import io.netty.channel.embedded.EmbeddedChannel;
|
import io.netty.channel.embedded.EmbeddedChannel;
|
||||||
import io.netty.util.internal.EmptyArrays;
|
import io.netty.util.internal.EmptyArrays;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
@ -49,7 +48,7 @@ public class ByteArrayEncoderTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testEncodeEmpty() {
|
public void testEncodeEmpty() {
|
||||||
ch.writeOutbound(EmptyArrays.EMPTY_BYTES);
|
ch.writeOutbound(EmptyArrays.EMPTY_BYTES);
|
||||||
assertThat((ByteBuf) ch.readOutbound(), is(Unpooled.EMPTY_BUFFER));
|
assertThat((ByteBuf) ch.readOutbound(), is(EMPTY_BUFFER));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -22,7 +22,7 @@ import io.netty.channel.embedded.EmbeddedChannel;
|
|||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import static io.netty.util.ReferenceCountUtil.releaseLater;
|
import static io.netty.util.ReferenceCountUtil.*;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
public class SnappyFramedEncoderTest {
|
public class SnappyFramedEncoderTest {
|
||||||
@ -90,7 +90,7 @@ public class SnappyFramedEncoderTest {
|
|||||||
|
|
||||||
CompositeByteBuf actual = Unpooled.compositeBuffer();
|
CompositeByteBuf actual = Unpooled.compositeBuffer();
|
||||||
for (;;) {
|
for (;;) {
|
||||||
ByteBuf m = (ByteBuf) channel.readOutbound();
|
ByteBuf m = channel.readOutbound();
|
||||||
if (m == null) {
|
if (m == null) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -145,7 +145,7 @@ public class SnappyFramedEncoderTest {
|
|||||||
|
|
||||||
channel.writeOutbound(in);
|
channel.writeOutbound(in);
|
||||||
assertTrue(channel.finish());
|
assertTrue(channel.finish());
|
||||||
ByteBuf out = (ByteBuf) channel.readOutbound();
|
ByteBuf out = channel.readOutbound();
|
||||||
out.release();
|
out.release();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -122,7 +122,7 @@ public class SnappyIntegrationTest {
|
|||||||
EmbeddedChannel decoder = new EmbeddedChannel(new SnappyFramedDecoder());
|
EmbeddedChannel decoder = new EmbeddedChannel(new SnappyFramedDecoder());
|
||||||
try {
|
try {
|
||||||
encoder.writeOutbound(in.copy());
|
encoder.writeOutbound(in.copy());
|
||||||
ByteBuf compressed = (ByteBuf) encoder.readOutbound();
|
ByteBuf compressed = encoder.readOutbound();
|
||||||
assertThat(compressed, is(notNullValue()));
|
assertThat(compressed, is(notNullValue()));
|
||||||
assertThat(compressed, is(not(in)));
|
assertThat(compressed, is(not(in)));
|
||||||
decoder.writeInbound(compressed.retain());
|
decoder.writeInbound(compressed.retain());
|
||||||
|
@ -50,7 +50,7 @@ public abstract class ZlibTest {
|
|||||||
EmbeddedChannel chDecoderGZip = new EmbeddedChannel(createDecoder(ZlibWrapper.GZIP));
|
EmbeddedChannel chDecoderGZip = new EmbeddedChannel(createDecoder(ZlibWrapper.GZIP));
|
||||||
chDecoderGZip.writeInbound(deflatedData.copy());
|
chDecoderGZip.writeInbound(deflatedData.copy());
|
||||||
assertTrue(chDecoderGZip.finish());
|
assertTrue(chDecoderGZip.finish());
|
||||||
ByteBuf buf = (ByteBuf) chDecoderGZip.readInbound();
|
ByteBuf buf = chDecoderGZip.readInbound();
|
||||||
assertEquals(buf, data);
|
assertEquals(buf, data);
|
||||||
assertNull(chDecoderGZip.readInbound());
|
assertNull(chDecoderGZip.readInbound());
|
||||||
data.release();
|
data.release();
|
||||||
@ -67,7 +67,7 @@ public abstract class ZlibTest {
|
|||||||
|
|
||||||
EmbeddedChannel chDecoderZlib = new EmbeddedChannel(createDecoder(decoderWrapper));
|
EmbeddedChannel chDecoderZlib = new EmbeddedChannel(createDecoder(decoderWrapper));
|
||||||
for (;;) {
|
for (;;) {
|
||||||
ByteBuf deflatedData = (ByteBuf) chEncoder.readOutbound();
|
ByteBuf deflatedData = chEncoder.readOutbound();
|
||||||
if (deflatedData == null) {
|
if (deflatedData == null) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -77,7 +77,7 @@ public abstract class ZlibTest {
|
|||||||
byte[] decompressed = new byte[bytes.length];
|
byte[] decompressed = new byte[bytes.length];
|
||||||
int offset = 0;
|
int offset = 0;
|
||||||
for (;;) {
|
for (;;) {
|
||||||
ByteBuf buf = (ByteBuf) chDecoderZlib.readInbound();
|
ByteBuf buf = chDecoderZlib.readInbound();
|
||||||
if (buf == null) {
|
if (buf == null) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -115,7 +115,7 @@ public abstract class ZlibTest {
|
|||||||
|
|
||||||
EmbeddedChannel chDecoderZlib = new EmbeddedChannel(createDecoder(decoderWrapper));
|
EmbeddedChannel chDecoderZlib = new EmbeddedChannel(createDecoder(decoderWrapper));
|
||||||
for (;;) {
|
for (;;) {
|
||||||
ByteBuf deflatedData = (ByteBuf) chEncoder.readOutbound();
|
ByteBuf deflatedData = chEncoder.readOutbound();
|
||||||
if (deflatedData == null) {
|
if (deflatedData == null) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -124,7 +124,7 @@ public abstract class ZlibTest {
|
|||||||
|
|
||||||
// Decoder should not generate anything at all.
|
// Decoder should not generate anything at all.
|
||||||
for (;;) {
|
for (;;) {
|
||||||
ByteBuf buf = (ByteBuf) chDecoderZlib.readInbound();
|
ByteBuf buf = chDecoderZlib.readInbound();
|
||||||
if (buf == null) {
|
if (buf == null) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -39,12 +39,12 @@ public class LengthFieldPrependerTest {
|
|||||||
public void testPrependLength() throws Exception {
|
public void testPrependLength() throws Exception {
|
||||||
final EmbeddedChannel ch = new EmbeddedChannel(new LengthFieldPrepender(4));
|
final EmbeddedChannel ch = new EmbeddedChannel(new LengthFieldPrepender(4));
|
||||||
ch.writeOutbound(msg);
|
ch.writeOutbound(msg);
|
||||||
ByteBuf buf = (ByteBuf) ch.readOutbound();
|
ByteBuf buf = ch.readOutbound();
|
||||||
assertEquals(4, buf.readableBytes());
|
assertEquals(4, buf.readableBytes());
|
||||||
assertEquals(msg.readableBytes(), buf.readInt());
|
assertEquals(msg.readableBytes(), buf.readInt());
|
||||||
buf.release();
|
buf.release();
|
||||||
|
|
||||||
buf = (ByteBuf) ch.readOutbound();
|
buf = ch.readOutbound();
|
||||||
assertSame(buf, msg);
|
assertSame(buf, msg);
|
||||||
buf.release();
|
buf.release();
|
||||||
}
|
}
|
||||||
@ -53,12 +53,12 @@ public class LengthFieldPrependerTest {
|
|||||||
public void testPrependLengthIncludesLengthFieldLength() throws Exception {
|
public void testPrependLengthIncludesLengthFieldLength() throws Exception {
|
||||||
final EmbeddedChannel ch = new EmbeddedChannel(new LengthFieldPrepender(4, true));
|
final EmbeddedChannel ch = new EmbeddedChannel(new LengthFieldPrepender(4, true));
|
||||||
ch.writeOutbound(msg);
|
ch.writeOutbound(msg);
|
||||||
ByteBuf buf = (ByteBuf) ch.readOutbound();
|
ByteBuf buf = ch.readOutbound();
|
||||||
assertEquals(4, buf.readableBytes());
|
assertEquals(4, buf.readableBytes());
|
||||||
assertEquals(5, buf.readInt());
|
assertEquals(5, buf.readInt());
|
||||||
buf.release();
|
buf.release();
|
||||||
|
|
||||||
buf = (ByteBuf) ch.readOutbound();
|
buf = ch.readOutbound();
|
||||||
assertSame(buf, msg);
|
assertSame(buf, msg);
|
||||||
buf.release();
|
buf.release();
|
||||||
}
|
}
|
||||||
@ -67,12 +67,12 @@ public class LengthFieldPrependerTest {
|
|||||||
public void testPrependAdjustedLength() throws Exception {
|
public void testPrependAdjustedLength() throws Exception {
|
||||||
final EmbeddedChannel ch = new EmbeddedChannel(new LengthFieldPrepender(4, -1));
|
final EmbeddedChannel ch = new EmbeddedChannel(new LengthFieldPrepender(4, -1));
|
||||||
ch.writeOutbound(msg);
|
ch.writeOutbound(msg);
|
||||||
ByteBuf buf = (ByteBuf) ch.readOutbound();
|
ByteBuf buf = ch.readOutbound();
|
||||||
assertEquals(4, buf.readableBytes());
|
assertEquals(4, buf.readableBytes());
|
||||||
assertEquals(msg.readableBytes() - 1, buf.readInt());
|
assertEquals(msg.readableBytes() - 1, buf.readInt());
|
||||||
buf.release();
|
buf.release();
|
||||||
|
|
||||||
buf = (ByteBuf) ch.readOutbound();
|
buf = ch.readOutbound();
|
||||||
assertSame(buf, msg);
|
assertSame(buf, msg);
|
||||||
buf.release();
|
buf.release();
|
||||||
}
|
}
|
||||||
|
@ -53,7 +53,7 @@ public abstract class AbstractCompatibleMarshallingDecoderTest {
|
|||||||
ch.writeInbound(input(testBytes));
|
ch.writeInbound(input(testBytes));
|
||||||
assertTrue(ch.finish());
|
assertTrue(ch.finish());
|
||||||
|
|
||||||
String unmarshalled = (String) ch.readInbound();
|
String unmarshalled = ch.readInbound();
|
||||||
|
|
||||||
assertEquals(testObject, unmarshalled);
|
assertEquals(testObject, unmarshalled);
|
||||||
|
|
||||||
@ -87,7 +87,7 @@ public abstract class AbstractCompatibleMarshallingDecoderTest {
|
|||||||
ch.writeInbound(buffer);
|
ch.writeInbound(buffer);
|
||||||
assertTrue(ch.finish());
|
assertTrue(ch.finish());
|
||||||
|
|
||||||
String unmarshalled = (String) ch.readInbound();
|
String unmarshalled = ch.readInbound();
|
||||||
|
|
||||||
assertEquals(testObject, unmarshalled);
|
assertEquals(testObject, unmarshalled);
|
||||||
|
|
||||||
|
@ -24,14 +24,12 @@ import org.jboss.marshalling.MarshallingConfiguration;
|
|||||||
import org.jboss.marshalling.Unmarshaller;
|
import org.jboss.marshalling.Unmarshaller;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
public abstract class AbstractCompatibleMarshallingEncoderTest {
|
public abstract class AbstractCompatibleMarshallingEncoderTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMarshalling() throws IOException, ClassNotFoundException {
|
public void testMarshalling() throws Exception {
|
||||||
@SuppressWarnings("RedundantStringConstructorCall")
|
@SuppressWarnings("RedundantStringConstructorCall")
|
||||||
String testObject = new String("test");
|
String testObject = new String("test");
|
||||||
|
|
||||||
@ -43,7 +41,7 @@ public abstract class AbstractCompatibleMarshallingEncoderTest {
|
|||||||
ch.writeOutbound(testObject);
|
ch.writeOutbound(testObject);
|
||||||
assertTrue(ch.finish());
|
assertTrue(ch.finish());
|
||||||
|
|
||||||
ByteBuf buffer = (ByteBuf) ch.readOutbound();
|
ByteBuf buffer = ch.readOutbound();
|
||||||
|
|
||||||
Unmarshaller unmarshaller = marshallerFactory.createUnmarshaller(configuration);
|
Unmarshaller unmarshaller = marshallerFactory.createUnmarshaller(configuration);
|
||||||
unmarshaller.start(Marshalling.createByteInput(truncate(buffer).nioBuffer()));
|
unmarshaller.start(Marshalling.createByteInput(truncate(buffer).nioBuffer()));
|
||||||
|
@ -29,7 +29,7 @@ public class StringEncoderTest {
|
|||||||
EmbeddedChannel channel = new EmbeddedChannel(new StringEncoder());
|
EmbeddedChannel channel = new EmbeddedChannel(new StringEncoder());
|
||||||
Assert.assertTrue(channel.writeOutbound(msg));
|
Assert.assertTrue(channel.writeOutbound(msg));
|
||||||
Assert.assertTrue(channel.finish());
|
Assert.assertTrue(channel.finish());
|
||||||
ByteBuf buf = (ByteBuf) channel.readOutbound();
|
ByteBuf buf = channel.readOutbound();
|
||||||
byte[] data = new byte[buf.readableBytes()];
|
byte[] data = new byte[buf.readableBytes()];
|
||||||
buf.readBytes(data);
|
buf.readBytes(data);
|
||||||
Assert.assertArrayEquals(msg.getBytes(CharsetUtil.UTF_8), data);
|
Assert.assertArrayEquals(msg.getBytes(CharsetUtil.UTF_8), data);
|
||||||
|
@ -150,7 +150,7 @@ public class XmlFrameDecoderTest {
|
|||||||
}
|
}
|
||||||
List<Object> actual = new ArrayList<Object>();
|
List<Object> actual = new ArrayList<Object>();
|
||||||
for (;;) {
|
for (;;) {
|
||||||
ByteBuf buf = (ByteBuf) ch.readInbound();
|
ByteBuf buf = ch.readInbound();
|
||||||
if (buf == null) {
|
if (buf == null) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -210,7 +210,7 @@ public class LoggingHandlerTest {
|
|||||||
channel.writeInbound(msg);
|
channel.writeInbound(msg);
|
||||||
verify(appender);
|
verify(appender);
|
||||||
|
|
||||||
String handledMsg = (String) channel.readInbound();
|
String handledMsg = channel.readInbound();
|
||||||
assertThat(msg, is(sameInstance(handledMsg)));
|
assertThat(msg, is(sameInstance(handledMsg)));
|
||||||
assertThat(channel.readInbound(), is(nullValue()));
|
assertThat(channel.readInbound(), is(nullValue()));
|
||||||
}
|
}
|
||||||
@ -224,7 +224,7 @@ public class LoggingHandlerTest {
|
|||||||
channel.writeInbound(msg);
|
channel.writeInbound(msg);
|
||||||
verify(appender);
|
verify(appender);
|
||||||
|
|
||||||
ByteBuf handledMsg = (ByteBuf) channel.readInbound();
|
ByteBuf handledMsg = channel.readInbound();
|
||||||
assertThat(msg, is(sameInstance(handledMsg)));
|
assertThat(msg, is(sameInstance(handledMsg)));
|
||||||
handledMsg.release();
|
handledMsg.release();
|
||||||
assertThat(channel.readInbound(), is(nullValue()));
|
assertThat(channel.readInbound(), is(nullValue()));
|
||||||
@ -239,7 +239,7 @@ public class LoggingHandlerTest {
|
|||||||
channel.writeInbound(msg);
|
channel.writeInbound(msg);
|
||||||
verify(appender);
|
verify(appender);
|
||||||
|
|
||||||
ByteBuf handledMsg = (ByteBuf) channel.readInbound();
|
ByteBuf handledMsg = channel.readInbound();
|
||||||
assertThat(msg, is(sameInstance(handledMsg)));
|
assertThat(msg, is(sameInstance(handledMsg)));
|
||||||
assertThat(channel.readInbound(), is(nullValue()));
|
assertThat(channel.readInbound(), is(nullValue()));
|
||||||
}
|
}
|
||||||
@ -259,7 +259,7 @@ public class LoggingHandlerTest {
|
|||||||
channel.writeInbound(msg);
|
channel.writeInbound(msg);
|
||||||
verify(appender);
|
verify(appender);
|
||||||
|
|
||||||
ByteBufHolder handledMsg = (ByteBufHolder) channel.readInbound();
|
ByteBufHolder handledMsg = channel.readInbound();
|
||||||
assertThat(msg, is(sameInstance(handledMsg)));
|
assertThat(msg, is(sameInstance(handledMsg)));
|
||||||
handledMsg.release();
|
handledMsg.release();
|
||||||
assertThat(channel.readInbound(), is(nullValue()));
|
assertThat(channel.readInbound(), is(nullValue()));
|
||||||
@ -279,12 +279,12 @@ public class LoggingHandlerTest {
|
|||||||
/**
|
/**
|
||||||
* A custom EasyMock matcher that matches on Logback messages.
|
* A custom EasyMock matcher that matches on Logback messages.
|
||||||
*/
|
*/
|
||||||
private static class RegexLogMatcher implements IArgumentMatcher {
|
private static final class RegexLogMatcher implements IArgumentMatcher {
|
||||||
|
|
||||||
private final String expected;
|
private final String expected;
|
||||||
private String actualMsg;
|
private String actualMsg;
|
||||||
|
|
||||||
public RegexLogMatcher(String expected) {
|
RegexLogMatcher(String expected) {
|
||||||
this.expected = expected;
|
this.expected = expected;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,6 +23,7 @@ import io.netty.channel.ChannelHandlerContext;
|
|||||||
import io.netty.channel.embedded.EmbeddedChannel;
|
import io.netty.channel.embedded.EmbeddedChannel;
|
||||||
import io.netty.util.CharsetUtil;
|
import io.netty.util.CharsetUtil;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
@ -30,7 +31,7 @@ import java.io.IOException;
|
|||||||
import java.nio.channels.Channels;
|
import java.nio.channels.Channels;
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
|
||||||
import static io.netty.util.ReferenceCountUtil.releaseLater;
|
import static io.netty.util.ReferenceCountUtil.*;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
public class ChunkedWriteHandlerTest {
|
public class ChunkedWriteHandlerTest {
|
||||||
@ -193,7 +194,7 @@ public class ChunkedWriteHandlerTest {
|
|||||||
int i = 0;
|
int i = 0;
|
||||||
int read = 0;
|
int read = 0;
|
||||||
for (;;) {
|
for (;;) {
|
||||||
ByteBuf buffer = (ByteBuf) ch.readOutbound();
|
ByteBuf buffer = ch.readOutbound();
|
||||||
if (buffer == null) {
|
if (buffer == null) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -147,15 +147,17 @@ public class EmbeddedChannel extends AbstractChannel {
|
|||||||
/**
|
/**
|
||||||
* Return received data from this {@link Channel}
|
* Return received data from this {@link Channel}
|
||||||
*/
|
*/
|
||||||
public Object readInbound() {
|
@SuppressWarnings("unchecked")
|
||||||
return inboundMessages.poll();
|
public <T> T readInbound() {
|
||||||
|
return (T) inboundMessages.poll();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Read data froum the outbound. This may return {@code null} if nothing is readable.
|
* Read data froum the outbound. This may return {@code null} if nothing is readable.
|
||||||
*/
|
*/
|
||||||
public Object readOutbound() {
|
@SuppressWarnings("unchecked")
|
||||||
return outboundMessages.poll();
|
public <T> T readOutbound() {
|
||||||
|
return (T) outboundMessages.poll();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user