+/*
+ * Copyright (c) 2014, 2015 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
package org.opendaylight.controller.cluster.raft.behaviors;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
import akka.actor.ActorRef;
import akka.actor.Props;
import akka.testkit.TestActorRef;
import org.opendaylight.controller.cluster.raft.messages.RaftRPC;
import org.opendaylight.controller.cluster.raft.messages.RequestVote;
import org.opendaylight.controller.cluster.raft.messages.RequestVoteReply;
+import org.opendaylight.controller.cluster.raft.policy.RaftPolicy;
import org.opendaylight.controller.cluster.raft.protobuff.client.messages.Payload;
import org.opendaylight.controller.cluster.raft.utils.MessageCollectorActor;
import org.slf4j.LoggerFactory;
behavior = createBehavior(context);
- if (behavior instanceof Candidate) {
- // Resetting the Candidates term to make sure it will match
- // the term sent by AppendEntries. If this was not done then
- // the test will fail because the Candidate will assume that
- // the message was sent to it from a lower term peer and will
- // thus respond with a failure
- context.getTermInformation().update(2, "test");
- }
+ assertFalse("This test should be overridden when testing Candidate", behavior instanceof Candidate);
// Send an unknown message so that the state of the RaftActor remains unchanged
RaftActorBehavior expected = behavior.handleMessage(behaviorActor, "unknown");
protected void logStart(String name) {
LoggerFactory.getLogger(LeaderTest.class).info("Starting " + name);
}
+
+ protected RaftPolicy createRaftPolicy(final boolean automaticElectionsEnabled,
+ final boolean applyModificationToStateBeforeConsensus){
+ return new RaftPolicy() {
+ @Override
+ public boolean automaticElectionsEnabled() {
+ return automaticElectionsEnabled;
+ }
+
+ @Override
+ public boolean applyModificationToStateBeforeConsensus() {
+ return applyModificationToStateBeforeConsensus;
+ }
+ };
+ }
}