11package com .somemore .volunteer .service ;
22
33import static org .assertj .core .api .Assertions .assertThat ;
4+ import static org .assertj .core .api .Assertions .assertThatThrownBy ;
5+ import static org .mockito .ArgumentMatchers .any ;
6+ import static org .mockito .ArgumentMatchers .anyLong ;
7+ import static org .mockito .BDDMockito .given ;
48
59import com .somemore .support .IntegrationTestSupport ;
610import com .somemore .volunteer .domain .NEWVolunteer ;
1216import org .junit .jupiter .api .AfterEach ;
1317import org .junit .jupiter .api .DisplayName ;
1418import org .junit .jupiter .api .Test ;
19+ import org .redisson .api .RLock ;
1520import org .springframework .beans .factory .annotation .Autowired ;
21+ import org .springframework .boot .test .mock .mockito .MockBean ;
1622
1723class UpdateVolunteerLockServiceTest extends IntegrationTestSupport {
1824
@@ -22,6 +28,9 @@ class UpdateVolunteerLockServiceTest extends IntegrationTestSupport {
2228 @ Autowired
2329 private NEWVolunteerJpaRepository volunteerRepository ;
2430
31+ @ MockBean
32+ private RLock lock ;
33+
2534 @ AfterEach
2635 void tearDown () {
2736 volunteerRepository .deleteAllInBatch ();
@@ -79,6 +88,24 @@ void updateVolunteerStatsWithConcurrency() throws InterruptedException {
7988 assertThat (find .getTotalVolunteerHours ()).isEqualTo (hours * threadCnt );
8089 }
8190
91+ @ DisplayName ("봉사활동 정보 업데이트 중 인터럽트 예외 발생" )
92+ @ Test
93+ void UpdateVolunteerStats_InterruptedException () throws InterruptedException {
94+ // given
95+ UUID id = UUID .randomUUID ();
96+ int hours = 5 ;
97+
98+ given (lock .tryLock (anyLong (), anyLong (), any ()))
99+ .willThrow (new InterruptedException ());
100+
101+ // when
102+ // then
103+ assertThatThrownBy (
104+ () -> updateVolunteerLockService .updateVolunteerStats (id , hours ))
105+ .isInstanceOf (RuntimeException .class );
106+
107+ }
108+
82109 private static NEWVolunteer createVolunteer () {
83110 UUID userId = UUID .randomUUID ();
84111 return NEWVolunteer .createDefault (userId );
0 commit comments