Code Review
/
controller.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
review
|
tree
raw
|
inline
| side by side
Merge "Refactor LeaderTest"
[controller.git]
/
opendaylight
/
md-sal
/
sal-akka-raft
/
src
/
test
/
java
/
org
/
opendaylight
/
controller
/
cluster
/
raft
/
behaviors
/
CandidateTest.java
diff --git
a/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/behaviors/CandidateTest.java
b/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/behaviors/CandidateTest.java
index c76368370506af15ab4b7b567672514514e41690..0a715b2d04416075da5a9344ada15af6a0b688f1 100644
(file)
--- a/
opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/behaviors/CandidateTest.java
+++ b/
opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/behaviors/CandidateTest.java
@@
-1,14
+1,19
@@
package org.opendaylight.controller.cluster.raft.behaviors;
package org.opendaylight.controller.cluster.raft.behaviors;
+import static org.junit.Assert.assertEquals;
import akka.actor.ActorRef;
import akka.actor.Props;
import akka.testkit.JavaTestKit;
import akka.actor.ActorRef;
import akka.actor.Props;
import akka.testkit.JavaTestKit;
-import junit.framework.Assert;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.Before;
import org.junit.Test;
+import org.opendaylight.controller.cluster.raft.DefaultConfigParamsImpl;
import org.opendaylight.controller.cluster.raft.MockRaftActorContext;
import org.opendaylight.controller.cluster.raft.RaftActorContext;
import org.opendaylight.controller.cluster.raft.MockRaftActorContext;
import org.opendaylight.controller.cluster.raft.RaftActorContext;
-import org.opendaylight.controller.cluster.raft.R
aftState
;
+import org.opendaylight.controller.cluster.raft.R
eplicatedLogEntry
;
import org.opendaylight.controller.cluster.raft.base.messages.ElectionTimeout;
import org.opendaylight.controller.cluster.raft.messages.AppendEntries;
import org.opendaylight.controller.cluster.raft.messages.AppendEntriesReply;
import org.opendaylight.controller.cluster.raft.base.messages.ElectionTimeout;
import org.opendaylight.controller.cluster.raft.messages.AppendEntries;
import org.opendaylight.controller.cluster.raft.messages.AppendEntriesReply;
@@
-16,12
+21,6
@@
import org.opendaylight.controller.cluster.raft.messages.RequestVote;
import org.opendaylight.controller.cluster.raft.messages.RequestVoteReply;
import org.opendaylight.controller.cluster.raft.utils.DoNothingActor;
import org.opendaylight.controller.cluster.raft.messages.RequestVoteReply;
import org.opendaylight.controller.cluster.raft.utils.DoNothingActor;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-
-import static org.junit.Assert.assertEquals;
-
public class CandidateTest extends AbstractRaftActorBehaviorTest {
private final ActorRef candidateActor = getSystem().actorOf(Props.create(
public class CandidateTest extends AbstractRaftActorBehaviorTest {
private final ActorRef candidateActor = getSystem().actorOf(Props.create(
@@
-80,13
+79,15
@@
public class CandidateTest extends AbstractRaftActorBehaviorTest {
public void testThatAnElectionTimeoutIsTriggered(){
new JavaTestKit(getSystem()) {{
public void testThatAnElectionTimeoutIsTriggered(){
new JavaTestKit(getSystem()) {{
- new Within(duration("1 seconds")) {
+ new Within(DefaultConfigParamsImpl.HEART_BEAT_INTERVAL.$times(6)) {
+ @Override
protected void run() {
Candidate candidate = new Candidate(createActorContext(getTestActor()));
protected void run() {
Candidate candidate = new Candidate(createActorContext(getTestActor()));
- final Boolean out = new ExpectMsg<Boolean>(
duration("1 seconds"
), "ElectionTimeout") {
+ final Boolean out = new ExpectMsg<Boolean>(
DefaultConfigParamsImpl.HEART_BEAT_INTERVAL.$times(6
), "ElectionTimeout") {
// do not put code outside this method, will run afterwards
// do not put code outside this method, will run afterwards
+ @Override
protected Boolean match(Object in) {
if (in instanceof ElectionTimeout) {
return true;
protected Boolean match(Object in) {
if (in instanceof ElectionTimeout) {
return true;
@@
-108,54
+109,54
@@
public class CandidateTest extends AbstractRaftActorBehaviorTest {
Candidate candidate =
new Candidate(raftActorContext);
Candidate candidate =
new Candidate(raftActorContext);
- Raft
State raftState
=
+ Raft
ActorBehavior raftBehavior
=
candidate.handleMessage(candidateActor, new ElectionTimeout());
candidate.handleMessage(candidateActor, new ElectionTimeout());
- Assert.assert
Equals(RaftState.Leader, raftState
);
+ Assert.assert
True(raftBehavior instanceof Leader
);
}
@Test
public void testHandleElectionTimeoutWhenThereAreTwoNodesInCluster(){
MockRaftActorContext raftActorContext =
}
@Test
public void testHandleElectionTimeoutWhenThereAreTwoNodesInCluster(){
MockRaftActorContext raftActorContext =
-
(MockRaftActorContext)
createActorContext();
+ createActorContext();
raftActorContext.setPeerAddresses(onePeer);
Candidate candidate =
new Candidate(raftActorContext);
raftActorContext.setPeerAddresses(onePeer);
Candidate candidate =
new Candidate(raftActorContext);
- Raft
State raftState
=
+ Raft
ActorBehavior raftBehavior
=
candidate.handleMessage(candidateActor, new ElectionTimeout());
candidate.handleMessage(candidateActor, new ElectionTimeout());
- Assert.assert
Equals(RaftState.Candidate, raftSt
ate);
+ Assert.assert
True(raftBehavior instanceof Candid
ate);
}
@Test
public void testBecomeLeaderOnReceivingMajorityVotesInThreeNodesInCluster(){
MockRaftActorContext raftActorContext =
}
@Test
public void testBecomeLeaderOnReceivingMajorityVotesInThreeNodesInCluster(){
MockRaftActorContext raftActorContext =
-
(MockRaftActorContext)
createActorContext();
+ createActorContext();
raftActorContext.setPeerAddresses(twoPeers);
Candidate candidate =
new Candidate(raftActorContext);
raftActorContext.setPeerAddresses(twoPeers);
Candidate candidate =
new Candidate(raftActorContext);
- Raft
State state
OnFirstVote = candidate.handleMessage(peerActor1, new RequestVoteReply(0, true));
+ Raft
ActorBehavior behavior
OnFirstVote = candidate.handleMessage(peerActor1, new RequestVoteReply(0, true));
- Assert.assert
Equals(RaftState.Leader, stateOnFirstVote
);
+ Assert.assert
True(behaviorOnFirstVote instanceof Leader
);
}
@Test
public void testBecomeLeaderOnReceivingMajorityVotesInFiveNodesInCluster(){
MockRaftActorContext raftActorContext =
}
@Test
public void testBecomeLeaderOnReceivingMajorityVotesInFiveNodesInCluster(){
MockRaftActorContext raftActorContext =
-
(MockRaftActorContext)
createActorContext();
+ createActorContext();
raftActorContext.setPeerAddresses(fourPeers);
Candidate candidate =
new Candidate(raftActorContext);
raftActorContext.setPeerAddresses(fourPeers);
Candidate candidate =
new Candidate(raftActorContext);
- Raft
State state
OnFirstVote = candidate.handleMessage(peerActor1, new RequestVoteReply(0, true));
+ Raft
ActorBehavior behavior
OnFirstVote = candidate.handleMessage(peerActor1, new RequestVoteReply(0, true));
- Raft
State state
OnSecondVote = candidate.handleMessage(peerActor2, new RequestVoteReply(0, true));
+ Raft
ActorBehavior behavior
OnSecondVote = candidate.handleMessage(peerActor2, new RequestVoteReply(0, true));
- Assert.assert
Equals(RaftState.Candidate, stateOnFirstVo
te);
- Assert.assert
Equals(RaftState.Leader, stateOnSecondVote
);
+ Assert.assert
True(behaviorOnFirstVote instanceof Candida
te);
+ Assert.assert
True(behaviorOnSecondVote instanceof Leader
);
}
}
@@
-164,14
+165,16
@@
public class CandidateTest extends AbstractRaftActorBehaviorTest {
new JavaTestKit(getSystem()) {{
new Within(duration("1 seconds")) {
new JavaTestKit(getSystem()) {{
new Within(duration("1 seconds")) {
+ @Override
protected void run() {
Candidate candidate = new Candidate(createActorContext(getTestActor()));
protected void run() {
Candidate candidate = new Candidate(createActorContext(getTestActor()));
- candidate.handleMessage(getTestActor(), new AppendEntries(0, "test", 0,0,Collections.
EMPTY_LIST, 0
));
+ candidate.handleMessage(getTestActor(), new AppendEntries(0, "test", 0,0,Collections.
<ReplicatedLogEntry>emptyList(), 0, -1
));
final Boolean out = new ExpectMsg<Boolean>(duration("1 seconds"), "AppendEntriesResponse") {
// do not put code outside this method, will run afterwards
final Boolean out = new ExpectMsg<Boolean>(duration("1 seconds"), "AppendEntriesResponse") {
// do not put code outside this method, will run afterwards
+ @Override
protected Boolean match(Object in) {
if (in instanceof AppendEntriesReply) {
AppendEntriesReply reply = (AppendEntriesReply) in;
protected Boolean match(Object in) {
if (in instanceof AppendEntriesReply) {
AppendEntriesReply reply = (AppendEntriesReply) in;
@@
-193,6
+196,7
@@
public class CandidateTest extends AbstractRaftActorBehaviorTest {
new JavaTestKit(getSystem()) {{
new Within(duration("1 seconds")) {
new JavaTestKit(getSystem()) {{
new Within(duration("1 seconds")) {
+ @Override
protected void run() {
Candidate candidate = new Candidate(createActorContext(getTestActor()));
protected void run() {
Candidate candidate = new Candidate(createActorContext(getTestActor()));
@@
-201,6
+205,7
@@
public class CandidateTest extends AbstractRaftActorBehaviorTest {
final Boolean out = new ExpectMsg<Boolean>(duration("1 seconds"), "AppendEntriesResponse") {
// do not put code outside this method, will run afterwards
final Boolean out = new ExpectMsg<Boolean>(duration("1 seconds"), "AppendEntriesResponse") {
// do not put code outside this method, will run afterwards
+ @Override
protected Boolean match(Object in) {
if (in instanceof RequestVoteReply) {
RequestVoteReply reply = (RequestVoteReply) in;
protected Boolean match(Object in) {
if (in instanceof RequestVoteReply) {
RequestVoteReply reply = (RequestVoteReply) in;
@@
-222,6
+227,7
@@
public class CandidateTest extends AbstractRaftActorBehaviorTest {
new JavaTestKit(getSystem()) {{
new Within(duration("1 seconds")) {
new JavaTestKit(getSystem()) {{
new Within(duration("1 seconds")) {
+ @Override
protected void run() {
RaftActorContext context = createActorContext(getTestActor());
protected void run() {
RaftActorContext context = createActorContext(getTestActor());
@@
-236,6
+242,7
@@
public class CandidateTest extends AbstractRaftActorBehaviorTest {
final Boolean out = new ExpectMsg<Boolean>(duration("1 seconds"), "RequestVoteReply") {
// do not put code outside this method, will run afterwards
final Boolean out = new ExpectMsg<Boolean>(duration("1 seconds"), "RequestVoteReply") {
// do not put code outside this method, will run afterwards
+ @Override
protected Boolean match(Object in) {
if (in instanceof RequestVoteReply) {
RequestVoteReply reply = (RequestVoteReply) in;
protected Boolean match(Object in) {
if (in instanceof RequestVoteReply) {
RequestVoteReply reply = (RequestVoteReply) in;
@@
-257,6
+264,7
@@
public class CandidateTest extends AbstractRaftActorBehaviorTest {
new JavaTestKit(getSystem()) {{
new Within(duration("1 seconds")) {
new JavaTestKit(getSystem()) {{
new Within(duration("1 seconds")) {
+ @Override
protected void run() {
RaftActorContext context = createActorContext(getTestActor());
protected void run() {
RaftActorContext context = createActorContext(getTestActor());
@@
-269,6
+277,7
@@
public class CandidateTest extends AbstractRaftActorBehaviorTest {
final Boolean out = new ExpectMsg<Boolean>(duration("1 seconds"), "RequestVoteReply") {
// do not put code outside this method, will run afterwards
final Boolean out = new ExpectMsg<Boolean>(duration("1 seconds"), "RequestVoteReply") {
// do not put code outside this method, will run afterwards
+ @Override
protected Boolean match(Object in) {
if (in instanceof RequestVoteReply) {
RequestVoteReply reply = (RequestVoteReply) in;
protected Boolean match(Object in) {
if (in instanceof RequestVoteReply) {
RequestVoteReply reply = (RequestVoteReply) in;
@@
-291,7
+300,7
@@
public class CandidateTest extends AbstractRaftActorBehaviorTest {
return new Candidate(actorContext);
}
return new Candidate(actorContext);
}
- @Override protected RaftActorContext createActorContext() {
+ @Override protected
Mock
RaftActorContext createActorContext() {
return new MockRaftActorContext("test", getSystem(), candidateActor);
}
return new MockRaftActorContext("test", getSystem(), candidateActor);
}