2012-02-02 09:40:17 +01:00
|
|
|
/**
|
2013-01-09 01:47:48 +01:00
|
|
|
* Copyright (C) 2009-2013 Typesafe Inc. <http://www.typesafe.com>
|
2012-02-02 09:40:17 +01:00
|
|
|
*/
|
2012-05-22 11:37:09 +02:00
|
|
|
package docs.remoting;
|
2012-02-02 09:40:17 +01:00
|
|
|
|
2013-05-02 17:12:36 +02:00
|
|
|
import akka.testkit.AkkaJUnitActorSystemResource;
|
|
|
|
|
import org.junit.ClassRule;
|
2012-02-02 09:40:17 +01:00
|
|
|
import org.junit.Test;
|
|
|
|
|
|
2012-10-05 11:56:59 -07:00
|
|
|
import com.typesafe.config.ConfigFactory;
|
|
|
|
|
|
2012-02-02 09:40:17 +01:00
|
|
|
//#import
|
|
|
|
|
import akka.actor.ActorRef;
|
|
|
|
|
import akka.actor.Address;
|
2012-02-27 10:28:20 +01:00
|
|
|
import akka.actor.AddressFromURIString;
|
2012-02-02 09:40:17 +01:00
|
|
|
import akka.actor.Deploy;
|
|
|
|
|
import akka.actor.Props;
|
|
|
|
|
import akka.actor.ActorSystem;
|
|
|
|
|
import akka.remote.RemoteScope;
|
|
|
|
|
//#import
|
|
|
|
|
|
2012-09-21 15:08:56 +02:00
|
|
|
import akka.actor.UntypedActor;
|
|
|
|
|
|
2013-05-08 09:42:25 +02:00
|
|
|
public class RemoteDeploymentDocTest {
|
2012-09-21 15:08:56 +02:00
|
|
|
|
2012-09-21 17:08:36 +02:00
|
|
|
public static class SampleActor extends UntypedActor {
|
2012-09-21 15:08:56 +02:00
|
|
|
public void onReceive(Object message) {
|
|
|
|
|
getSender().tell(getSelf(), getSelf());
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-05-02 17:12:36 +02:00
|
|
|
|
|
|
|
|
@ClassRule
|
|
|
|
|
public static AkkaJUnitActorSystemResource actorSystemResource =
|
|
|
|
|
new AkkaJUnitActorSystemResource("RemoteDeploymentDocTest");
|
|
|
|
|
|
|
|
|
|
private final ActorSystem system = actorSystemResource.getSystem();
|
2012-02-02 09:40:17 +01:00
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void demonstrateDeployment() {
|
|
|
|
|
//#make-address
|
2013-01-23 11:38:20 +01:00
|
|
|
Address addr = new Address("akka.tcp", "sys", "host", 1234);
|
|
|
|
|
addr = AddressFromURIString.parse("akka.tcp://sys@host:1234"); // the same
|
2012-02-02 09:40:17 +01:00
|
|
|
//#make-address
|
|
|
|
|
//#deploy
|
2013-04-14 22:56:41 +02:00
|
|
|
ActorRef ref = system.actorOf(Props.create(SampleActor.class).withDeploy(
|
2012-10-01 20:35:19 +02:00
|
|
|
new Deploy(new RemoteScope(addr))));
|
2012-02-02 09:40:17 +01:00
|
|
|
//#deploy
|
|
|
|
|
assert ref.path().address().equals(addr);
|
|
|
|
|
}
|
2012-09-21 15:08:56 +02:00
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void demonstrateSampleActor() {
|
|
|
|
|
//#sample-actor
|
|
|
|
|
|
2013-04-14 22:56:41 +02:00
|
|
|
ActorRef actor = system.actorOf(Props.create(SampleActor.class), "sampleActor");
|
2012-09-21 15:08:56 +02:00
|
|
|
actor.tell("Pretty slick", null);
|
|
|
|
|
//#sample-actor
|
|
|
|
|
}
|
2012-10-05 11:56:59 -07:00
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void demonstrateProgrammaticConfig() {
|
|
|
|
|
//#programmatic
|
2013-01-23 11:38:20 +01:00
|
|
|
ConfigFactory.parseString("akka.remote.netty.tcp.hostname=\"1.2.3.4\"")
|
2012-10-05 11:56:59 -07:00
|
|
|
.withFallback(ConfigFactory.load());
|
|
|
|
|
//#programmatic
|
|
|
|
|
}
|
2012-09-21 15:08:56 +02:00
|
|
|
|
2012-02-02 09:40:17 +01:00
|
|
|
|
2013-01-09 01:47:48 +01:00
|
|
|
}
|