From 773be9787df1a654036f7dccf750bc0c16a559fd Mon Sep 17 00:00:00 2001 From: Norman Maurer Date: Fri, 27 Jun 2014 17:55:55 +0200 Subject: [PATCH] Let EpollReuseAddrTest also work with kernel versions that not have bugfix release part --- .../channel/epoll/EpollReuseAddrTest.java | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/transport-native-epoll/src/test/java/io/netty/channel/epoll/EpollReuseAddrTest.java b/transport-native-epoll/src/test/java/io/netty/channel/epoll/EpollReuseAddrTest.java index 3170b94090..21d835e234 100644 --- a/transport-native-epoll/src/test/java/io/netty/channel/epoll/EpollReuseAddrTest.java +++ b/transport-native-epoll/src/test/java/io/netty/channel/epoll/EpollReuseAddrTest.java @@ -27,6 +27,7 @@ import io.netty.testsuite.util.TestUtils; import io.netty.util.NetUtil; import io.netty.util.ReferenceCountUtil; import io.netty.util.ResourceLeakDetector; +import io.netty.util.internal.StringUtil; import org.junit.Assert; import org.junit.Assume; import org.junit.Test; @@ -47,17 +48,21 @@ public class EpollReuseAddrTest { private static final int BUGFIX; static { String kernelVersion = Native.kernelVersion(); - int index = kernelVersion.indexOf("-"); + int index = kernelVersion.indexOf('-'); if (index > -1) { kernelVersion = kernelVersion.substring(0, index); } - String[] versionParts = kernelVersion.split("\\."); - if (versionParts.length == 3) { + String[] versionParts = StringUtil.split(kernelVersion, '.'); + if (versionParts.length <= 3) { MAJOR = Integer.parseInt(versionParts[0]); MINOR = Integer.parseInt(versionParts[1]); - BUGFIX = Integer.parseInt(versionParts[2]); + if (versionParts.length == 3) { + BUGFIX = Integer.parseInt(versionParts[2]); + } else { + BUGFIX = 0; + } } else { - throw new IllegalStateException(); + throw new IllegalStateException("Can not parse kernel version " + kernelVersion); } } @@ -162,7 +167,7 @@ public class EpollReuseAddrTest { Assert.assertTrue(received2.get()); } - private ServerBootstrap createServerBootstrap() { + private static ServerBootstrap createServerBootstrap() { ServerBootstrap bootstrap = new ServerBootstrap(); bootstrap.group(EpollSocketTestPermutation.EPOLL_BOSS_GROUP, EpollSocketTestPermutation.EPOLL_WORKER_GROUP); bootstrap.channel(EpollServerSocketChannel.class); @@ -172,7 +177,7 @@ public class EpollReuseAddrTest { return bootstrap; } - private Bootstrap createBootstrap() { + private static Bootstrap createBootstrap() { Bootstrap bootstrap = new Bootstrap(); bootstrap.group(EpollSocketTestPermutation.EPOLL_WORKER_GROUP); bootstrap.channel(EpollDatagramChannel.class); @@ -184,7 +189,8 @@ public class EpollReuseAddrTest { private static boolean versionEqOrGt(int major, int minor, int bugfix) { if (MAJOR > major) { return true; - } else if (MAJOR == major) { + } + if (MAJOR == major) { if (MINOR > minor) { return true; } else if (MINOR == minor) {