1
UnTypedProcessor를 확장하는 액터를 만들었습니다. 나는이 액터를 사용하여 디스크에 메시지의 일부를 저장하려고합니다. 배우 akka UntypedProcessor에 대한 단위 테스트를 작성하는 방법
public class ShardTest extends AbstractActorTest{
@Test
public void testOnReceiveCreateTransaction() throws Exception {
System.out.println("running tests");
new JavaTestKit(getSystem()) {{
final Props props = Props.create(Shard.class);
final TestActorRef<Shard> subject = TestActorRef.create(getSystem(), props, "test");
// can also use JavaTestKit “from the outside”
final JavaTestKit probe = new JavaTestKit(getSystem());
// the run() method needs to finish within 3 seconds
new Within(duration("3 seconds")) {
protected void run() {
subject.tell(new CreateTransactionChain(), getRef());
final String out = new ExpectMsg<String>("match hint") {
// do not put code outside this method, will run afterwards
protected String match(Object in) {
if (in instanceof CreateTransactionReply) {
return "match";
} else {
throw noMatch();
}
}
}.get(); // this extracts the received message
assertEquals("match", out);
// Will wait for the rest of the 3 seconds
expectNoMsg();
}
};
}};
}
}
나는이 시험에게 UntypeProcessor의 onReceive 방법을 실행
가 호출되지 않습니다,public class Shard extends UntypedProcessor {
LoggingAdapter log = Logging.getLogger(getContext().system(), this);
@Override
public void onReceive(Object message) throws Exception {
if(message instanceof CreateTransactionChain) {
System.out.println("Received a CreateTransactionChain message");
ActorRef transactionChain = getContext().actorOf(Props.create(TransactionChain.class), "transactionChain");
Address address = transactionChain.path().address();
getSender().tell(new CreateTransactionReply(address), getSelf());
}
}
}
난과 같이이 작성된 단위 테스트, 그래서 것 같습니다. UntypedActor에서 클래스를 확장하면 일이 잘됩니다. UntypedProcessor를 확장하는 것이 왜 효과가 없습니까? 이 기능을 사용하려면 추가해야 할 구성이 있습니까? 조롱을받을 필요가있는 것이 있습니까?