diff --git a/.travis.yml b/.travis.yml index c6dad00aa..adbef8277 100644 --- a/.travis.yml +++ b/.travis.yml @@ -37,4 +37,5 @@ before_script: - $REDIS_BIN/redis-cli PING - export REDIS_VERSION="$(redis-cli INFO SERVER | sed -n 2p)" - echo $REDIS_VERSION -script: mvn -DargLine="-DredisBinary=$REDIS_BIN/redis-server -DtravisEnv=true" -Punit-test -Ptravis clean verify + - redis-cli SHUTDOWN NOSAVE +script: mvn -DargLine="-DredisBinary=$REDIS_BIN/redis-server -DtravisEnv=true" -Punit-test clean verify diff --git a/nbactions-unit-test.xml b/nbactions-unit-test.xml new file mode 100644 index 000000000..651e627fb --- /dev/null +++ b/nbactions-unit-test.xml @@ -0,0 +1,107 @@ + + + + test + + * + + + test + + + "-DredisBinary=/usr/local/bin/redis-server" + + + + test.single + + * + + + test-compile + surefire:test + + + ${packageClassName} + "-DredisBinary=/usr/local/bin/redis-server" + + + + run.single.main + + * + + + process-classes + org.codehaus.mojo:exec-maven-plugin:1.2.1:exec + + + -classpath %classpath ${packageClassName} + java + ${classPathScope} + "-DredisBinary=/usr/local/bin/redis-server" + + + + debug + + "-DredisBinary=/usr/local/bin/redis-server" + + + + debug.single.main + + * + + + process-classes + org.codehaus.mojo:exec-maven-plugin:1.2.1:exec + + + -Xdebug -Xrunjdwp:transport=dt_socket,server=n,address=${jpda.address} -classpath %classpath ${packageClassName} + java + ${classPathScope} + true + "-DredisBinary=/usr/local/bin/redis-server" + + + + debug.test.single + + * + + + test-compile + surefire:test + + + ${packageClassName} + once + -Xdebug -Xrunjdwp:transport=dt_socket,server=n,address=${jpda.address} + true + "-DredisBinary=/usr/local/bin/redis-server" + + + + profile + + "-DredisBinary=/usr/local/bin/redis-server" + + + + profile.single.main + + * + + + process-classes + org.codehaus.mojo:exec-maven-plugin:1.2.1:exec + + + -classpath %classpath ${packageClassName} + java + ${classPathScope} + "-DredisBinary=/usr/local/bin/redis-server" + + + diff --git a/src/test/java/org/redisson/BaseTest.java b/src/test/java/org/redisson/BaseTest.java index 48c549c92..6ef6904c4 100644 --- a/src/test/java/org/redisson/BaseTest.java +++ b/src/test/java/org/redisson/BaseTest.java @@ -1,5 +1,8 @@ package org.redisson; +import java.io.IOException; +import java.util.logging.Level; +import java.util.logging.Logger; import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; @@ -7,15 +10,26 @@ import org.junit.BeforeClass; public abstract class BaseTest { protected static RedissonClient redisson; - + protected static RedisRunner.RedisProcess redis; + @BeforeClass - public static void beforeClass() { + public static void beforeClass() throws IOException, InterruptedException { + System.out.println("Starting up..."); + redis = defaultRedisTestInstance(); redisson = createInstance(); + Runtime.getRuntime().addShutdownHook(new Thread(() -> { + try { + afterClass(); + } catch (InterruptedException ex) { + } + })); } @AfterClass - public static void afterClass() { + public static void afterClass() throws InterruptedException { + System.out.println("Shutting down..."); redisson.shutdown(); + redis.stop(); } public static Config createConfig() { @@ -45,5 +59,9 @@ public abstract class BaseTest { public void before() { redisson.getKeys().flushall(); } + + private static RedisRunner.RedisProcess defaultRedisTestInstance() throws IOException, InterruptedException { + return new RedisRunner().run(); + } } diff --git a/src/test/java/org/redisson/RedisClientTest.java b/src/test/java/org/redisson/RedisClientTest.java index b9f97e7c7..f43fb5c89 100644 --- a/src/test/java/org/redisson/RedisClientTest.java +++ b/src/test/java/org/redisson/RedisClientTest.java @@ -27,9 +27,45 @@ import org.redisson.client.protocol.pubsub.PubSubType; import io.netty.util.concurrent.Future; import io.netty.util.concurrent.FutureListener; import io.netty.util.concurrent.Promise; +import java.io.IOException; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import static org.redisson.BaseTest.afterClass; public class RedisClientTest { + protected static RedisRunner.RedisProcess redis; + + @BeforeClass + public static void beforeClass() throws IOException, InterruptedException { + System.out.println("Starting up..."); + redis = defaultRedisTestInstance(); + Runtime.getRuntime().addShutdownHook(new Thread(() -> { + try { + afterClass(); + } catch (InterruptedException ex) { + } + })); + } + + @AfterClass + public static void afterClass() throws InterruptedException { + System.out.println("Shutting down..."); + redis.stop(); + } + + private static RedisRunner.RedisProcess defaultRedisTestInstance() throws IOException, InterruptedException { + return new RedisRunner().run(); + } + + @Before + public void before() { + System.out.println("Cleaning up..."); + RedisClient c = new RedisClient("localhost", 6379); + c.connect().sync(RedisCommands.FLUSHDB); + } + @Test public void testConnectAsync() throws InterruptedException { RedisClient c = new RedisClient("localhost", 6379); @@ -43,7 +79,7 @@ public class RedisClientTest { l.countDown(); } }); - l.await(); + l.await(10, TimeUnit.SECONDS); } @Test @@ -71,7 +107,7 @@ public class RedisClientTest { }); pubSubConnection.subscribe(StringCodec.INSTANCE, "test1", "test2"); - latch.await(); + latch.await(10, TimeUnit.SECONDS); } @Test @@ -80,7 +116,7 @@ public class RedisClientTest { final RedisConnection conn = c.connect(); conn.sync(StringCodec.INSTANCE, RedisCommands.SET, "test", 0); - ExecutorService pool = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors()*2); + ExecutorService pool = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors() * 2); for (int i = 0; i < 100000; i++) { pool.execute(new Runnable() { @Override @@ -94,7 +130,7 @@ public class RedisClientTest { assertThat(pool.awaitTermination(1, TimeUnit.HOURS)).isTrue(); - assertThat((Long)conn.sync(LongCodec.INSTANCE, RedisCommands.GET, "test")).isEqualTo(100000); + assertThat((Long) conn.sync(LongCodec.INSTANCE, RedisCommands.GET, "test")).isEqualTo(100000); conn.sync(RedisCommands.FLUSHDB); } diff --git a/src/test/java/org/redisson/RedisRunner.java b/src/test/java/org/redisson/RedisRunner.java index 532e9c1b1..8d18c884b 100644 --- a/src/test/java/org/redisson/RedisRunner.java +++ b/src/test/java/org/redisson/RedisRunner.java @@ -213,7 +213,7 @@ public class RedisRunner { System.out.println("Exception: " + ex.getLocalizedMessage()); } }).start(); - Thread.sleep(1000); + Thread.sleep(3000); return new RedisProcess(p); }