Skip to content

Commit

Permalink
RedisRunner.RedisProcess.stop no longer throws Exception
Browse files Browse the repository at this point in the history
  • Loading branch information
jackygurui committed Apr 20, 2017
1 parent 032c53f commit 010d780
Showing 1 changed file with 26 additions and 11 deletions.
37 changes: 26 additions & 11 deletions redisson/src/test/java/org/redisson/RedisRunner.java
Expand Up @@ -290,10 +290,7 @@ public RedisProcess runAndCheck() throws IOException, InterruptedException, Fail
throw new FailedToStartRedisException();
}
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
try {
rp.stop();
} catch (InterruptedException ex) {
}
rp.stop();
}));
return rp;
}
Expand Down Expand Up @@ -884,17 +881,36 @@ private RedisProcess(Process redisProcess, RedisRunner runner) {
this.runner = runner;
}

public int stop() throws InterruptedException {
public int stop() {
if (runner.isNosave() && !runner.isRandomDir()) {
RedisClient c = createDefaultRedisClientInstance();
RedisConnection connection = c.connect();
connection.async(new RedisStrictCommand<Void>("SHUTDOWN", "NOSAVE", new VoidReplayConvertor()))
.await(3, TimeUnit.SECONDS);
try {
connection.async(new RedisStrictCommand<Void>("SHUTDOWN", "NOSAVE", new VoidReplayConvertor()))
.await(3, TimeUnit.SECONDS);
} catch (InterruptedException interruptedException) {
//shutdown via command failed, lets wait and kill it later.
}
c.shutdown();
connection.closeAsync().syncUninterruptibly();
}
redisProcess.destroy();
int exitCode = redisProcess.isAlive() ? redisProcess.waitFor() : redisProcess.exitValue();
Process p = redisProcess;
p.destroy();
boolean normalTermination = false;
try {
normalTermination = p.waitFor(5, TimeUnit.SECONDS);
} catch (InterruptedException ex) {
//OK lets hurry up by force kill;
}
if (!normalTermination) {
p = p.destroyForcibly();
}
cleanup();
int exitCode = p.exitValue();
return exitCode == 1 && RedissonRuntimeEnvironment.isWindows ? 0 : exitCode;
}

private void cleanup() {
if (runner.isSentinel()) {
runner.deleteSentinelFile();
}
Expand All @@ -904,9 +920,8 @@ public int stop() throws InterruptedException {
if (runner.isRandomDir()) {
runner.deleteDBfileDir();
}
return exitCode == 1 && RedissonRuntimeEnvironment.isWindows ? 0 : exitCode;
}

public Process getRedisProcess() {
return redisProcess;
}
Expand Down

0 comments on commit 010d780

Please sign in to comment.