Search in sources :

Example 66 with Executable

use of org.junit.jupiter.api.function.Executable in project netty by netty.

the class ZlibTest method testMaxAllocation.

@Test
public void testMaxAllocation() throws Exception {
    int maxAllocation = 1024;
    ZlibDecoder decoder = createDecoder(ZlibWrapper.ZLIB, maxAllocation);
    final EmbeddedChannel chDecoder = new EmbeddedChannel(decoder);
    TestByteBufAllocator alloc = new TestByteBufAllocator(chDecoder.alloc());
    chDecoder.config().setAllocator(alloc);
    DecompressionException e = assertThrows(DecompressionException.class, new Executable() {

        @Override
        public void execute() throws Throwable {
            chDecoder.writeInbound(Unpooled.wrappedBuffer(deflate(BYTES_LARGE)));
        }
    });
    assertTrue(e.getMessage().startsWith("Decompression buffer has reached maximum size"));
    assertEquals(maxAllocation, alloc.getMaxAllocation());
    assertTrue(decoder.isClosed());
    assertFalse(chDecoder.finish());
}
Also used : EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) Executable(org.junit.jupiter.api.function.Executable) Test(org.junit.jupiter.api.Test)

Example 67 with Executable

use of org.junit.jupiter.api.function.Executable in project netty by netty.

the class SnappyTest method testDecodeWithOverlyLongPreamble.

@Test
public void testDecodeWithOverlyLongPreamble() {
    final ByteBuf in = Unpooled.wrappedBuffer(new byte[] { // preamble length
    -0x80, // preamble length
    -0x80, // preamble length
    -0x80, // preamble length
    -0x80, // preamble length
    0x7f, // literal tag + length
    0x04 << 2, // "netty"
    0x6e, // "netty"
    0x65, // "netty"
    0x74, // "netty"
    0x74, // "netty"
    0x79 });
    final ByteBuf out = Unpooled.buffer(10);
    try {
        assertThrows(DecompressionException.class, new Executable() {

            @Override
            public void execute() {
                snappy.decode(in, out);
            }
        });
    } finally {
        in.release();
        out.release();
    }
}
Also used : ByteBuf(io.netty.buffer.ByteBuf) Executable(org.junit.jupiter.api.function.Executable) Test(org.junit.jupiter.api.Test)

Example 68 with Executable

use of org.junit.jupiter.api.function.Executable in project netty by netty.

the class SnappyTest method testDecodeCopyWithOffsetBeforeChunk.

@Test
public void testDecodeCopyWithOffsetBeforeChunk() {
    final ByteBuf in = Unpooled.wrappedBuffer(new byte[] { // preamble length
    0x0a, // literal tag + length
    0x04 << 2, // "netty"
    0x6e, // "netty"
    0x65, // "netty"
    0x74, // "netty"
    0x74, // "netty"
    0x79, // copy with 1-byte offset + length
    0x05 << 2 | 0x01, // INVALID offset (greater than chunk size)
    0x0b });
    final ByteBuf out = Unpooled.buffer(10);
    try {
        assertThrows(DecompressionException.class, new Executable() {

            @Override
            public void execute() {
                snappy.decode(in, out);
            }
        });
    } finally {
        in.release();
        out.release();
    }
}
Also used : ByteBuf(io.netty.buffer.ByteBuf) Executable(org.junit.jupiter.api.function.Executable) Test(org.junit.jupiter.api.Test)

Example 69 with Executable

use of org.junit.jupiter.api.function.Executable in project netty by netty.

the class Lz4FrameDecoderTest method testDecompressedAndCompressedLengthMismatch.

@Test
public void testDecompressedAndCompressedLengthMismatch() {
    final byte[] data = Arrays.copyOf(DATA, DATA.length);
    data[13] = 0x01;
    final ByteBuf in = Unpooled.wrappedBuffer(data);
    assertThrows(DecompressionException.class, new Executable() {

        @Override
        public void execute() {
            channel.writeInbound(in);
        }
    }, "mismatch");
}
Also used : ByteBuf(io.netty.buffer.ByteBuf) Executable(org.junit.jupiter.api.function.Executable) Test(org.junit.jupiter.api.Test)

Example 70 with Executable

use of org.junit.jupiter.api.function.Executable in project netty by netty.

the class Lz4FrameEncoderTest method testAllocateOnHeapBufferOverflowsOutputSize.

/**
 * This test might be a invasive in terms of knowing what happens inside
 * {@link Lz4FrameEncoder#allocateBuffer(ChannelHandlerContext, ByteBuf, boolean)}, but this is safest way
 * of testing the overflow conditions as allocating the huge buffers fails in many CI environments.
 */
@Test
public void testAllocateOnHeapBufferOverflowsOutputSize() {
    final int maxEncodeSize = Integer.MAX_VALUE;
    final Lz4FrameEncoder encoder = newEncoder(Lz4Constants.DEFAULT_BLOCK_SIZE, maxEncodeSize);
    when(buffer.readableBytes()).thenReturn(maxEncodeSize);
    buffer.writerIndex(maxEncodeSize);
    assertThrows(EncoderException.class, new Executable() {

        @Override
        public void execute() {
            encoder.allocateBuffer(ctx, buffer, false);
        }
    });
}
Also used : Executable(org.junit.jupiter.api.function.Executable) Test(org.junit.jupiter.api.Test)

Aggregations

Executable (org.junit.jupiter.api.function.Executable)476 Test (org.junit.jupiter.api.Test)434 lombok.val (lombok.val)112 ByteBuf (io.netty.buffer.ByteBuf)83 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)42 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)36 CucumberException (io.cucumber.core.exception.CucumberException)20 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)19 StubStepDefinition (io.cucumber.core.backend.StubStepDefinition)15 Feature (io.cucumber.core.gherkin.Feature)15 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)15 StepDefinition (io.cucumber.core.backend.StepDefinition)14 Step (io.cucumber.core.gherkin.Step)14 Argument (io.cucumber.core.stepexpression.Argument)14 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)13 LocalChannel (io.netty.channel.local.LocalChannel)12 CucumberBackendException (io.cucumber.core.backend.CucumberBackendException)11 StepExpression (io.cucumber.core.stepexpression.StepExpression)11 SSLEngine (javax.net.ssl.SSLEngine)11 Bootstrap (io.netty.bootstrap.Bootstrap)10