Created
January 8, 2016 14:12
-
-
Save patelm5/4e4f82e62ccd230a00cf to your computer and use it in GitHub Desktop.
Gist of forwarding actor test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Test | |
public void shouldForwardLookupMessageLookupActor(){ | |
createActorWithPath("lookup-source-"+SOURCE_ID, testProbe); | |
ActorRef ref = testProbe.ref(); | |
lookupActor.tell(new GetContent(SOURCE_ID, SYSTEM_ENTRY_TIME), ref); | |
LookupResponse actual = testProbe.expectMsgClass(LookupResponse.class); | |
assertEquals(EXPECTED_CONTENT, actual.getContent()); | |
} | |
protected void createActorWithPath(String path,TestProbe probe) { | |
TestActorRef.create(actorSystem, Props.create(ForwardingActor.class, probe.ref()), path); | |
} | |
public class ForwardingActor extends UntypedActor { | |
private static final Logger LOGGER = LoggerFactory.getLogger(ForwardingActor.class.getName()); | |
final ActorRef target; | |
public ForwardingActor(ActorRef target) { | |
this.target = target; | |
} | |
@Override | |
public void onReceive(Object msg) { | |
LOGGER.warn("forwarding message given to me {} to actor {}, thread {}, dispatcher is {}",self().path(),target.path().toString(),Thread.currentThread().getName(),getContext().dispatcher()); | |
target.forward(msg, getContext()); | |
} | |
@Override | |
public void postStop(){ | |
LOGGER.info("stopped forwarding actor fowarding from {} -> {}",getSelf().path(), target.path().toString()); | |
} | |
@Override | |
public void preStart(){ | |
LOGGER.info("started forwarding actor fowarding from {} -> {}",getSelf().path(),target.path().toString()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment