-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
♻️ [REFACTOR] 테스트 스케줄링 동시성 문제 해결
- Loading branch information
Showing
7 changed files
with
61 additions
and
12 deletions.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
src/main/java/swm_nm/morandi/domain/testDuring/dataLoader/TestMapLoader.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,31 @@ | ||
package swm_nm.morandi.domain.testDuring.dataLoader; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.boot.CommandLineRunner; | ||
import org.springframework.stereotype.Component; | ||
import swm_nm.morandi.domain.member.entity.Member; | ||
import swm_nm.morandi.domain.member.repository.MemberRepository; | ||
import swm_nm.morandi.domain.testDuring.dto.TestCheckDto; | ||
import swm_nm.morandi.domain.testDuring.scheduler.TestMapManager; | ||
import swm_nm.morandi.domain.testInfo.entity.Tests; | ||
|
||
import java.util.List; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
public class TestMapLoader implements CommandLineRunner { | ||
|
||
private final MemberRepository memberRepository; | ||
|
||
private final TestMapManager testMapManager; | ||
@Override | ||
public void run(String... args) { | ||
List<Member> members = memberRepository.findAll(); | ||
members.stream().filter(member -> member.getCurrentTestId() != null) | ||
.filter(member -> member.getCurrentTestId() != -1) | ||
.map(member -> TestCheckDto.builder() | ||
.testId(member.getCurrentTestId()) | ||
.bojId(member.getBojId()) | ||
.build()).forEach(testMapManager::addTest); | ||
} | ||
} |
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 |
---|---|---|
|
@@ -9,5 +9,4 @@ | |
public class TestCheckDto { | ||
private Long testId; | ||
private String bojId; | ||
private Long testTypeId; | ||
} |
18 changes: 18 additions & 0 deletions
18
src/main/java/swm_nm/morandi/domain/testDuring/scheduler/TestMapManager.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,18 @@ | ||
package swm_nm.morandi.domain.testDuring.scheduler; | ||
|
||
import org.springframework.stereotype.Component; | ||
import swm_nm.morandi.domain.testDuring.dto.TestCheckDto; | ||
|
||
import java.util.HashMap; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
|
||
@Component | ||
public class TestMapManager { | ||
private final ConcurrentHashMap<Long, TestCheckDto> testMap = new ConcurrentHashMap<>(); | ||
public ConcurrentHashMap<Long, TestCheckDto> getTestMap() { | ||
return testMap; | ||
} | ||
public void addTest(TestCheckDto testCheckDto) { | ||
testMap.put(testCheckDto.getTestId(), testCheckDto); | ||
} | ||
} |
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
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