From a1328419fdba14c52a249368166fb8ce09d34bc7 Mon Sep 17 00:00:00 2001 From: Idel Pivnitskiy Date: Sat, 14 Oct 2017 06:49:45 -0700 Subject: [PATCH] Make methods 'static' where it possible Motivation: Even if it's a super micro-optimization (most JVM could optimize such cases in runtime), in theory (and according to some perf tests) it may help a bit. It also makes a code more clear and allows you to access such methods in the test scope directly, without instance of the class. Modifications: Add 'static' modifier for all methods, where it possible. Mostly in test scope. Result: Cleaner code with proper 'static' modifiers. --- .../io/netty/buffer/ReadOnlyByteBufTest.java | 2 +- .../java/io/netty/util/NettyRuntimeTests.java | 2 +- .../util/concurrent/DefaultPromiseTest.java | 16 ++++++++-------- .../concurrent/DefaultThreadFactoryTest.java | 2 +- .../io/netty/util/internal/StringUtilTest.java | 2 +- .../handler/ssl/CipherSuiteConverterTest.java | 4 ++-- .../java/io/netty/handler/ssl/ocsp/OcspTest.java | 12 ++++++------ .../handler/timeout/IdleStateHandlerTest.java | 8 ++++---- .../epoll/EpollSocketChannelConfigTest.java | 4 ++-- 9 files changed, 26 insertions(+), 26 deletions(-) diff --git a/buffer/src/test/java/io/netty/buffer/ReadOnlyByteBufTest.java b/buffer/src/test/java/io/netty/buffer/ReadOnlyByteBufTest.java index a185f7700a..29bf89181e 100644 --- a/buffer/src/test/java/io/netty/buffer/ReadOnlyByteBufTest.java +++ b/buffer/src/test/java/io/netty/buffer/ReadOnlyByteBufTest.java @@ -201,7 +201,7 @@ public class ReadOnlyByteBufTest { ensureWritableIntStatusShouldFailButNotThrow(true); } - private void ensureWritableIntStatusShouldFailButNotThrow(boolean force) { + private static void ensureWritableIntStatusShouldFailButNotThrow(boolean force) { ByteBuf buf = buffer(1); ByteBuf readOnly = unmodifiableBuffer(buf); int result = readOnly.ensureWritable(1, force); diff --git a/common/src/test/java/io/netty/util/NettyRuntimeTests.java b/common/src/test/java/io/netty/util/NettyRuntimeTests.java index 123ffe5f57..e66c6cc6ee 100644 --- a/common/src/test/java/io/netty/util/NettyRuntimeTests.java +++ b/common/src/test/java/io/netty/util/NettyRuntimeTests.java @@ -98,7 +98,7 @@ public class NettyRuntimeTests { assertNull(secondRefernce.get()); } - private Runnable getRunnable( + private static Runnable getRunnable( final NettyRuntime.AvailableProcessorsHolder holder, final CyclicBarrier barrier, final AtomicReference reference) { diff --git a/common/src/test/java/io/netty/util/concurrent/DefaultPromiseTest.java b/common/src/test/java/io/netty/util/concurrent/DefaultPromiseTest.java index 0f3c50de75..c041c10db3 100644 --- a/common/src/test/java/io/netty/util/concurrent/DefaultPromiseTest.java +++ b/common/src/test/java/io/netty/util/concurrent/DefaultPromiseTest.java @@ -230,8 +230,8 @@ public class DefaultPromiseTest { } } - private void testStackOverFlowChainedFuturesA(int promiseChainLength, final EventExecutor executor, - boolean runTestInExecutorThread) + private static void testStackOverFlowChainedFuturesA(int promiseChainLength, final EventExecutor executor, + boolean runTestInExecutorThread) throws InterruptedException { final Promise[] p = new DefaultPromise[promiseChainLength]; final CountDownLatch latch = new CountDownLatch(promiseChainLength); @@ -253,8 +253,8 @@ public class DefaultPromiseTest { } } - private void testStackOverFlowChainedFuturesA(EventExecutor executor, final Promise[] p, - final CountDownLatch latch) { + private static void testStackOverFlowChainedFuturesA(EventExecutor executor, final Promise[] p, + final CountDownLatch latch) { for (int i = 0; i < p.length; i ++) { final int finalI = i; p[i] = new DefaultPromise(executor); @@ -272,8 +272,8 @@ public class DefaultPromiseTest { p[0].setSuccess(null); } - private void testStackOverFlowChainedFuturesB(int promiseChainLength, final EventExecutor executor, - boolean runTestInExecutorThread) + private static void testStackOverFlowChainedFuturesB(int promiseChainLength, final EventExecutor executor, + boolean runTestInExecutorThread) throws InterruptedException { final Promise[] p = new DefaultPromise[promiseChainLength]; final CountDownLatch latch = new CountDownLatch(promiseChainLength); @@ -295,8 +295,8 @@ public class DefaultPromiseTest { } } - private void testStackOverFlowChainedFuturesB(EventExecutor executor, final Promise[] p, - final CountDownLatch latch) { + private static void testStackOverFlowChainedFuturesB(EventExecutor executor, final Promise[] p, + final CountDownLatch latch) { for (int i = 0; i < p.length; i ++) { final int finalI = i; p[i] = new DefaultPromise(executor); diff --git a/common/src/test/java/io/netty/util/concurrent/DefaultThreadFactoryTest.java b/common/src/test/java/io/netty/util/concurrent/DefaultThreadFactoryTest.java index ae050b3721..8d788a2103 100644 --- a/common/src/test/java/io/netty/util/concurrent/DefaultThreadFactoryTest.java +++ b/common/src/test/java/io/netty/util/concurrent/DefaultThreadFactoryTest.java @@ -186,7 +186,7 @@ public class DefaultThreadFactoryTest { } } - private void runStickyThreadGroupTest( + private static void runStickyThreadGroupTest( final Callable callable, final ThreadGroup expected) throws InterruptedException { final AtomicReference captured = new AtomicReference(); diff --git a/common/src/test/java/io/netty/util/internal/StringUtilTest.java b/common/src/test/java/io/netty/util/internal/StringUtilTest.java index 177e1ae0db..018b817b9b 100644 --- a/common/src/test/java/io/netty/util/internal/StringUtilTest.java +++ b/common/src/test/java/io/netty/util/internal/StringUtilTest.java @@ -389,7 +389,7 @@ public class StringUtilTest { assertEscapeCsvAndUnEscapeCsv("\n"); } - private void assertEscapeCsvAndUnEscapeCsv(String value) { + private static void assertEscapeCsvAndUnEscapeCsv(String value) { assertEquals(value, unescapeCsv(StringUtil.escapeCsv(value))); } diff --git a/handler/src/test/java/io/netty/handler/ssl/CipherSuiteConverterTest.java b/handler/src/test/java/io/netty/handler/ssl/CipherSuiteConverterTest.java index d7395d1a1c..ffe53d2ba8 100644 --- a/handler/src/test/java/io/netty/handler/ssl/CipherSuiteConverterTest.java +++ b/handler/src/test/java/io/netty/handler/ssl/CipherSuiteConverterTest.java @@ -307,14 +307,14 @@ public class CipherSuiteConverterTest { testUnknownJavaCiphersToOpenSSL(""); } - private void testUnknownOpenSSLCiphersToJava(String openSslCipherSuite) { + private static void testUnknownOpenSSLCiphersToJava(String openSslCipherSuite) { CipherSuiteConverter.clearCache(); assertNull(CipherSuiteConverter.toJava(openSslCipherSuite, "TLS")); assertNull(CipherSuiteConverter.toJava(openSslCipherSuite, "SSL")); } - private void testUnknownJavaCiphersToOpenSSL(String javaCipherSuite) { + private static void testUnknownJavaCiphersToOpenSSL(String javaCipherSuite) { CipherSuiteConverter.clearCache(); assertNull(CipherSuiteConverter.toOpenSsl(javaCipherSuite)); diff --git a/handler/src/test/java/io/netty/handler/ssl/ocsp/OcspTest.java b/handler/src/test/java/io/netty/handler/ssl/ocsp/OcspTest.java index e8e6d40967..496c5be30b 100644 --- a/handler/src/test/java/io/netty/handler/ssl/ocsp/OcspTest.java +++ b/handler/src/test/java/io/netty/handler/ssl/ocsp/OcspTest.java @@ -99,7 +99,7 @@ public class OcspTest { testClientOcspNotEnabled(SslProvider.OPENSSL_REFCNT); } - private void testClientOcspNotEnabled(SslProvider sslProvider) throws Exception { + private static void testClientOcspNotEnabled(SslProvider sslProvider) throws Exception { SslContext context = SslContextBuilder.forClient() .sslProvider(sslProvider) .build(); @@ -126,7 +126,7 @@ public class OcspTest { testServerOcspNotEnabled(SslProvider.OPENSSL_REFCNT); } - private void testServerOcspNotEnabled(SslProvider sslProvider) throws Exception { + private static void testServerOcspNotEnabled(SslProvider sslProvider) throws Exception { SelfSignedCertificate ssc = new SelfSignedCertificate(); try { SslContext context = SslContextBuilder.forServer(ssc.certificate(), ssc.privateKey()) @@ -161,7 +161,7 @@ public class OcspTest { /** * The Server provides an OCSP staple and the Client accepts it. */ - private void testClientAcceptingOcspStaple(SslProvider sslProvider) throws Exception { + private static void testClientAcceptingOcspStaple(SslProvider sslProvider) throws Exception { final CountDownLatch latch = new CountDownLatch(1); ChannelInboundHandlerAdapter serverHandler = new ChannelInboundHandlerAdapter() { @Override @@ -207,7 +207,7 @@ public class OcspTest { /** * The Server provides an OCSP staple and the Client rejects it. */ - private void testClientRejectingOcspStaple(SslProvider sslProvider) throws Exception { + private static void testClientRejectingOcspStaple(SslProvider sslProvider) throws Exception { final AtomicReference causeRef = new AtomicReference(); final CountDownLatch latch = new CountDownLatch(1); @@ -250,7 +250,7 @@ public class OcspTest { /** * The server has OCSP stapling enabled but doesn't provide a staple. */ - private void testServerHasNoStaple(SslProvider sslProvider) throws Exception { + private static void testServerHasNoStaple(SslProvider sslProvider) throws Exception { final CountDownLatch latch = new CountDownLatch(1); ChannelInboundHandlerAdapter serverHandler = new ChannelInboundHandlerAdapter() { @Override @@ -297,7 +297,7 @@ public class OcspTest { * * The exception should bubble up on the client side and the connection should get closed. */ - private void testClientException(SslProvider sslProvider) throws Exception { + private static void testClientException(SslProvider sslProvider) throws Exception { final AtomicReference causeRef = new AtomicReference(); final CountDownLatch latch = new CountDownLatch(1); diff --git a/handler/src/test/java/io/netty/handler/timeout/IdleStateHandlerTest.java b/handler/src/test/java/io/netty/handler/timeout/IdleStateHandlerTest.java index 32daf4a948..0a5b627822 100644 --- a/handler/src/test/java/io/netty/handler/timeout/IdleStateHandlerTest.java +++ b/handler/src/test/java/io/netty/handler/timeout/IdleStateHandlerTest.java @@ -67,7 +67,7 @@ public class IdleStateHandlerTest { IdleStateEvent.ALL_IDLE_STATE_EVENT, IdleStateEvent.ALL_IDLE_STATE_EVENT); } - private void anyIdle(TestableIdleStateHandler idleStateHandler, Object... expected) throws Exception { + private static void anyIdle(TestableIdleStateHandler idleStateHandler, Object... expected) throws Exception { assertTrue("The number of expected events must be >= 1", expected.length >= 1); @@ -159,8 +159,8 @@ public class IdleStateHandlerTest { anyNotIdle(idleStateHandler, writer, IdleStateEvent.FIRST_ALL_IDLE_STATE_EVENT); } - private void anyNotIdle(TestableIdleStateHandler idleStateHandler, - Action action, Object expected) throws Exception { + private static void anyNotIdle(TestableIdleStateHandler idleStateHandler, + Action action, Object expected) throws Exception { final List events = new ArrayList(); ChannelInboundHandlerAdapter handler = new ChannelInboundHandlerAdapter() { @@ -205,7 +205,7 @@ public class IdleStateHandlerTest { observeOutputIdle(false); } - private void observeOutputIdle(boolean writer) throws Exception { + private static void observeOutputIdle(boolean writer) throws Exception { long writerIdleTime = 0L; long allIdleTime = 0L; 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 5e8f69e4cb..1015e389d8 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 @@ -56,11 +56,11 @@ public class EpollSocketChannelConfigTest { } } - private long randLong(long min, long max) { + private static long randLong(long min, long max) { return min + nextLong(max - min + 1); } - private long nextLong(long n) { + private static long nextLong(long n) { long bits, val; do { bits = (rand.nextLong() << 1) >>> 1;