Code Review
/
controller.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
review
|
tree
raw
|
inline
| side by side
Bug 7521: Convert install snapshot chunking to use streams
[controller.git]
/
opendaylight
/
md-sal
/
sal-akka-raft
/
src
/
test
/
java
/
org
/
opendaylight
/
controller
/
cluster
/
raft
/
behaviors
/
AbstractRaftActorBehaviorTest.java
diff --git
a/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/behaviors/AbstractRaftActorBehaviorTest.java
b/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/behaviors/AbstractRaftActorBehaviorTest.java
index 1cee5e0d88347cf629f2412c534f90e26b852b7d..df219436007be602f73946e178f8bf510577df84 100644
(file)
--- a/
opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/behaviors/AbstractRaftActorBehaviorTest.java
+++ b/
opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/behaviors/AbstractRaftActorBehaviorTest.java
@@
-11,6
+11,7
@@
package org.opendaylight.controller.cluster.raft.behaviors;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
+
import akka.actor.ActorRef;
import akka.actor.Props;
import akka.testkit.TestActorRef;
import akka.actor.ActorRef;
import akka.actor.Props;
import akka.testkit.TestActorRef;
@@
-35,6
+36,7
@@
import org.opendaylight.controller.cluster.raft.messages.AppendEntriesReply;
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.messages.RaftRPC;
import org.opendaylight.controller.cluster.raft.messages.RequestVote;
import org.opendaylight.controller.cluster.raft.messages.RequestVoteReply;
+import org.opendaylight.controller.cluster.raft.persisted.SimpleReplicatedLogEntry;
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.opendaylight.controller.cluster.raft.policy.RaftPolicy;
import org.opendaylight.controller.cluster.raft.protobuff.client.messages.Payload;
import org.opendaylight.controller.cluster.raft.utils.MessageCollectorActor;
@@
-51,7
+53,7
@@
public abstract class AbstractRaftActorBehaviorTest<T extends RaftActorBehavior>
@After
public void tearDown() throws Exception {
@After
public void tearDown() throws Exception {
- if(behavior != null) {
+ if
(behavior != null) {
behavior.close();
}
behavior.close();
}
@@
-61,8
+63,6
@@
public abstract class AbstractRaftActorBehaviorTest<T extends RaftActorBehavior>
/**
* This test checks that when a new Raft RPC message is received with a newer
* term the RaftActor gets into the Follower state.
/**
* This test checks that when a new Raft RPC message is received with a newer
* term the RaftActor gets into the Follower state.
- *
- * @throws Exception
*/
@Test
public void testHandleRaftRPCWithNewerTerm() throws Exception {
*/
@Test
public void testHandleRaftRPCWithNewerTerm() throws Exception {
@@
-85,9
+85,7
@@
public abstract class AbstractRaftActorBehaviorTest<T extends RaftActorBehavior>
/**
* This test verifies that when an AppendEntries is received with a term that
* is less that the currentTerm of the RaftActor then the RaftActor does not
/**
* This test verifies that when an AppendEntries is received with a term that
* is less that the currentTerm of the RaftActor then the RaftActor does not
- * change it's state and it responds back with a failure
- *
- * @throws Exception
+ * change it's state and it responds back with a failure.
*/
@Test
public void testHandleAppendEntriesSenderTermLessThanReceiverTerm() throws Exception {
*/
@Test
public void testHandleAppendEntriesSenderTermLessThanReceiverTerm() throws Exception {
@@
-129,9
+127,9
@@
public abstract class AbstractRaftActorBehaviorTest<T extends RaftActorBehavior>
setLastLogEntry(context, 2, 0, payload);
List<ReplicatedLogEntry> entries = new ArrayList<>();
setLastLogEntry(context, 2, 0, payload);
List<ReplicatedLogEntry> entries = new ArrayList<>();
- entries.add(new
MockRaftActorContext.MockReplicatedLogEntry(2, 0
, payload));
+ entries.add(new
SimpleReplicatedLogEntry(0, 2
, payload));
- AppendEntries appendEntries = new AppendEntries(2, "leader-1", -1, -1, entries, 2, -1, (short)0);
+
final
AppendEntries appendEntries = new AppendEntries(2, "leader-1", -1, -1, entries, 2, -1, (short)0);
behavior = createBehavior(context);
behavior = createBehavior(context);
@@
-181,7
+179,7
@@
public abstract class AbstractRaftActorBehaviorTest<T extends RaftActorBehavior>
/**
* This test verifies that when a RaftActor receives a RequestVote message
* with a term that is greater than it's currentTerm but a less up-to-date
/**
* This test verifies that when a RaftActor receives a RequestVote message
* with a term that is greater than it's currentTerm but a less up-to-date
- * log then the receiving RaftActor will not grant the vote to the sender
+ * log then the receiving RaftActor will not grant the vote to the sender
.
*/
@Test
public void testHandleRequestVoteWhenSenderLogLessUptoDate() {
*/
@Test
public void testHandleRequestVoteWhenSenderLogLessUptoDate() {
@@
-209,7
+207,7
@@
public abstract class AbstractRaftActorBehaviorTest<T extends RaftActorBehavior>
/**
* This test verifies that the receiving RaftActor will not grant a vote
* to a sender if the sender's term is lesser than the currentTerm of the
/**
* This test verifies that the receiving RaftActor will not grant a vote
* to a sender if the sender's term is lesser than the currentTerm of the
- * recipient RaftActor
+ * recipient RaftActor
.
*/
@Test
public void testHandleRequestVoteWhenSenderTermLessThanCurrentTerm() {
*/
@Test
public void testHandleRequestVoteWhenSenderTermLessThanCurrentTerm() {
@@
-257,7
+255,8
@@
public abstract class AbstractRaftActorBehaviorTest<T extends RaftActorBehavior>
assertEquals(0, abstractBehavior.getReplicatedToAllIndex());
assertEquals(1, context.getReplicatedLog().size());
assertEquals(0, abstractBehavior.getReplicatedToAllIndex());
assertEquals(1, context.getReplicatedLog().size());
- //5 entries, lastApplied =2 and replicatedIndex = 3, but since we want to keep the lastapplied, indices 0 and 1 will only get purged
+ // 5 entries, lastApplied =2 and replicatedIndex = 3, but since we want to keep the lastapplied, indices 0 and
+ // 1 will only get purged
context.setReplicatedLog(new MockRaftActorContext.MockReplicatedLogBuilder().createEntries(0, 5, 1).build());
context.setLastApplied(2);
abstractBehavior.performSnapshotWithoutCapture(3);
context.setReplicatedLog(new MockRaftActorContext.MockReplicatedLogBuilder().createEntries(0, 5, 1).build());
context.setLastApplied(2);
abstractBehavior.performSnapshotWithoutCapture(3);
@@
-276,8
+275,8
@@
public abstract class AbstractRaftActorBehaviorTest<T extends RaftActorBehavior>
protected void assertStateChangesToFollowerWhenRaftRPCHasNewerTerm(MockRaftActorContext actorContext,
ActorRef actorRef, RaftRPC rpc) throws Exception {
protected void assertStateChangesToFollowerWhenRaftRPCHasNewerTerm(MockRaftActorContext actorContext,
ActorRef actorRef, RaftRPC rpc) throws Exception {
- Payload p = new MockRaftActorContext.MockPayload("");
- setLastLogEntry(actorContext, 1, 0, p);
+ Payload p
ayload
= new MockRaftActorContext.MockPayload("");
+ setLastLogEntry(actorContext, 1, 0, p
ayload
);
actorContext.getTermInformation().update(1, "test");
RaftActorBehavior origBehavior = createBehavior(actorContext);
actorContext.getTermInformation().update(1, "test");
RaftActorBehavior origBehavior = createBehavior(actorContext);
@@
-292,8
+291,7
@@
public abstract class AbstractRaftActorBehaviorTest<T extends RaftActorBehavior>
protected MockRaftActorContext.SimpleReplicatedLog setLastLogEntry(
MockRaftActorContext actorContext, long term, long index, Payload data) {
protected MockRaftActorContext.SimpleReplicatedLog setLastLogEntry(
MockRaftActorContext actorContext, long term, long index, Payload data) {
- return setLastLogEntry(actorContext,
- new MockRaftActorContext.MockReplicatedLogEntry(term, index, data));
+ return setLastLogEntry(actorContext, new SimpleReplicatedLogEntry(index, term, data));
}
protected MockRaftActorContext.SimpleReplicatedLog setLastLogEntry(MockRaftActorContext actorContext,
}
protected MockRaftActorContext.SimpleReplicatedLog setLastLogEntry(MockRaftActorContext actorContext,
@@
-343,7
+341,7
@@
public abstract class AbstractRaftActorBehaviorTest<T extends RaftActorBehavior>
protected ByteString toByteString(Map<String, String> state) {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
protected ByteString toByteString(Map<String, String> state) {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
- try(ObjectOutputStream oos = new ObjectOutputStream(bos)) {
+ try
(ObjectOutputStream oos = new ObjectOutputStream(bos)) {
oos.writeObject(state);
return ByteString.copyFrom(bos.toByteArray());
} catch (IOException e) {
oos.writeObject(state);
return ByteString.copyFrom(bos.toByteArray());
} catch (IOException e) {
@@
-356,7
+354,7
@@
public abstract class AbstractRaftActorBehaviorTest<T extends RaftActorBehavior>
}
protected RaftPolicy createRaftPolicy(final boolean automaticElectionsEnabled,
}
protected RaftPolicy createRaftPolicy(final boolean automaticElectionsEnabled,
- final boolean applyModificationToStateBeforeConsensus){
+ final boolean applyModificationToStateBeforeConsensus)
{
return new RaftPolicy() {
@Override
public boolean automaticElectionsEnabled() {
return new RaftPolicy() {
@Override
public boolean automaticElectionsEnabled() {