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%2FMockRaftActorContext.java;h=297d781251cc69854363800171599dcdc2bdc1c7;hb=64db87e8fb5de25e68ba824ec2eaa17e3f217c96;hp=c490cb21e48a4885458e44d5e0ee82653b6badf9;hpb=e4c11407593914ed4520253909d0d7669e51cfac;p=controller.git diff --git a/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/MockRaftActorContext.java b/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/MockRaftActorContext.java index c490cb21e4..297d781251 100644 --- a/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/MockRaftActorContext.java +++ b/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/MockRaftActorContext.java @@ -53,7 +53,7 @@ public class MockRaftActorContext implements RaftActorContext { * Identifier of the actor whose election term information this is */ private final String id = id1; - private long currentTerm = 0; + private long currentTerm = 1; private String votedFor = ""; @Override @@ -88,7 +88,9 @@ public class MockRaftActorContext implements RaftActorContext { public void initReplicatedLog(){ this.replicatedLog = new SimpleReplicatedLog(); - this.replicatedLog.append(new MockReplicatedLogEntry(1, 1, new MockPayload(""))); + long term = getTermInformation().getCurrentTerm(); + this.replicatedLog.append(new MockReplicatedLogEntry(term, 0, new MockPayload("1"))); + this.replicatedLog.append(new MockReplicatedLogEntry(term, 1, new MockPayload("2"))); } @Override public ActorRef actorOf(Props props) { @@ -132,6 +134,16 @@ public class MockRaftActorContext implements RaftActorContext { } @Override + // FIXME : A lot of tests try to manipulate the replicated log by setting it using this method + // This is OK to do if the underlyingActor is not RafActor or a derived class. If not then you should not + // used this way to manipulate the log because the RaftActor actually has a field replicatedLog + // which it creates internally and sets on the RaftActorContext + // The only right way to manipulate the replicated log therefore is to get it from either the RaftActor + // or the RaftActorContext and modify the entries in there instead of trying to replace it by using this setter + // Simple assertion that will fail if you do so + // ReplicatedLog log = new ReplicatedLogImpl(); + // raftActor.underlyingActor().getRaftActorContext().setReplicatedLog(log); + // assertEquals(log, raftActor.underlyingActor().getReplicatedLog()) public void setReplicatedLog(ReplicatedLog replicatedLog) { this.replicatedLog = replicatedLog; } @@ -254,6 +266,36 @@ public class MockRaftActorContext implements RaftActorContext { public String toString() { return value; } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((value == null) ? 0 : value.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + MockPayload other = (MockPayload) obj; + if (value == null) { + if (other.value != null) { + return false; + } + } else if (!value.equals(other.value)) { + return false; + } + return true; + } } public static class MockReplicatedLogEntry implements ReplicatedLogEntry, Serializable { @@ -286,6 +328,52 @@ public class MockRaftActorContext implements RaftActorContext { public int size() { return getData().size(); } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((data == null) ? 0 : data.hashCode()); + result = prime * result + (int) (index ^ (index >>> 32)); + result = prime * result + (int) (term ^ (term >>> 32)); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + MockReplicatedLogEntry other = (MockReplicatedLogEntry) obj; + if (data == null) { + if (other.data != null) { + return false; + } + } else if (!data.equals(other.data)) { + return false; + } + if (index != other.index) { + return false; + } + if (term != other.term) { + return false; + } + return true; + } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("MockReplicatedLogEntry [term=").append(term).append(", index=").append(index) + .append(", data=").append(data).append("]"); + return builder.toString(); + } } public static class MockReplicatedLogBuilder {