import com.google.common.collect.ImmutableMap;
import com.google.common.util.concurrent.Uninterruptibles;
import java.io.OutputStream;
+import java.time.Duration;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
}
}
+ /**
+ * Message intended for testing to allow triggering persistData via the mailbox.
+ */
+ public static final class TestPersist {
+
+ private final ActorRef actorRef;
+ private final Identifier identifier;
+ private final Payload payload;
+
+ TestPersist(final ActorRef actorRef, final Identifier identifier, final Payload payload) {
+ this.actorRef = actorRef;
+ this.identifier = identifier;
+ this.payload = payload;
+ }
+
+ public ActorRef getActorRef() {
+ return actorRef;
+ }
+
+ public Identifier getIdentifier() {
+ return identifier;
+ }
+
+ public Payload getPayload() {
+ return payload;
+ }
+ }
+
public static class TestRaftActor extends MockRaftActor {
private final ActorRef collectorActor;
return;
}
+ if (message instanceof TestPersist) {
+ persistData(((TestPersist) message).getActorRef(), ((TestPersist) message).getIdentifier(),
+ ((TestPersist) message).getPayload(), false);
+ return;
+ }
+
try {
Predicate drop = dropMessages.get(message.getClass());
if (drop == null || !drop.test(message)) {
testkit.watch(actor);
actor.tell(PoisonPill.getInstance(), null);
- testkit.expectMsgClass(testkit.duration("5 seconds"), Terminated.class);
+ testkit.expectMsgClass(Duration.ofSeconds(5), Terminated.class);
testkit.unwatch(actor);
}
}
protected void verifySnapshot(final String prefix, final Snapshot snapshot, final long lastAppliedTerm,
- final long lastAppliedIndex, final long lastTerm, final long lastIndex)
- throws Exception {
+ final long lastAppliedIndex, final long lastTerm, final long lastIndex) {
assertEquals(prefix + " Snapshot getLastAppliedTerm", lastAppliedTerm, snapshot.getLastAppliedTerm());
assertEquals(prefix + " Snapshot getLastAppliedIndex", lastAppliedIndex, snapshot.getLastAppliedIndex());
assertEquals(prefix + " Snapshot getLastTerm", lastTerm, snapshot.getLastTerm());