Versions Compared

Key

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

...

Code Block
languagejava
themeEmacs
import akka.testkit.javadsl.TestKit;


@RunWith(SpringRunner.class)
@SpringBootTest
public class CachedbApplicationTests {	
	@Autowired
	ApplicationContext context;
	
	@Test
	public void contextLoads() {
		ActorSystem system = context.getBean(ActorSystem.class);
		SpringExtension ext = context.getBean(SpringExtension.class);		
		actorTest2(system,ext);
	}
	
	protected void actorTest2(ActorSystem system,SpringExtension ext) {
		ActorRef testActor = system.actorOf(ext.props("testActor"),"service1");		
	    new TestKit(system) {{			
			testActor.tell( "hi", getRef() );
		      // await the correct response
		    expectMsg(java.time.Duration.ofSeconds(1), "너의 메시지에 응답을함");				    	
	    }};		
	}
}
Expand
title동일한 테스트를 방식을 다르게하기
Code Block
languagejava
themeEmacs
	protected void actorTest3(ActorSystem system,SpringExtension ext) {
	    new TestKit(system) {{
	    	final ActorRef testActor = system.actorOf( ext.props("testActor"),"test2");	    	
	    	final TestKit probe = new TestKit(system);	//추가 테스트 객체생성..	    	
		    within(java.time.Duration.ofSeconds(3), () -> {
		    	testActor.tell( "hi", probe.getRef() );
		    	//메시지가 오기를 기다림
		    	awaitCond(probe::msgAvailable);
		    	//메시지검사
		    	probe.expectMsg(java.time.Duration.ofSeconds(0), "너의 메시지에 응답을함");
		    	return null;
		    });
	    }};		
	}
	
	protected void actorTest4(ActorSystem system,SpringExtension ext) {
	    final TestActorRef<TestActor> testB = TestActorRef.create(system, ext.props("testActor") , "test3");
	    final CompletableFuture<Object> future = PatternsCS.ask(testB, "hi", 3000).toCompletableFuture();
	    assertTrue(future.isDone());
	    try {
			assertEquals("너의 메시지에 응답을함", future.get() );
		} catch (InterruptedException | ExecutionException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}		
	}


full src : http://git.webnori.com/projects/WEBF/repos/spring_cachedb/browse

...