-
Notifications
You must be signed in to change notification settings - Fork 6
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
[STEP3-1] shorten url에 expiredAt 추가 #35
Conversation
// Authorization | ||
EXPIRED_SHORTEN_URL(HttpStatus.UNAUTHORIZED, "만료된 단축 URL입니다."), |
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 에 접근할 수 없다.
라는 건 비즈니스 정책이라고 생각 합니다.
|
||
@Component | ||
@Slf4j | ||
@EnableScheduling |
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.
스케줄러의 위험성은 무엇이 있을까요?
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이 존재하는 여부만 확인하는 것으로 변경하였습니다.
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대면 어떻게 되나요?
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개일 경우 스케줄링 작업이 중복 실행될 수 있습니다. 하나의 서버에서만 작업을 처리하도록 설정이 필요할 것 같습니다.
try { | ||
urlShortenService.deleteByExpiredAtBefore(LocalDateTime.now()); | ||
} catch (Exception e) { | ||
log.error("{} - Error occurred: {}", batchName, e.getMessage(), e); | ||
} |
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.
nit
저는 코드 중간에 try-catch 사용을 를 별로 좋아하지 않습니다.
- Exception 을 catch 하는거면 global handler 에서 하는 것과 어떤 차이가 있나요?
|
||
import java.time.LocalDateTime; | ||
|
||
public class UrlShorten { |
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.
getter 밖에 없다면 record 를 사용할 수도 있지 않을까요?
public class UrlShorten { | ||
|
||
private String originUrl; | ||
private String shortenUrlKey; |
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.
nit
id, key
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.
id나 key 필드를 추가해서 관리하라는 말씀이실까요?
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.
대리키를 두는 방법도 있다는 뜻 입니다. 사용할지 여부는 개발자의 판단 입니다. nit
@@ -22,13 +25,26 @@ public UrlShortenService(UrlShortenValidator urlShortenValidator, | |||
public String createShortenUrl(String originUrl) { | |||
urlShortenValidator.validateUrl(originUrl); | |||
String shortenUrlKey = UrlShortener.shorten(); | |||
urlShortenRepository.save(shortenUrlKey, originUrl); | |||
|
|||
UrlShorten urlShorten = new UrlShorten(originUrl, shortenUrlKey, LocalDateTime.now().plusMinutes(1)); |
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분이 되면 어떻게 되나요?
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.
request에서 만료시간을 받거나 yml로 관리하는 방법으로 변경할 것 같습니다.
if (urlShorten.getExpiredAt().isBefore(LocalDateTime.now())) { | ||
throw new UnAuthorizedException(ErrorCode.EXPIRED_SHORTEN_URL); | ||
} |
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.
스케줄러의 로직을 보면 hard delete 되고 있습니다.
저는 이런 경우에는 존재만 하면 정상이라고 간주하곤 합니다.
@Test | ||
void 잘못된_url일_경우_예외가_발생한다() { | ||
String originUrl = "ftp://www.google.com"; | ||
String originUrl = "htp://www.google.com"; |
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.
ftp 형태는 테스트 대상에서 배제 했나요?
- fyi.
@ParameterizedTest
, Faker
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.
ftp의 경우 예외 케이스가 아니여서 수정하였습니다.
ParameterizedTest를 추가하였습니다.
|
||
public void setExpirationTime(int expirationTime) { | ||
this.expirationTime = expirationTime; | ||
} |
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.
fyi. duration
Arguments.of(Named.of("http가 누락된 URL", "://google.com"), ValidationException.class, ErrorCode.INVALID_URL_FORMAT.getMessage()), | ||
Arguments.of(Named.of("잘못된 프로토콜", "htp://example.com"), ValidationException.class, ErrorCode.INVALID_URL_FORMAT.getMessage()), | ||
Arguments.of(Named.of("차단된 URL", "https://www.example.com"), ValidationException.class, ErrorCode.BLOCKED_URL.getMessage()) | ||
); | ||
} |
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.
nit
저는 MethodSource 는 잘 안씁니다. 너무 장황해져서 입니다. 주로 CsvSource 정도만 씁니다.
|
||
@Component | ||
@Slf4j | ||
@EnableScheduling |
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대면 어떻게 되나요?
public class UrlShorten { | ||
|
||
private String originUrl; | ||
private String shortenUrlKey; |
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.
대리키를 두는 방법도 있다는 뜻 입니다. 사용할지 여부는 개발자의 판단 입니다. nit
shorten url에 expiredAt 추가