diff --git a/transport-sctp/src/main/test/io/netty/channel/sctp/SctpLimitStreamsTest.java b/transport-sctp/src/test/java/io/netty/channel/sctp/SctpLimitStreamsTest.java similarity index 84% rename from transport-sctp/src/main/test/io/netty/channel/sctp/SctpLimitStreamsTest.java rename to transport-sctp/src/test/java/io/netty/channel/sctp/SctpLimitStreamsTest.java index c9b7f0b965..f9c06c8c1e 100644 --- a/transport-sctp/src/main/test/io/netty/channel/sctp/SctpLimitStreamsTest.java +++ b/transport-sctp/src/test/java/io/netty/channel/sctp/SctpLimitStreamsTest.java @@ -22,14 +22,28 @@ import io.netty.channel.Channel; import io.netty.channel.ChannelInboundHandlerAdapter; import io.netty.channel.ChannelOption; import io.netty.channel.EventLoopGroup; -import org.junit.Test; -import java.net.InetSocketAddress; +import io.netty.util.SuppressForbidden; -import static org.junit.Assert.*; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.Timeout; + +import java.net.InetSocketAddress; +import java.util.concurrent.TimeUnit; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assumptions.assumeTrue; public abstract class SctpLimitStreamsTest { - @Test(timeout = 5000) + @BeforeAll + public static void checkSupported() { + assumeTrue(SctpTestUtil.isSctpSupported()); + } + + @SuppressForbidden(reason = "test-only") + @Test + @Timeout(value = 5000, unit = TimeUnit.MILLISECONDS) public void testSctpInitMaxstreams() throws Exception { EventLoopGroup loop = newEventLoopGroup(); try { diff --git a/transport-sctp/src/test/java/io/netty/channel/sctp/SctpTestUtil.java b/transport-sctp/src/test/java/io/netty/channel/sctp/SctpTestUtil.java new file mode 100644 index 0000000000..08897dcba1 --- /dev/null +++ b/transport-sctp/src/test/java/io/netty/channel/sctp/SctpTestUtil.java @@ -0,0 +1,55 @@ +/* + * Copyright 2021 The Netty Project + * + * The Netty Project licenses this file to you under the Apache License, + * version 2.0 (the "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at: + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + */ +package io.netty.channel.sctp; + +import com.sun.nio.sctp.SctpChannel; +import io.netty.util.SuppressForbidden; + +import java.io.IOException; +import java.nio.channels.Channel; + +@SuppressForbidden(reason = "test-only") +final class SctpTestUtil { + + private static final boolean SCTP_SUPPORTED; + + static { + boolean supported = true; + Channel channel = null; + try { + channel = SctpChannel.open(); + } catch (UnsupportedOperationException e) { + supported = false; + } catch (IOException e) { + // ignore + } finally { + if (channel != null) { + try { + channel.close(); + } catch (IOException ignore) { + // ignore + } + } + } + SCTP_SUPPORTED = supported; + } + + public static boolean isSctpSupported() { + return SCTP_SUPPORTED; + } + + private SctpTestUtil() { } +} diff --git a/transport-sctp/src/main/test/io/netty/channel/sctp/nio/NioSctpLimitStreamsTest.java b/transport-sctp/src/test/java/io/netty/channel/sctp/nio/NioSctpLimitStreamsTest.java similarity index 100% rename from transport-sctp/src/main/test/io/netty/channel/sctp/nio/NioSctpLimitStreamsTest.java rename to transport-sctp/src/test/java/io/netty/channel/sctp/nio/NioSctpLimitStreamsTest.java diff --git a/transport-sctp/src/main/test/io/netty/channel/sctp/oio/OioSctpLimitStreamsTest.java b/transport-sctp/src/test/java/io/netty/channel/sctp/oio/OioSctpLimitStreamsTest.java similarity index 100% rename from transport-sctp/src/main/test/io/netty/channel/sctp/oio/OioSctpLimitStreamsTest.java rename to transport-sctp/src/test/java/io/netty/channel/sctp/oio/OioSctpLimitStreamsTest.java diff --git a/transport-sctp/src/main/test/io/netty/handler/codec/sctp/SctpMessageCompletionHandlerTest.java b/transport-sctp/src/test/java/io/netty/handler/codec/sctp/SctpMessageCompletionHandlerTest.java similarity index 93% rename from transport-sctp/src/main/test/io/netty/handler/codec/sctp/SctpMessageCompletionHandlerTest.java rename to transport-sctp/src/test/java/io/netty/handler/codec/sctp/SctpMessageCompletionHandlerTest.java index 89ae37e9e0..99ebe94f8e 100644 --- a/transport-sctp/src/main/test/io/netty/handler/codec/sctp/SctpMessageCompletionHandlerTest.java +++ b/transport-sctp/src/test/java/io/netty/handler/codec/sctp/SctpMessageCompletionHandlerTest.java @@ -21,12 +21,13 @@ import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import io.netty.channel.embedded.EmbeddedChannel; import io.netty.channel.sctp.SctpMessage; -import org.junit.Test; +import io.netty.util.SuppressForbidden; +import org.junit.jupiter.api.Test; import java.net.SocketAddress; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertEquals; public class SctpMessageCompletionHandlerTest { @@ -46,6 +47,7 @@ public class SctpMessageCompletionHandlerTest { assertEquals(0, buffer2.refCnt()); } + @SuppressForbidden(reason = "test-only") private final class TestMessageInfo extends MessageInfo { private final boolean complete;