From 9484687e13049731cde88fc647ac1143289d712a Mon Sep 17 00:00:00 2001 From: Scott Mitchell Date: Tue, 2 Jun 2015 12:44:18 -0700 Subject: [PATCH] Linux EPOLL Channel Configuration test unsupported options Motivation: The unit tests should not fail due to using a channel option which is not supported by the underlying kernel. Modifications: - Ignore RuntimeExceptions which are thrown by JNI code when setsockopt or getsockopt fails. Result: Unit tests pass if socket option is not supported by kernel. --- .../epoll/EpollSocketChannelConfigTest.java | 38 ++++++++++++++----- 1 file changed, 29 insertions(+), 9 deletions(-) diff --git a/transport-native-epoll/src/test/java/io/netty/channel/epoll/EpollSocketChannelConfigTest.java b/transport-native-epoll/src/test/java/io/netty/channel/epoll/EpollSocketChannelConfigTest.java index 5f2364a4f1..ffd0067a00 100644 --- a/transport-native-epoll/src/test/java/io/netty/channel/epoll/EpollSocketChannelConfigTest.java +++ b/transport-native-epoll/src/test/java/io/netty/channel/epoll/EpollSocketChannelConfigTest.java @@ -16,6 +16,7 @@ package io.netty.channel.epoll; import static org.junit.Assert.*; +import static org.junit.Assume.*; import io.netty.bootstrap.Bootstrap; import io.netty.channel.ChannelInboundHandlerAdapter; import io.netty.channel.EventLoopGroup; @@ -64,22 +65,41 @@ public class EpollSocketChannelConfigTest { @Test public void testRandomTcpNotSentLowAt() { - final long value = randLong(0, 0xFFFFFFFFL); - ch.config().setTcpNotSentLowAt(value); - assertEquals(value, ch.config().getTcpNotSentLowAt()); + final long expected = randLong(0, 0xFFFFFFFFL); + final long actual; + try { + ch.config().setTcpNotSentLowAt(expected); + actual = ch.config().getTcpNotSentLowAt(); + } catch (RuntimeException e) { + assumeNoException(e); + return; // Needed to prevent compile error for final variables to be used below + } + assertEquals(expected, actual); } - @Test(expected = IllegalArgumentException.class) + @Test public void testInvalidHighTcpNotSentLowAt() { - final long value = 0xFFFFFFFFL + 1; - ch.config().setTcpNotSentLowAt(value); + try { + final long value = 0xFFFFFFFFL + 1; + ch.config().setTcpNotSentLowAt(value); + } catch (IllegalArgumentException e) { + return; + } catch (RuntimeException e) { + assumeNoException(e); + } fail(); } - @Test(expected = IllegalArgumentException.class) + @Test public void testInvalidLowTcpNotSentLowAt() { - final long value = -1; - ch.config().setTcpNotSentLowAt(value); + try { + final long value = -1; + ch.config().setTcpNotSentLowAt(value); + } catch (IllegalArgumentException e) { + return; + } catch (RuntimeException e) { + assumeNoException(e); + } fail(); }