Remove MockReplicatedLogEntry
[controller.git] / opendaylight / md-sal / sal-akka-raft / src / test / java / org / opendaylight / controller / cluster / raft / MockRaftActorContext.java
index 95764ad202cfd8a3f3b875cd88edf418d3035dd6..65f0a624e6b83c6a3fb3cfff52a00d9d64c55850 100644 (file)
@@ -19,6 +19,7 @@ import java.util.HashMap;
 import java.util.Map;
 import org.opendaylight.controller.cluster.NonPersistentDataProvider;
 import org.opendaylight.controller.cluster.raft.behaviors.RaftActorBehavior;
+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.slf4j.Logger;
@@ -78,8 +79,8 @@ public class MockRaftActorContext extends RaftActorContextImpl {
     public void initReplicatedLog() {
         SimpleReplicatedLog replicatedLog = new SimpleReplicatedLog();
         long term = getTermInformation().getCurrentTerm();
-        replicatedLog.append(new MockReplicatedLogEntry(term, 0, new MockPayload("1")));
-        replicatedLog.append(new MockReplicatedLogEntry(term, 1, new MockPayload("2")));
+        replicatedLog.append(new SimpleReplicatedLogEntry(0, term, new MockPayload("1")));
+        replicatedLog.append(new SimpleReplicatedLogEntry(1, term, new MockPayload("2")));
         setReplicatedLog(replicatedLog);
         setCommitIndex(replicatedLog.lastIndex());
         setLastApplied(replicatedLog.lastIndex());
@@ -146,15 +147,10 @@ public class MockRaftActorContext extends RaftActorContextImpl {
             return removeFrom(index) >= 0;
         }
 
-        @Override
-        public void appendAndPersist(
-            ReplicatedLogEntry replicatedLogEntry) {
-            append(replicatedLogEntry);
-        }
-
         @Override
         @SuppressWarnings("checkstyle:IllegalCatch")
-        public void appendAndPersist(ReplicatedLogEntry replicatedLogEntry, Procedure<ReplicatedLogEntry> callback) {
+        public boolean appendAndPersist(ReplicatedLogEntry replicatedLogEntry, Procedure<ReplicatedLogEntry> callback,
+                boolean doAsync) {
             append(replicatedLogEntry);
 
             if (callback != null) {
@@ -164,6 +160,8 @@ public class MockRaftActorContext extends RaftActorContextImpl {
                     Throwables.propagate(e);
                 }
             }
+
+            return true;
         }
     }
 
@@ -226,97 +224,19 @@ public class MockRaftActorContext extends RaftActorContextImpl {
         }
     }
 
-    public static class MockReplicatedLogEntry implements ReplicatedLogEntry, Serializable {
-        private static final long serialVersionUID = 1L;
-
-        private final long term;
-        private final long index;
-        private final Payload data;
-
-        public MockReplicatedLogEntry(long term, long index, Payload data) {
-
-            this.term = term;
-            this.index = index;
-            this.data = data;
-        }
-
-        @Override public Payload getData() {
-            return data;
-        }
-
-        @Override public long getTerm() {
-            return term;
-        }
-
-        @Override public long getIndex() {
-            return index;
-        }
-
-        @Override
-        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 {
         private final ReplicatedLog mockLog = new SimpleReplicatedLog();
 
         public  MockReplicatedLogBuilder createEntries(int start, int end, int term) {
             for (int i = start; i < end; i++) {
-                this.mockLog.append(new ReplicatedLogImplEntry(i, term,
+                this.mockLog.append(new SimpleReplicatedLogEntry(i, term,
                         new MockRaftActorContext.MockPayload(Integer.toString(i))));
             }
             return this;
         }
 
         public  MockReplicatedLogBuilder addEntry(int index, int term, MockPayload payload) {
-            this.mockLog.append(new ReplicatedLogImplEntry(index, term, payload));
+            this.mockLog.append(new SimpleReplicatedLogEntry(index, term, payload));
             return this;
         }