Skip to content
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
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Redis_project
## 4주차

커머스의 핵심 프로세스인 상품 조회 및 주문 과정에서 발생할 수 있는 동시성 이슈 해결 및 성능 개선을 경험하고, 안정성을 높이기 위한 방법을 배웁니다.
#### Jacoco Test Report

`build/jacocoTestReportHtml` 에 위치 <br>
![Jacoco 커버리지 리포트](docs/images/jacoco.png)
139 changes: 99 additions & 40 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,53 +1,112 @@
plugins {
id 'java'
id 'org.springframework.boot' version '3.4.3'
id 'io.spring.dependency-management' version '1.1.7'
id 'java'
id 'org.springframework.boot' version '3.4.3'
id 'io.spring.dependency-management' version '1.1.7'
id 'jacoco'
}

group = 'com.cinema'
version = '1.0.0'

allprojects {
bootJar{
enabled = false
}
repositories {
mavenCentral()
}

jar{
enabled = true
}
bootJar {
enabled = false
}

jar {
enabled = true
}
}

subprojects {
apply plugin: 'java'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'

java {
toolchain {
languageVersion = JavaLanguageVersion.of(17)
}
}

repositories {
mavenCentral()
}

dependencies {
implementation 'org.springframework.boot:spring-boot-starter'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
}

test {
useJUnitPlatform()
}

bootJar{
enabled = false
}

jar{
enabled = true
}
apply plugin: 'java'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'jacoco'

java {
toolchain {
languageVersion = JavaLanguageVersion.of(17)
}
}

dependencies {
implementation 'org.springframework.boot:spring-boot-starter'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
}

test {
useJUnitPlatform()
}

bootJar {
enabled = false
}

jar {
enabled = true
}
}

jacoco {
toolVersion = '0.8.12'
}

// 커버리지 결과를 리포트로 생성하는 작업
tasks.register('jacocoRootTestReport', JacocoReport) {
dependsOn subprojects.collect {
it.tasks.named('test')
}

// 서브프로젝트의 .exec 파일을 포함
executionData.from(fileTree(dir: '.', include: '**/build/jacoco/*.exec'))
executionData.from(fileTree(dir: '.', include: '**/**/build/jacoco/*.exec'))

reports {
xml.required = true
html.required = true
csv.required = false
html.outputLocation = file('build/jacocoTestReportHtml')
xml.outputLocation = file('build/reports/jacoco/test/jacocoTestReport.xml')
}

classDirectories.setFrom(files(subprojects.collect {
// 서브 프로젝트들의 컴파일된 클래스 파일이 저장되는 디렉토리
it.sourceSets.main.output
}))

finalizedBy 'jacocoTestVerification'
}

// 커버리지 측정을 위한 조건을 명시하는 task
tasks.register('jacocoTestVerification') {
dependsOn 'jacocoRootTestReport' // 리포트 생성 후 실행

doLast {
// 커버리지 검증 로직 추가
def coverageRules = [
[
enabled: true,
element: 'CLASS',
limits : [
[counter: 'LINE', value: 'COVEREDRATIO', minimum: 0.0],
[counter: 'METHOD', value: 'COVEREDRATIO', minimum: 0.0]
]
]
]
}
}

test.dependsOn 'jacocoRootTestReport'

tasks.withType(Test).configureEach {
useJUnitPlatform()
javaLauncher = javaToolchains.launcherFor {
languageVersion = JavaLanguageVersion.of(17)
}
}
3 changes: 3 additions & 0 deletions cinema-app-api/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ dependencies {

implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-validation'

implementation 'org.springframework.boot:spring-boot-starter-data-redis:3.4.0'
implementation 'org.springframework.boot:spring-boot-starter-aop'
}

bootJar {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.cinema.api.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.ClassPathResource;
import org.springframework.data.redis.core.script.DefaultRedisScript;

@Configuration
public class RateLimitScriptConfig {
@Bean(name = "searchRateLimitScript")
public DefaultRedisScript<Long> searchRateLimit() {
DefaultRedisScript<Long> redisScript = new DefaultRedisScript<>();
redisScript.setLocation(new ClassPathResource("scripts/rate-limit-search.lua"));
redisScript.setResultType(Long.class);
return redisScript;
}

@Bean(name = "reservationRateLimitScript")
public DefaultRedisScript<Long> reservationRateLimit() {
DefaultRedisScript<Long> redisScript = new DefaultRedisScript<>();
redisScript.setLocation(new ClassPathResource("scripts/rate-limit-reservation.lua"));
redisScript.setResultType(Long.class);
return redisScript;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.cinema.api.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;

@Configuration
public class RedisConfig {

@Bean
public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory connectionFactory) {
RedisTemplate<String, Object> template = new RedisTemplate<>();
template.setConnectionFactory(connectionFactory);
template.setKeySerializer(new StringRedisSerializer());
template.setValueSerializer(new GenericJackson2JsonRedisSerializer());
return template;
}

}

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading