Skip to content

Commit

Permalink
fix: fixed an Issue Redis test does not work in an M1 environment (#161)
Browse files Browse the repository at this point in the history
* fix(redis): fixed Redis test does not work in an M1 environment

* chore: change submodule commit pointer to recent
  • Loading branch information
KAispread authored Oct 15, 2023
1 parent f4b3da8 commit 86c85ca
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
Binary file added src/main/resources/binary/redis/redis-server
Binary file not shown.
2 changes: 1 addition & 1 deletion src/main/resources/sub
Submodule sub updated from 64d678 to 0a4627
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,22 @@
import jakarta.annotation.PostConstruct;
import jakarta.annotation.PreDestroy;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Objects;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.core.io.ClassPathResource;
import org.springframework.util.StringUtils;
import redis.embedded.RedisServer;
import redis.embedded.exceptions.EmbeddedRedisException;

/*
* Test 용 EmbeddedRedis / profile 이 local, default 일때만 활성화
* */
* Test 용 EmbeddedRedis / profile 이 local, default 일때만 활성화
* */
@Slf4j
@Profile({"local", "default"})
@Configuration
Expand All @@ -30,7 +34,14 @@ public void redisServer() throws IOException {
// Application Context 가 2번 이상 실행될 때 포트 충돌 문제 해결
int port = isRedisRunning() ? findAvailablePort() : redisPort;

redisServer = new RedisServer(port);
if (isArmMac()) {
redisServer = new RedisServer(Objects.requireNonNull(getRedisFileForArcMac()),
port);
}
if (!isArmMac()) {
redisServer = new RedisServer(port);
}

redisServer.start();
}

Expand All @@ -41,6 +52,19 @@ public void stopRedis() {
}
}

private boolean isArmMac() {
return Objects.equals(System.getProperty("os.arch"), "aarch64") &&
Objects.equals(System.getProperty("os.name"), "Mac OS X");
}

private File getRedisFileForArcMac() {
try {
return new ClassPathResource("binary/redis/redis-server").getFile();
} catch (Exception e) {
throw new EmbeddedRedisException("fail to get redis-server binary file");
}
}

/**
* Embedded Redis가 현재 실행중인지 확인
*/
Expand Down

0 comments on commit 86c85ca

Please sign in to comment.