|
1 | 1 | package io.f1.backend.domain.game.app; |
2 | 2 |
|
3 | | -import static org.assertj.core.api.Assertions.assertThat; |
4 | 3 | import static org.mockito.Mockito.verify; |
5 | 4 | import static org.mockito.Mockito.when; |
6 | 5 |
|
7 | | -import io.f1.backend.domain.game.dto.request.RoomValidationRequest; |
8 | 6 | import io.f1.backend.domain.game.model.GameSetting; |
9 | 7 | import io.f1.backend.domain.game.model.Player; |
10 | 8 | import io.f1.backend.domain.game.model.Room; |
|
17 | 15 | import io.f1.backend.domain.user.dto.UserPrincipal; |
18 | 16 | import io.f1.backend.domain.user.entity.User; |
19 | 17 | import io.f1.backend.global.util.SecurityUtils; |
20 | | -import java.lang.reflect.Field; |
21 | | -import java.time.LocalDateTime; |
22 | | -import java.util.ArrayList; |
23 | | -import java.util.Collections; |
24 | | -import java.util.List; |
25 | | -import java.util.Optional; |
26 | | -import java.util.concurrent.CountDownLatch; |
27 | | -import java.util.concurrent.ExecutorService; |
28 | | -import java.util.concurrent.Executors; |
| 18 | + |
29 | 19 | import lombok.extern.slf4j.Slf4j; |
| 20 | + |
30 | 21 | import org.junit.jupiter.api.AfterEach; |
31 | 22 | import org.junit.jupiter.api.BeforeEach; |
32 | 23 | import org.junit.jupiter.api.DisplayName; |
|
38 | 29 | import org.springframework.context.ApplicationEventPublisher; |
39 | 30 | import org.springframework.security.core.context.SecurityContextHolder; |
40 | 31 |
|
| 32 | +import java.lang.reflect.Field; |
| 33 | +import java.time.LocalDateTime; |
| 34 | +import java.util.ArrayList; |
| 35 | +import java.util.Collections; |
| 36 | +import java.util.List; |
| 37 | +import java.util.Optional; |
| 38 | +import java.util.concurrent.CountDownLatch; |
| 39 | +import java.util.concurrent.ExecutorService; |
| 40 | +import java.util.concurrent.Executors; |
| 41 | + |
41 | 42 | @Slf4j |
42 | 43 | @ExtendWith(MockitoExtension.class) |
43 | 44 | class RoomServiceTests { |
@@ -72,45 +73,46 @@ void afterEach() { |
72 | 73 | SecurityContextHolder.clearContext(); |
73 | 74 | } |
74 | 75 |
|
75 | | -// @Test |
76 | | -// @DisplayName("enterRoom_동시성_테스트") |
77 | | -// void enterRoom_synchronized() throws Exception { |
78 | | -// Long roomId = 1L; |
79 | | -// Long quizId = 1L; |
80 | | -// Long playerId = 1L; |
81 | | -// int maxUserCount = 5; |
82 | | -// String password = "123"; |
83 | | -// boolean locked = true; |
84 | | -// |
85 | | -// Room room = createRoom(roomId, playerId, quizId, password, maxUserCount, locked); |
86 | | -// |
87 | | -// when(roomRepository.findRoom(roomId)).thenReturn(Optional.of(room)); |
88 | | -// |
89 | | -// int threadCount = 10; |
90 | | -// ExecutorService executorService = Executors.newFixedThreadPool(threadCount); |
91 | | -// CountDownLatch countDownLatch = new CountDownLatch(threadCount); |
92 | | -// RoomValidationRequest roomValidationRequest = new RoomValidationRequest(roomId, password); |
93 | | -// |
94 | | -// for (int i = 1; i <= threadCount; i++) { |
95 | | -// User user = createUser(i); |
96 | | -// when(userRoomRepository.getRoomId(user.getId())).thenReturn(null); |
97 | | -// executorService.submit( |
98 | | -// () -> { |
99 | | -// try { |
100 | | -// SecurityUtils.setAuthentication(user); |
101 | | -// |
102 | | -// roomService.enterRoom(roomValidationRequest); |
103 | | -// } catch (Exception e) { |
104 | | -// //e.printStackTrace(); |
105 | | -// } finally { |
106 | | -// SecurityContextHolder.clearContext(); |
107 | | -// countDownLatch.countDown(); |
108 | | -// } |
109 | | -// }); |
110 | | -// } |
111 | | -// countDownLatch.await(); |
112 | | -// assertThat(room.getCurrentUserCnt()).isEqualTo(room.getRoomSetting().maxUserCount()); |
113 | | -// } |
| 76 | + // @Test |
| 77 | + // @DisplayName("enterRoom_동시성_테스트") |
| 78 | + // void enterRoom_synchronized() throws Exception { |
| 79 | + // Long roomId = 1L; |
| 80 | + // Long quizId = 1L; |
| 81 | + // Long playerId = 1L; |
| 82 | + // int maxUserCount = 5; |
| 83 | + // String password = "123"; |
| 84 | + // boolean locked = true; |
| 85 | + // |
| 86 | + // Room room = createRoom(roomId, playerId, quizId, password, maxUserCount, locked); |
| 87 | + // |
| 88 | + // when(roomRepository.findRoom(roomId)).thenReturn(Optional.of(room)); |
| 89 | + // |
| 90 | + // int threadCount = 10; |
| 91 | + // ExecutorService executorService = Executors.newFixedThreadPool(threadCount); |
| 92 | + // CountDownLatch countDownLatch = new CountDownLatch(threadCount); |
| 93 | + // RoomValidationRequest roomValidationRequest = new RoomValidationRequest(roomId, |
| 94 | + // password); |
| 95 | + // |
| 96 | + // for (int i = 1; i <= threadCount; i++) { |
| 97 | + // User user = createUser(i); |
| 98 | + // when(userRoomRepository.getRoomId(user.getId())).thenReturn(null); |
| 99 | + // executorService.submit( |
| 100 | + // () -> { |
| 101 | + // try { |
| 102 | + // SecurityUtils.setAuthentication(user); |
| 103 | + // |
| 104 | + // roomService.enterRoom(roomValidationRequest); |
| 105 | + // } catch (Exception e) { |
| 106 | + // //e.printStackTrace(); |
| 107 | + // } finally { |
| 108 | + // SecurityContextHolder.clearContext(); |
| 109 | + // countDownLatch.countDown(); |
| 110 | + // } |
| 111 | + // }); |
| 112 | + // } |
| 113 | + // countDownLatch.await(); |
| 114 | + // assertThat(room.getCurrentUserCnt()).isEqualTo(room.getRoomSetting().maxUserCount()); |
| 115 | + // } |
114 | 116 |
|
115 | 117 | @Test |
116 | 118 | @DisplayName("exitRoom_동시성_테스트") |
|
0 commit comments