Enhancements

added a method to retrieve Redis server version.
renamed RedisRunner.startDefaultRedisTestInstance to
RedisRunner.startDefaultRedisServerInstance
renamed RedisRunner.shutDownDefaultRedisTestInstance to
RedisRunner.shutDownDefaultRedisServerInstance
removed redis version related code from RedissonRuntimeEnvironment
travis.yml no longer need to pass redisVersion environment to run tests
pull/509/head
Rui Gu 9 years ago
parent 103d0f6fd4
commit fca888987d

@ -218,4 +218,4 @@ before_script:
- export REDIS_VERSION="$(redis-cli INFO SERVER | sed -n 2p)"
- echo $REDIS_VERSION
- redis-cli SHUTDOWN NOSAVE
script: mvn -Dtest=$REDISSON_TEST -Dsurefire.rerunFailingTestsCount=5 -DargLine="-DredisBinary=$REDIS_BIN/redis-server -DtravisEnv=true -DredisVersion=${REDIS_VERSION}" -Punit-test test
script: mvn -Dtest=$REDISSON_TEST -Dsurefire.rerunFailingTestsCount=5 -DargLine="-DredisBinary=$REDIS_BIN/redis-server -DtravisEnv=true" -Punit-test test

@ -25,7 +25,7 @@ public abstract class BaseReactiveTest {
@BeforeClass
public static void beforeClass() throws IOException, InterruptedException {
if (!RedissonRuntimeEnvironment.isTravis) {
RedisRunner.startDefaultRedisTestInstance();
RedisRunner.startDefaultRedisServerInstance();
defaultRedisson = createInstance();
}
}
@ -33,7 +33,7 @@ public abstract class BaseReactiveTest {
@AfterClass
public static void afterClass() throws IOException, InterruptedException {
if (!RedissonRuntimeEnvironment.isTravis) {
RedisRunner.startDefaultRedisTestInstance();
RedisRunner.startDefaultRedisServerInstance();
defaultRedisson.shutdown();
}
}
@ -41,7 +41,7 @@ public abstract class BaseReactiveTest {
@Before
public void before() throws IOException, InterruptedException {
if (RedissonRuntimeEnvironment.isTravis) {
RedisRunner.startDefaultRedisTestInstance();
RedisRunner.startDefaultRedisServerInstance();
} else {
if (redisson == null) {
redisson = defaultRedisson;
@ -54,7 +54,7 @@ public abstract class BaseReactiveTest {
public void after() throws InterruptedException {
if (RedissonRuntimeEnvironment.isTravis) {
redisson.shutdown();
RedisRunner.shutDownDefaultRedisTestInstance();
RedisRunner.shutDownDefaultRedisServerInstance();
}
}

@ -14,7 +14,7 @@ public abstract class BaseTest {
@BeforeClass
public static void beforeClass() throws IOException, InterruptedException {
if (!RedissonRuntimeEnvironment.isTravis) {
RedisRunner.startDefaultRedisTestInstance();
RedisRunner.startDefaultRedisServerInstance();
defaultRedisson = createInstance();
}
}
@ -22,7 +22,7 @@ public abstract class BaseTest {
@AfterClass
public static void afterClass() throws IOException, InterruptedException {
if (!RedissonRuntimeEnvironment.isTravis) {
RedisRunner.startDefaultRedisTestInstance();
RedisRunner.startDefaultRedisServerInstance();
defaultRedisson.shutdown();
}
}
@ -30,7 +30,7 @@ public abstract class BaseTest {
@Before
public void before() throws IOException, InterruptedException {
if (RedissonRuntimeEnvironment.isTravis) {
RedisRunner.startDefaultRedisTestInstance();
RedisRunner.startDefaultRedisServerInstance();
} else {
if (redisson == null) {
redisson = defaultRedisson;
@ -43,7 +43,7 @@ public abstract class BaseTest {
public void after() throws InterruptedException {
if (RedissonRuntimeEnvironment.isTravis) {
redisson.shutdown();
RedisRunner.shutDownDefaultRedisTestInstance();
RedisRunner.shutDownDefaultRedisServerInstance();
}
}

@ -38,28 +38,28 @@ public class RedisClientTest {
@BeforeClass
public static void beforeClass() throws IOException, InterruptedException {
if (!RedissonRuntimeEnvironment.isTravis) {
RedisRunner.startDefaultRedisTestInstance();
RedisRunner.startDefaultRedisServerInstance();
}
}
@AfterClass
public static void afterClass() throws IOException, InterruptedException {
if (!RedissonRuntimeEnvironment.isTravis) {
RedisRunner.startDefaultRedisTestInstance();
RedisRunner.shutDownDefaultRedisServerInstance();
}
}
@Before
public void before() throws IOException, InterruptedException {
if (RedissonRuntimeEnvironment.isTravis) {
RedisRunner.startDefaultRedisTestInstance();
RedisRunner.startDefaultRedisServerInstance();
}
}
@After
public void after() throws InterruptedException {
if (RedissonRuntimeEnvironment.isTravis) {
RedisRunner.shutDownDefaultRedisTestInstance();
RedisRunner.shutDownDefaultRedisServerInstance();
}
}

@ -11,12 +11,13 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Locale;
import java.util.Optional;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import org.redisson.client.RedisClient;
import org.redisson.client.RedisConnection;
import org.redisson.client.protocol.RedisStrictCommand;
import org.redisson.client.protocol.convertor.VoidReplayConvertor;
@ -202,7 +203,6 @@ public class RedisRunner {
}
private static RedisProcess runWithOptions(RedisRunner runner, String... options) throws IOException, InterruptedException {
System.out.println("REDIS VER: " + RedissonRuntimeEnvironment.redisFullVersion);
List<String> launchOptions = Arrays.stream(options)
.map(x -> Arrays.asList(x.split(" "))).flatMap(x -> x.stream())
.collect(Collectors.toList());
@ -267,7 +267,7 @@ public class RedisRunner {
addConfigOption(REDIS_OPTIONS.PORT, port);
return this;
}
public int getPort() {
return this.port;
}
@ -286,7 +286,7 @@ public class RedisRunner {
public ArrayList<String> getBindAddr() {
return this.bindAddr;
}
public RedisRunner unixsocket(String unixsocket) {
addConfigOption(REDIS_OPTIONS.UNIXSOCKET, unixsocket);
return this;
@ -385,6 +385,7 @@ public class RedisRunner {
/**
* Phantom option
*
* @return RedisRunner
*/
public RedisRunner randomDir() {
@ -671,6 +672,10 @@ public class RedisRunner {
return this.defaultDir;
}
public String getInitialBindAddr() {
return bindAddr.size() > 0 ? bindAddr.get(0) : "localhost";
}
public boolean deleteDBfileDir() {
File f = new File(defaultDir);
if (f.exists()) {
@ -695,6 +700,10 @@ public class RedisRunner {
private final Process redisProcess;
private final RedisRunner runner;
private String redisFullVersion;
private Integer redisMajorVersion;
private Integer redisMinorVersion;
private Integer redisPatchVersion;
private RedisProcess(Process redisProcess, RedisRunner runner) {
this.redisProcess = redisProcess;
@ -703,37 +712,76 @@ public class RedisRunner {
public int stop() throws InterruptedException {
if (runner.isNosave() && !runner.isRandomDir()) {
ArrayList<String> b = runner.getBindAddr();
RedisClient c = new RedisClient(b.size() > 0 ? b.get(0) : "localhost", runner.getPort());
c.connect()
.async(new RedisStrictCommand<Void>("SHUTDOWN", "NOSAVE", new VoidReplayConvertor()))
RedisClient c = createDefaultRedisClientInstance();
RedisConnection connection = c.connect();
connection.async(new RedisStrictCommand<Void>("SHUTDOWN", "NOSAVE", new VoidReplayConvertor()))
.await(3, TimeUnit.SECONDS);
c.shutdown();
connection.closeAsync().syncUninterruptibly();
}
redisProcess.destroy();
int exitCode = redisProcess.isAlive() ? redisProcess.waitFor() : redisProcess.exitValue();
if (runner.isRandomDir()) {
runner.deleteDBfileDir();
}
return exitCode == 1 && isWindows() ? 0 : exitCode;
return exitCode == 1 && RedissonRuntimeEnvironment.isWindows ? 0 : exitCode;
}
public Process getRedisProcess() {
return redisProcess;
}
private boolean isWindows() {
return RedissonRuntimeEnvironment.isWindows;
public RedisClient createRedisClientInstance() {
if (redisProcess.isAlive()) {
return new RedisClient(runner.getInitialBindAddr(), runner.getPort());
}
throw new IllegalStateException("Redis server instance is not running.");
}
public String getRedisFullVersion() {
if (redisFullVersion == null) {
redisFullVersion = createRedisClientInstance().serverInfo().get("redis_version");
}
return redisFullVersion;
}
public int getRedisMajorVersion() {
if (redisMajorVersion == null) {
parseVersion();
}
return redisMajorVersion;
}
public int getRedisMinorVersion() {
if (redisMinorVersion == null) {
parseVersion();
}
return redisMinorVersion;
}
public int getRedisPatchVersion() {
if (redisPatchVersion == null) {
parseVersion();
}
return redisPatchVersion;
}
private void parseVersion() {
Matcher matcher = Pattern.compile("^([\\d]{0,2})\\.([\\d]{0,2})\\.([\\d]{0,2})$").matcher(getRedisFullVersion());
matcher.find();
redisMajorVersion = Integer.parseInt(matcher.group(1));
redisMinorVersion = Integer.parseInt(matcher.group(2));
redisPatchVersion = Integer.parseInt(matcher.group(3));
}
}
public static RedisRunner.RedisProcess startDefaultRedisTestInstance() throws IOException, InterruptedException {
public static RedisRunner.RedisProcess startDefaultRedisServerInstance() throws IOException, InterruptedException {
if (defaultRedisInstance == null) {
System.out.println("REDIS RUNNER: Starting up default instance...");
defaultRedisInstance = new RedisRunner().nosave().randomDir().run();
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
try {
shutDownDefaultRedisTestInstance();
shutDownDefaultRedisServerInstance();
} catch (InterruptedException ex) {
}
}));
@ -741,7 +789,7 @@ public class RedisRunner {
return defaultRedisInstance;
}
public static int shutDownDefaultRedisTestInstance() throws InterruptedException {
public static int shutDownDefaultRedisServerInstance() throws InterruptedException {
if (defaultRedisInstance != null) {
System.out.println("REDIS RUNNER: Shutting down default instance...");
try {
@ -758,4 +806,9 @@ public class RedisRunner {
public static boolean isDefaultRedisTestInstanceRunning() {
return defaultRedisInstance != null && defaultRedisInstance.redisProcess.isAlive();
}
public static RedisClient createDefaultRedisClientInstance() {
return defaultRedisInstance.createRedisClientInstance();
}
}

@ -24,6 +24,9 @@ import org.redisson.RedisRunner.RedisProcess;
import org.redisson.core.RBlockingQueue;
import io.netty.util.concurrent.Future;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
public class RedissonBlockingQueueTest extends BaseTest {

@ -19,28 +19,28 @@ public class RedissonCountDownLatchConcurrentTest {
@BeforeClass
public static void beforeClass() throws IOException, InterruptedException {
if (!RedissonRuntimeEnvironment.isTravis) {
RedisRunner.startDefaultRedisTestInstance();
RedisRunner.startDefaultRedisServerInstance();
}
}
@AfterClass
public static void afterClass() throws IOException, InterruptedException {
if (!RedissonRuntimeEnvironment.isTravis) {
RedisRunner.startDefaultRedisTestInstance();
RedisRunner.startDefaultRedisServerInstance();
}
}
@Before
public void before() throws IOException, InterruptedException {
if (RedissonRuntimeEnvironment.isTravis) {
RedisRunner.startDefaultRedisTestInstance();
RedisRunner.startDefaultRedisServerInstance();
}
}
@After
public void after() throws InterruptedException {
if (RedissonRuntimeEnvironment.isTravis) {
RedisRunner.shutDownDefaultRedisTestInstance();
RedisRunner.shutDownDefaultRedisServerInstance();
}
}

@ -13,6 +13,12 @@ import org.redisson.core.RedissonMultiLock;
import io.netty.channel.nio.NioEventLoopGroup;
import org.redisson.RedisRunner.RedisProcess;
import static com.jayway.awaitility.Awaitility.await;
import static org.assertj.core.api.Assertions.assertThat;
import static com.jayway.awaitility.Awaitility.await;
import static org.assertj.core.api.Assertions.assertThat;
import static com.jayway.awaitility.Awaitility.await;
import static org.assertj.core.api.Assertions.assertThat;
public class RedissonMultiLockTest {

@ -1,8 +1,6 @@
package org.redisson;
import java.util.Locale;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class RedissonRuntimeEnvironment {
@ -11,18 +9,8 @@ public class RedissonRuntimeEnvironment {
public static final String tempDir = System.getProperty("java.io.tmpdir");
public static final String OS;
public static final boolean isWindows;
public static final String redisFullVersion;
public static final int redisMajorVersion;
public static final int redisMinorVersion;
public static final int redisPatchVersion;
static {
redisFullVersion = System.getProperty("redisVersion", "0.0.0");
Matcher matcher = Pattern.compile("^([\\d]{0,2})\\.([\\d]{0,2})\\.([\\d]{0,2})$").matcher(redisFullVersion);
matcher.find();
redisMajorVersion = Integer.parseInt(matcher.group(1));
redisMinorVersion = Integer.parseInt(matcher.group(2));
redisPatchVersion = Integer.parseInt(matcher.group(3));
OS = System.getProperty("os.name", "generic");
isWindows = OS.toLowerCase(Locale.ENGLISH).contains("win");
}

@ -27,6 +27,12 @@ import org.redisson.connection.ConnectionListener;
import org.redisson.core.ClusterNode;
import org.redisson.core.Node;
import org.redisson.core.NodesGroup;
import static com.jayway.awaitility.Awaitility.await;
import static org.assertj.core.api.Assertions.assertThat;
import static com.jayway.awaitility.Awaitility.await;
import static org.assertj.core.api.Assertions.assertThat;
import static com.jayway.awaitility.Awaitility.await;
import static org.assertj.core.api.Assertions.assertThat;
public class RedissonTest {
@ -36,7 +42,7 @@ public class RedissonTest {
@BeforeClass
public static void beforeClass() throws IOException, InterruptedException {
if (!RedissonRuntimeEnvironment.isTravis) {
RedisRunner.startDefaultRedisTestInstance();
RedisRunner.startDefaultRedisServerInstance();
defaultRedisson = BaseTest.createInstance();
}
}
@ -44,7 +50,7 @@ public class RedissonTest {
@AfterClass
public static void afterClass() throws IOException, InterruptedException {
if (!RedissonRuntimeEnvironment.isTravis) {
RedisRunner.startDefaultRedisTestInstance();
RedisRunner.startDefaultRedisServerInstance();
defaultRedisson.shutdown();
}
}
@ -52,7 +58,7 @@ public class RedissonTest {
@Before
public void before() throws IOException, InterruptedException {
if (RedissonRuntimeEnvironment.isTravis) {
RedisRunner.startDefaultRedisTestInstance();
RedisRunner.startDefaultRedisServerInstance();
} else {
if (redisson == null) {
redisson = defaultRedisson;
@ -65,7 +71,7 @@ public class RedissonTest {
public void after() throws InterruptedException {
if (RedissonRuntimeEnvironment.isTravis) {
redisson.shutdown();
RedisRunner.shutDownDefaultRedisTestInstance();
RedisRunner.shutDownDefaultRedisServerInstance();
}
}

@ -21,28 +21,28 @@ public class RedissonTopicPatternTest {
@BeforeClass
public static void beforeClass() throws IOException, InterruptedException {
if (!RedissonRuntimeEnvironment.isTravis) {
RedisRunner.startDefaultRedisTestInstance();
RedisRunner.startDefaultRedisServerInstance();
}
}
@AfterClass
public static void afterClass() throws IOException, InterruptedException {
if (!RedissonRuntimeEnvironment.isTravis) {
RedisRunner.startDefaultRedisTestInstance();
RedisRunner.startDefaultRedisServerInstance();
}
}
@Before
public void before() throws IOException, InterruptedException {
if (RedissonRuntimeEnvironment.isTravis) {
RedisRunner.startDefaultRedisTestInstance();
RedisRunner.startDefaultRedisServerInstance();
}
}
@After
public void after() throws InterruptedException {
if (RedissonRuntimeEnvironment.isTravis) {
RedisRunner.shutDownDefaultRedisTestInstance();
RedisRunner.shutDownDefaultRedisServerInstance();
}
}

@ -21,28 +21,28 @@ public class RedissonTopicTest {
@BeforeClass
public static void beforeClass() throws IOException, InterruptedException {
if (!RedissonRuntimeEnvironment.isTravis) {
RedisRunner.startDefaultRedisTestInstance();
RedisRunner.startDefaultRedisServerInstance();
}
}
@AfterClass
public static void afterClass() throws IOException, InterruptedException {
if (!RedissonRuntimeEnvironment.isTravis) {
RedisRunner.startDefaultRedisTestInstance();
RedisRunner.startDefaultRedisServerInstance();
}
}
@Before
public void before() throws IOException, InterruptedException {
if (RedissonRuntimeEnvironment.isTravis) {
RedisRunner.startDefaultRedisTestInstance();
RedisRunner.startDefaultRedisServerInstance();
}
}
@After
public void after() throws InterruptedException {
if (RedissonRuntimeEnvironment.isTravis) {
RedisRunner.shutDownDefaultRedisTestInstance();
RedisRunner.shutDownDefaultRedisServerInstance();
}
}

@ -34,21 +34,21 @@ public class RedissonTwoLockedThread {
@BeforeClass
public static void beforeClass() throws IOException, InterruptedException {
if (!RedissonRuntimeEnvironment.isTravis) {
RedisRunner.startDefaultRedisTestInstance();
RedisRunner.startDefaultRedisServerInstance();
}
}
@AfterClass
public static void afterClass() throws IOException, InterruptedException {
if (!RedissonRuntimeEnvironment.isTravis) {
RedisRunner.startDefaultRedisTestInstance();
RedisRunner.startDefaultRedisServerInstance();
}
}
@Before
public void before() throws IOException, InterruptedException {
if (RedissonRuntimeEnvironment.isTravis) {
RedisRunner.startDefaultRedisTestInstance();
RedisRunner.startDefaultRedisServerInstance();
}
Config config = BaseTest.createConfig();
config.setCodec(codec);
@ -59,7 +59,7 @@ public class RedissonTwoLockedThread {
public void after() throws InterruptedException {
redisson.shutdown();
if (RedissonRuntimeEnvironment.isTravis) {
RedisRunner.shutDownDefaultRedisTestInstance();
RedisRunner.shutDownDefaultRedisServerInstance();
}
}

Loading…
Cancel
Save