Closed yummygyudon closed 6 days ago
OpenFeign - Test
์๋ํ๊ณ ์ ํ๋ ๋ฐฉ์์ ๋ฐ๋ก ์๋์ค ๊ฐ์ ์ฝ๋์ด๋
ํด๋น ์ฝ๋๋ Spring ์์์ @Retryable
๊ณผ @Recover
๋ฅผ ํตํ ๊ตฌํ์ ์ ํฉํ ๋ฐฉ์์ผ๋ก ๋ณด์ฌ์ง๋ค.
์ด์ ๋ ์ค์ ํ ์๋ฒ๋ก๋ถํฐ์ ๊ฒฐ๊ณผ์ ๋ฐ๋ฅธ ๋์ ์ฒ๋ฆฌ์ ๋ํด์ ํ
์คํธํ๋ ๊ฒ์ด ์๋
๋จ์ ํ์๋ง ์ง์ ํด์ฃผ๋ ๊ฒ์ด๊ธฐ์ ์๋ฏธ๊ฐ ์๋ ํ
์คํธ๊ฐ ๋ ์ ๋ฐ์ ์๋ค.
...
BDDMockito
.willThrow(new RuntimeException("", new Exception()))
.willThrow(new RuntimeException("", new Exception()))
.willReturn(expected)
.given(playgroundClient).getHealthStatus();
// when
Assertions.assertThatThrownBy(() -> playgroundClient.getHealthStatus())
.isInstanceOf(RetryableException.class);
// then
Mockito.verify(playgroundClient, Mockito.times(3)).getHealthStatus();
์ถํ ์๋์ ๊ฐ์ ๋ฐฉ์์ผ๋ก ๊ฒ์ฆํ ํ์๊ฐ ์์ต๋๋ค.
// ์ด์ ๊ฐ์ RetryableException์ ํ์ฉํ๊ธฐ ์ํด์ ์ค์ MockServer์์์ ํ
์คํธ๊ฐ ํ์ํ ๊ฒ์ผ๋ก ์์๋ฉ๋๋ค.
/*
WireMock(Open Feign) / MockRestServiceServer(RestTemplate) ์ ํ์ฉํ ํ
์คํธ
*/
// when - RetryableException์ ์ก๊ธฐ์ํด์ `thenThrow()`Mocking์ด ์๋ ์ค์ Feign ํธ์ถ์ ํตํด์ Retry์ ์ ๋ํด์ผํฉ๋๋ค.
Assertions.assertThatThrownBy(() -> playgroundClient.getHealthStatus())
.isInstanceOf(RetryableException.class);
// then
Mockito.verify(playgroundClient, Mockito.times(3)).getHealthStatus();
About Issue ๐
์ ์ญ์ ์ธ ์ดํ๋ฆฌ์ผ์ด์ ์ธ์ฆ/์ธ๊ฐ Filter๋ฅผ ๊ตฌ์ถํ๊ณ ๊ธฐ๋ณธ์ ์ธ ์๋ฒ๊ฐ ํต์ ์ ์ฌ์ฉํ client๋ฅผ ๊ตฌํํฉ๋๋ค.
Progress โ๏ธ
support
moduleinfra
module