누군가가 추상 Akka 배우 의사 코드에 따라 테스트 케이스를 작성하는 데 도움을 줄 수 있습니까?추상 Akka 배우의 감독 전략을위한 테스트 사례 작성 방법
문제 부모에게 감독 전략을 적용하지 않고 모든 감독 전략 메시지 (테스트 사례의 일부로 전송)가 소비되고 있습니다.
부모 추상 배우가 자식을 만듭니다.
Abstract class Parent extends UntypedActor {
String name;
int noOfChildActors;
//this set is used to manage the children i.e noOfChildActors = children.size()
Set<ActorRef> children;
public Parent(String name, int noOfChildActors, Props childProps){
this.name=name;
this.noOfChildActors = noOfChildActors;
createChildern(childProps);
}
public void createChildern(Props props){
for(int i = 0 ; i< no_of_child_actors;i++)
final ActorRef actor = getContext().actorOf(props, "worker"+i);
getContext().watch(actor);
children.add(actor);
}
@Override
public void onReceive(final Object message) {
//actor functionalities goes here.
}
@Override
public SupervisorStrategy supervisorStrategy() {
return defaultSupervisorStrategy();
}
private SupervisorStrategy defaultSupervisorStrategy() {
return new AllForOneStrategy(-1, Duration.Inf(), new Strategy());
}
private class Strategy implements Function<Throwable, Directive> {
@Override
public Directive apply(final Throwable t) {
//my own strategies.
}
}
//child managing methods.
//Abstract functions
}
상위 클래스를 확장
하위 클래스
class Child extends Parent{
String name;
public static Props props(final String name, int noOfChildActors, Props childProps) {
return Props.create(Child.class, name, noOfChildActors, childProps);
}
public Child(String name, int noOfChildActors, Props childProps){
super(name, noOfChildActors, childProps);
}
//followed by my abstract function definition
}
// 테스트 케이스 Akka의 parent
개념 트리의 클래스 계층 구조에서 부모 만 부모없는
private static final FiniteDuration WAIT_TIME = Duration.create(5, TimeUnit.SECONDS);
JavaTestKit sender = new JavaTestKit(system);
final Props props = Child.Props("name", 3, Props.empty());
ActorRef consumer = system.actorOf(props, "test-supervision");
final TestProbe probe = new TestProbe(system);
probe.watch(consumer);
consumer.tell(ActorInitializationException.class, sender.getRef());
probe.expectMsgClass(WAIT_TIME, Terminated.class);
감사합니다 요한 복음을 읽어보십시오. 나는 Akka의 학부모가 OO 모델과 같지 않다는 것을 이해합니다. 필자가 제공 한 의사 코드는 API입니다. 추상 클래스'Parent'는 자식 행위자 (Kafka 클러스터의 생산자와 소비자)를 생성합니다. 자녀가되는 '학부모'의 감독을 테스트하는 방법을 도울 수 있습니까? –
문서의이 섹션을보십시오 : http://doc.akka.io/docs/akka/2.4/java/testing.html#Testing_parent-child_relationships 그것은 당신에게 아이디어를 줄 것입니다. – johanandren