use of org.opendaylight.controller.cluster.raft.SnapshotManager.LastAppliedTermInformationReader in project controller by opendaylight.
the class SnapshotManagerTest method testLastAppliedTermInformationReader.
@Test
public void testLastAppliedTermInformationReader() {
LastAppliedTermInformationReader reader = new LastAppliedTermInformationReader();
doReturn(4L).when(mockReplicatedLog).getSnapshotTerm();
doReturn(7L).when(mockReplicatedLog).getSnapshotIndex();
ReplicatedLogEntry lastLogEntry = new SimpleReplicatedLogEntry(9L, 6L, new MockRaftActorContext.MockPayload());
// No followers and valid lastLogEntry
reader.init(mockReplicatedLog, 1L, lastLogEntry, false);
assertEquals("getTerm", 6L, reader.getTerm());
assertEquals("getIndex", 9L, reader.getIndex());
// No followers and null lastLogEntry
reader.init(mockReplicatedLog, 1L, null, false);
assertEquals("getTerm", -1L, reader.getTerm());
assertEquals("getIndex", -1L, reader.getIndex());
// Followers and valid originalIndex entry
doReturn(new SimpleReplicatedLogEntry(8L, 5L, new MockRaftActorContext.MockPayload())).when(mockReplicatedLog).get(8L);
reader.init(mockReplicatedLog, 8L, lastLogEntry, true);
assertEquals("getTerm", 5L, reader.getTerm());
assertEquals("getIndex", 8L, reader.getIndex());
// Followers and null originalIndex entry and valid snapshot index
reader.init(mockReplicatedLog, 7L, lastLogEntry, true);
assertEquals("getTerm", 4L, reader.getTerm());
assertEquals("getIndex", 7L, reader.getIndex());
// Followers and null originalIndex entry and invalid snapshot index
doReturn(-1L).when(mockReplicatedLog).getSnapshotIndex();
reader.init(mockReplicatedLog, 7L, lastLogEntry, true);
assertEquals("getTerm", -1L, reader.getTerm());
assertEquals("getIndex", -1L, reader.getIndex());
}
Aggregations