Merge pull request #441 from mrniko/revert-439-crossplatform-tests
Revert "Untie tests from Windows absolute paths"pull/442/head^2
commit
ecfd2502a1
@ -1,77 +1,22 @@
|
||||
package org.redisson;
|
||||
|
||||
import java.io.*;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.file.*;
|
||||
import java.util.Objects;
|
||||
|
||||
public class RedisRunner {
|
||||
|
||||
public static final int REDIS_EXIT_CODE;
|
||||
|
||||
private static final String defaultRedisDirectory = "C:\\Devel\\projects\\redis\\Redis-x64-3.0.500\\";
|
||||
private static final String defaultRedisExecutable = defaultRedisDirectory + "redis-server.exe";
|
||||
private static final String redisExecutable;
|
||||
|
||||
static {
|
||||
String path = System.getenv("PATH");
|
||||
if (path != null) {
|
||||
String os = System.getProperty("os.name");
|
||||
String pathSeparator = ":";
|
||||
String executableName = "redis-server";
|
||||
if (os.toLowerCase().startsWith("windows")) {
|
||||
pathSeparator = ";";
|
||||
executableName = "redis-server.exe";
|
||||
REDIS_EXIT_CODE = 1;
|
||||
} else {
|
||||
REDIS_EXIT_CODE = 0;
|
||||
}
|
||||
|
||||
String[] pathEntries = path.split(pathSeparator);
|
||||
Path fullExecutablePath = null;
|
||||
for (String pathEntry : pathEntries) {
|
||||
fullExecutablePath = Paths.get(pathEntry, executableName);
|
||||
if (Files.exists(fullExecutablePath)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (fullExecutablePath != null) {
|
||||
redisExecutable = fullExecutablePath.toString();
|
||||
} else {
|
||||
redisExecutable = defaultRedisExecutable;
|
||||
}
|
||||
} else {
|
||||
redisExecutable = defaultRedisExecutable;
|
||||
REDIS_EXIT_CODE = 1;
|
||||
}
|
||||
|
||||
if (!new File(redisExecutable).exists()) {
|
||||
throw new RuntimeException("Redis executable not found");
|
||||
}
|
||||
}
|
||||
private static final String redisFolder = "C:\\Devel\\projects\\redis\\Redis-x64-3.0.500\\";
|
||||
|
||||
public static Process runRedis(String configPath) throws IOException, InterruptedException {
|
||||
URL resource = RedisRunner.class.getResource(configPath);
|
||||
String fullConfigPath = Paths.get(resource.getFile()).toAbsolutePath().toString();
|
||||
|
||||
ProcessBuilder master = new ProcessBuilder(redisExecutable, fullConfigPath, "--dir", getWorkingDirectory());
|
||||
master.directory(new File(getWorkingDirectory()));
|
||||
ProcessBuilder master = new ProcessBuilder(redisFolder + "redis-server.exe", resource.getFile().substring(1));
|
||||
master.directory(new File(redisFolder));
|
||||
Process p = master.start();
|
||||
Thread.sleep(1000);
|
||||
|
||||
if (!p.isAlive()) {
|
||||
throw new RuntimeException("Redis executable stopped with exit code " + p.exitValue());
|
||||
}
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
private static String getWorkingDirectory() {
|
||||
if (redisExecutable.equals(defaultRedisExecutable)) {
|
||||
return defaultRedisDirectory;
|
||||
}
|
||||
return System.getProperty("user.dir");
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue