Skip to content
Merged
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
9 changes: 0 additions & 9 deletions .github/workflows/yappu-world-ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,6 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: Set up Docker
run: |
sudo apt-get update
sudo apt-get install docker-compose

- name: Start MySQL with Docker Compose
run: |
docker-compose -f docker/docker-compose-test.yaml up -d

- name: Set up JDK 21
uses: actions/setup-java@v4
with:
Expand Down
8 changes: 8 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ dependencies {
runtimeOnly("com.mysql:mysql-connector-j")
runtimeOnly("com.oracle.database.jdbc:ojdbc11")
runtimeOnly("com.oracle.database.security:oraclepki:23.5.0.24.07")
runtimeOnly("com.h2database:h2")
implementation("org.springframework.boot:spring-boot-starter-data-jpa")
implementation("com.linecorp.kotlin-jdsl:jpql-dsl:3.5.5")
implementation("com.linecorp.kotlin-jdsl:jpql-render:3.5.5")
Expand Down Expand Up @@ -85,6 +86,13 @@ ktlint {
tasks {
test {
useJUnitPlatform()
testLogging {
events("passed", "skipped", "failed")
showExceptions = true
showCauses = true
showStackTraces = true
exceptionFormat = org.gradle.api.tasks.testing.logging.TestExceptionFormat.FULL
}
}
bootJar {
archiveBaseName = "yappu-world"
Expand Down
27 changes: 14 additions & 13 deletions docker/docker-compose-local.yaml
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
name: yappu-world-server

services:
mysql:
image: mysql:8.1
oracle:
image: gvenzl/oracle-xe:21-slim-faststart
environment:
MYSQL_DATABASE: yappu_world
MYSQL_USER: yapp
MYSQL_PASSWORD: yapp
MYSQL_ROOT_PASSWORD: yapp
ORACLE_PASSWORD: yapp1234
APP_USER: yapp
APP_USER_PASSWORD: yapp1234
volumes:
- yappu_mysql_data:/var/lib/mysql
- yappu_oracle_data:/opt/oracle/oradata
ports:
- '3306:3306'
- '1521:1521'
restart: always
command:
- --character-set-server=utf8mb4
- --collation-server=utf8mb4_unicode_ci
- --skip-character-set-client-handshake
healthcheck:
test: ["CMD-SHELL", "healthcheck.sh"]
interval: 10s
timeout: 5s
retries: 30
start_period: 60s

volumes:
yappu_mysql_data:
yappu_oracle_data:
24 changes: 12 additions & 12 deletions docker/docker-compose-test.yaml
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
services:
mysql:
image: mysql:8.1
oracle:
image: gvenzl/oracle-xe:21-slim-faststart
environment:
MYSQL_DATABASE: yappu_world
MYSQL_USER: yapp
MYSQL_PASSWORD: yapp
MYSQL_ROOT_PASSWORD: yapp
ORACLE_PASSWORD: test1234
APP_USER: testuser
APP_USER_PASSWORD: test1234
ports:
- '3306:3306'
restart: always
command:
- --character-set-server=utf8mb4
- --collation-server=utf8mb4_unicode_ci
- --skip-character-set-client-handshake
- '1521:1521'
healthcheck:
test: ["CMD-SHELL", "healthcheck.sh"]
interval: 10s
timeout: 5s
retries: 30
start_period: 60s
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import co.yappuworld.global.exception.BusinessException
import co.yappuworld.operation.client.dto.param.GenerationActivationControlResult
import co.yappuworld.operation.domain.GenerationEntity
import co.yappuworld.operation.domain.OperationError
import co.yappuworld.operation.infrastructure.GenerationFindService
import co.yappuworld.operation.infrastructure.GenerationRepository
import io.github.oshai.kotlinlogging.KotlinLogging
import org.springframework.data.repository.findByIdOrNull
Expand All @@ -14,6 +15,7 @@ private val logger = KotlinLogging.logger { }

@Component
class GenerationActiveStateManager(
private val generationFindService: GenerationFindService,
private val generationRepository: GenerationRepository
) {

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

private fun deactivateGeneration(targetGenerationValue: Int? = null): Int? {
if (!generationRepository.existsGenerationByIsActiveIsTrue()) return null
if (!generationFindService.existsActiveGeneration()) return null

val activeGenerations = generationRepository.findAllByIsActiveIsTrue()
val activeGenerations = generationFindService.findAllActiveGeneration()
checkDeactivatingConsistency(activeGenerations, targetGenerationValue)

return activeGenerations
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,21 @@ class GenerationFindService(

fun existsGeneration(value: Int): Boolean = generationRepository.existsById(value)

fun existsActiveGeneration(): Boolean =
generationRepository
.findAll(limit = 1) {
select(intLiteral(1))
.from(entity(GenerationEntity::class))
.where(path(GenerationEntity::isActive).equal(true))
}.isNotEmpty()

fun findGenerations(values: List<Int>): List<GenerationEntity> = generationRepository.findAllByValueIn(values)

fun findAllActiveGeneration(): List<GenerationEntity> =
generationRepository
.findAll {
select(entity(GenerationEntity::class))
.from(entity(GenerationEntity::class))
.where(path(GenerationEntity::isActive).equal(true))
}.filterNotNull()
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
package co.yappuworld.operation.infrastructure

import co.yappuworld.operation.domain.GenerationEntity
import com.linecorp.kotlinjdsl.support.spring.data.jpa.repository.KotlinJdslJpqlExecutor
import org.springframework.data.jpa.repository.JpaRepository

interface GenerationRepository : JpaRepository<GenerationEntity, Int> {

fun existsGenerationByIsActiveIsTrue(): Boolean
interface GenerationRepository :
JpaRepository<GenerationEntity, Int>,
KotlinJdslJpqlExecutor {

fun getGenerationOrNullByIsActiveIsTrue(): GenerationEntity?

fun findAllByIsActiveIsTrue(): List<GenerationEntity>

fun findAllByValueIn(values: List<Int>): List<GenerationEntity>
}
28 changes: 14 additions & 14 deletions src/main/resources/application-local.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,28 @@ spring:
docker:
compose:
enabled: false
service: yappu-world-server
lifecycle-management: none
# stop:
# command: down
# timeout: 1m
skip:
in-tests: false
file: docker/docker-compose-local.yaml

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

sql:
init:
# schema-locations: classpath:schema.sql
# data-locations: classpath:data.sql
mode: never
mode: always

jpa:
open-in-view: false
database-platform: org.hibernate.dialect.OracleDialect
hibernate:
ddl-auto: none
show-sql: true

h2:
console:
enabled: true
path: /h2-console

logging:
level:
Expand Down
21 changes: 10 additions & 11 deletions src/main/resources/application-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,20 @@ spring:
enabled: true
docker:
compose:
file: docker/docker-compose-test.yaml
enabled: true
lifecycle-management: start-and-stop
stop:
command: down
timeout: 1m
skip:
in-tests: false
enabled: false
datasource:
url: jdbc:mysql://mysql:3306/yappu_world
username: yapp
password: yapp
driver-class-name: org.h2.Driver
url: jdbc:h2:mem:testdb;MODE=Oracle;DATABASE_TO_LOWER=TRUE;NON_KEYWORDS=VALUE
username: sa
password:
sql:
init:
mode: always
jpa:
database-platform: org.hibernate.dialect.OracleDialect
hibernate:
ddl-auto: none
show-sql: true

jwt:
secret_key: ${DEV_JWT_SECRET_KEY}
Expand Down
Loading