Merge pull request #1395 from akka/wip-3217-remotedeathwatchspec-failure-ban
Wait on shutdown of extra actor systems in tests. #3217
This commit is contained in:
commit
ddade2c59e
84 changed files with 762 additions and 845 deletions
|
|
@ -5,6 +5,7 @@ package docs.config
|
|||
|
||||
import org.scalatest.WordSpec
|
||||
import org.scalatest.matchers.MustMatchers
|
||||
import akka.testkit.TestKit
|
||||
|
||||
//#imports
|
||||
import akka.actor.ActorSystem
|
||||
|
|
@ -28,6 +29,6 @@ class ConfigDocSpec extends WordSpec with MustMatchers {
|
|||
val system = ActorSystem("MySystem", ConfigFactory.load(customConf))
|
||||
//#custom-config
|
||||
|
||||
system.shutdown()
|
||||
TestKit.shutdownActorSystem(system)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ import akka.actor.UntypedActor;
|
|||
|
||||
import akka.actor.ActorSystem;
|
||||
import akka.actor.Props;
|
||||
import akka.testkit.JavaTestKit;
|
||||
import akka.testkit.TestProbe;
|
||||
import akka.testkit.AkkaSpec;
|
||||
|
||||
|
|
@ -201,7 +202,7 @@ public class FSMDocTestBase {
|
|||
|
||||
@org.junit.After
|
||||
public void cleanup() {
|
||||
system.shutdown();
|
||||
JavaTestKit.shutdownActorSystem(system);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ import akka.testkit.TestProbe;
|
|||
import akka.testkit.ErrorFilter;
|
||||
import akka.testkit.EventFilter;
|
||||
import akka.testkit.TestEvent;
|
||||
import akka.testkit.JavaTestKit;
|
||||
import static java.util.concurrent.TimeUnit.SECONDS;
|
||||
import static akka.japi.Util.immutableSeq;
|
||||
import akka.japi.Function;
|
||||
|
|
@ -155,7 +156,8 @@ public class FaultHandlingTestBase {
|
|||
|
||||
@AfterClass
|
||||
public static void cleanup() {
|
||||
system.shutdown();
|
||||
JavaTestKit.shutdownActorSystem(system);
|
||||
system = null;
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
|||
|
|
@ -6,8 +6,8 @@ package docs.actor;
|
|||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import akka.testkit.AkkaJUnitActorSystemResource;
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.Test;
|
||||
|
||||
import scala.concurrent.duration.Duration;
|
||||
|
|
@ -21,19 +21,12 @@ import akka.testkit.JavaTestKit;
|
|||
|
||||
public class InboxDocTest {
|
||||
|
||||
private static ActorSystem system;
|
||||
@ClassRule
|
||||
public static AkkaJUnitActorSystemResource actorSystemResource =
|
||||
new AkkaJUnitActorSystemResource("InboxDocTest", AkkaSpec.testConf());
|
||||
|
||||
@BeforeClass
|
||||
public static void beforeAll() {
|
||||
system = ActorSystem.create("MySystem", AkkaSpec.testConf());
|
||||
}
|
||||
private final ActorSystem system = actorSystemResource.getSystem();
|
||||
|
||||
@AfterClass
|
||||
public static void afterAll() {
|
||||
system.shutdown();
|
||||
system = null;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void demonstrateInbox() {
|
||||
final JavaTestKit probe = new JavaTestKit(system);
|
||||
|
|
|
|||
|
|
@ -1,96 +1,86 @@
|
|||
/**
|
||||
* Copyright (C) 2009-2013 Typesafe Inc. <http://www.typesafe.com>
|
||||
*/
|
||||
package docs.actor;
|
||||
|
||||
import akka.actor.*;
|
||||
import akka.japi.Procedure;
|
||||
import akka.testkit.AkkaJUnitActorSystemResource;
|
||||
import akka.testkit.JavaTestKit;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.Test;
|
||||
import scala.Option;
|
||||
|
||||
/**
|
||||
* Copyright (C) 2009-2013 Typesafe Inc. <http://www.typesafe.com>
|
||||
*/
|
||||
public class InitializationDocSpecJava {
|
||||
|
||||
static public class PreStartInitExample extends UntypedActor {
|
||||
static public class PreStartInitExample extends UntypedActor {
|
||||
|
||||
public void onReceive(Object message) throws Exception {}
|
||||
|
||||
//#preStartInit
|
||||
@Override
|
||||
public void preStart() {
|
||||
// Initialize children here
|
||||
}
|
||||
|
||||
// Overriding postRestart to disable the call to preStart()
|
||||
// after restarts
|
||||
@Override
|
||||
public void postRestart(Throwable reason) {
|
||||
}
|
||||
|
||||
// The default implementation of preRestart() stops all the children
|
||||
// of the actor. To opt-out from stopping the children, we
|
||||
// have to override preRestart()
|
||||
@Override
|
||||
public void preRestart(Throwable reason, Option<Object> message)
|
||||
throws Exception {
|
||||
// Keep the call to postStop(), but no stopping of children
|
||||
postStop();
|
||||
}
|
||||
//#preStartInit
|
||||
public void onReceive(Object message) throws Exception {}
|
||||
|
||||
//#preStartInit
|
||||
@Override
|
||||
public void preStart() {
|
||||
// Initialize children here
|
||||
}
|
||||
|
||||
public static class MessageInitExample extends UntypedActor {
|
||||
//#messageInit
|
||||
private String initializeMe = null;
|
||||
|
||||
@Override
|
||||
public void onReceive(Object message) throws Exception {
|
||||
if (message.equals("init")) {
|
||||
initializeMe = "Up and running";
|
||||
getContext().become(new Procedure<Object>() {
|
||||
@Override
|
||||
public void apply(Object message) throws Exception {
|
||||
if (message.equals("U OK?"))
|
||||
getSender().tell(initializeMe, getSelf());
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
//#messageInit
|
||||
// Overriding postRestart to disable the call to preStart()
|
||||
// after restarts
|
||||
@Override
|
||||
public void postRestart(Throwable reason) {
|
||||
}
|
||||
|
||||
static ActorSystem system;
|
||||
|
||||
@BeforeClass
|
||||
public static void setup() {
|
||||
system = ActorSystem.create("TestSystem");
|
||||
// The default implementation of preRestart() stops all the children
|
||||
// of the actor. To opt-out from stopping the children, we
|
||||
// have to override preRestart()
|
||||
@Override
|
||||
public void preRestart(Throwable reason, Option<Object> message)
|
||||
throws Exception {
|
||||
// Keep the call to postStop(), but no stopping of children
|
||||
postStop();
|
||||
}
|
||||
//#preStartInit
|
||||
|
||||
@AfterClass
|
||||
public static void teardown() {
|
||||
system.shutdown();
|
||||
}
|
||||
|
||||
public static class MessageInitExample extends UntypedActor {
|
||||
//#messageInit
|
||||
private String initializeMe = null;
|
||||
|
||||
@Override
|
||||
public void onReceive(Object message) throws Exception {
|
||||
if (message.equals("init")) {
|
||||
initializeMe = "Up and running";
|
||||
getContext().become(new Procedure<Object>() {
|
||||
@Override
|
||||
public void apply(Object message) throws Exception {
|
||||
if (message.equals("U OK?"))
|
||||
getSender().tell(initializeMe, getSelf());
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
//#messageInit
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIt() {
|
||||
@ClassRule
|
||||
public static AkkaJUnitActorSystemResource actorSystemResource =
|
||||
new AkkaJUnitActorSystemResource("InitializationDocSpecJava");
|
||||
|
||||
new JavaTestKit(system) {{
|
||||
ActorRef testactor = system.actorOf(Props.create(MessageInitExample.class), "testactor");
|
||||
String probe = "U OK?";
|
||||
private final ActorSystem system = actorSystemResource.getSystem();
|
||||
|
||||
testactor.tell(probe, getRef());
|
||||
expectNoMsg();
|
||||
@Test
|
||||
public void testIt() {
|
||||
|
||||
testactor.tell("init", getRef());
|
||||
testactor.tell(probe, getRef());
|
||||
expectMsgEquals("Up and running");
|
||||
}};
|
||||
new JavaTestKit(system) {{
|
||||
ActorRef testactor = system.actorOf(Props.create(MessageInitExample.class), "testactor");
|
||||
String probe = "U OK?";
|
||||
|
||||
testactor.tell(probe, getRef());
|
||||
expectNoMsg();
|
||||
|
||||
|
||||
}
|
||||
|
||||
testactor.tell("init", getRef());
|
||||
testactor.tell(probe, getRef());
|
||||
expectMsgEquals("Up and running");
|
||||
}};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,26 +17,17 @@ import akka.actor.Cancellable;
|
|||
import akka.actor.ActorRef;
|
||||
import akka.actor.ActorSystem;
|
||||
import akka.testkit.AkkaSpec;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import akka.testkit.AkkaJUnitActorSystemResource;
|
||||
import org.junit.*;
|
||||
|
||||
public class SchedulerDocTestBase {
|
||||
|
||||
ActorSystem system;
|
||||
ActorRef testActor;
|
||||
@Rule
|
||||
public AkkaJUnitActorSystemResource actorSystemResource =
|
||||
new AkkaJUnitActorSystemResource("SchedulerDocTest", AkkaSpec.testConf());
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
system = ActorSystem.create("MySystem", AkkaSpec.testConf());
|
||||
testActor = system.actorOf(Props.create(MyUntypedActor.class));
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
system.shutdown();
|
||||
}
|
||||
private final ActorSystem system = actorSystemResource.getSystem();
|
||||
private ActorRef testActor = system.actorOf(Props.create(MyUntypedActor.class));
|
||||
|
||||
@Test
|
||||
public void scheduleOneOffTask() {
|
||||
|
|
|
|||
|
|
@ -15,8 +15,8 @@ import java.util.ArrayList;
|
|||
import java.util.Iterator;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import akka.testkit.AkkaJUnitActorSystemResource;
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.Test;
|
||||
|
||||
//#import-gracefulStop
|
||||
|
|
@ -82,18 +82,11 @@ import akka.util.Timeout;
|
|||
|
||||
public class UntypedActorDocTestBase {
|
||||
|
||||
private static ActorSystem system;
|
||||
@ClassRule
|
||||
public static AkkaJUnitActorSystemResource actorSystemResource =
|
||||
new AkkaJUnitActorSystemResource("UntypedActorDocTest", AkkaSpec.testConf());
|
||||
|
||||
@BeforeClass
|
||||
public static void beforeAll() {
|
||||
system = ActorSystem.create("MySystem", AkkaSpec.testConf());
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void afterAll() {
|
||||
system.shutdown();
|
||||
system = null;
|
||||
}
|
||||
private final ActorSystem system = actorSystemResource.getSystem();
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@Test
|
||||
|
|
@ -156,7 +149,7 @@ public class UntypedActorDocTestBase {
|
|||
}
|
||||
};
|
||||
} finally {
|
||||
system.shutdown();
|
||||
JavaTestKit.shutdownActorSystem(system);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -9,8 +9,8 @@ import akka.actor.ActorRef;
|
|||
|
||||
//#imports
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import akka.testkit.AkkaJUnitActorSystemResource;
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.Test;
|
||||
|
||||
import akka.testkit.AkkaSpec;
|
||||
|
|
@ -20,18 +20,12 @@ import akka.actor.UntypedActor;
|
|||
|
||||
public class DurableMailboxDocTestBase {
|
||||
|
||||
ActorSystem system;
|
||||
@ClassRule
|
||||
public static AkkaJUnitActorSystemResource actorSystemResource =
|
||||
new AkkaJUnitActorSystemResource("DurableMailboxDocTest",
|
||||
ConfigFactory.parseString(DurableMailboxDocSpec.config()).withFallback(AkkaSpec.testConf()));
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
system = ActorSystem.create("MySystem",
|
||||
ConfigFactory.parseString(DurableMailboxDocSpec.config()).withFallback(AkkaSpec.testConf()));
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
system.shutdown();
|
||||
}
|
||||
private final ActorSystem system = actorSystemResource.getSystem();
|
||||
|
||||
@Test
|
||||
public void configDefinedDispatcher() {
|
||||
|
|
|
|||
|
|
@ -5,10 +5,7 @@ package docs.agent;
|
|||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import akka.testkit.AkkaSpec;
|
||||
|
||||
import scala.concurrent.Await;
|
||||
import scala.concurrent.duration.Duration;
|
||||
|
|
|
|||
|
|
@ -6,6 +6,8 @@ package docs.camel;
|
|||
import akka.camel.Camel;
|
||||
import akka.camel.CamelExtension;
|
||||
import akka.camel.javaapi.UntypedConsumerActor;
|
||||
import akka.testkit.JavaTestKit;
|
||||
import akka.testkit.TestKit;
|
||||
import akka.util.Timeout;
|
||||
import scala.concurrent.Future;
|
||||
import scala.concurrent.duration.Duration;
|
||||
|
|
@ -38,7 +40,7 @@ public class ActivationTestBase {
|
|||
Future<ActorRef> deactivationFuture = camel.deactivationFutureFor(producer,
|
||||
timeout, system.dispatcher());
|
||||
//#CamelDeactivation
|
||||
system.shutdown();
|
||||
JavaTestKit.shutdownActorSystem(system);
|
||||
}
|
||||
|
||||
public static class MyConsumer extends UntypedConsumerActor {
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ package docs.camel;
|
|||
import akka.actor.ActorSystem;
|
||||
import akka.camel.Camel;
|
||||
import akka.camel.CamelExtension;
|
||||
import akka.testkit.JavaTestKit;
|
||||
import org.apache.camel.CamelContext;
|
||||
import org.apache.camel.ProducerTemplate;
|
||||
import org.junit.Test;
|
||||
|
|
@ -16,7 +17,7 @@ public class CamelExtensionTestBase {
|
|||
CamelContext camelContext = camel.context();
|
||||
ProducerTemplate producerTemplate = camel.template();
|
||||
//#CamelExtension
|
||||
system.shutdown();
|
||||
JavaTestKit.shutdownActorSystem(system);
|
||||
}
|
||||
public void addActiveMQComponent() {
|
||||
//#CamelExtensionAddComponent
|
||||
|
|
@ -26,7 +27,7 @@ public class CamelExtensionTestBase {
|
|||
// camelContext.addComponent("activemq", ActiveMQComponent.activeMQComponent(
|
||||
// "vm://localhost?broker.persistent=false"));
|
||||
//#CamelExtensionAddComponent
|
||||
system.shutdown();
|
||||
JavaTestKit.shutdownActorSystem(system);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import akka.actor.ActorSystem;
|
|||
import akka.actor.Props;
|
||||
import akka.camel.Camel;
|
||||
import akka.camel.CamelExtension;
|
||||
import akka.testkit.JavaTestKit;
|
||||
|
||||
public class CustomRouteTestBase {
|
||||
public void customRoute() throws Exception{
|
||||
|
|
@ -15,6 +16,6 @@ public class CustomRouteTestBase {
|
|||
camel.context().addRoutes(new CustomRouteBuilder(responder));
|
||||
//#CustomRoute
|
||||
system.stop(responder);
|
||||
system.shutdown();
|
||||
JavaTestKit.shutdownActorSystem(system);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package docs.camel;
|
||||
|
||||
import akka.actor.*;
|
||||
import akka.testkit.JavaTestKit;
|
||||
|
||||
public class OnRouteResponseTestBase {
|
||||
|
||||
|
|
@ -17,6 +18,6 @@ public class OnRouteResponseTestBase {
|
|||
//#RouteResponse
|
||||
system.stop(receiver);
|
||||
system.stop(forwardResponse);
|
||||
system.shutdown();
|
||||
JavaTestKit.shutdownActorSystem(system);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ package docs.camel;
|
|||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import akka.testkit.JavaTestKit;
|
||||
import scala.concurrent.Future;
|
||||
import akka.actor.ActorRef;
|
||||
import akka.actor.ActorSystem;
|
||||
|
|
@ -18,7 +19,7 @@ public class ProducerTestBase {
|
|||
ActorRef producer = system.actorOf(props, "jmsproducer");
|
||||
producer.tell("<order amount=\"100\" currency=\"PLN\" itemId=\"12345\"/>", null);
|
||||
//#TellProducer
|
||||
system.shutdown();
|
||||
JavaTestKit.shutdownActorSystem(system);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
|
|
@ -30,7 +31,7 @@ public class ProducerTestBase {
|
|||
Future<Object> future = Patterns.ask(producer, "some request", 1000);
|
||||
//#AskProducer
|
||||
system.stop(producer);
|
||||
system.shutdown();
|
||||
JavaTestKit.shutdownActorSystem(system);
|
||||
}
|
||||
|
||||
public void correlate(){
|
||||
|
|
@ -44,6 +45,6 @@ public class ProducerTestBase {
|
|||
"itemId=\"12345\"/>",headers), null);
|
||||
//#Correlate
|
||||
system.stop(producer);
|
||||
system.shutdown();
|
||||
JavaTestKit.shutdownActorSystem(system);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,7 +16,9 @@ import akka.event.LoggingAdapter;
|
|||
//#imports-prio-mailbox
|
||||
import akka.dispatch.PriorityGenerator;
|
||||
import akka.dispatch.UnboundedPriorityMailbox;
|
||||
import akka.testkit.AkkaJUnitActorSystemResource;
|
||||
import akka.testkit.JavaTestKit;
|
||||
import akka.testkit.TestKit;
|
||||
import com.typesafe.config.Config;
|
||||
|
||||
//#imports-prio-mailbox
|
||||
|
|
@ -35,8 +37,7 @@ import java.util.concurrent.ConcurrentLinkedQueue;
|
|||
//#imports-required-mailbox
|
||||
|
||||
import docs.actor.MyBoundedUntypedActor;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.Test;
|
||||
import scala.Option;
|
||||
import scala.concurrent.ExecutionContext;
|
||||
|
|
@ -48,20 +49,13 @@ import akka.testkit.AkkaSpec;
|
|||
|
||||
public class DispatcherDocTestBase {
|
||||
|
||||
static ActorSystem system;
|
||||
@ClassRule
|
||||
public static AkkaJUnitActorSystemResource actorSystemResource =
|
||||
new AkkaJUnitActorSystemResource("DispatcherDocTest", ConfigFactory.parseString(
|
||||
DispatcherDocSpec.javaConfig()).withFallback(ConfigFactory.parseString(
|
||||
DispatcherDocSpec.config())).withFallback(AkkaSpec.testConf()));
|
||||
|
||||
@BeforeClass
|
||||
public static void beforeAll() {
|
||||
system = ActorSystem.create("MySystem",
|
||||
ConfigFactory.parseString(DispatcherDocSpec.javaConfig()).withFallback(
|
||||
ConfigFactory.parseString(DispatcherDocSpec.config())).withFallback(AkkaSpec.testConf()));
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void afterAll() {
|
||||
system.shutdown();
|
||||
system = null;
|
||||
}
|
||||
private final ActorSystem system = actorSystemResource.getSystem();
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@Test
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ import akka.event.Logging.Debug;
|
|||
//#imports-listener
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import akka.testkit.JavaTestKit;
|
||||
import scala.Option;
|
||||
|
||||
//#imports-deadletter
|
||||
|
|
@ -37,7 +37,7 @@ public class LoggingDocTestBase {
|
|||
ActorSystem system = ActorSystem.create("MySystem");
|
||||
ActorRef myActor = system.actorOf(Props.create(MyActor.class, this));
|
||||
myActor.tell("test", null);
|
||||
system.shutdown();
|
||||
JavaTestKit.shutdownActorSystem(system);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -47,7 +47,7 @@ public class LoggingDocTestBase {
|
|||
final ActorRef actor = system.actorOf(Props.create(DeadLetterActor.class));
|
||||
system.eventStream().subscribe(actor, DeadLetter.class);
|
||||
//#deadletters
|
||||
system.shutdown();
|
||||
JavaTestKit.shutdownActorSystem(system);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -57,7 +57,7 @@ public class LoggingDocTestBase {
|
|||
final Object[] args = new Object[] { "The", "brown", "fox", "jumps", 42 };
|
||||
system.log().debug("five parameters: {}, {}, {}, {}, {}", args);
|
||||
//#array
|
||||
system.shutdown();
|
||||
JavaTestKit.shutdownActorSystem(system);
|
||||
}
|
||||
|
||||
//#my-actor
|
||||
|
|
|
|||
|
|
@ -51,8 +51,8 @@ import java.util.List;
|
|||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import akka.testkit.AkkaJUnitActorSystemResource;
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.Test;
|
||||
|
||||
import akka.testkit.AkkaSpec;
|
||||
|
|
@ -67,45 +67,39 @@ import static org.junit.Assert.*;
|
|||
|
||||
public class FutureDocTestBase {
|
||||
|
||||
ActorSystem system;
|
||||
@ClassRule
|
||||
public static AkkaJUnitActorSystemResource actorSystemResource =
|
||||
new AkkaJUnitActorSystemResource("FutureDocTest", AkkaSpec.testConf());
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
system = ActorSystem.create("MySystem", AkkaSpec.testConf());
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
system.shutdown();
|
||||
}
|
||||
private final ActorSystem system = actorSystemResource.getSystem();
|
||||
|
||||
public final static class PrintResult<T> extends OnSuccess<T> {
|
||||
@Override public final void onSuccess(T t) {
|
||||
// print t
|
||||
}
|
||||
@Override public final void onSuccess(T t) {
|
||||
// print t
|
||||
}
|
||||
}
|
||||
|
||||
public final static class Demo {
|
||||
//#print-result
|
||||
public final static class PrintResult<T> extends OnSuccess<T> {
|
||||
@Override public final void onSuccess(T t) {
|
||||
System.out.println(t);
|
||||
}
|
||||
//#print-result
|
||||
public final static class PrintResult<T> extends OnSuccess<T> {
|
||||
@Override public final void onSuccess(T t) {
|
||||
System.out.println(t);
|
||||
}
|
||||
//#print-result
|
||||
}
|
||||
//#print-result
|
||||
}
|
||||
@SuppressWarnings("unchecked") @Test public void useCustomExecutionContext() throws Exception {
|
||||
ExecutorService yourExecutorServiceGoesHere = Executors.newSingleThreadExecutor();
|
||||
//#diy-execution-context
|
||||
ExecutionContext ec =
|
||||
ExecutionContexts.fromExecutorService(yourExecutorServiceGoesHere);
|
||||
ExecutorService yourExecutorServiceGoesHere = Executors.newSingleThreadExecutor();
|
||||
//#diy-execution-context
|
||||
ExecutionContext ec =
|
||||
ExecutionContexts.fromExecutorService(yourExecutorServiceGoesHere);
|
||||
|
||||
//Use ec with your Futures
|
||||
Future<String> f1 = Futures.successful("foo");
|
||||
//Use ec with your Futures
|
||||
Future<String> f1 = Futures.successful("foo");
|
||||
|
||||
// Then you shut down the ExecutorService at the end of your application.
|
||||
yourExecutorServiceGoesHere.shutdown();
|
||||
//#diy-execution-context
|
||||
// Then you shut down the ExecutorService at the end of your application.
|
||||
yourExecutorServiceGoesHere.shutdown();
|
||||
//#diy-execution-context
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -134,8 +128,8 @@ public class FutureDocTestBase {
|
|||
|
||||
f.onSuccess(new PrintResult<String>(), system.dispatcher());
|
||||
//#future-eval
|
||||
String result = (String) Await.result(f, Duration.create(5, SECONDS));
|
||||
assertEquals("HelloWorld", result);
|
||||
String result = (String) Await.result(f, Duration.create(5, SECONDS));
|
||||
assertEquals("HelloWorld", result);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -504,13 +498,13 @@ public class FutureDocTestBase {
|
|||
final ExecutionContext ec = system.dispatcher();
|
||||
|
||||
future.onComplete(new OnComplete<String>() {
|
||||
public void onComplete(Throwable failure, String result) {
|
||||
if (failure != null) {
|
||||
//We got a failure, handle it here
|
||||
} else {
|
||||
// We got a result, do something with it
|
||||
}
|
||||
public void onComplete(Throwable failure, String result) {
|
||||
if (failure != null) {
|
||||
//We got a failure, handle it here
|
||||
} else {
|
||||
// We got a result, do something with it
|
||||
}
|
||||
}
|
||||
}, ec);
|
||||
//#onComplete
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,8 +4,8 @@
|
|||
|
||||
package docs.io;
|
||||
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import akka.testkit.AkkaJUnitActorSystemResource;
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.Test;
|
||||
|
||||
import akka.actor.ActorSystem;
|
||||
|
|
@ -27,6 +27,7 @@ public class UdpConnectedDocTest {
|
|||
static public class Demo extends UntypedActor {
|
||||
ActorRef connectionActor = null;
|
||||
ActorRef handler = getSelf();
|
||||
ActorSystem system = context().system();
|
||||
|
||||
@Override
|
||||
public void onReceive(Object msg) {
|
||||
|
|
@ -78,18 +79,6 @@ public class UdpConnectedDocTest {
|
|||
}
|
||||
}
|
||||
|
||||
static ActorSystem system;
|
||||
|
||||
@BeforeClass
|
||||
static public void setup() {
|
||||
system = ActorSystem.create("UdpConnectedDocTest");
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
static public void teardown() {
|
||||
system.shutdown();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void demonstrateConnect() {
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,83 +19,73 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
//#imports
|
||||
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import akka.testkit.AkkaJUnitActorSystemResource;
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.Test;
|
||||
|
||||
|
||||
public class UdpDocTest {
|
||||
static public class Demo extends UntypedActor {
|
||||
public void onReceive(Object message) {
|
||||
//#manager
|
||||
final ActorRef udp = Udp.get(system).manager();
|
||||
//#manager
|
||||
static public class Demo extends UntypedActor {
|
||||
ActorSystem system = context().system();
|
||||
|
||||
//#simplesend
|
||||
udp.tell(UdpMessage.simpleSender(), getSelf());
|
||||
public void onReceive(Object message) {
|
||||
//#manager
|
||||
final ActorRef udp = Udp.get(system).manager();
|
||||
//#manager
|
||||
|
||||
// ... or with socket options:
|
||||
final List<Inet.SocketOption> options = new ArrayList<Inet.SocketOption>();
|
||||
options.add(UdpSO.broadcast(true));
|
||||
udp.tell(UdpMessage.simpleSender(), getSelf());
|
||||
//#simplesend
|
||||
//#simplesend
|
||||
udp.tell(UdpMessage.simpleSender(), getSelf());
|
||||
|
||||
ActorRef simpleSender = null;
|
||||
// ... or with socket options:
|
||||
final List<Inet.SocketOption> options = new ArrayList<Inet.SocketOption>();
|
||||
options.add(UdpSO.broadcast(true));
|
||||
udp.tell(UdpMessage.simpleSender(), getSelf());
|
||||
//#simplesend
|
||||
|
||||
//#simplesend-finish
|
||||
if (message instanceof Udp.SimpleSendReady) {
|
||||
simpleSender = getSender();
|
||||
}
|
||||
//#simplesend-finish
|
||||
ActorRef simpleSender = null;
|
||||
|
||||
final ByteString data = ByteString.empty();
|
||||
//#simplesend-finish
|
||||
if (message instanceof Udp.SimpleSendReady) {
|
||||
simpleSender = getSender();
|
||||
}
|
||||
//#simplesend-finish
|
||||
|
||||
//#simplesend-send
|
||||
simpleSender.tell(UdpMessage.send(data, new InetSocketAddress("127.0.0.1", 7654)), getSelf());
|
||||
//#simplesend-send
|
||||
final ByteString data = ByteString.empty();
|
||||
|
||||
final ActorRef handler = getSelf();
|
||||
//#simplesend-send
|
||||
simpleSender.tell(UdpMessage.send(data, new InetSocketAddress("127.0.0.1", 7654)), getSelf());
|
||||
//#simplesend-send
|
||||
|
||||
//#bind
|
||||
udp.tell(UdpMessage.bind(handler, new InetSocketAddress("127.0.0.1", 9876)), getSelf());
|
||||
//#bind
|
||||
final ActorRef handler = getSelf();
|
||||
|
||||
ActorRef udpWorker = null;
|
||||
//#bind
|
||||
udp.tell(UdpMessage.bind(handler, new InetSocketAddress("127.0.0.1", 9876)), getSelf());
|
||||
//#bind
|
||||
|
||||
//#bind-finish
|
||||
if (message instanceof Udp.Bound) {
|
||||
udpWorker = getSender();
|
||||
}
|
||||
//#bind-finish
|
||||
ActorRef udpWorker = null;
|
||||
|
||||
//#bind-receive
|
||||
if (message instanceof Udp.Received) {
|
||||
final Udp.Received rcvd = (Udp.Received) message;
|
||||
final ByteString payload = rcvd.data();
|
||||
final InetSocketAddress sender = rcvd.sender();
|
||||
}
|
||||
//#bind-receive
|
||||
//#bind-finish
|
||||
if (message instanceof Udp.Bound) {
|
||||
udpWorker = getSender();
|
||||
}
|
||||
//#bind-finish
|
||||
|
||||
//#bind-send
|
||||
udpWorker.tell(UdpMessage.send(data, new InetSocketAddress("127.0.0.1", 7654)), getSelf());
|
||||
//#bind-send
|
||||
}
|
||||
//#bind-receive
|
||||
if (message instanceof Udp.Received) {
|
||||
final Udp.Received rcvd = (Udp.Received) message;
|
||||
final ByteString payload = rcvd.data();
|
||||
final InetSocketAddress sender = rcvd.sender();
|
||||
}
|
||||
//#bind-receive
|
||||
|
||||
//#bind-send
|
||||
udpWorker.tell(UdpMessage.send(data, new InetSocketAddress("127.0.0.1", 7654)), getSelf());
|
||||
//#bind-send
|
||||
}
|
||||
}
|
||||
|
||||
static ActorSystem system;
|
||||
|
||||
@BeforeClass
|
||||
static public void setup() {
|
||||
system = ActorSystem.create("IODocTest");
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
static public void teardown() {
|
||||
system.shutdown();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void demonstrateConnect() {
|
||||
}
|
||||
@Test
|
||||
public void demonstrateConnect() {
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,8 +5,8 @@
|
|||
package docs.io.japi;
|
||||
|
||||
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import akka.testkit.AkkaJUnitActorSystemResource;
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.Test;
|
||||
|
||||
//#imports
|
||||
|
|
@ -138,19 +138,13 @@ public class IODocTest {
|
|||
|
||||
}
|
||||
//#client
|
||||
|
||||
private static ActorSystem system;
|
||||
|
||||
@BeforeClass
|
||||
public static void setup() {
|
||||
system = ActorSystem.create("IODocTest", AkkaSpec.testConf());
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void teardown() {
|
||||
system.shutdown();
|
||||
}
|
||||
|
||||
|
||||
@ClassRule
|
||||
public static AkkaJUnitActorSystemResource actorSystemResource =
|
||||
new AkkaJUnitActorSystemResource("IODocTest", AkkaSpec.testConf());
|
||||
|
||||
private final ActorSystem system = actorSystemResource.getSystem();
|
||||
|
||||
@Test
|
||||
public void testConnection() {
|
||||
new JavaTestKit(system) {
|
||||
|
|
|
|||
|
|
@ -7,8 +7,8 @@ package docs.io.japi;
|
|||
import java.nio.ByteOrder;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import akka.testkit.AkkaJUnitActorSystemResource;
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.Test;
|
||||
|
||||
import scala.concurrent.duration.Duration;
|
||||
|
|
@ -48,18 +48,12 @@ public class PipelineTest {
|
|||
}
|
||||
final Context ctx = new Context();
|
||||
//#byteorder
|
||||
|
||||
static ActorSystem system = null;
|
||||
|
||||
@BeforeClass
|
||||
public static void setup() {
|
||||
system = ActorSystem.create("PipelineTest");
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void teardown() {
|
||||
system.shutdown();
|
||||
}
|
||||
|
||||
@ClassRule
|
||||
public static AkkaJUnitActorSystemResource actorSystemResource =
|
||||
new AkkaJUnitActorSystemResource("PipelineTest");
|
||||
|
||||
private final ActorSystem system = actorSystemResource.getSystem();
|
||||
|
||||
@Test
|
||||
public void demonstratePipeline() throws Exception {
|
||||
|
|
|
|||
|
|
@ -9,8 +9,8 @@ import java.net.InetSocketAddress;
|
|||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.SSLEngine;
|
||||
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import akka.testkit.AkkaJUnitActorSystemResource;
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.Test;
|
||||
|
||||
import akka.actor.ActorContext;
|
||||
|
|
@ -184,17 +184,11 @@ public class SslDocTest {
|
|||
}
|
||||
//#server
|
||||
|
||||
private static ActorSystem system;
|
||||
|
||||
@BeforeClass
|
||||
public static void setup() {
|
||||
system = ActorSystem.create("IODocTest", AkkaSpec.testConf());
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void teardown() {
|
||||
system.shutdown();
|
||||
}
|
||||
@ClassRule
|
||||
public static AkkaJUnitActorSystemResource actorSystemResource =
|
||||
new AkkaJUnitActorSystemResource("SslDocTest", AkkaSpec.testConf());
|
||||
|
||||
private final ActorSystem system = actorSystemResource.getSystem();
|
||||
|
||||
@Test
|
||||
public void demonstrateSslClient() {
|
||||
|
|
|
|||
|
|
@ -3,8 +3,8 @@
|
|||
*/
|
||||
package docs.jrouting;
|
||||
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import akka.testkit.AkkaJUnitActorSystemResource;
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.Test;
|
||||
import akka.testkit.JavaTestKit;
|
||||
import akka.actor.ActorSystem;
|
||||
|
|
@ -27,17 +27,11 @@ import akka.routing.ConsistentHashingRouter.ConsistentHashableEnvelope;
|
|||
|
||||
public class ConsistentHashingRouterDocTestBase {
|
||||
|
||||
static ActorSystem system;
|
||||
|
||||
@BeforeClass
|
||||
public static void setup() {
|
||||
system = ActorSystem.create();
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void teardown() {
|
||||
system.shutdown();
|
||||
}
|
||||
@ClassRule
|
||||
public static AkkaJUnitActorSystemResource actorSystemResource =
|
||||
new AkkaJUnitActorSystemResource("ConsistentHashingRouterDocTest");
|
||||
|
||||
private final ActorSystem system = actorSystemResource.getSystem();
|
||||
|
||||
static
|
||||
//#cache-actor
|
||||
|
|
|
|||
|
|
@ -14,9 +14,8 @@ import java.util.Arrays;
|
|||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import akka.testkit.AkkaJUnitActorSystemResource;
|
||||
import org.junit.*;
|
||||
|
||||
import scala.concurrent.Await;
|
||||
import scala.concurrent.Future;
|
||||
|
|
@ -38,17 +37,11 @@ import akka.util.Timeout;
|
|||
|
||||
public class CustomRouterDocTestBase {
|
||||
|
||||
ActorSystem system;
|
||||
@ClassRule
|
||||
public static AkkaJUnitActorSystemResource actorSystemResource =
|
||||
new AkkaJUnitActorSystemResource("CustomRouterDocTest", AkkaSpec.testConf());
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
system = ActorSystem.create("MySystem", AkkaSpec.testConf());
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
system.shutdown();
|
||||
}
|
||||
private final ActorSystem system = actorSystemResource.getSystem();
|
||||
|
||||
public static class MyActor extends UntypedActor {
|
||||
@Override public void onReceive(Object o) {}
|
||||
|
|
|
|||
|
|
@ -5,8 +5,8 @@ package docs.jrouting;
|
|||
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import akka.testkit.AkkaJUnitActorSystemResource;
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.Test;
|
||||
|
||||
import akka.actor.ActorRef;
|
||||
|
|
@ -23,17 +23,11 @@ import docs.routing.RouterViaProgramDocSpec.Echo;
|
|||
|
||||
public class RouterViaProgramDocTestBase {
|
||||
|
||||
static ActorSystem system;
|
||||
|
||||
@BeforeClass
|
||||
public static void setup() {
|
||||
system = ActorSystem.create();
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void teardown() {
|
||||
system.shutdown();
|
||||
}
|
||||
@ClassRule
|
||||
public static AkkaJUnitActorSystemResource actorSystemResource =
|
||||
new AkkaJUnitActorSystemResource("RouterViaProgramDocTest");
|
||||
|
||||
private final ActorSystem system = actorSystemResource.getSystem();
|
||||
|
||||
private static class JavaTestKitWithSelf extends JavaTestKit {
|
||||
public JavaTestKitWithSelf(ActorSystem system) {
|
||||
|
|
|
|||
|
|
@ -16,17 +16,11 @@ import java.util.concurrent.TimeUnit;
|
|||
|
||||
public class SchedulerPatternTest {
|
||||
|
||||
static ActorSystem system;
|
||||
@ClassRule
|
||||
public static AkkaJUnitActorSystemResource actorSystemResource =
|
||||
new AkkaJUnitActorSystemResource("SchedulerPatternTest", AkkaSpec.testConf());
|
||||
|
||||
@BeforeClass
|
||||
public static void setUp() {
|
||||
system = ActorSystem.create("SchedulerPatternTest", AkkaSpec.testConf());
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void tearDown() {
|
||||
system.shutdown();
|
||||
}
|
||||
private final ActorSystem system = actorSystemResource.getSystem();
|
||||
|
||||
static
|
||||
//#schedule-constructor
|
||||
|
|
|
|||
|
|
@ -3,8 +3,8 @@
|
|||
*/
|
||||
package docs.remoting;
|
||||
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import akka.testkit.AkkaJUnitActorSystemResource;
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.typesafe.config.ConfigFactory;
|
||||
|
|
@ -28,18 +28,12 @@ public class RemoteDeploymentDocTestBase {
|
|||
getSender().tell(getSelf(), getSelf());
|
||||
}
|
||||
}
|
||||
|
||||
static ActorSystem system;
|
||||
|
||||
@BeforeClass
|
||||
public static void init() {
|
||||
system = ActorSystem.create();
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void cleanup() {
|
||||
system.shutdown();
|
||||
}
|
||||
|
||||
@ClassRule
|
||||
public static AkkaJUnitActorSystemResource actorSystemResource =
|
||||
new AkkaJUnitActorSystemResource("RemoteDeploymentDocTest");
|
||||
|
||||
private final ActorSystem system = actorSystemResource.getSystem();
|
||||
|
||||
@Test
|
||||
public void demonstrateDeployment() {
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
*/
|
||||
package docs.serialization;
|
||||
|
||||
import akka.testkit.JavaTestKit;
|
||||
import org.junit.Test;
|
||||
import static org.junit.Assert.*;
|
||||
//#imports
|
||||
|
|
@ -66,7 +67,7 @@ public class SerializationDocTestBase {
|
|||
final ActorRef deserializedActorRef = extendedSystem.provider().resolveActorRef(identifier);
|
||||
// Then just use the ActorRef
|
||||
//#actorref-serializer
|
||||
extendedSystem.shutdown();
|
||||
JavaTestKit.shutdownActorSystem(extendedSystem);
|
||||
}
|
||||
|
||||
static
|
||||
|
|
@ -187,6 +188,6 @@ public class SerializationDocTestBase {
|
|||
assertEquals(original, back);
|
||||
|
||||
//#programmatic
|
||||
system.shutdown();
|
||||
JavaTestKit.shutdownActorSystem(system);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,12 +5,12 @@ package docs.testkit;
|
|||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import akka.testkit.*;
|
||||
import docs.actor.mailbox.DurableMailboxDocSpec;
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.typesafe.config.ConfigFactory;
|
||||
import com.typesafe.config.Config;
|
||||
|
||||
import akka.actor.ActorKilledException;
|
||||
import akka.actor.ActorRef;
|
||||
|
|
@ -22,15 +22,18 @@ import akka.actor.Terminated;
|
|||
import akka.actor.UntypedActor;
|
||||
import scala.concurrent.Await;
|
||||
import scala.concurrent.Future;
|
||||
import akka.testkit.CallingThreadDispatcher;
|
||||
import akka.testkit.TestActor;
|
||||
import akka.testkit.TestActor.AutoPilot;
|
||||
import akka.testkit.TestActorRef;
|
||||
import akka.testkit.JavaTestKit;
|
||||
import scala.concurrent.duration.Duration;
|
||||
|
||||
public class TestKitDocTest {
|
||||
|
||||
@ClassRule
|
||||
public static AkkaJUnitActorSystemResource actorSystemResource =
|
||||
new AkkaJUnitActorSystemResource("TestKitDocTest",
|
||||
ConfigFactory.parseString("akka.loggers = [akka.testkit.TestEventListener]"));
|
||||
|
||||
private final ActorSystem system = actorSystemResource.getSystem();
|
||||
|
||||
//#test-actor-ref
|
||||
static class MyActor extends UntypedActor {
|
||||
public void onReceive(Object o) throws Exception {
|
||||
|
|
@ -43,23 +46,6 @@ public class TestKitDocTest {
|
|||
public boolean testMe() { return true; }
|
||||
}
|
||||
|
||||
//#test-actor-ref
|
||||
|
||||
private static ActorSystem system;
|
||||
|
||||
@BeforeClass
|
||||
public static void setup() {
|
||||
final Config config = ConfigFactory.parseString(
|
||||
"akka.loggers = [akka.testkit.TestEventListener]");
|
||||
system = ActorSystem.create("demoSystem", config);
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void cleanup() {
|
||||
system.shutdown();
|
||||
}
|
||||
|
||||
//#test-actor-ref
|
||||
@Test
|
||||
public void demonstrateTestActorRef() {
|
||||
final Props props = Props.create(MyActor.class);
|
||||
|
|
@ -415,7 +401,7 @@ public class TestKitDocTest {
|
|||
public void demonstrateEventFilter() {
|
||||
//#test-event-filter
|
||||
new JavaTestKit(system) {{
|
||||
assertEquals("demoSystem", system.name());
|
||||
assertEquals("TestKitDocTest", system.name());
|
||||
final ActorRef victim = system.actorOf(Props.empty(), "victim");
|
||||
|
||||
final int result = new EventFilter<Integer>(ActorKilledException.class) {
|
||||
|
|
@ -423,7 +409,7 @@ public class TestKitDocTest {
|
|||
victim.tell(Kill.getInstance(), null);
|
||||
return 42;
|
||||
}
|
||||
}.from("akka://demoSystem/user/victim").occurrences(1).exec();
|
||||
}.from("akka://TestKitDocTest/user/victim").occurrences(1).exec();
|
||||
|
||||
assertEquals(42, result);
|
||||
}};
|
||||
|
|
|
|||
|
|
@ -43,7 +43,8 @@ public class TestKitSampleTest {
|
|||
|
||||
@AfterClass
|
||||
public static void teardown() {
|
||||
system.shutdown();
|
||||
JavaTestKit.shutdownActorSystem(system);
|
||||
system = null;
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
|||
|
|
@ -5,6 +5,8 @@
|
|||
package docs.transactor;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import akka.testkit.JavaTestKit;
|
||||
import org.junit.Test;
|
||||
|
||||
//#imports
|
||||
|
|
@ -18,83 +20,83 @@ import static java.util.concurrent.TimeUnit.SECONDS;
|
|||
|
||||
public class TransactorDocTest {
|
||||
|
||||
@Test
|
||||
public void coordinatedExample() throws Exception {
|
||||
//#coordinated-example
|
||||
ActorSystem system = ActorSystem.create("CoordinatedExample");
|
||||
@Test
|
||||
public void coordinatedExample() throws Exception {
|
||||
//#coordinated-example
|
||||
ActorSystem system = ActorSystem.create("CoordinatedExample");
|
||||
|
||||
ActorRef counter1 = system.actorOf(Props.create(CoordinatedCounter.class));
|
||||
ActorRef counter2 = system.actorOf(Props.create(CoordinatedCounter.class));
|
||||
ActorRef counter1 = system.actorOf(Props.create(CoordinatedCounter.class));
|
||||
ActorRef counter2 = system.actorOf(Props.create(CoordinatedCounter.class));
|
||||
|
||||
Timeout timeout = new Timeout(5, SECONDS);
|
||||
Timeout timeout = new Timeout(5, SECONDS);
|
||||
|
||||
counter1.tell(new Coordinated(new Increment(counter2), timeout), null);
|
||||
counter1.tell(new Coordinated(new Increment(counter2), timeout), null);
|
||||
|
||||
Integer count = (Integer) Await.result(
|
||||
ask(counter1, "GetCount", timeout), timeout.duration());
|
||||
//#coordinated-example
|
||||
Integer count = (Integer) Await.result(
|
||||
ask(counter1, "GetCount", timeout), timeout.duration());
|
||||
//#coordinated-example
|
||||
|
||||
assertEquals(count, new Integer(1));
|
||||
assertEquals(count, new Integer(1));
|
||||
|
||||
system.shutdown();
|
||||
}
|
||||
JavaTestKit.shutdownActorSystem(system);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void coordinatedApi() {
|
||||
//#create-coordinated
|
||||
Timeout timeout = new Timeout(5, SECONDS);
|
||||
Coordinated coordinated = new Coordinated(timeout);
|
||||
//#create-coordinated
|
||||
@Test
|
||||
public void coordinatedApi() {
|
||||
//#create-coordinated
|
||||
Timeout timeout = new Timeout(5, SECONDS);
|
||||
Coordinated coordinated = new Coordinated(timeout);
|
||||
//#create-coordinated
|
||||
|
||||
ActorSystem system = ActorSystem.create("CoordinatedApi");
|
||||
ActorRef actor = system.actorOf(Props.create(Coordinator.class));
|
||||
ActorSystem system = ActorSystem.create("CoordinatedApi");
|
||||
ActorRef actor = system.actorOf(Props.create(Coordinator.class));
|
||||
|
||||
//#send-coordinated
|
||||
actor.tell(new Coordinated(new Message(), timeout), null);
|
||||
//#send-coordinated
|
||||
//#send-coordinated
|
||||
actor.tell(new Coordinated(new Message(), timeout), null);
|
||||
//#send-coordinated
|
||||
|
||||
//#include-coordinated
|
||||
actor.tell(coordinated.coordinate(new Message()), null);
|
||||
//#include-coordinated
|
||||
//#include-coordinated
|
||||
actor.tell(coordinated.coordinate(new Message()), null);
|
||||
//#include-coordinated
|
||||
|
||||
coordinated.await();
|
||||
coordinated.await();
|
||||
|
||||
system.shutdown();
|
||||
}
|
||||
JavaTestKit.shutdownActorSystem(system);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void counterTransactor() throws Exception {
|
||||
ActorSystem system = ActorSystem.create("CounterTransactor");
|
||||
ActorRef counter = system.actorOf(Props.create(Counter.class));
|
||||
@Test
|
||||
public void counterTransactor() throws Exception {
|
||||
ActorSystem system = ActorSystem.create("CounterTransactor");
|
||||
ActorRef counter = system.actorOf(Props.create(Counter.class));
|
||||
|
||||
Timeout timeout = new Timeout(5, SECONDS);
|
||||
Coordinated coordinated = new Coordinated(timeout);
|
||||
counter.tell(coordinated.coordinate(new Increment()), null);
|
||||
coordinated.await();
|
||||
Timeout timeout = new Timeout(5, SECONDS);
|
||||
Coordinated coordinated = new Coordinated(timeout);
|
||||
counter.tell(coordinated.coordinate(new Increment()), null);
|
||||
coordinated.await();
|
||||
|
||||
Integer count = (Integer) Await.result(ask(counter, "GetCount", timeout), timeout.duration());
|
||||
assertEquals(count, new Integer(1));
|
||||
Integer count = (Integer) Await.result(ask(counter, "GetCount", timeout), timeout.duration());
|
||||
assertEquals(count, new Integer(1));
|
||||
|
||||
system.shutdown();
|
||||
}
|
||||
JavaTestKit.shutdownActorSystem(system);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void friendlyCounterTransactor() throws Exception {
|
||||
ActorSystem system = ActorSystem.create("FriendlyCounterTransactor");
|
||||
ActorRef friend = system.actorOf(Props.create(Counter.class));
|
||||
ActorRef friendlyCounter = system.actorOf(Props.create(FriendlyCounter.class));
|
||||
@Test
|
||||
public void friendlyCounterTransactor() throws Exception {
|
||||
ActorSystem system = ActorSystem.create("FriendlyCounterTransactor");
|
||||
ActorRef friend = system.actorOf(Props.create(Counter.class));
|
||||
ActorRef friendlyCounter = system.actorOf(Props.create(FriendlyCounter.class));
|
||||
|
||||
Timeout timeout = new Timeout(5, SECONDS);
|
||||
Coordinated coordinated = new Coordinated(timeout);
|
||||
friendlyCounter.tell(coordinated.coordinate(new Increment(friend)), null);
|
||||
coordinated.await();
|
||||
Timeout timeout = new Timeout(5, SECONDS);
|
||||
Coordinated coordinated = new Coordinated(timeout);
|
||||
friendlyCounter.tell(coordinated.coordinate(new Increment(friend)), null);
|
||||
coordinated.await();
|
||||
|
||||
Integer count1 = (Integer) Await.result(ask(friendlyCounter, "GetCount", timeout), timeout.duration());
|
||||
assertEquals(count1, new Integer(1));
|
||||
Integer count1 = (Integer) Await.result(ask(friendlyCounter, "GetCount", timeout), timeout.duration());
|
||||
assertEquals(count1, new Integer(1));
|
||||
|
||||
Integer count2 = (Integer) Await.result(ask(friend, "GetCount", timeout), timeout.duration());
|
||||
assertEquals(count2, new Integer(1));
|
||||
Integer count2 = (Integer) Await.result(ask(friend, "GetCount", timeout), timeout.duration());
|
||||
assertEquals(count2, new Integer(1));
|
||||
|
||||
system.shutdown();
|
||||
}
|
||||
JavaTestKit.shutdownActorSystem(system);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ import akka.actor.UntypedActor;
|
|||
import akka.actor.Props;
|
||||
import akka.event.Logging;
|
||||
import akka.event.LoggingAdapter;
|
||||
import org.junit.*;
|
||||
import scala.concurrent.duration.Duration;
|
||||
import akka.serialization.SerializationExtension;
|
||||
import akka.serialization.Serialization;
|
||||
|
|
@ -47,26 +48,16 @@ import java.text.SimpleDateFormat;
|
|||
|
||||
import akka.actor.ActorSystem;
|
||||
import akka.testkit.AkkaSpec;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.Assume;
|
||||
import akka.testkit.AkkaJUnitActorSystemResource;
|
||||
|
||||
public class ZeromqDocTestBase {
|
||||
|
||||
ActorSystem system;
|
||||
@ClassRule
|
||||
public static AkkaJUnitActorSystemResource actorSystemResource =
|
||||
new AkkaJUnitActorSystemResource("ZeromqDocTest",
|
||||
ConfigFactory.parseString("akka.loglevel=INFO").withFallback(AkkaSpec.testConf()));
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
system = ActorSystem.create("ZeromqDocTest",
|
||||
ConfigFactory.parseString("akka.loglevel=INFO").withFallback(AkkaSpec.testConf()));
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
system.shutdown();
|
||||
}
|
||||
private final ActorSystem system = actorSystemResource.getSystem();
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@Test
|
||||
|
|
|
|||
|
|
@ -267,7 +267,7 @@ class ActorDocSpec extends AkkaSpec(Map("akka.loglevel" -> "INFO")) {
|
|||
val system = ActorSystem("mySystem")
|
||||
val myActor = system.actorOf(Props[MyActor].withDispatcher("my-dispatcher"), "myactor2")
|
||||
//#system-actorOf
|
||||
system.shutdown()
|
||||
shutdown(system)
|
||||
}
|
||||
|
||||
"creating actor with IndirectActorProducer" in {
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ class RemoteDeploymentDocSpec extends AkkaSpec("""
|
|||
val other = ActorSystem("remote", system.settings.config)
|
||||
val address = other.asInstanceOf[ExtendedActorSystem].provider.getExternalAddressFor(Address("akka.tcp", "s", "host", 1)).get
|
||||
|
||||
override def afterTermination() { other.shutdown() }
|
||||
override def afterTermination() { shutdown(other) }
|
||||
|
||||
"demonstrate programmatic deployment" in {
|
||||
//#deploy
|
||||
|
|
|
|||
|
|
@ -64,7 +64,7 @@ package docs.serialization {
|
|||
//#serialize-messages-config
|
||||
val a = ActorSystem("system", config)
|
||||
a.settings.SerializeAllMessages must be(true)
|
||||
a.shutdown()
|
||||
shutdown(a)
|
||||
}
|
||||
|
||||
"demonstrate configuration of serialize creators" in {
|
||||
|
|
@ -79,7 +79,7 @@ package docs.serialization {
|
|||
//#serialize-creators-config
|
||||
val a = ActorSystem("system", config)
|
||||
a.settings.SerializeAllCreators must be(true)
|
||||
a.shutdown()
|
||||
shutdown(a)
|
||||
}
|
||||
|
||||
"demonstrate configuration of serializers" in {
|
||||
|
|
@ -97,7 +97,7 @@ package docs.serialization {
|
|||
""")
|
||||
//#serialize-serializers-config
|
||||
val a = ActorSystem("system", config)
|
||||
a.shutdown()
|
||||
shutdown(a)
|
||||
}
|
||||
|
||||
"demonstrate configuration of serialization-bindings" in {
|
||||
|
|
@ -126,7 +126,7 @@ package docs.serialization {
|
|||
SerializationExtension(a).serializerFor(classOf[String]).getClass must equal(classOf[JavaSerializer])
|
||||
SerializationExtension(a).serializerFor(classOf[Customer]).getClass must equal(classOf[JavaSerializer])
|
||||
SerializationExtension(a).serializerFor(classOf[java.lang.Boolean]).getClass must equal(classOf[MyOwnSerializer])
|
||||
a.shutdown()
|
||||
shutdown(a)
|
||||
}
|
||||
|
||||
"demonstrate the programmatic API" in {
|
||||
|
|
@ -152,7 +152,7 @@ package docs.serialization {
|
|||
back must equal(original)
|
||||
|
||||
//#programmatic
|
||||
system.shutdown()
|
||||
shutdown(system)
|
||||
}
|
||||
|
||||
"demonstrate serialization of ActorRefs" in {
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ class MySpec(_system: ActorSystem) extends TestKit(_system) with ImplicitSender
|
|||
import MySpec._
|
||||
|
||||
override def afterAll {
|
||||
system.shutdown()
|
||||
TestKit.shutdownActorSystem(system)
|
||||
}
|
||||
|
||||
"An Echo actor" must {
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ class TestKitUsageSpec
|
|||
system.actorOf(Props(classOf[SequencingActor], testActor, headList, tailList))
|
||||
|
||||
override def afterAll {
|
||||
system.shutdown()
|
||||
shutdown(system)
|
||||
}
|
||||
|
||||
"An EchoActor" should {
|
||||
|
|
|
|||
|
|
@ -264,7 +264,7 @@ class TestkitDocSpec extends AkkaSpec with DefaultTimeout with ImplicitSender {
|
|||
actor ! Kill
|
||||
}
|
||||
} finally {
|
||||
system.shutdown()
|
||||
shutdown(system)
|
||||
}
|
||||
//#event-filter
|
||||
}
|
||||
|
|
@ -282,7 +282,7 @@ class TestkitDocSpec extends AkkaSpec with DefaultTimeout with ImplicitSender {
|
|||
try expectMsg("hello") catch { case NonFatal(e) ⇒ system.shutdown(); throw e }
|
||||
//#put-your-test-code-here
|
||||
|
||||
system.shutdown()
|
||||
shutdown(system)
|
||||
}
|
||||
//#test-kit-base
|
||||
}
|
||||
|
|
|
|||
|
|
@ -161,7 +161,7 @@ class TransactorDocSpec extends AkkaSpec {
|
|||
|
||||
count must be === 1
|
||||
|
||||
system.shutdown()
|
||||
shutdown(system)
|
||||
}
|
||||
|
||||
"coordinated api" in {
|
||||
|
|
@ -191,7 +191,7 @@ class TransactorDocSpec extends AkkaSpec {
|
|||
|
||||
coordinated.await()
|
||||
|
||||
system.shutdown()
|
||||
shutdown(system)
|
||||
}
|
||||
|
||||
"counter transactor" in {
|
||||
|
|
@ -208,7 +208,7 @@ class TransactorDocSpec extends AkkaSpec {
|
|||
|
||||
underlyingCounter.count.single.get must be === 1
|
||||
|
||||
system.shutdown()
|
||||
shutdown(system)
|
||||
}
|
||||
|
||||
"friendly counter transactor" in {
|
||||
|
|
@ -229,6 +229,6 @@ class TransactorDocSpec extends AkkaSpec {
|
|||
underlyingFriendlyCounter.count.single.get must be === 1
|
||||
underlyingFriend.count.single.get must be === 1
|
||||
|
||||
system.shutdown()
|
||||
shutdown(system)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue