Skip to content

Commit d009cf9

Browse files
committed
infra: h2 기반으로 CI 환경 구축 (#197)
* infra: h2 기반으로 ci 환경 구축 * infra: 테스트 스택트레이스 추가 * test: 테스트 수정
1 parent ea423aa commit d009cf9

File tree

13 files changed

+156
-95
lines changed

13 files changed

+156
-95
lines changed

.github/workflows/yappu-world-ci.yaml

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,6 @@ jobs:
1414
steps:
1515
- uses: actions/checkout@v4
1616

17-
- name: Set up Docker
18-
run: |
19-
sudo apt-get update
20-
sudo apt-get install docker-compose
21-
22-
- name: Start MySQL with Docker Compose
23-
run: |
24-
docker-compose -f docker/docker-compose-test.yaml up -d
25-
2617
- name: Set up JDK 21
2718
uses: actions/setup-java@v4
2819
with:

build.gradle.kts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ dependencies {
3333
runtimeOnly("com.mysql:mysql-connector-j")
3434
runtimeOnly("com.oracle.database.jdbc:ojdbc11")
3535
runtimeOnly("com.oracle.database.security:oraclepki:23.5.0.24.07")
36+
runtimeOnly("com.h2database:h2")
3637
implementation("org.springframework.boot:spring-boot-starter-data-jpa")
3738
implementation("com.linecorp.kotlin-jdsl:jpql-dsl:3.5.5")
3839
implementation("com.linecorp.kotlin-jdsl:jpql-render:3.5.5")
@@ -85,6 +86,13 @@ ktlint {
8586
tasks {
8687
test {
8788
useJUnitPlatform()
89+
testLogging {
90+
events("passed", "skipped", "failed")
91+
showExceptions = true
92+
showCauses = true
93+
showStackTraces = true
94+
exceptionFormat = org.gradle.api.tasks.testing.logging.TestExceptionFormat.FULL
95+
}
8896
}
8997
bootJar {
9098
archiveBaseName = "yappu-world"

docker/docker-compose-local.yaml

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
11
name: yappu-world-server
22

33
services:
4-
mysql:
5-
image: mysql:8.1
4+
oracle:
5+
image: gvenzl/oracle-xe:21-slim-faststart
66
environment:
7-
MYSQL_DATABASE: yappu_world
8-
MYSQL_USER: yapp
9-
MYSQL_PASSWORD: yapp
10-
MYSQL_ROOT_PASSWORD: yapp
7+
ORACLE_PASSWORD: yapp1234
8+
APP_USER: yapp
9+
APP_USER_PASSWORD: yapp1234
1110
volumes:
12-
- yappu_mysql_data:/var/lib/mysql
11+
- yappu_oracle_data:/opt/oracle/oradata
1312
ports:
14-
- '3306:3306'
13+
- '1521:1521'
1514
restart: always
16-
command:
17-
- --character-set-server=utf8mb4
18-
- --collation-server=utf8mb4_unicode_ci
19-
- --skip-character-set-client-handshake
15+
healthcheck:
16+
test: ["CMD-SHELL", "healthcheck.sh"]
17+
interval: 10s
18+
timeout: 5s
19+
retries: 30
20+
start_period: 60s
2021

2122
volumes:
22-
yappu_mysql_data:
23+
yappu_oracle_data:

docker/docker-compose-test.yaml

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
services:
2-
mysql:
3-
image: mysql:8.1
2+
oracle:
3+
image: gvenzl/oracle-xe:21-slim-faststart
44
environment:
5-
MYSQL_DATABASE: yappu_world
6-
MYSQL_USER: yapp
7-
MYSQL_PASSWORD: yapp
8-
MYSQL_ROOT_PASSWORD: yapp
5+
ORACLE_PASSWORD: test1234
6+
APP_USER: testuser
7+
APP_USER_PASSWORD: test1234
98
ports:
10-
- '3306:3306'
11-
restart: always
12-
command:
13-
- --character-set-server=utf8mb4
14-
- --collation-server=utf8mb4_unicode_ci
15-
- --skip-character-set-client-handshake
9+
- '1521:1521'
10+
healthcheck:
11+
test: ["CMD-SHELL", "healthcheck.sh"]
12+
interval: 10s
13+
timeout: 5s
14+
retries: 30
15+
start_period: 60s

src/main/kotlin/co/yappuworld/operation/client/application/GenerationActiveStateManager.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import co.yappuworld.global.exception.BusinessException
44
import co.yappuworld.operation.client.dto.param.GenerationActivationControlResult
55
import co.yappuworld.operation.domain.GenerationEntity
66
import co.yappuworld.operation.domain.OperationError
7+
import co.yappuworld.operation.infrastructure.GenerationFindService
78
import co.yappuworld.operation.infrastructure.GenerationRepository
89
import io.github.oshai.kotlinlogging.KotlinLogging
910
import org.springframework.data.repository.findByIdOrNull
@@ -14,6 +15,7 @@ private val logger = KotlinLogging.logger { }
1415

1516
@Component
1617
class GenerationActiveStateManager(
18+
private val generationFindService: GenerationFindService,
1719
private val generationRepository: GenerationRepository
1820
) {
1921

@@ -39,9 +41,9 @@ class GenerationActiveStateManager(
3941
fun getActiveGenerationOrNull(): Int? = generationRepository.getGenerationOrNullByIsActiveIsTrue()?.value
4042

4143
private fun deactivateGeneration(targetGenerationValue: Int? = null): Int? {
42-
if (!generationRepository.existsGenerationByIsActiveIsTrue()) return null
44+
if (!generationFindService.existsActiveGeneration()) return null
4345

44-
val activeGenerations = generationRepository.findAllByIsActiveIsTrue()
46+
val activeGenerations = generationFindService.findAllActiveGeneration()
4547
checkDeactivatingConsistency(activeGenerations, targetGenerationValue)
4648

4749
return activeGenerations

src/main/kotlin/co/yappuworld/operation/infrastructure/GenerationFindService.kt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,23 @@ class GenerationFindService(
1818
generationRepository.getGenerationOrNullByIsActiveIsTrue()?.value
1919
?: throw BusinessException(AttendanceError.NO_ACTIVE_GENERATION)
2020

21+
fun existsGeneration(value: Int): Boolean = generationRepository.existsById(value)
22+
23+
fun existsActiveGeneration(): Boolean =
24+
generationRepository
25+
.findAll(limit = 1) {
26+
select(intLiteral(1))
27+
.from(entity(GenerationEntity::class))
28+
.where(path(GenerationEntity::isActive).equal(true))
29+
}.isNotEmpty()
30+
2131
fun findGenerations(values: List<Int>): List<GenerationEntity> = generationRepository.findAllByValueIn(values)
32+
33+
fun findAllActiveGeneration(): List<GenerationEntity> =
34+
generationRepository
35+
.findAll {
36+
select(entity(GenerationEntity::class))
37+
.from(entity(GenerationEntity::class))
38+
.where(path(GenerationEntity::isActive).equal(true))
39+
}.filterNotNull()
2240
}
Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
package co.yappuworld.operation.infrastructure
22

33
import co.yappuworld.operation.domain.GenerationEntity
4+
import com.linecorp.kotlinjdsl.support.spring.data.jpa.repository.KotlinJdslJpqlExecutor
45
import org.springframework.data.jpa.repository.JpaRepository
56

6-
interface GenerationRepository : JpaRepository<GenerationEntity, Int> {
7-
8-
fun existsGenerationByIsActiveIsTrue(): Boolean
7+
interface GenerationRepository :
8+
JpaRepository<GenerationEntity, Int>,
9+
KotlinJdslJpqlExecutor {
910

1011
fun getGenerationOrNullByIsActiveIsTrue(): GenerationEntity?
1112

12-
fun findAllByIsActiveIsTrue(): List<GenerationEntity>
13-
1413
fun findAllByValueIn(values: List<Int>): List<GenerationEntity>
1514
}

src/main/resources/application-local.yaml

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,26 @@ spring:
1717
file: docker/docker-compose-local.yaml
1818

1919
datasource:
20-
url: jdbc:mysql://localhost:3306/yappu_world
21-
username: yapp
22-
password: yapp
20+
driver-class-name: org.h2.Driver
21+
url: jdbc:h2:mem:yappu;MODE=Oracle;DATABASE_TO_LOWER=TRUE;NON_KEYWORDS=VALUE
22+
username: sa
23+
password:
2324

2425
sql:
2526
init:
26-
# schema-locations: classpath:schema.sql
27-
# data-locations: classpath:data.sql
28-
mode: never
27+
mode: always
2928

3029
jpa:
3130
open-in-view: false
31+
database-platform: org.hibernate.dialect.OracleDialect
32+
hibernate:
33+
ddl-auto: none
34+
show-sql: true
35+
36+
h2:
37+
console:
38+
enabled: true
39+
path: /h2-console
3240

3341
logging:
3442
level:

src/main/resources/application-test.yaml

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,20 @@ spring:
55
enabled: true
66
docker:
77
compose:
8-
file: docker/docker-compose-test.yaml
9-
enabled: true
10-
lifecycle-management: start-and-stop
11-
stop:
12-
command: down
13-
timeout: 1m
14-
skip:
15-
in-tests: false
8+
enabled: false
169
datasource:
17-
url: jdbc:mysql://mysql:3306/yappu_world
18-
username: yapp
19-
password: yapp
10+
driver-class-name: org.h2.Driver
11+
url: jdbc:h2:mem:testdb;MODE=Oracle;DATABASE_TO_LOWER=TRUE;NON_KEYWORDS=VALUE
12+
username: sa
13+
password:
2014
sql:
2115
init:
2216
mode: always
17+
jpa:
18+
database-platform: org.hibernate.dialect.OracleDialect
19+
hibernate:
20+
ddl-auto: none
21+
show-sql: true
2322

2423
jwt:
2524
secret_key: ${DEV_JWT_SECRET_KEY}

0 commit comments

Comments
 (0)