I have created an actor which extends UnTypedProcessor. I intend to use this actor to persist some of it's messages to disk. The actor looks like so,
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());
}
}
}
I have a unit test written for this like so,
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();
}
};
}};
}
}
When I run this test the onReceive method of the UntypeProcessor does not get invoked. If I extended my class from UntypedActor instead things work just fine. Any ideas why extending UntypedProcessor does not work? Is there some configuration I need to add to get this to work? Is there something that needs to be mocked?