Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  • ActorTestKit은 유닛테스트 환경에서 AkkaSystem의 환경을 동일하게 구동합니다. 
  • 설정파일을 통해 각각 다른 역할을 수행하는 멀티노드를 구성할수 있게됩니다.
  • 유닛테스트 작성을 "시간이 없어서~ 유용하지않아서" 라고 이야기하곤 합니다.
    • 우리가 만든기능이 분산되었을때  단일지점에서 유닛테스트를 수행 할수 "있느냐? 없느냐?" 의 문제입니다. 

유닛테스트 코드작성

Code Block
themeEmacs
    @Test
    fun testSingleCluster(){

        var givenInItCount = 5

        val testProbe = nodeA.createTestProbe<CounterState>()
        val testProbe2 = nodeB.createTestProbe<CounterState>()

        val sigleton1:ClusterSingleton = ClusterSingleton.get(nodeA.system())

        var proxy1:ActorRef<CounterCommand> = sigleton1.init(SingletonActor.of(CounterActor.create("singleId"), "GlobalCounter"))

        val sigleton2:ClusterSingleton = ClusterSingleton.get(nodeB.system())

        var proxy2:ActorRef<CounterCommand> = sigleton2.init(SingletonActor.of(CounterActor.create("singleId"), "GlobalCounter"))

        proxy1.tell(Increment(3))

        proxy1.tell(GetCount(testProbe.ref()))

        testProbe.expectMessage(CounterState(3 + givenInItCount))

        proxy2.tell(Increment(2))

        proxy2.tell(GetCount(testProbe2.ref()))

        testProbe2.expectMessage(CounterState(5 + givenInItCount))
    }

...