AKKA를 학습하기위해서는, 자신에게 맞는 유닛테스트 가능한 구조를 설계하는것이 중요합니다.

여기서 소개되는 방식은 UnitTest를 위한 최상의 설계는 아니며 , 학습과정에서 액터패턴을

검증하고 시도하는것에 대한 불편함을 현재까지 조금씩 개선한 버젼입니다.

src : git-CachedbApplicationTests.java

의존성이 없는 유니테스트 구성


public class ActorBase {
   
   protected final Logger log = LoggerFactory.getLogger(this.getClass());
   
   public void runAll() {
      
   }
   
   protected ActorSystem system;
   protected SpringExtension ext;
   
   public ActorSystem getSystem() {
      return system;
   }
   public void setSystem(ActorSystem system) {
      this.system = system;
   }
   public SpringExtension getExt() {
      return ext;
   }
   public void setExt(SpringExtension ext) {
      this.ext = ext;
   }
}





Actor는 기본적으로 공통적으로 사용되는 ActorSystem 이 있으며, 외부로부터 설정이 가능해야합니다.

기능별로 분리를 하고, 각각의 모듈은 다른모듈 실행 의존없이 단독으로 작동가능한것이 목표입니다.


JUNIT을 활용하여 구조적인 Unit테스트 환경만들기


JUnit 환경 구성시 테스트 항목을 리스트업하여 제어할수 있습니다.

전체실행을 할수 있으며 부분실패에대해 집중도 할수가 있습니다.


동시성 처리 가능 유닛테스트 이해하기

protected void actorTest2() {         
    new TestKit(system) {{
       final ActorRef testActor = system.actorOf( ext.props("testActor"),"test1");                  
      testActor.tell( "hi", getRef() );        
         // await the correct response
       expectMsg(java.time.Duration.ofSeconds(1), "hi too");
       
    }};   
}


실시간으로 처리되고 적재되는 메시지를 검증할수 있는 새로운 방법이 필요하며

Junit만으로는 부족합니다. Akka TestKit을 상호 사용할수 있는 방법을 익혀둡니다. 

참고: 00.UnitTest

  • No labels