Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: m1 support #129

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/main/java/redis/embedded/AbstractRedisInstance.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
abstract class AbstractRedisInstance implements Redis {
protected List<String> args = Collections.emptyList();
private volatile boolean active = false;
private Process redisProcess;
private Process redisProcess;
private final int port;

private ExecutorService executor;
Expand All @@ -28,7 +28,7 @@ public boolean isActive() {
return active;
}

@Override
@Override
public synchronized void start() throws EmbeddedRedisException {
if (active) {
throw new EmbeddedRedisException("This redis server instance is already running...");
Expand Down Expand Up @@ -61,7 +61,7 @@ private void awaitRedisServerReady() throws IOException {
//Something goes wrong. Stream is ended before server was activated.
throw new RuntimeException("Can't start redis server. Check logs for details.");
}
} while (!outputLine.matches(redisReadyPattern()));
} while (!outputLine.contains(redisReadyPattern()));
} finally {
IOUtils.closeQuietly(reader);
}
Expand Down
11 changes: 6 additions & 5 deletions src/main/java/redis/embedded/RedisExecProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,19 @@
import java.util.Map;

public class RedisExecProvider {

private final Map<OsArchitecture, String> executables = Maps.newHashMap();

public static RedisExecProvider defaultProvider() {
return new RedisExecProvider();
}

private RedisExecProvider() {
initExecutables();
}

private void initExecutables() {
executables.put(OsArchitecture.UNIX_aarch64, "redis-server");
executables.put(OsArchitecture.WINDOWS_x86, "redis-server-2.8.19.exe");
executables.put(OsArchitecture.WINDOWS_x86_64, "redis-server-2.8.19.exe");

Expand All @@ -47,14 +48,14 @@ public RedisExecProvider override(OS os, Architecture arch, String executable) {
executables.put(new OsArchitecture(os, arch), executable);
return this;
}

public File get() throws IOException {
OsArchitecture osArch = OsArchitecture.detect();
String executablePath = executables.get(osArch);
return fileExists(executablePath) ?
return fileExists(executablePath) ?
new File(executablePath) :
JarUtil.extractExecutableFromJar(executablePath);

}

private boolean fileExists(String executablePath) {
Expand Down
12 changes: 9 additions & 3 deletions src/main/java/redis/embedded/RedisServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
import java.util.List;

public class RedisServer extends AbstractRedisInstance {
String arch = System.getProperty("os.arch");
private static final String REDIS_READY_PATTERN_ARM64 = "Server initialized";
;
private static final String REDIS_READY_PATTERN = ".*The server is now ready to accept connections on port.*";
private static final int DEFAULT_REDIS_PORT = 6379;

Expand All @@ -21,7 +24,7 @@ public RedisServer(int port) throws IOException {
executable.getAbsolutePath(),
"--port", Integer.toString(port)
);
}
}

public RedisServer(File executable, int port) {
super(port);
Expand Down Expand Up @@ -50,6 +53,9 @@ public static RedisServerBuilder builder() {

@Override
protected String redisReadyPattern() {
return REDIS_READY_PATTERN;
if (arch.equals("aarch64")) {
return REDIS_READY_PATTERN_ARM64;
} else {
return REDIS_READY_PATTERN;
}
}
}
3 changes: 2 additions & 1 deletion src/main/java/redis/embedded/util/Architecture.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@

public enum Architecture {
x86,
x86_64
x86_64,
aarch64
}
6 changes: 5 additions & 1 deletion src/main/java/redis/embedded/util/OSDetector.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@ private static Architecture getUnixArchitecture() {
while ((line = input.readLine()) != null) {
if (line.length() > 0) {
if (line.contains("64")) {
return Architecture.x86_64;
if (line.contains("aarch")) {
return Architecture.aarch64;
} else {
return Architecture.x86_64;
}
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/redis/embedded/util/OsArchitecture.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ public class OsArchitecture {

public static final OsArchitecture WINDOWS_x86 = new OsArchitecture(OS.WINDOWS, Architecture.x86);
public static final OsArchitecture WINDOWS_x86_64 = new OsArchitecture(OS.WINDOWS, Architecture.x86_64);


public static final OsArchitecture UNIX_aarch64 = new OsArchitecture(OS.UNIX, Architecture.aarch64);
public static final OsArchitecture UNIX_x86 = new OsArchitecture(OS.UNIX, Architecture.x86);
public static final OsArchitecture UNIX_x86_64 = new OsArchitecture(OS.UNIX, Architecture.x86_64);

Expand Down
1 change: 1 addition & 0 deletions src/test/java/redis/embedded/RedisServerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ public void shouldIndicateInactiveAfterStop() throws Exception {
@Test
public void shouldOverrideDefaultExecutable() throws Exception {
RedisExecProvider customProvider = RedisExecProvider.defaultProvider()
.override(OS.UNIX, Architecture.aarch64, Resources.getResource("redis-server").getFile())
.override(OS.UNIX, Architecture.x86, Resources.getResource("redis-server-2.8.19-32").getFile())
.override(OS.UNIX, Architecture.x86_64, Resources.getResource("redis-server-2.8.19").getFile())
.override(OS.WINDOWS, Architecture.x86, Resources.getResource("redis-server-2.8.19.exe").getFile())
Expand Down