From 28b0c49acbb2fb1e32612a043e3a0b2d5013aadc Mon Sep 17 00:00:00 2001 From: Nikita Date: Fri, 11 May 2018 13:19:02 +0300 Subject: [PATCH] Redis shutdown improvements --- .../src/test/java/org/redisson/BaseTest.java | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/redisson/src/test/java/org/redisson/BaseTest.java b/redisson/src/test/java/org/redisson/BaseTest.java index ac6ba763d..4e73334f1 100644 --- a/redisson/src/test/java/org/redisson/BaseTest.java +++ b/redisson/src/test/java/org/redisson/BaseTest.java @@ -1,8 +1,8 @@ package org.redisson; import java.io.IOException; + import org.junit.After; -import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; import org.redisson.api.RedissonClient; @@ -18,14 +18,18 @@ public abstract class BaseTest { if (!RedissonRuntimeEnvironment.isTravis) { RedisRunner.startDefaultRedisServerInstance(); defaultRedisson = createInstance(); - } - } - - @AfterClass - public static void afterClass() throws IOException, InterruptedException { - if (!RedissonRuntimeEnvironment.isTravis) { - defaultRedisson.shutdown(); - RedisRunner.shutDownDefaultRedisServerInstance(); + Runtime.getRuntime().addShutdownHook(new Thread() { + @Override + public void run() { + defaultRedisson.shutdown(); + try { + RedisRunner.shutDownDefaultRedisServerInstance(); + } catch (InterruptedException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + }); } }