Search in sources :

Example 81 with Executable

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

the class DnsNameResolverTest method testFollowCNAMELoop.

@Test
public void testFollowCNAMELoop() throws IOException {
    TestDnsServer dnsServer2 = new TestDnsServer(new RecordStore() {

        @Override
        public Set<ResourceRecord> getRecords(QuestionRecord question) {
            Set<ResourceRecord> records = new LinkedHashSet<ResourceRecord>(4);
            records.add(new TestDnsServer.TestResourceRecord("x." + question.getDomainName(), RecordType.A, Collections.<String, Object>singletonMap(DnsAttribute.IP_ADDRESS.toLowerCase(), "10.0.0.99")));
            records.add(new TestDnsServer.TestResourceRecord("cname2.netty.io", RecordType.CNAME, Collections.<String, Object>singletonMap(DnsAttribute.DOMAIN_NAME.toLowerCase(), "cname.netty.io")));
            records.add(new TestDnsServer.TestResourceRecord("cname.netty.io", RecordType.CNAME, Collections.<String, Object>singletonMap(DnsAttribute.DOMAIN_NAME.toLowerCase(), "cname2.netty.io")));
            records.add(new TestDnsServer.TestResourceRecord(question.getDomainName(), RecordType.CNAME, Collections.<String, Object>singletonMap(DnsAttribute.DOMAIN_NAME.toLowerCase(), "cname.netty.io")));
            return records;
        }
    });
    dnsServer2.start();
    DnsNameResolver resolver = null;
    try {
        DnsNameResolverBuilder builder = newResolver().recursionDesired(false).resolvedAddressTypes(ResolvedAddressTypes.IPV4_ONLY).maxQueriesPerResolve(16).nameServerProvider(new SingletonDnsServerAddressStreamProvider(dnsServer2.localAddress()));
        resolver = builder.build();
        final DnsNameResolver finalResolver = resolver;
        assertThrows(UnknownHostException.class, new Executable() {

            @Override
            public void execute() throws Throwable {
                finalResolver.resolveAll("somehost.netty.io").syncUninterruptibly().getNow();
            }
        });
    } finally {
        dnsServer2.stop();
        if (resolver != null) {
            resolver.close();
        }
    }
}
Also used : QuestionRecord(org.apache.directory.server.dns.messages.QuestionRecord) Set(java.util.Set) LinkedHashSet(java.util.LinkedHashSet) HashSet(java.util.HashSet) ResourceRecord(org.apache.directory.server.dns.messages.ResourceRecord) RecordStore(org.apache.directory.server.dns.store.RecordStore) Executable(org.junit.jupiter.api.function.Executable) Test(org.junit.jupiter.api.Test)

Example 82 with Executable

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

the class DnsNameResolverTest method testAddressAlreadyInUse.

@Test
public void testAddressAlreadyInUse() throws Exception {
    DatagramSocket datagramSocket = new DatagramSocket();
    try {
        assertTrue(datagramSocket.isBound());
        try {
            final DnsNameResolver resolver = newResolver().localAddress(datagramSocket.getLocalSocketAddress()).build();
            try {
                Throwable cause = assertThrows(UnknownHostException.class, new Executable() {

                    @Override
                    public void execute() throws Throwable {
                        resolver.resolve("netty.io").sync();
                    }
                });
                assertThat(cause.getCause(), Matchers.<Throwable>instanceOf(BindException.class));
            } finally {
                resolver.close();
            }
        } catch (IllegalStateException cause) {
            // We might also throw directly here... in this case let's verify that we use the correct exception.
            assertThat(cause.getCause(), Matchers.<Throwable>instanceOf(BindException.class));
        }
    } finally {
        datagramSocket.close();
    }
}
Also used : DatagramSocket(java.net.DatagramSocket) BindException(java.net.BindException) Executable(org.junit.jupiter.api.function.Executable) Test(org.junit.jupiter.api.Test)

Example 83 with Executable

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

the class LongPriorityQueueTest method mustThrowWhenAddingNoValue.

@Test
public void mustThrowWhenAddingNoValue() {
    final LongPriorityQueue pq = new LongPriorityQueue();
    assertThrows(IllegalArgumentException.class, new Executable() {

        @Override
        public void execute() {
            pq.offer(LongPriorityQueue.NO_VALUE);
        }
    });
}
Also used : Executable(org.junit.jupiter.api.function.Executable) Test(org.junit.jupiter.api.Test)

Example 84 with Executable

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

the class UnpooledTest method testGetBytesByteBuffer2.

@Test
public void testGetBytesByteBuffer2() {
    byte[] bytes = { 'a', 'b', 'c', 'd', 'e', 'f', 'g' };
    // Ensure destination buffer is bigger then what is wrapped in the ByteBuf.
    final ByteBuffer nioBuffer = ByteBuffer.allocate(bytes.length + 1);
    final ByteBuf wrappedBuffer = wrappedBuffer(bytes, 0, bytes.length);
    try {
        assertThrows(IndexOutOfBoundsException.class, new Executable() {

            @Override
            public void execute() throws Throwable {
                wrappedBuffer.getBytes(wrappedBuffer.readerIndex(), nioBuffer);
            }
        });
    } finally {
        wrappedBuffer.release();
    }
}
Also used : Executable(org.junit.jupiter.api.function.Executable) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.jupiter.api.Test)

Example 85 with Executable

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

the class SlicedByteBufTest method testGetBytesByteBuffer.

@Override
@Test
public void testGetBytesByteBuffer() {
    byte[] bytes = { 'a', 'b', 'c', 'd', 'e', 'f', 'g' };
    // Ensure destination buffer is bigger then what is wrapped in the ByteBuf.
    final ByteBuffer nioBuffer = ByteBuffer.allocate(bytes.length + 1);
    final ByteBuf wrappedBuffer = Unpooled.wrappedBuffer(bytes).slice(0, bytes.length - 1);
    try {
        assertThrows(IndexOutOfBoundsException.class, new Executable() {

            @Override
            public void execute() {
                wrappedBuffer.getBytes(wrappedBuffer.readerIndex(), nioBuffer);
            }
        });
    } finally {
        wrappedBuffer.release();
    }
}
Also used : Executable(org.junit.jupiter.api.function.Executable) ByteBuffer(java.nio.ByteBuffer) 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