본문 바로가기

전체글139

WebClient 사용할때 주의 (6편) WebClient 로 요청을 보내고 받은 응답 객체는 아래와 같다. 이때 message 값이 nullable 하다고 해보자. public class ResponseDto { private String id; @Nullable private String message; public String getMessage() { return message; } } ResponseDto 로 deserialize 한 후에 map 연산자를 이용해 message 를 가져오면 NPE가 발생한다. webClientBuilder ... 생략 .retrieve() .bodyToMono(ResponseDto.class) .map(responseDto -> responseDto.getMessage()) .onErrorResume(t.. 2021. 12. 15.
fixture monkey 로 예외 발생 테스트 fixture monkey 는 테스트 객체 라이브러리다. fixture 를 자동으로 만들어준다. 사용 예제를 하나 보자. 아래 Order 객체가 있다. import lombok.Data; @Data // lombok getter, setter public class Order { @NotNull private Long id; @NotBlank private String orderNo; @Size(min = 2, max = 10) private String productName; @Min(1) @Max(100) private int quantity; @Min(0) private long price; @Size(max = 3) private List items = new ArrayList(); @PastOr.. 2021. 12. 15.
[구현] 자물쇠와 열쇠 2020 카카오 신입 공채 문제다. 먼저 2차원 배열을 시계방향으로 90도 회전시키는 함수다. def rotate_a_matrix_by_90_degree(a): n = len(a) # 행 길이 계산 m = len(a[0]) # 열 길이 계산 # 90도 돌리기 위해서 n, m 위치 변경 result = [[0] * n for _ in range(m)] for i in range(n): for j in range(m): result[j][n-i-1] = a[i][j] return result a = [[0,0], [1,0], [0,1], [0,0]] # 결과 [[0, 0, 1, 0], [0, 1, 0, 0]] print(rotate_a_matrix_by_90_degree(a)) 다음 soultion 함수를 .. 2021. 12. 6.
application warm up warm up 은 애플리케이션 로딩 후, 타 서비스 api 커넥션 연결, db 커넥션 연결, 캐시 등의 작업을 미리 수행하는 것을 의미한다. 만약 warm up 을 하지 않으면 초기 요청들은 실패할 위험이 있고, 순단에 가까운 장애까지 발생할 수 있다. 그래서 서비스 규모가 클수록 warm up 은 필수가 된다. warm up 의 개념은 단순하다. 그래서 구현이 크게 어렵지 않다. 애플리케이션 배포 후 실제 사용자 요청을 받기 전에 미리 요청을 보내면 되기 때문에 스크립트로 구현하기도 한다. 하지만 이글에서 소개하는 방법은 spring-boot-actuator-health 를 이용한다. cf) 팀에서 사용중인 warm up 기능 중 핵심부분만 따로 정리했다. 먼저 spring-boot-actuate-he.. 2021. 12. 5.
[구현] 문자열 압축 2020 카카오 신입 공채 문제다. 먼저 단순히 1개 단위로 자르면 어떻게 만들수 있을까 생각하면서 cutByOne 함수를 만들었다. 문자열 s 전체를 for문 돌면서 targetChar 를 이용해 resultS를 만들어갔다. def cutByOne(s): resultS = '' count = 1 targetChar = 'F' for i in range(len(s)): if targetChar == 'F': targetChar = s[i] count = 1 continue if targetChar == s[i]: count += 1 else: if count == 1: resultS += targetChar count = 1 targetChar = s[i] else: resultS += str(count.. 2021. 11. 29.
json error stack trace print 여부 커스텀 프로퍼티 먼저 application.yml 에 원하는 커스텀 프로퍼티를 추가한다. 보통 deploy phase 에 따라 다르게 설정된다. response: print-stack-trace: true 다음으로 /resources/META-INF/spring-configuration-metadata.json 파일에 프로퍼티에 대한 메타데이터를 추가한다. { "groups": [ { "name": "response", "type": "com.toy.config.ResponseProperties", "sourceType": "com.toy.config.ResponseProperties" } ], "properties": [ { "name": "response.print-stack-trace", "type": "java... 2021. 11. 22.