-
Notifications
You must be signed in to change notification settings - Fork 0
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
[Test] Redis 분산 락 검증 테스트
- Loading branch information
Showing
4 changed files
with
99 additions
and
29 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
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
71 changes: 71 additions & 0 deletions
71
src/test/java/com/fc/mini3server/service/ScheduleServiceTest.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,71 @@ | ||
package com.fc.mini3server.service; | ||
|
||
import com.fc.mini3server.domain.Work; | ||
import com.fc.mini3server.repository.WorkRepository; | ||
import com.querydsl.jpa.impl.JPAQueryFactory; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import javax.persistence.EntityManager; | ||
import java.util.List; | ||
import java.util.concurrent.CountDownLatch; | ||
import java.util.concurrent.ExecutorService; | ||
import java.util.concurrent.Executors; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
|
||
@SpringBootTest | ||
@Transactional | ||
@DisplayName("스케줄 서비스 테스트") | ||
public class ScheduleServiceTest { | ||
|
||
@Autowired | ||
EntityManager em; | ||
@Autowired | ||
JPAQueryFactory queryFactory; | ||
@Autowired | ||
ScheduleService scheduleService; | ||
@Autowired | ||
AdminService adminService; | ||
@Autowired | ||
WorkRepository workRepository; | ||
|
||
@Test | ||
@DisplayName("레디스 분산 락을 구현 후 동시성 이슈 테스트") | ||
public void testStartWorkUsingRedisWithLock() throws InterruptedException { | ||
Long userId = 142L; | ||
int threadCnt = 10; | ||
ExecutorService service = Executors.newFixedThreadPool(threadCnt); | ||
CountDownLatch latch = new CountDownLatch(threadCnt); | ||
|
||
for (int i=0; i<threadCnt; i++) { | ||
service.execute(() -> { | ||
try { | ||
scheduleService.startWorkUsingRedis(userId); | ||
} finally { | ||
latch.countDown(); | ||
} | ||
}); | ||
} | ||
System.out.println("ON EXECUTE DONE"); | ||
|
||
latch.await(); | ||
service.shutdown(); | ||
|
||
List<Work> works = workRepository.findByUserId(userId); | ||
if (works == null) { | ||
System.out.println("NULL"); | ||
|
||
} | ||
int expectedCnt = 1; | ||
|
||
assertThat(works.size()).isEqualTo(expectedCnt); | ||
} | ||
|
||
|
||
|
||
} |