-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: implement dividend scheduler #11
Conversation
|
||
@SpringBootTest | ||
@TestPropertySource(properties = { "spring.config.location=classpath:application-test.yml" }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ActiveProfiles("test")
이렇게도 사용 가능해요!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
오 이 부분 처음 알았네요!! 더 간결해서 말씀해주신 방식대로 쓰는게 나을거 같아요!
@@ -2,8 +2,10 @@ | |||
|
|||
import org.junit.jupiter.api.Test; | |||
import org.springframework.boot.test.context.SpringBootTest; | |||
import org.springframework.test.context.TestPropertySource; | |||
|
|||
@SpringBootTest |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
테스트 로직을 보면 @SpringBootTest
를 사용하지 않아도 될 것 같은데 단위테스트를 사용하는건 어떨까요~?
추가로 스케줄러 메서드 직접 호출해서 로직에 대한 테스트도 하면 좋을 것 같아요!!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
스케쥴러가 원하는 주기에 잘 동작하는지 확인하려면 @SpringBootTest
애노테이션을 붙여야 되더라구요...?? 그래서 붙였어요!
스케쥴러 메서드 로직 테스트도 추가하면 좋을 거 같아요! 추가해볼게요!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
흠 그렇다면 @Scheduled
어노테이션을 테스트하는 것 밖에 안될 것 같아서 의미가 있을지 고민이 되네용 😭
어떻게 생각하시나요?!!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
사실 저도 그 부분이 고민되서 어떻게 짜야 할지 고민이 있었는데, 밑에 달아주신 코멘트와 종합해서 생각해보니, FmpClient 로직 테스트, FmpClient를 mock으로 생성하여 스케쥴러 로직 테스트로 짜면 좋을 거 같아요! 그렇게 수정해볼게요!!
*/ | ||
@Scheduled(cron = "${schedules.cron.dividend}", zone = "America/New_York") | ||
public void run() { | ||
WebClient client = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FMP API 호출 및 결과를 가져오는 부분은 따로 클래스로 빼서 역할을 나누는 건 어떨까요?
인터페이스(ex.FinancialCllient)를 따로 두고 그 아래에 FmpClient 를 만들면 SRP 를 좀 더 잘 지킬 수 있을 것 같아요!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
오 그렇게 분리하면 테스트 작성도 더 용이할거 같네요! 나누는게 맞는거 같습니다!
@Value("${fmp.key}") | ||
private String FMP_API_KEY; | ||
private final String FMP_API_BASE_URL = "https://financialmodelingprep.com/api/v3"; | ||
private final String FMP_API_STOCK_DIVIDEND_CALENDAR_POSTFIX = "/stock_dividend_calendar"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
URL 자체도 설정파일로 빼는 것은 어떤가요? 추후 API 도메인 또는 path가 바뀌었을 때 대처가 좀 더 쉬울 것 같아요!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
아 그러네요 API 도메인이 바뀌는거까지는 생각하지 못했는데 그게 더 관리가 편할거 같네요!!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
구현 고생하셨습니다 👍👍
코멘트 남겨놓았는데 함께 고민해보면 좋을 것 같아요!!
import static org.mockito.Mockito.verify; | ||
|
||
@SpringBootTest | ||
@Transactional |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
테스트코드에서 @transactional
을 추가하신 이유가 궁금해요! 👀
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
테스트 코드에서 DB를 조작하는 코드를 수행할 때 @Transactional
애노테이션을 추가해야 테스트 코드가 수행되고 DB가 롤백되는 것으로 알고 있어요!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이 부분은 제 PR 에서 얘기하는걸로 하시죠! 👀
#12 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FmpClient의 경우 FMP API로부터 받은 응답에 대한 값을 제공하는 역할만 하고 스케줄러에서 스케줄링 로직을 구현하는 방식으로 책임을 나누는 것도 좋아보여요! (테스트시 FmpClient 만 모킹하고 스케줄러 로직에 대한 검증만 가능하도록..?)
추후 다른 OPEN API 로 갈아탈 가능성도 있기 때문에 아래와 같이 구현체만 바꾸는 것이 가능하도록 짜면 더 좋을 것 같아요 😸
FinancialClient (Interface)
- FmpFinancialClient
- OtherFinancialClient
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
앗 그러네요 API가 바뀔 가능성은 생각하지 못했네요...!! 해당 방향으로 수정해볼게요!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
고생하셨습니다 🙌🏻
Issue Number
close: #8
작업 내역
변경사항
PR 특이 사항