목록Study/Spring (10)
DevYGwan
기본적으로 스프링에서 비동기 처리를 할때, 기본적으로 비동기 처리에 필요한 Executor를 등록하고 @Async 어노테이션과 @EnableAsync을 사용해서 비동기 처리를 진행합니다. 이때 이에 대한 원리를 제대로 알지 못해 제가 등록한 Executor와 @Async 어노테이션에서 사용하는 Executor가 다른 문제를 확인했고 이를 공유하려고 합니다. 간단하게 위에서 말한 개념들을 설명하자면,Executor : Java 표준 라이브러리에서 제공하는 인터페이스로, 비동기 작업을 실행하는 데 사용됩니다.구현체로 ThreadPoolExecutor, ForkJoinPool이 있습니다.쓰레드풀을 관리하고 작업을 실행하는 역할을 합니다.@Async : 메서드를 비동기적으로 실행하도록 만들어줍니다. 이를 통해 ..
Test 코드를 작성하면서, Controller로직 테스트 시 Mocking처리를 한 경험은 자주 있을 것입니다. Mocking을 처리하면서, 특정 메서드가 호출될 때 원하는 동작을 지정할 수 있게 하기 위해 when() 메서드를 사용할때 발생한 문제에 대해서 공유하고 이를 해결하기 위한 여러가지 방법에 대해서 설명드리려고 합니다. 간단하게 제가 겪은 문제는 인스턴스 간의 "동등성" 문제로 인해, when()에서 사용한 메서드의 파라미터로 들어온 dto 클래스를 같은 클래스라고 인식하지 못해 when()이 제대로 동작하지 않아 생기는 문제입니다. 좀 더 문제가 된 상황을 자세히 설명드리겠습니다. 문제 상황 저는 회원가입에 관한 controller로직 테스트를 진행하려고 했습니다. 테스트 코드는 다음과 같..
요즘 들어, 테스트 코드에 관심히 생겨 테스트 코드를 공부하고 있습니다. 예전에는 단순히 내가 일일이 기능을 사용해보면서 제대로 기능이 수행되는지 확인하는 식의 수동 테스트로 테스트 코드를 별도로 짜지 않고 기능 구현 위주로 코드를 작성했습니다. 단순히 "내가 직접 사용해보면서 테스트해보면 되겠지" 라는 안일한 생각을 가지고 주어진 테스크를 만족하기 위한 기능 구현 위주의 개발을 했었습니다. 그러다보니 계속해서 문제가 발생하더라구요... 그래서 이번 기회에 테스트 코드를 제대로 짜보자 라는 생각이 들었습니다. 더이상 미루면 안될 것 같더라구요... ㅎㅎ ※ 테스트 코드란 간단하게 말해서 소프트웨어의 기능과 동작을 테스트하는데 사용되는 코드로, 작은 코드 단위(클래스 & 메서드)를 독립적으로 검증하는 테..
요즘 들어 서버 유지/보수에 관심이 생겨 모니터링 하는 방법에 대해서 공부를 했습니다. 모니터링은 크게 " 데이터 수집 -> 통합 -> 시각화 " 로 이루어져 있습니다. 이를 구현할 수 있는 여러가지 기술이 있지만, 제가 사용한 방법은 Actuator, Promethues, Grafana를 사용해서 모니터링을 하는 방법을 선택했습니다. 제가 이 방법을 선택한 이유는, Spring Actuator가 스프링에서 공식으로 지원하는 라이브러리이다. 대표적인 Spring 모니터링 라이브러리 중 하나이다. 관련 자료들이 많다. 등이 있습니다. 저는 대부분 어떤 기술을 선택할 때, 신뢰할 수 있는 자료인가를 젤 먼저 확인하고 이 후 자료들이 많은지를 기준으로 선택하는 것 같습니다. 물론 자료가 없다면, 공식 문서나 ..
프로젝트를 진행하다보니, 사용자 데이터 조회시 최근 사용자의 데이터를 조회할 일이 많다는 것을 알게 되었습니다. 이를 매번 DB를 통해 조회하는 것보다 캐싱해 조회하는 것이 성능상 이점이 있겠다 라는 생각이 들었습니다. 또한 사용자 데이터는 자주 바뀌지 않기 때문에 캐시를 도입하는게 유리하다고 생각했습니다. 정리하자면, 제가 캐시를 도입한 이유는,최근 사용자 데이터를 조회할 일이 많다. (캐시 히트율이 높다.)사용자 데이터는 수정이 빈번하게 일어나지 않는다.데이터가 손실돼도 큰 서비스 장애를 발생시키지 않는다. (다시 DB에서 가져오면 되기 때문에)입니다. 그렇다면 캐시를 도입했을때의 기대 효과는 어떤게 있을까요? 제가 생각하는 캐시를 도입했을 때의 주 효과는 캐시 히트가 됐을 경우 DB에 접근하지 않고..