Skip to content

Commit

Permalink
fix: CircuitBreaker 테스트 시간 조정
Browse files Browse the repository at this point in the history
  • Loading branch information
This2sho committed Jun 15, 2024
1 parent 5567217 commit 1476691
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class CircuitBreakerAspectTest {

/**
* 요청 중 20%의 예외가 발생하면 api 요청 잠김
* 잠긴 후, 2초 후에 다시 요청보내지도록 reset
* 잠긴 후, 200ms 후에 다시 요청보내지도록 reset
*/
@Autowired
private CircuitBreakerTestService service;
Expand All @@ -41,20 +41,18 @@ class CircuitBreakerAspectTest {
}

@Test
void 서비스가_잠긴후_특정시간이_지나면_다시_요청을_보낼수있다() throws ExecutionException, InterruptedException {
void 서비스가_잠긴후_특정시간이_지나면_다시_요청을_보낼수있다() throws InterruptedException {
//given
for (int i = 0; i < 8; i++) {
service.call(() -> {});
}
for (int i = 0; i < 2; i++) {
service.call(() -> {throw new RuntimeException();});
}
ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
Thread.sleep(1000);

//when
ScheduledFuture<?> future = scheduler.schedule(() -> service.call(() -> isExecuted[1] = true), 2,
TimeUnit.SECONDS);
future.get();
service.call(() -> isExecuted[1] = true);

//then
Assertions.assertThat(isExecuted[1]).isTrue();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@
import com.parkingcomestrue.external.api.CircuitBreaker;
import java.util.concurrent.TimeUnit;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

@Component
public class CircuitBreakerTestService {

@CircuitBreaker(resetTime = 2, timeUnit = TimeUnit.SECONDS)
@CircuitBreaker(resetTime = 200, timeUnit = TimeUnit.MILLISECONDS)
public void call(Runnable runnable) {
runnable.run();
}
Expand Down

0 comments on commit 1476691

Please sign in to comment.