Skip to content

Commit e00ab53

Browse files
committed
Wait on shutdown of extra actor systems in tests. See #3217
1 parent 3bc661b commit e00ab53

File tree

84 files changed

+780
-863
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

84 files changed

+780
-863
lines changed

akka-actor-tests/src/test/java/akka/actor/JavaAPI.java

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,35 +4,27 @@
44

55
package akka.actor;
66

7-
import akka.actor.ActorSystem;
87
import akka.event.Logging;
98
import akka.event.Logging.LoggerInitialized;
109
import akka.japi.Creator;
1110
import akka.routing.CurrentRoutees;
1211
import akka.routing.FromConfig;
1312
import akka.routing.NoRouter;
13+
import akka.testkit.AkkaJUnitActorSystemResource;
1414
import akka.testkit.AkkaSpec;
1515

16-
import org.junit.AfterClass;
17-
import org.junit.BeforeClass;
16+
import org.junit.ClassRule;
1817
import org.junit.Test;
1918
import static org.junit.Assert.*;
2019

2120
public class JavaAPI {
2221

23-
private static ActorSystem system;
22+
@ClassRule
23+
public static AkkaJUnitActorSystemResource actorSystemResource =
24+
new AkkaJUnitActorSystemResource("JAvaAPI", AkkaSpec.testConf());
2425

25-
@BeforeClass
26-
public static void beforeAll() {
27-
system = ActorSystem.create("JavaAPI", AkkaSpec.testConf());
28-
}
26+
private final ActorSystem system = actorSystemResource.getSystem();
2927

30-
@AfterClass
31-
public static void afterAll() {
32-
system.shutdown();
33-
system = null;
34-
}
35-
3628
// compilation tests
3729
@SuppressWarnings("unused")
3830
public void mustCompile() {

akka-actor-tests/src/test/java/akka/actor/JavaExtension.java

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,10 @@
33
*/
44
package akka.actor;
55

6-
import org.junit.AfterClass;
7-
import org.junit.BeforeClass;
8-
import org.junit.Test;
9-
6+
import akka.testkit.AkkaJUnitActorSystemResource;
7+
import org.junit.*;
108
import akka.testkit.AkkaSpec;
11-
129
import com.typesafe.config.ConfigFactory;
13-
import com.typesafe.config.Config;
1410

1511
import static org.junit.Assert.*;
1612

@@ -47,20 +43,13 @@ public OtherExtension(ExtendedActorSystem system) {
4743
}
4844
}
4945

50-
private static ActorSystem system;
46+
@ClassRule
47+
public static AkkaJUnitActorSystemResource actorSystemResource =
48+
new AkkaJUnitActorSystemResource("JavaExtension",
49+
ConfigFactory.parseString("akka.extensions = [ \"akka.actor.JavaExtension$TestExtensionId\" ]")
50+
.withFallback(AkkaSpec.testConf()));
5151

52-
@BeforeClass
53-
public static void beforeAll() {
54-
Config c = ConfigFactory.parseString("akka.extensions = [ \"akka.actor.JavaExtension$TestExtensionId\" ]")
55-
.withFallback(AkkaSpec.testConf());
56-
system = ActorSystem.create("JavaExtension", c);
57-
}
58-
59-
@AfterClass
60-
public static void afterAll() {
61-
system.shutdown();
62-
system = null;
63-
}
52+
private final ActorSystem system = actorSystemResource.getSystem();
6453

6554
@Test
6655
public void mustBeAccessible() {

akka-actor-tests/src/test/java/akka/actor/StashJavaAPI.java

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,18 @@
11
package akka.actor;
22

3-
import org.junit.AfterClass;
4-
import org.junit.BeforeClass;
3+
import akka.testkit.AkkaJUnitActorSystemResource;
4+
import org.junit.ClassRule;
55
import org.junit.Test;
66

77
import com.typesafe.config.ConfigFactory;
88

99
public class StashJavaAPI {
1010

11-
private static ActorSystem system;
11+
@ClassRule
12+
public static AkkaJUnitActorSystemResource actorSystemResource =
13+
new AkkaJUnitActorSystemResource("StashJavaAPI", ActorWithBoundedStashSpec.testConf());
1214

13-
@BeforeClass
14-
public static void beforeAll() {
15-
system = ActorSystem.create("StashJavaAPI",
16-
ConfigFactory.parseString(ActorWithStashSpec.testConf()));
17-
}
18-
19-
@AfterClass
20-
public static void afterAll() {
21-
system.shutdown();
22-
system = null;
23-
}
15+
private final ActorSystem system = actorSystemResource.getSystem();
2416

2517
@Test
2618
public void mustBeAbleToUseStash() {

akka-actor-tests/src/test/java/akka/dispatch/JavaFutureTests.java

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
package akka.dispatch;
22

3-
import akka.util.Timeout;
3+
import akka.testkit.AkkaJUnitActorSystemResource;
44
import akka.actor.ActorSystem;
55

66
import akka.japi.*;
7+
import org.junit.ClassRule;
78
import scala.concurrent.Await;
89
import scala.concurrent.Future;
910
import scala.concurrent.Promise;
1011
import scala.concurrent.duration.Duration;
11-
import akka.testkit.TestKitExtension;
12-
import org.junit.AfterClass;
13-
import org.junit.BeforeClass;
1412
import org.junit.Test;
1513
import static org.junit.Assert.*;
1614

@@ -26,23 +24,13 @@
2624

2725
public class JavaFutureTests {
2826

29-
private static ActorSystem system;
30-
private static Timeout t;
27+
@ClassRule
28+
public static AkkaJUnitActorSystemResource actorSystemResource =
29+
new AkkaJUnitActorSystemResource("JavaFutureTests", AkkaSpec.testConf());
3130

31+
private final ActorSystem system = actorSystemResource.getSystem();
3232
private final Duration timeout = Duration.create(5, TimeUnit.SECONDS);
3333

34-
@BeforeClass
35-
public static void beforeAll() {
36-
system = ActorSystem.create("JavaFutureTests", AkkaSpec.testConf());
37-
t = TestKitExtension.get(system).DefaultTimeout();
38-
}
39-
40-
@AfterClass
41-
public static void afterAll() {
42-
system.shutdown();
43-
system = null;
44-
}
45-
4634
@Test
4735
public void mustBeAbleToMapAFuture() throws Exception {
4836

akka-actor-tests/src/test/scala/akka/actor/ActorSystemSpec.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ class ActorSystemSpec extends AkkaSpec(ActorSystemSpec.config) with ImplicitSend
147147
}
148148

149149
"allow valid names" in {
150-
ActorSystem("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-").shutdown()
150+
shutdown(ActorSystem("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-"))
151151
}
152152

153153
"support extensions" in {
@@ -199,14 +199,14 @@ class ActorSystemSpec extends AkkaSpec(ActorSystemSpec.config) with ImplicitSend
199199
val system = ActorSystem()
200200
system.isTerminated must be(false)
201201
system.shutdown()
202-
system.awaitTermination()
202+
system.awaitTermination(10 seconds)
203203
system.isTerminated must be(true)
204204
}
205205

206206
"throw RejectedExecutionException when shutdown" in {
207207
val system2 = ActorSystem("AwaitTermination", AkkaSpec.testConf)
208208
system2.shutdown()
209-
system2.awaitTermination(5 seconds)
209+
system2.awaitTermination(10 seconds)
210210

211211
intercept[RejectedExecutionException] {
212212
system2.registerOnTermination { println("IF YOU SEE THIS THEN THERE'S A BUG HERE") }
@@ -275,7 +275,7 @@ class ActorSystemSpec extends AkkaSpec(ActorSystemSpec.config) with ImplicitSend
275275
val t = probe.expectMsg(Terminated(a)(existenceConfirmed = true, addressTerminated = false))
276276
t.existenceConfirmed must be(true)
277277
t.addressTerminated must be(false)
278-
system.shutdown()
278+
shutdown(system)
279279
}
280280

281281
"shut down when /user escalates" in {

akka-actor-tests/src/test/scala/akka/actor/DeployerSpec.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ class DeployerSpec extends AkkaSpec(DeployerSpec.deployerConf) {
132132
}
133133
""", ConfigParseOptions.defaults).withFallback(AkkaSpec.testConf)
134134

135-
ActorSystem("invalid", invalidDeployerConf).shutdown()
135+
shutdown(ActorSystem("invalid", invalidDeployerConf))
136136
}
137137
}
138138

akka-actor-tests/src/test/scala/akka/actor/FSMActorSpec.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ class FSMActorSpec extends AkkaSpec(Map("akka.actor.debug.fsm" -> true)) with Im
295295
}
296296
}
297297
} finally {
298-
fsmEventSystem.shutdown()
298+
TestKit.shutdownActorSystem(fsmEventSystem)
299299
}
300300
}
301301

akka-actor-tests/src/test/scala/akka/event/EventStreamSpec.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ class EventStreamSpec extends AkkaSpec(EventStreamSpec.config) {
104104
expectMsgAllOf(m, Logging.Debug(sys.deadLetters.path.toString, sys.deadLetters.getClass, "unhandled message from " + sys.deadLetters + ": 42"))
105105
sys.eventStream.unsubscribe(testActor)
106106
} finally {
107-
sys.shutdown()
107+
shutdown(sys)
108108
}
109109
}
110110

akka-actor-tests/src/test/scala/akka/event/LoggerSpec.scala

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,7 @@ class LoggerSpec extends WordSpec with MustMatchers {
9999
probe.expectNoMsg(0.5.seconds.dilated)
100100
}
101101
} finally {
102-
system.shutdown()
103-
system.awaitTermination(5.seconds.dilated)
102+
TestKit.shutdownActorSystem(system)
104103
}
105104
}
106105
out
@@ -139,8 +138,7 @@ class LoggerSpec extends WordSpec with MustMatchers {
139138
probe1.expectMsg("log it")
140139
probe2.expectMsg("log it")
141140
} finally {
142-
system.shutdown()
143-
system.awaitTermination(5.seconds.dilated)
141+
TestKit.shutdownActorSystem(system)
144142
}
145143
}
146144
}
@@ -165,8 +163,7 @@ class LoggerSpec extends WordSpec with MustMatchers {
165163
try {
166164
SerializationExtension(s).serialize(Warning("foo", classOf[String]))
167165
} finally {
168-
s.shutdown()
169-
s.awaitTermination(5.seconds.dilated)
166+
TestKit.shutdownActorSystem(s)
170167
}
171168
}
172169
}

akka-actor-tests/src/test/scala/akka/event/LoggingReceiveSpec.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ class LoggingReceiveSpec extends WordSpec with BeforeAndAfterEach with BeforeAnd
4747
}
4848

4949
override def afterAll {
50-
appLogging.shutdown()
51-
appAuto.shutdown()
52-
appLifecycle.shutdown()
50+
TestKit.shutdownActorSystem(appLogging)
51+
TestKit.shutdownActorSystem(appAuto)
52+
TestKit.shutdownActorSystem(appLifecycle)
5353
}
5454

5555
"A LoggingReceive" must {

0 commit comments

Comments
 (0)