Skip to content

Commit 341953e

Browse files
committed
Merge branch 'test' into develop
2 parents f3cfdde + 84cd422 commit 341953e

File tree

6 files changed

+109
-9
lines changed

6 files changed

+109
-9
lines changed

.github/workflows/run-tests.yml

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ name: Run Tests
22

33
on:
44
push:
5-
branches: [ main, develop ]
5+
branches: [ main, develop, test ]
66
pull_request:
7-
branches: [ main, develop ]
7+
branches: [ main, develop, test ]
88

99
jobs:
1010
test:
@@ -21,8 +21,22 @@ jobs:
2121
distribution: 'temurin'
2222
cache: gradle
2323

24+
- name: Check Docker availability
25+
run: |
26+
docker --version
27+
docker info
28+
29+
- name: Make gradlew executable
30+
run: chmod +x ./gradlew
31+
2432
- name: Run memory-api tests with coverage
25-
run: ./gradlew :memory-api:test :memory-api:jacocoTestReport
33+
run: ./gradlew :memory-api:test :memory-api:jacocoTestReport --info --stacktrace
34+
env:
35+
SPRING_PROFILES_ACTIVE: test
36+
TESTCONTAINERS_RYUK_DISABLED: true
37+
TESTCONTAINERS_DOCKER_SOCKET_OVERRIDE: /var/run/docker.sock
38+
# ElasticSearch TestContainer 설정
39+
ES_JAVA_OPTS: "-Xms512m -Xmx512m"
2640

2741
- name: Upload coverage reports to Codecov
2842
uses: codecov/codecov-action@v3

memory-api/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ dependencies {
2222
testImplementation 'org.springframework.boot:spring-boot-testcontainers'
2323
testImplementation 'org.testcontainers:junit-jupiter'
2424
testImplementation 'org.testcontainers:postgresql'
25+
testImplementation 'org.testcontainers:elasticsearch:1.19.3'
2526
}
2627

2728
tasks.named('test') {

memory-api/src/test/java/com/memory/controller/BaseIntegrationTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,18 @@
1313
@Transactional
1414
public abstract class BaseIntegrationTest {
1515
static final PostgresTC PG = PostgresTC.getInstance();
16+
// ElasticSearch 임시 비활성화
17+
static final ElasticSearchTC ES = ElasticSearchTC.getInstance();
1618

1719
@DynamicPropertySource
1820
static void props(DynamicPropertyRegistry r) {
21+
// PostgreSQL 설정
1922
r.add("spring.datasource.url", PG::getJdbcUrl);
2023
r.add("spring.datasource.username", PG::getUsername);
2124
r.add("spring.datasource.password", PG::getPassword);
2225
r.add("spring.datasource.driver-class-name", () -> "org.postgresql.Driver");
26+
27+
// ElasticSearch 설정 임시 비활성화
28+
r.add("spring.elasticsearch.uris", ES::getHttpHostAddress);
2329
}
2430
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package com.memory.controller;
2+
3+
import org.slf4j.Logger;
4+
import org.slf4j.LoggerFactory;
5+
import org.testcontainers.containers.wait.strategy.Wait;
6+
import org.testcontainers.elasticsearch.ElasticsearchContainer;
7+
import org.testcontainers.images.builder.ImageFromDockerfile;
8+
import org.testcontainers.utility.DockerImageName;
9+
10+
import java.time.Duration;
11+
import java.time.LocalDateTime;
12+
13+
public class ElasticSearchTC extends ElasticsearchContainer {
14+
private static final Logger log = LoggerFactory.getLogger(ElasticSearchTC.class);
15+
private static final String TAGGED_IMAGE = "es-nori:8.11.0";
16+
private static final String UPSTREAM = "docker.elastic.co/elasticsearch/elasticsearch";
17+
private static ElasticSearchTC INSTANCE;
18+
19+
private static DockerImageName imageName() {
20+
// 1) Dockerfile을 즉석 빌드(최초 1회). 태그: es-nori:8.11.0
21+
new ImageFromDockerfile(TAGGED_IMAGE, false)
22+
.withDockerfileFromBuilder(b -> b
23+
.from("docker.elastic.co/elasticsearch/elasticsearch:8.11.0")
24+
.run("bin/elasticsearch-plugin install --batch analysis-nori")
25+
.build()
26+
)
27+
.get();
28+
29+
// 2) 커스텀 이미지를 '엘라스틱 공식 이미지와 호환'이라고 선언
30+
return DockerImageName.parse(TAGGED_IMAGE)
31+
.asCompatibleSubstituteFor(UPSTREAM);
32+
}
33+
34+
private ElasticSearchTC() {
35+
super(imageName());
36+
log.info("[{}] ElasticSearchTC 생성자 호출 - 컨테이너 설정 시작", LocalDateTime.now());
37+
38+
withEnv("discovery.type", "single-node");
39+
withEnv("xpack.security.enabled", "false"); // 8.x 필수(비인증 테스트용)
40+
withEnv("xpack.ml.enabled", "false"); // 메모리 절약
41+
withEnv("ingest.geoip.downloader.enabled", "false"); // 외부 네트워크/시간 절약
42+
withEnv("ES_JAVA_OPTS", "-Xms512m -Xmx512m"); // 힙 축소 (필요시 256/512 조정)
43+
44+
waitingFor(Wait.forHttp("/").forPort(9200).forStatusCode(200));
45+
withStartupTimeout(Duration.ofMinutes(3))
46+
.withReuse(false);
47+
}
48+
49+
public static synchronized ElasticSearchTC getInstance() {
50+
if (INSTANCE == null) {
51+
INSTANCE = new ElasticSearchTC();
52+
INSTANCE.start();
53+
}
54+
return INSTANCE;
55+
}
56+
}
Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,36 @@
11
package com.memory.controller;
22

3+
import org.slf4j.Logger;
4+
import org.slf4j.LoggerFactory;
35
import org.testcontainers.containers.PostgreSQLContainer;
6+
import org.testcontainers.containers.wait.strategy.Wait;
47
import org.testcontainers.utility.DockerImageName;
58

9+
import java.time.Duration;
10+
611
public class PostgresTC extends PostgreSQLContainer<PostgresTC> {
12+
private static final Logger log = LoggerFactory.getLogger(PostgresTC.class);
713
private static final DockerImageName IMG = DockerImageName.parse("postgis/postgis:15-3.3")
814
.asCompatibleSubstituteFor("postgres");
915
private static PostgresTC INSTANCE;
1016

1117
private PostgresTC() {
1218
super(IMG);
19+
log.info("[{}] PostgresTC 생성자 호출 - 컨테이너 설정 시작", java.time.LocalDateTime.now());
20+
1321
withDatabaseName("memory_test");
1422
withUsername("test");
1523
withPassword("test");
16-
// 필요하면 .waitingFor(Wait.forListeningPort());
24+
withStartupTimeout(Duration.ofMinutes(5));
25+
waitingFor(Wait.forListeningPort())
26+
.withReuse(false);
1727
}
28+
1829
public static synchronized PostgresTC getInstance() {
19-
if (INSTANCE == null) { INSTANCE = new PostgresTC(); INSTANCE.start(); }
30+
if (INSTANCE == null) {
31+
INSTANCE = new PostgresTC();
32+
INSTANCE.start();
33+
}
2034
return INSTANCE;
2135
}
2236
}

memory-api/src/test/resources/application-test.yml

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@ cloud:
1919
aws:
2020
enabled: false
2121

22-
# ElasticSearch Configuration for testing (disabled)
23-
elasticsearch:
24-
enabled: false
2522

2623
jwt:
2724
token:
@@ -34,4 +31,16 @@ logging:
3431
level:
3532
org.springframework.web: INFO
3633
com.memory: INFO
37-
com.amazonaws: WARN
34+
com.amazonaws: WARN
35+
# TestContainers 관련 디버깅 로그
36+
com.memory.controller.PostgresTC: DEBUG
37+
com.memory.controller.ElasticSearchTC: DEBUG
38+
com.memory.controller.BaseIntegrationTest: DEBUG
39+
org.testcontainers: INFO
40+
org.springframework.boot.test: DEBUG
41+
org.springframework.test.context: DEBUG
42+
org.flywaydb: INFO
43+
org.postgresql: INFO
44+
# ElasticSearch 로깅
45+
org.elasticsearch: INFO
46+
org.springframework.data.elasticsearch: DEBUG

0 commit comments

Comments
 (0)