diff --git a/akka-persistence/src/test/java/akka/persistence/fsm/AbstractPersistentFSMTest.java b/akka-persistence/src/test/java/akka/persistence/fsm/AbstractPersistentFSMTest.java
index adeab19ddc..13473cf337 100644
--- a/akka-persistence/src/test/java/akka/persistence/fsm/AbstractPersistentFSMTest.java
+++ b/akka-persistence/src/test/java/akka/persistence/fsm/AbstractPersistentFSMTest.java
@@ -126,7 +126,7 @@ public class AbstractPersistentFSMTest extends JUnitSuite {
PersistentFSM.Transition stateTransition = expectMsgClass(PersistentFSM.Transition.class);
assertTransition(stateTransition, fsmRef, UserState.LOOKING_AROUND, UserState.SHOPPING);
- new Within(duration("0.9 seconds"), duration("1.9 seconds")) {
+ new Within(duration("0.9 seconds"), remainingOrDefault()) {
@Override
protected void run() {
PersistentFSM.Transition stateTransition = expectMsgClass(PersistentFSM.Transition.class);
@@ -134,7 +134,7 @@ public class AbstractPersistentFSMTest extends JUnitSuite {
}
};
- new Within(duration("1.9 seconds"), duration("2.9 seconds")) {
+ new Within(duration("1.9 seconds"), remainingOrDefault()) {
@Override
protected void run() {
expectTerminated(fsmRef);
@@ -312,7 +312,7 @@ public class AbstractPersistentFSMTest extends JUnitSuite {
currentState = expectMsgClass(akka.persistence.fsm.PersistentFSM.CurrentState.class);
assertEquals(currentState.state(), UserState.SHOPPING);
- new Within(duration("0.9 seconds"), duration("1.9 seconds")) {
+ new Within(duration("0.9 seconds"), remainingOrDefault()) {
@Override
protected void run() {
PersistentFSM.Transition stateTransition = expectMsgClass(PersistentFSM.Transition.class);
@@ -331,7 +331,7 @@ public class AbstractPersistentFSMTest extends JUnitSuite {
currentState = expectMsgClass(akka.persistence.fsm.PersistentFSM.CurrentState.class);
assertEquals(currentState.state(), UserState.INACTIVE);
- new Within(duration("1.9 seconds"), duration("2.9 seconds")) {
+ new Within(duration("1.9 seconds"), remainingOrDefault()) {
@Override
protected void run() {
expectTerminated(recoveredFsmRef2);
diff --git a/akka-persistence/src/test/scala/akka/persistence/fsm/PersistentFSMSpec.scala b/akka-persistence/src/test/scala/akka/persistence/fsm/PersistentFSMSpec.scala
index 2022b1d1dc..5dbeb63417 100644
--- a/akka-persistence/src/test/scala/akka/persistence/fsm/PersistentFSMSpec.scala
+++ b/akka-persistence/src/test/scala/akka/persistence/fsm/PersistentFSMSpec.scala
@@ -71,7 +71,7 @@ abstract class PersistentFSMSpec(config: Config) extends PersistenceSpec(config)
expectMsg(CurrentState(fsmRef, LookingAround, None))
expectMsg(Transition(fsmRef, LookingAround, Shopping, Some(1 second)))
- within(0.9 seconds, 1.9 seconds) {
+ within(0.9 seconds, remainingOrDefault) {
expectMsg(Transition(fsmRef, Shopping, Inactive, Some(2 seconds)))
}
@@ -201,7 +201,7 @@ abstract class PersistentFSMSpec(config: Config) extends PersistenceSpec(config)
expectMsg(CurrentState(recoveredFsmRef, Shopping, Some(1 second)))
- within(0.9 seconds, 1.9 seconds) {
+ within(0.9 seconds, remainingOrDefault) {
expectMsg(Transition(recoveredFsmRef, Shopping, Inactive, Some(2 seconds)))
}
diff --git a/akka-testkit/src/main/java/akka/testkit/JavaTestKit.java b/akka-testkit/src/main/java/akka/testkit/JavaTestKit.java
index ce0a98097d..6ea34a3048 100644
--- a/akka-testkit/src/main/java/akka/testkit/JavaTestKit.java
+++ b/akka-testkit/src/main/java/akka/testkit/JavaTestKit.java
@@ -26,24 +26,24 @@ import java.util.concurrent.TimeUnit;
* bounds concerning timing are available in the form of Within
* blocks.
*
- *
+ *
* Beware of two points:
*
- *
+ *
*
*
the ActorSystem passed into the constructor needs to be shutdown,
* otherwise thread pools and memory will be leaked - this trait is not
* thread-safe (only one actor with one queue, one stack of Within
* blocks); take care not to run tests within a single test class instance in
* parallel.
- *
+ *
*
It should be noted that for CI servers and the like all maximum Durations
* are scaled using the dilated method, which uses the
* TestKitExtension.Settings.TestTimeFactor settable via akka.conf entry
* "akka.test.timefactor".
*
- *
- *
+ *
+ *
*/
public class JavaTestKit {
/**
@@ -203,6 +203,16 @@ public class JavaTestKit {
return p.remainingOr(duration);
}
+ /**
+ * Obtain time remaining for execution of the innermost enclosing
+ * Within block or missing that it returns the properly dilated
+ * default for this case from settings (key
+ * "akka.test.single-expect-default").
+ */
+ public FiniteDuration remainingOrDefault() {
+ return p.remainingOrDefault();
+ }
+
/**
* Execute code block while bounding its execution time between
* min and max. Within blocks may be
@@ -210,11 +220,11 @@ public class JavaTestKit {
* available in a version which implicitly uses the remaining time governed by
* the innermost enclosing Within block.
*
- *
+ *
* Note that the timeout is scaled using dilated, which uses the
* configuration entry "akka.test.timefactor", while the min Duration is not.
*
- *
+ *
*
*
* // the run() method needs to finish within 3 seconds
@@ -231,6 +241,7 @@ public class JavaTestKit {
public Within(FiniteDuration max) {
p.within(max, new AbstractFunction0