-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #88 from HongDam-org/feat/redis-cache-lock
[FEAT] redis 을 통한 lock 적용과 api 캐싱 및 test container 적용
- Loading branch information
Showing
61 changed files
with
886 additions
and
202 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,25 +26,28 @@ jobs: | |
- name: Login to Docker Hub | ||
uses: docker/login-action@v1 | ||
with: | ||
username: ${{ secrets.DOCKERHUB_USERNAME }} | ||
password: ${{ secrets.DOCKERHUB_PASSWORD }} | ||
username: ${{ secrets.DOCKER_USERNAME }} | ||
password: ${{ secrets.DOCKER_PASSWORD }} | ||
|
||
- name: Apply Environment Variables | ||
run: | | ||
mkdir -p src/test/resources | ||
echo "${{ secrets.ENVIRONMENT }}" | base64 --decode > src/main/resources/application-env.yml | ||
find src | ||
mkdir -p src/main/resources | ||
echo "${{ secrets.ENVIRONMENT_YML }}" > src/test/resources/application-env.yml | ||
echo "${{ secrets.ENVIRONMENT_YML }}" > src/main/resources/application-env.yml | ||
echo "${{ secrets.STORAGE_JSON }}" > src/test/resources/engaged-shade-405207-b8ba9bb8a30f.json | ||
echo "${{ secrets.STORAGE_JSON }}" > src/main/resources/engaged-shade-405207-b8ba9bb8a30f.json | ||
- run: chmod +x gradlew | ||
- run: ./gradlew build -x test | ||
- run: ./gradlew build | ||
- run: ./gradlew jib | ||
|
||
- name: Test Coverage Report | ||
- name: Check test coverage | ||
id: jacoco | ||
uses: madrapps/[email protected] | ||
with: | ||
paths: ${{ github.workspace }}/build/reports/jacoco/test/jacocoTestReport.xml | ||
token: ${{ secrets.GITHUB_TOKEN }} | ||
title: "test coverage" | ||
min-coverage-overall: 60 | ||
min-coverage-changed-files: 60 | ||
paths: ${{ github.workspace }}/backend/build/reports/jacoco/test/jacocoTestReport.xml | ||
token: ${{ secrets.FLOWS_PAT }} | ||
title: "Test Coverage" | ||
min-coverage-overall: 50 | ||
min-coverage-changed-files: 50 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ | |
backend/src/main/resources/application-env.yml | ||
.env | ||
secret.yml | ||
data/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,3 +44,4 @@ out/ | |
|
||
*.html | ||
application-env.yml | ||
*.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
backend/src/main/java/com/twtw/backend/aspect/DistributedLockAspect.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package com.twtw.backend.aspect; | ||
|
||
import com.twtw.backend.global.lock.DistributedLock; | ||
import com.twtw.backend.utils.SpringELParser; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.aspectj.lang.ProceedingJoinPoint; | ||
import org.aspectj.lang.annotation.Around; | ||
import org.aspectj.lang.annotation.Aspect; | ||
import org.aspectj.lang.reflect.MethodSignature; | ||
import org.redisson.api.RLock; | ||
import org.redisson.api.RedissonClient; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.lang.reflect.Method; | ||
|
||
@Slf4j | ||
@Aspect | ||
@Component | ||
@RequiredArgsConstructor | ||
public class DistributedLockAspect { | ||
private static final String REDISSON_LOCK_PREFIX = "LOCK:"; | ||
private static final String INTERRUPTED_EXCEPTION = "INTERRUPTED EXCEPTION"; | ||
private static final String UNLOCK_EXCEPTION = "UNLOCK EXCEPTION"; | ||
|
||
private final RedissonClient redissonClient; | ||
private final TransactionAspect transactionAspect; | ||
private final SpringELParser springELParser; | ||
|
||
@Around("@annotation(com.twtw.backend.global.lock.DistributedLock)") | ||
public Object lock(final ProceedingJoinPoint joinPoint) throws Throwable { | ||
MethodSignature signature = (MethodSignature) joinPoint.getSignature(); | ||
Method method = signature.getMethod(); | ||
DistributedLock distributedLock = method.getAnnotation(DistributedLock.class); | ||
|
||
String key = | ||
REDISSON_LOCK_PREFIX | ||
+ springELParser.getDynamicValue( | ||
signature.getParameterNames(), | ||
joinPoint.getArgs(), | ||
distributedLock.name()); | ||
RLock rLock = redissonClient.getLock(key); | ||
|
||
try { | ||
boolean available = | ||
rLock.tryLock( | ||
distributedLock.waitTime(), | ||
distributedLock.leaseTime(), | ||
distributedLock.timeUnit()); | ||
if (!available) { | ||
return false; | ||
} | ||
return transactionAspect.proceed(joinPoint); | ||
} catch (final InterruptedException e) { | ||
log.error(INTERRUPTED_EXCEPTION, e); | ||
throw e; | ||
} finally { | ||
try { | ||
rLock.unlock(); | ||
} catch (final Exception e) { | ||
log.error(UNLOCK_EXCEPTION, e); | ||
} | ||
} | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
backend/src/main/java/com/twtw/backend/aspect/TransactionAspect.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.twtw.backend.aspect; | ||
|
||
import org.aspectj.lang.ProceedingJoinPoint; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.transaction.annotation.Propagation; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Component | ||
public class TransactionAspect { | ||
@Transactional(propagation = Propagation.REQUIRES_NEW) | ||
public Object proceed(final ProceedingJoinPoint joinPoint) throws Throwable { | ||
return joinPoint.proceed(); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
backend/src/main/java/com/twtw/backend/config/circuitbreaker/Resilience4jConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.twtw.backend.config.circuitbreaker; | ||
|
||
import org.springframework.boot.actuate.health.SimpleStatusAggregator; | ||
import org.springframework.boot.actuate.health.StatusAggregator; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@Configuration | ||
public class Resilience4jConfig { | ||
|
||
@Bean | ||
public StatusAggregator statusAggregator() { | ||
return new SimpleStatusAggregator(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.