Search in sources :

Example 26 with ReplicatedLogEntry

use of org.opendaylight.controller.cluster.raft.ReplicatedLogEntry in project controller by opendaylight.

the class CandidateTest method testResponseToHandleAppendEntriesWithEqualTerm.

@Test
public void testResponseToHandleAppendEntriesWithEqualTerm() {
    MockRaftActorContext actorContext = createActorContext();
    candidate = new Candidate(actorContext);
    setupPeers(1);
    RaftActorBehavior newBehavior = candidate.handleMessage(peerActors[0], new AppendEntries(2, "test", 0, 0, Collections.<ReplicatedLogEntry>emptyList(), 0, -1, (short) 0));
    assertTrue("New Behavior : " + newBehavior + " term = " + actorContext.getTermInformation().getCurrentTerm(), newBehavior instanceof Follower);
}
Also used : SimpleReplicatedLogEntry(org.opendaylight.controller.cluster.raft.persisted.SimpleReplicatedLogEntry) ReplicatedLogEntry(org.opendaylight.controller.cluster.raft.ReplicatedLogEntry) MockRaftActorContext(org.opendaylight.controller.cluster.raft.MockRaftActorContext) AppendEntries(org.opendaylight.controller.cluster.raft.messages.AppendEntries) Test(org.junit.Test)

Example 27 with ReplicatedLogEntry

use of org.opendaylight.controller.cluster.raft.ReplicatedLogEntry in project controller by opendaylight.

the class CandidateTest method testResponseToHandleAppendEntriesWithLowerTerm.

@Test
public void testResponseToHandleAppendEntriesWithLowerTerm() {
    candidate = new Candidate(createActorContext());
    setupPeers(1);
    RaftActorBehavior newBehavior = candidate.handleMessage(peerActors[0], new AppendEntries(1, "test", 0, 0, Collections.<ReplicatedLogEntry>emptyList(), 0, -1, (short) 0));
    AppendEntriesReply reply = MessageCollectorActor.expectFirstMatching(peerActors[0], AppendEntriesReply.class);
    assertEquals("isSuccess", false, reply.isSuccess());
    assertEquals("getTerm", 2, reply.getTerm());
    assertTrue("New Behavior : " + newBehavior, newBehavior instanceof Candidate);
}
Also used : SimpleReplicatedLogEntry(org.opendaylight.controller.cluster.raft.persisted.SimpleReplicatedLogEntry) ReplicatedLogEntry(org.opendaylight.controller.cluster.raft.ReplicatedLogEntry) AppendEntriesReply(org.opendaylight.controller.cluster.raft.messages.AppendEntriesReply) AppendEntries(org.opendaylight.controller.cluster.raft.messages.AppendEntries) Test(org.junit.Test)

Example 28 with ReplicatedLogEntry

use of org.opendaylight.controller.cluster.raft.ReplicatedLogEntry in project controller by opendaylight.

the class CandidateTest method testResponseToHandleAppendEntriesWithHigherTerm.

@Test
public void testResponseToHandleAppendEntriesWithHigherTerm() {
    candidate = new Candidate(createActorContext());
    setupPeers(1);
    RaftActorBehavior newBehavior = candidate.handleMessage(peerActors[0], new AppendEntries(5, "test", 0, 0, Collections.<ReplicatedLogEntry>emptyList(), 0, -1, (short) 0));
    assertTrue("New Behavior : " + newBehavior, newBehavior instanceof Follower);
}
Also used : SimpleReplicatedLogEntry(org.opendaylight.controller.cluster.raft.persisted.SimpleReplicatedLogEntry) ReplicatedLogEntry(org.opendaylight.controller.cluster.raft.ReplicatedLogEntry) AppendEntries(org.opendaylight.controller.cluster.raft.messages.AppendEntries) Test(org.junit.Test)

Example 29 with ReplicatedLogEntry

use of org.opendaylight.controller.cluster.raft.ReplicatedLogEntry in project controller by opendaylight.

the class CandidateTest method testHandleAppendEntriesAddSameEntryToLog.

@Test
@Override
public void testHandleAppendEntriesAddSameEntryToLog() {
    MockRaftActorContext context = createActorContext();
    context.getTermInformation().update(2, "test");
    // Prepare the receivers log
    MockRaftActorContext.MockPayload payload = new MockRaftActorContext.MockPayload("zero");
    setLastLogEntry(context, 2, 0, payload);
    List<ReplicatedLogEntry> entries = new ArrayList<>();
    entries.add(new SimpleReplicatedLogEntry(0, 2, payload));
    final AppendEntries appendEntries = new AppendEntries(2, "leader-1", -1, -1, entries, 2, -1, (short) 0);
    behavior = createBehavior(context);
    // 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");
    // Send an unknown message so that the state of the RaftActor remains unchanged
    behavior.handleMessage(candidateActor, "unknown");
    RaftActorBehavior raftBehavior = behavior.handleMessage(candidateActor, appendEntries);
    assertEquals("Raft state", RaftState.Follower, raftBehavior.state());
    assertEquals("ReplicatedLog size", 1, context.getReplicatedLog().size());
    handleAppendEntriesAddSameEntryToLogReply(candidateActor);
}
Also used : SimpleReplicatedLogEntry(org.opendaylight.controller.cluster.raft.persisted.SimpleReplicatedLogEntry) ReplicatedLogEntry(org.opendaylight.controller.cluster.raft.ReplicatedLogEntry) SimpleReplicatedLogEntry(org.opendaylight.controller.cluster.raft.persisted.SimpleReplicatedLogEntry) MockRaftActorContext(org.opendaylight.controller.cluster.raft.MockRaftActorContext) ArrayList(java.util.ArrayList) AppendEntries(org.opendaylight.controller.cluster.raft.messages.AppendEntries) Test(org.junit.Test)

Example 30 with ReplicatedLogEntry

use of org.opendaylight.controller.cluster.raft.ReplicatedLogEntry in project controller by opendaylight.

the class FollowerTest method testHandleFirstAppendEntries.

@Test
public void testHandleFirstAppendEntries() {
    logStart("testHandleFirstAppendEntries");
    MockRaftActorContext context = createActorContext();
    context.getReplicatedLog().clear(0, 2);
    context.getReplicatedLog().append(newReplicatedLogEntry(1, 100, "bar"));
    context.getReplicatedLog().setSnapshotIndex(99);
    List<ReplicatedLogEntry> entries = Arrays.asList(newReplicatedLogEntry(2, 101, "foo"));
    Assert.assertEquals(1, context.getReplicatedLog().size());
    // The new commitIndex is 101
    AppendEntries appendEntries = new AppendEntries(2, "leader-1", 100, 1, entries, 101, 100, (short) 0);
    follower = createBehavior(context);
    follower.handleMessage(leaderActor, appendEntries);
    FollowerInitialSyncUpStatus syncStatus = MessageCollectorActor.expectFirstMatching(followerActor, FollowerInitialSyncUpStatus.class);
    AppendEntriesReply reply = MessageCollectorActor.expectFirstMatching(leaderActor, AppendEntriesReply.class);
    assertFalse(syncStatus.isInitialSyncDone());
    assertTrue("append entries reply should be true", reply.isSuccess());
}
Also used : SimpleReplicatedLogEntry(org.opendaylight.controller.cluster.raft.persisted.SimpleReplicatedLogEntry) ReplicatedLogEntry(org.opendaylight.controller.cluster.raft.ReplicatedLogEntry) AppendEntriesReply(org.opendaylight.controller.cluster.raft.messages.AppendEntriesReply) MockRaftActorContext(org.opendaylight.controller.cluster.raft.MockRaftActorContext) AppendEntries(org.opendaylight.controller.cluster.raft.messages.AppendEntries) FollowerInitialSyncUpStatus(org.opendaylight.controller.cluster.raft.base.messages.FollowerInitialSyncUpStatus) Test(org.junit.Test)

Aggregations

ReplicatedLogEntry (org.opendaylight.controller.cluster.raft.ReplicatedLogEntry)38 SimpleReplicatedLogEntry (org.opendaylight.controller.cluster.raft.persisted.SimpleReplicatedLogEntry)31 Test (org.junit.Test)30 AppendEntries (org.opendaylight.controller.cluster.raft.messages.AppendEntries)30 MockRaftActorContext (org.opendaylight.controller.cluster.raft.MockRaftActorContext)24 AppendEntriesReply (org.opendaylight.controller.cluster.raft.messages.AppendEntriesReply)15 FollowerInitialSyncUpStatus (org.opendaylight.controller.cluster.raft.base.messages.FollowerInitialSyncUpStatus)9 ArrayList (java.util.ArrayList)8 DefaultConfigParamsImpl (org.opendaylight.controller.cluster.raft.DefaultConfigParamsImpl)7 ByteString (com.google.protobuf.ByteString)5 FollowerLogInformation (org.opendaylight.controller.cluster.raft.FollowerLogInformation)5 ApplyState (org.opendaylight.controller.cluster.raft.base.messages.ApplyState)5 InstallSnapshot (org.opendaylight.controller.cluster.raft.messages.InstallSnapshot)5 ApplySnapshot (org.opendaylight.controller.cluster.raft.base.messages.ApplySnapshot)4 Snapshot (org.opendaylight.controller.cluster.raft.persisted.Snapshot)4 FiniteDuration (scala.concurrent.duration.FiniteDuration)4 AtomicReference (java.util.concurrent.atomic.AtomicReference)3 MockRaftActor (org.opendaylight.controller.cluster.raft.MockRaftActor)3 Builder (org.opendaylight.controller.cluster.raft.MockRaftActor.Builder)3 ActorSelection (akka.actor.ActorSelection)2