X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-akka-raft%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fraft%2Fbehaviors%2FFollowerTest.java;h=63bf14922a1b1c10acab2f0f37543c004f52d99d;hb=24a5bafd22b83c4d838b7c3fc5225934fe969561;hp=f189e2d2ee6d140cbc738940540fb66adde82656;hpb=a93bcbe711f66ef6ec7bc97972f108859c87a11e;p=controller.git diff --git a/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/behaviors/FollowerTest.java b/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/behaviors/FollowerTest.java index f189e2d2ee..63bf14922a 100644 --- a/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/behaviors/FollowerTest.java +++ b/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/behaviors/FollowerTest.java @@ -87,7 +87,7 @@ public class FollowerTest extends AbstractRaftActorBehaviorTest { return context; } - private int getElectionTimeoutCount(RaftActorBehavior follower){ + private static int getElectionTimeoutCount(RaftActorBehavior follower){ if(follower instanceof TestFollower){ return ((TestFollower) follower).getElectionTimeoutCount(); } @@ -109,7 +109,7 @@ public class FollowerTest extends AbstractRaftActorBehaviorTest { follower = new Follower(createActorContext()); - RaftActorBehavior raftBehavior = follower.handleMessage(followerActor, new ElectionTimeout()); + RaftActorBehavior raftBehavior = follower.handleMessage(followerActor, ElectionTimeout.INSTANCE); assertTrue(raftBehavior instanceof Candidate); } @@ -749,6 +749,7 @@ public class FollowerTest extends AbstractRaftActorBehaviorTest { logStart("testHandleInstallSnapshot"); MockRaftActorContext context = createActorContext(); + context.getTermInformation().update(1, "leader"); follower = createBehavior(context); @@ -762,7 +763,7 @@ public class FollowerTest extends AbstractRaftActorBehaviorTest { InstallSnapshot lastInstallSnapshot = null; for(int i = 0; i < totalChunks; i++) { - ByteString chunkData = getNextChunk(bsSnapshot, offset, chunkSize); + byte[] chunkData = getNextChunk(bsSnapshot, offset, chunkSize); lastInstallSnapshot = new InstallSnapshot(1, "leader", lastIncludedIndex, 1, chunkData, chunkIndex, totalChunks); follower.handleMessage(leaderActor, lastInstallSnapshot); @@ -782,6 +783,9 @@ public class FollowerTest extends AbstractRaftActorBehaviorTest { snapshot.getLastAppliedIndex()); assertEquals("getLastTerm", lastInstallSnapshot.getLastIncludedTerm(), snapshot.getLastTerm()); Assert.assertArrayEquals("getState", bsSnapshot.toByteArray(), snapshot.getState()); + assertEquals("getElectionTerm", 1, snapshot.getElectionTerm()); + assertEquals("getElectionVotedFor", "leader", snapshot.getElectionVotedFor()); + applySnapshot.getCallback().onSuccess(); List replies = MessageCollectorActor.getAllMatching( leaderActor, InstallSnapshotReply.class); @@ -826,7 +830,7 @@ public class FollowerTest extends AbstractRaftActorBehaviorTest { assertTrue(totalChunks > 1); // Send an install snapshot with the first chunk to start the process of installing a snapshot - ByteString chunkData = getNextChunk(bsSnapshot, 0, chunkSize); + byte[] chunkData = getNextChunk(bsSnapshot, 0, chunkSize); follower.handleMessage(leaderActor, new InstallSnapshot(1, "leader", lastIncludedIndex, 1, chunkData, 1, totalChunks)); @@ -867,7 +871,7 @@ public class FollowerTest extends AbstractRaftActorBehaviorTest { InstallSnapshot lastInstallSnapshot = null; for(int i = 0; i < totalChunks; i++) { - ByteString chunkData = getNextChunk(bsSnapshot, offset, chunkSize); + byte[] chunkData = getNextChunk(bsSnapshot, offset, chunkSize); lastInstallSnapshot = new InstallSnapshot(1, "leader", lastIncludedIndex, 1, chunkData, chunkIndex, totalChunks); follower.handleMessage(leaderActor, lastInstallSnapshot); @@ -963,6 +967,8 @@ public class FollowerTest extends AbstractRaftActorBehaviorTest { MockRaftActorContext context = createActorContext(); follower = createBehavior(context); follower.handleMessage(leaderActor, new RaftRPC() { + private static final long serialVersionUID = 1L; + @Override public long getTerm() { return 100; @@ -979,7 +985,7 @@ public class FollowerTest extends AbstractRaftActorBehaviorTest { assertEquals("schedule election", 0, getElectionTimeoutCount(follower)); } - public ByteString getNextChunk (ByteString bs, int offset, int chunkSize){ + public byte[] getNextChunk (ByteString bs, int offset, int chunkSize){ int snapshotLength = bs.size(); int start = offset; int size = chunkSize; @@ -990,7 +996,10 @@ public class FollowerTest extends AbstractRaftActorBehaviorTest { size = snapshotLength - start; } } - return bs.substring(start, start + size); + + byte[] nextChunk = new byte[size]; + bs.copyTo(nextChunk, start, 0, size); + return nextChunk; } private void expectAndVerifyAppendEntriesReply(int expTerm, boolean expSuccess, @@ -1015,7 +1024,7 @@ public class FollowerTest extends AbstractRaftActorBehaviorTest { } - private ReplicatedLogEntry newReplicatedLogEntry(long term, long index, String data) { + private static ReplicatedLogEntry newReplicatedLogEntry(long term, long index, String data) { return new MockRaftActorContext.MockReplicatedLogEntry(term, index, new MockRaftActorContext.MockPayload(data)); }