use of io.netty.channel.embedded.EmbeddedChannel in project netty by netty.
the class SocksAuthRequestDecoderTest method testAuthRequestDecoder.
@Test
public void testAuthRequestDecoder() {
SocksAuthRequest msg = new SocksAuthRequest(username, password);
SocksAuthRequestDecoder decoder = new SocksAuthRequestDecoder();
EmbeddedChannel embedder = new EmbeddedChannel(decoder);
SocksCommonTestUtils.writeMessageIntoEmbedder(embedder, msg);
msg = embedder.readInbound();
assertEquals(username, msg.username());
assertEquals(password, msg.password());
assertNull(embedder.readInbound());
}
use of io.netty.channel.embedded.EmbeddedChannel in project netty by netty.
the class SocksAuthRequestDecoderTest method testAuthRequestDecoderPartialSend.
@Test
public void testAuthRequestDecoderPartialSend() {
EmbeddedChannel ch = new EmbeddedChannel(new SocksAuthRequestDecoder());
ByteBuf byteBuf = Unpooled.buffer(16);
// Send username and password size
byteBuf.writeByte(SocksSubnegotiationVersion.AUTH_PASSWORD.byteValue());
byteBuf.writeByte(username.length());
byteBuf.writeBytes(username.getBytes());
byteBuf.writeByte(password.length());
ch.writeInbound(byteBuf);
// Check that channel is empty
assertNull(ch.readInbound());
// Send password
ByteBuf byteBuf2 = Unpooled.buffer();
byteBuf2.writeBytes(password.getBytes());
ch.writeInbound(byteBuf2);
// Read message from channel
SocksAuthRequest msg = ch.readInbound();
// Check message
assertEquals(username, msg.username());
assertEquals(password, msg.password());
assertFalse(ch.finishAndReleaseAll());
}
use of io.netty.channel.embedded.EmbeddedChannel in project netty by netty.
the class SocksAuthResponseDecoderTest method testSocksAuthResponseDecoderWithDifferentParams.
private static void testSocksAuthResponseDecoderWithDifferentParams(SocksAuthStatus authStatus) {
logger.debug("Testing SocksAuthResponseDecoder with authStatus: " + authStatus);
SocksAuthResponse msg = new SocksAuthResponse(authStatus);
SocksAuthResponseDecoder decoder = new SocksAuthResponseDecoder();
EmbeddedChannel embedder = new EmbeddedChannel(decoder);
SocksCommonTestUtils.writeMessageIntoEmbedder(embedder, msg);
msg = embedder.readInbound();
assertSame(msg.authStatus(), authStatus);
assertNull(embedder.readInbound());
}
use of io.netty.channel.embedded.EmbeddedChannel in project netty by netty.
the class SocksCmdRequestDecoderTest method testSocksCmdRequestDecoderWithDifferentParams.
private static void testSocksCmdRequestDecoderWithDifferentParams(SocksCmdType cmdType, SocksAddressType addressType, String host, int port) {
logger.debug("Testing cmdType: " + cmdType + " addressType: " + addressType + " host: " + host + " port: " + port);
SocksCmdRequest msg = new SocksCmdRequest(cmdType, addressType, host, port);
SocksCmdRequestDecoder decoder = new SocksCmdRequestDecoder();
EmbeddedChannel embedder = new EmbeddedChannel(decoder);
SocksCommonTestUtils.writeMessageIntoEmbedder(embedder, msg);
if (msg.addressType() == SocksAddressType.UNKNOWN) {
assertTrue(embedder.readInbound() instanceof UnknownSocksRequest);
} else {
msg = embedder.readInbound();
assertSame(msg.cmdType(), cmdType);
assertSame(msg.addressType(), addressType);
assertEquals(msg.host(), host);
assertEquals(msg.port(), port);
}
assertNull(embedder.readInbound());
}
use of io.netty.channel.embedded.EmbeddedChannel in project netty by netty.
the class BinaryMemcacheDecoderTest method shouldDecodeSeparatedValues.
@Test
public void shouldDecodeSeparatedValues() {
String msgBody = "Not found";
channel = new EmbeddedChannel(new BinaryMemcacheResponseDecoder());
channel.writeInbound(Unpooled.buffer().writeBytes(GET_RESPONSE_CHUNK_1));
channel.writeInbound(Unpooled.buffer().writeBytes(GET_RESPONSE_CHUNK_2));
// First message
BinaryMemcacheResponse response = channel.readInbound();
assertThat(response.status(), is(BinaryMemcacheResponseStatus.KEY_ENOENT));
assertThat(response.totalBodyLength(), is(msgBody.length()));
response.release();
// First message first content chunk
MemcacheContent content = channel.readInbound();
assertThat(content, instanceOf(LastMemcacheContent.class));
assertThat(content.content().toString(CharsetUtil.UTF_8), is(msgBody));
content.release();
// Second message
response = channel.readInbound();
assertThat(response.status(), is(BinaryMemcacheResponseStatus.KEY_ENOENT));
assertThat(response.totalBodyLength(), is(msgBody.length()));
response.release();
// Second message first content chunk
content = channel.readInbound();
assertThat(content, instanceOf(MemcacheContent.class));
assertThat(content.content().toString(CharsetUtil.UTF_8), is(msgBody.substring(0, 7)));
content.release();
// Second message second content chunk
content = channel.readInbound();
assertThat(content, instanceOf(LastMemcacheContent.class));
assertThat(content.content().toString(CharsetUtil.UTF_8), is(msgBody.substring(7, 9)));
content.release();
// Third message
response = channel.readInbound();
assertThat(response.status(), is(BinaryMemcacheResponseStatus.KEY_ENOENT));
assertThat(response.totalBodyLength(), is(msgBody.length()));
response.release();
// Third message first content chunk
content = channel.readInbound();
assertThat(content, instanceOf(LastMemcacheContent.class));
assertThat(content.content().toString(CharsetUtil.UTF_8), is(msgBody));
content.release();
}
Aggregations