-
Notifications
You must be signed in to change notification settings - Fork 3
feat : 추천 동시성 문제 해결 및 테스트 완료 #83
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
- 추천에서 발생할 수 있는 연속 요청(따닥 문제) 문제는 따로 락을 걸지 않고, 유니크 제약조건을 걸어서 해결함 - 이 문제의 경우 여러 스레드가 하나의 공유 자원을 두고 경쟁(race condition)하는 케이스가 아니기 때문 - 단순 insert는 유니크 제약조건으로 충분히 제어 가능 - DataIntegrityViolationException 예외 처리 코드 추가
Walkthrough이번 변경에서는 투표 도메인 서비스에 중복 투표 시 예외 처리를 추가하고, 동시성 상황에서 투표 데이터 무결성을 검증하는 통합 테스트가 새로 도입되었습니다. 또한, 테스트 환경을 위한 Spring Boot 설정 파일이 추가되고, 불필요한 주석이 제거되었습니다. Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant DiscussionVoteService
participant BaseVoteDomainService
participant Database
User->>DiscussionVoteService: manageVote(UP, userId, discussionId)
DiscussionVoteService->>BaseVoteDomainService: manageVote(...)
BaseVoteDomainService->>Database: save(vote)
alt 정상 저장
Database-->>BaseVoteDomainService: 저장 성공
BaseVoteDomainService-->>DiscussionVoteService: 완료
else 중복 투표 (DataIntegrityViolationException)
Database-->>BaseVoteDomainService: 예외 발생
BaseVoteDomainService->>BaseVoteDomainService: 예외 로그 기록 (중복 투표 시도)
BaseVoteDomainService-->>DiscussionVoteService: 처리 계속
end
DiscussionVoteService-->>User: 완료 응답
Possibly related PRs
Suggested reviewers
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
⏰ Context from checks skipped due to timeout of 90000ms (1)
✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
🧹 Nitpick comments (1)
src/test/java/org/ezcode/codetest/application/community/service/DiscussionVoteServiceConcurrencyTest.java (1)
85-85: Thread.sleep 사용을 더 안정적인 방법으로 교체하드코딩된
Thread.sleep(500)은 테스트를 불안정하게 만들 수 있습니다. 모든 스레드가 완료된 후 추가 대기가 필요한 이유를 명확히 하거나, 더 안정적인 동기화 방법을 사용하는 것을 권장합니다.비동기 작업 완료를 기다려야 한다면 다음과 같은 방법을 고려해보세요:
-Thread.sleep(500); +// 필요한 경우에만 사용하고, 이유를 명시 +// 예: DB 트랜잭션 완료 대기가 필요한 경우또는
@DirtiestContext나 적절한 트랜잭션 관리를 통해 해결할 수 있습니다.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
src/main/java/org/ezcode/codetest/domain/community/repository/BaseVoteRepository.java(0 hunks)src/main/java/org/ezcode/codetest/domain/community/service/BaseVoteDomainService.java(2 hunks)src/test/java/org/ezcode/codetest/application/community/service/DiscussionVoteServiceConcurrencyTest.java(1 hunks)src/test/resources/application-test.properties(1 hunks)
💤 Files with no reviewable changes (1)
- src/main/java/org/ezcode/codetest/domain/community/repository/BaseVoteRepository.java
⏰ Context from checks skipped due to timeout of 90000ms (1)
- GitHub Check: build
🔇 Additional comments (4)
src/main/java/org/ezcode/codetest/domain/community/service/BaseVoteDomainService.java (1)
10-10: 로깅 관련 의존성 추가 확인됨DataIntegrityViolationException 처리를 위한 import와 @slf4j 어노테이션이 적절히 추가되었습니다.
Also applies to: 13-13, 15-15
src/test/resources/application-test.properties (1)
1-108: 테스트 환경 설정이 포괄적으로 잘 구성됨모든 필요한 외부 시스템 연동 설정이 환경변수를 통해 적절히 구성되어 있습니다. 특히 동시성 테스트를 위한 실제 데이터베이스 연결 설정이 포함되어 있어 테스트 목적에 부합합니다.
몇 가지 확인사항:
- JPA의
ddl-auto=update설정이 테스트에 적합한지 검토 (create-drop을 고려할 수도 있음)- 디버그 로깅이 많이 활성화되어 있어 테스트 성능에 영향을 줄 수 있음
src/test/java/org/ezcode/codetest/application/community/service/DiscussionVoteServiceConcurrencyTest.java (2)
51-97: 동시성 테스트 로직이 잘 구현됨CountDownLatch를 사용한 동기화와 예외 처리가 적절하게 구현되어 있습니다. 특히 DataIntegrityViolationException과 ObjectOptimisticLockingFailureException을 모두 고려한 점이 좋습니다.
테스트가 데이터 정합성을 올바르게 검증하고 있으며, 동시성 문제 해결 방식이 효과적으로 테스트되고 있습니다.
65-65: ```shell
#!/bin/bashDiscussionVoteService 클래스 내 manageVoteOnDiscussion 메서드 시그니처 확인
rg -n "manageVoteOnDiscussion" -n src
</details> </blockquote></details> </details> <!-- This is an auto-generated comment by CodeRabbit for review status -->
src/main/java/org/ezcode/codetest/domain/community/service/BaseVoteDomainService.java
Show resolved
Hide resolved
.../org/ezcode/codetest/application/community/service/DiscussionVoteServiceConcurrencyTest.java
Show resolved
Hide resolved
- 동시성 문제 해결이 된 것을 확인했으므로 더 이상 사용되지 않음
thezz9
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
좋은 해결 방법인 거 같습니다
작업 내용
참고 사항
코드 리뷰 전 확인 체크리스트
type :)Summary by CodeRabbit
버그 수정
테스트
환경설정