use of io.netty.channel.embedded.EmbeddedChannel in project netty by netty.
the class SnappyFrameDecoderTest method testInvalidChecksumThrowsException.
// The following two tests differ in only the checksum provided for the literal
// uncompressed string "netty"
@Test(expected = DecompressionException.class)
public void testInvalidChecksumThrowsException() throws Exception {
EmbeddedChannel channel = new EmbeddedChannel(new SnappyFrameDecoder(true));
// checksum here is presented as 0
ByteBuf in = Unpooled.wrappedBuffer(new byte[] { (byte) 0xff, 0x06, 0x00, 0x00, 0x73, 0x4e, 0x61, 0x50, 0x70, 0x59, 0x01, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 'n', 'e', 't', 't', 'y' });
channel.writeInbound(in);
}
use of io.netty.channel.embedded.EmbeddedChannel in project netty by netty.
the class AbstractCompatibleMarshallingDecoderTest method testTooBigObject.
@Test
public void testTooBigObject() throws IOException {
MarshallerFactory marshallerFactory = createMarshallerFactory();
MarshallingConfiguration configuration = createMarshallingConfig();
ChannelHandler mDecoder = createDecoder(4);
EmbeddedChannel ch = new EmbeddedChannel(mDecoder);
ByteArrayOutputStream bout = new ByteArrayOutputStream();
Marshaller marshaller = marshallerFactory.createMarshaller(configuration);
marshaller.start(Marshalling.createByteOutput(bout));
marshaller.writeObject(testObject);
marshaller.finish();
marshaller.close();
byte[] testBytes = bout.toByteArray();
onTooBigFrame(ch, input(testBytes));
}
use of io.netty.channel.embedded.EmbeddedChannel in project netty by netty.
the class AbstractCompatibleMarshallingDecoderTest method testFragmentedUnmarshalling.
@Test
public void testFragmentedUnmarshalling() throws IOException {
MarshallerFactory marshallerFactory = createMarshallerFactory();
MarshallingConfiguration configuration = createMarshallingConfig();
EmbeddedChannel ch = new EmbeddedChannel(createDecoder(Integer.MAX_VALUE));
ByteArrayOutputStream bout = new ByteArrayOutputStream();
Marshaller marshaller = marshallerFactory.createMarshaller(configuration);
marshaller.start(Marshalling.createByteOutput(bout));
marshaller.writeObject(testObject);
marshaller.finish();
marshaller.close();
byte[] testBytes = bout.toByteArray();
ByteBuf buffer = input(testBytes);
ByteBuf slice = buffer.readRetainedSlice(2);
ch.writeInbound(slice);
ch.writeInbound(buffer);
assertTrue(ch.finish());
String unmarshalled = ch.readInbound();
assertEquals(testObject, unmarshalled);
assertNull(ch.readInbound());
}
use of io.netty.channel.embedded.EmbeddedChannel in project netty by netty.
the class LengthFieldBasedFrameDecoderTest method testFailFastTooLongFrameRecovery.
@Test
public void testFailFastTooLongFrameRecovery() throws Exception {
EmbeddedChannel ch = new EmbeddedChannel(new LengthFieldBasedFrameDecoder(5, 0, 4, 0, 4));
for (int i = 0; i < 2; i++) {
try {
assertTrue(ch.writeInbound(Unpooled.wrappedBuffer(new byte[] { 0, 0, 0, 2 })));
fail(DecoderException.class.getSimpleName() + " must be raised.");
} catch (TooLongFrameException e) {
// Expected
}
ch.writeInbound(Unpooled.wrappedBuffer(new byte[] { 0, 0, 0, 0, 0, 1, 'A' }));
ByteBuf buf = ch.readInbound();
assertEquals("A", buf.toString(CharsetUtil.ISO_8859_1));
buf.release();
}
}
use of io.netty.channel.embedded.EmbeddedChannel in project netty by netty.
the class JsonObjectDecoderTest method testBackslashInString3.
@Test
public void testBackslashInString3() {
EmbeddedChannel ch = new EmbeddedChannel(new JsonObjectDecoder());
// {"foo" : "bar\\\""}
String json = "{\"foo\" : \"bar\\\\\\\"\"}";
System.out.println(json);
ch.writeInbound(Unpooled.copiedBuffer(json, CharsetUtil.UTF_8));
ByteBuf res = ch.readInbound();
assertEquals(json, res.toString(CharsetUtil.UTF_8));
res.release();
assertFalse(ch.finish());
}
Aggregations