[Java] Decorator Pattern
·
JVM/Java
요구사항FileRepository 인터페이스는 파일 스토리지로부터 파일키를 입력받아 파일 InputStream을 반환한다./** * Get the file contents from a file storage (e.g. LocalFile System, S3, GCS, Azure Blob Storage, etc.) */public interface FileRepository { InputStream getFile(FileKey fileKey) throws IOException;}LocalFile 은 LocalFileRepository,AWS S3 File 은 S3FileRepository 클래스로 파일을 가져와 InputStream 을 반환한다.기존 기능에 다음과 같은 스팩이 추가되어야 한다.".zip, ..
[Java] JUnit Inner class 를 정의하는 팁
·
JVM/Java
PurposeInner class 로 static class 로 선언하는 방식과 class 로 선언하는 방식의 차이를 안다.static inner classclass Car { public static final Duration fixDuration; private final String name; static class Painting { private final String color; public void paint(){ }; }}ProsOutter 인스턴스 생성없이 바로 인스턴스 생성이 가능하다.Painting painting = new Painting("RED");painting.paint();ConsOutter 인스턴스의 내부 변수에 접근 불가능하다.오로지 static ..
[Java] Primitive 타입보다 VO 를 의존하라
·
JVM/Java
Kafka Record 에 들어갈 Record Key, Record Value 를 OffsetRecord 인터페이스로 추상화했다.OffsetRecord 는 오로지 오프셋을 저장하는 토픽에 쓰인다.예를 들면 이런식이다.Record KeyC:\\Users\M_Faclon\path\a.txtRecord value30/** * Domain interface used by OffsetManager and SourceConnector Producer. * Consists of object unique identifier and offset. * Stored in the Offset topic partition. */public interface OffsetRecord { /** * The unique ke..
[Java] Clean Code - index, array 대신 Iterator
·
JVM/Java
class Args { private String[] args; int currentIndex;}args 를 하나씩 파싱하는 메소드가 필요하다고 해보자,인자를 넘길때마다 이런 형식이 된다.Object parseArgument(String[] args, int index);인자 수는 적으면 적을수록 좋다. 인자가 많을수록 복잡하다. - 클린코드Args 클래스를 Iterator 로 리팩터링해보자.class Args { List args; Iterator currentElement;}이제 args 속 원소를 하나씩 넘길 수 있다.그저 currentElement 만 넘겨주면 된다.Ob..
[Spring] SpringBoot 수동 빈 등록 테스트
·
JVM/Spring
요구 사항아래와 같은 yaml 설정에 따라수동으로 사용할 빈을 등록하고싶다.app: storage: type: 'local' # [local, s3]type 항목에 따라 아래와 같이 사용할 클래스를 스프링 빈에 등록하고자한다.local -> LocalFileLister, LocalFileRepository's3' -> S3FileLister, S3FileRepositoryJava 로 수동 빈 등록 코드를 작성했다.@Configurationpublic class StorageRepositoryConfiguration { @Bean public FileValidator fileValidator(FiltersConfig filtersConfig) { return filtersConfig.toV..
[Spring] ConfigurationProperties POJOs 설계
·
JVM/Spring
File Storage -> Kafka 로 중복 없이 레코드를 전송하는 라이브러리를 만들고 있다.다음과 같이 Configuration yaml 을 디자인했다고 해보자.storage: type: local, s3, blob # here is deciding which storage is used. paths: - 'df' - 'df.log' filters: - type: Exclude expressions: - '*empty*' - type: Extension expressions: - .ndjson - .csv # So, bean injection is decided here s3: bucket: reg..