import org.opendaylight.controller.cluster.raft.base.messages.SendInstallSnapshot;
import org.opendaylight.controller.cluster.raft.base.messages.SnapshotComplete;
import org.opendaylight.controller.cluster.raft.behaviors.RaftActorBehavior;
+import org.opendaylight.controller.cluster.raft.persisted.SimpleReplicatedLogEntry;
import org.opendaylight.controller.cluster.raft.utils.MessageCollectorActor;
import org.slf4j.LoggerFactory;
public void testCaptureToInstall() throws Exception {
// Force capturing toInstall = true
- snapshotManager.captureToInstall(new MockRaftActorContext.MockReplicatedLogEntry(1, 0,
+ snapshotManager.captureToInstall(new SimpleReplicatedLogEntry(0, 1,
new MockRaftActorContext.MockPayload()), 0, "follower-1");
assertEquals(true, snapshotManager.isCapturing());
@Test
public void testCapture() throws Exception {
- boolean capture = snapshotManager.capture(new MockRaftActorContext.MockReplicatedLogEntry(1,9,
+ boolean capture = snapshotManager.capture(new SimpleReplicatedLogEntry(9, 1,
new MockRaftActorContext.MockPayload()), 9);
assertTrue(capture);
public void testCaptureWithCreateProcedureError() throws Exception {
doThrow(new RuntimeException("mock")).when(mockProcedure).run();
- boolean capture = snapshotManager.capture(new MockRaftActorContext.MockReplicatedLogEntry(1,9,
+ boolean capture = snapshotManager.capture(new SimpleReplicatedLogEntry(9, 1,
new MockRaftActorContext.MockPayload()), 9);
assertFalse(capture);
@Test
public void testIllegalCapture() throws Exception {
- boolean capture = snapshotManager.capture(new MockRaftActorContext.MockReplicatedLogEntry(1,9,
+ boolean capture = snapshotManager.capture(new SimpleReplicatedLogEntry(9, 1,
new MockRaftActorContext.MockPayload()), 9);
assertTrue(capture);
reset(mockProcedure);
// This will not cause snapshot capture to start again
- capture = snapshotManager.capture(new MockRaftActorContext.MockReplicatedLogEntry(1,9,
+ capture = snapshotManager.capture(new SimpleReplicatedLogEntry(9, 1,
new MockRaftActorContext.MockPayload()), 9);
assertFalse(capture);
doReturn(8L).when(mockRaftActorContext).getLastApplied();
- MockRaftActorContext.MockReplicatedLogEntry lastLogEntry = new MockRaftActorContext.MockReplicatedLogEntry(
- 3L, 9L, new MockRaftActorContext.MockPayload());
+ ReplicatedLogEntry lastLogEntry = new SimpleReplicatedLogEntry(9L, 3L, new MockRaftActorContext.MockPayload());
- MockRaftActorContext.MockReplicatedLogEntry lastAppliedEntry = new MockRaftActorContext.MockReplicatedLogEntry(
- 2L, 8L, new MockRaftActorContext.MockPayload());
+ ReplicatedLogEntry lastAppliedEntry = new SimpleReplicatedLogEntry(
+ 8L, 2L, new MockRaftActorContext.MockPayload());
doReturn(lastAppliedEntry).when(mockReplicatedLog).get(8L);
doReturn(Arrays.asList(lastLogEntry)).when(mockReplicatedLog).getFrom(9L);
doReturn(9L).when(replicatedLogEntry).getIndex();
// when replicatedToAllIndex != -1
- snapshotManager.capture(new MockRaftActorContext.MockReplicatedLogEntry(6,9,
- new MockRaftActorContext.MockPayload()), 9);
+ snapshotManager.capture(new SimpleReplicatedLogEntry(9, 6, new MockRaftActorContext.MockPayload()), 9);
byte[] bytes = new byte[] {1,2,3,4,5,6,7,8,9,10};
snapshotManager.persist(bytes, Runtime.getRuntime().totalMemory());
doReturn(Integer.MAX_VALUE).when(mockReplicatedLog).dataSize();
// when replicatedToAllIndex = -1
- snapshotManager.capture(new MockRaftActorContext.MockReplicatedLogEntry(6,9,
- new MockRaftActorContext.MockPayload()), -1);
+ snapshotManager.capture(new SimpleReplicatedLogEntry(9, 6, new MockRaftActorContext.MockPayload()), -1);
snapshotManager.persist(new byte[]{}, Runtime.getRuntime().totalMemory());
doReturn(6L).when(replicatedLogEntry).getTerm();
doReturn(replicatedToAllIndex).when(replicatedLogEntry).getIndex();
- snapshotManager.capture(new MockRaftActorContext.MockReplicatedLogEntry(6, 9,
+ snapshotManager.capture(new SimpleReplicatedLogEntry(9, 6,
new MockRaftActorContext.MockPayload()), replicatedToAllIndex);
snapshotManager.persist(new byte[]{}, 2000000L);
doReturn(Integer.MAX_VALUE).when(mockReplicatedLog).dataSize();
// when replicatedToAllIndex = -1
- boolean capture = snapshotManager.captureToInstall(new MockRaftActorContext.MockReplicatedLogEntry(6, 9,
+ boolean capture = snapshotManager.captureToInstall(new SimpleReplicatedLogEntry(9, 6,
new MockRaftActorContext.MockPayload()), -1, "follower-1");
assertTrue(capture);
doReturn(Integer.MAX_VALUE).when(mockReplicatedLog).dataSize();
// when replicatedToAllIndex = -1
- snapshotManager.captureToInstall(new MockRaftActorContext.MockReplicatedLogEntry(6, 9,
+ snapshotManager.captureToInstall(new SimpleReplicatedLogEntry(9, 6,
new MockRaftActorContext.MockPayload()), -1, "follower-1");
snapshotManager.persist(new byte[]{}, Runtime.getRuntime().totalMemory());
doReturn(50L).when(mockDataPersistenceProvider).getLastSequenceNumber();
// when replicatedToAllIndex = -1
- snapshotManager.captureToInstall(new MockRaftActorContext.MockReplicatedLogEntry(6, 9,
+ snapshotManager.captureToInstall(new SimpleReplicatedLogEntry(9, 6,
new MockRaftActorContext.MockPayload()), -1, "follower-1");
snapshotManager.persist(new byte[]{}, Runtime.getRuntime().totalMemory());
@Test
public void testCommitBeforePersist() {
// when replicatedToAllIndex = -1
- snapshotManager.captureToInstall(new MockRaftActorContext.MockReplicatedLogEntry(6, 9,
+ snapshotManager.captureToInstall(new SimpleReplicatedLogEntry(9, 6,
new MockRaftActorContext.MockPayload()), -1, "follower-1");
snapshotManager.commit(100L, 0);
doReturn(50L).when(mockDataPersistenceProvider).getLastSequenceNumber();
// when replicatedToAllIndex = -1
- snapshotManager.captureToInstall(new MockRaftActorContext.MockReplicatedLogEntry(6, 9,
+ snapshotManager.captureToInstall(new SimpleReplicatedLogEntry(9, 6,
new MockRaftActorContext.MockPayload()), -1, "follower-1");
snapshotManager.persist(new byte[]{}, Runtime.getRuntime().totalMemory());
@Test
public void testRollback() {
// when replicatedToAllIndex = -1
- snapshotManager.captureToInstall(new MockRaftActorContext.MockReplicatedLogEntry(6, 9,
+ snapshotManager.captureToInstall(new SimpleReplicatedLogEntry(9, 6,
new MockRaftActorContext.MockPayload()), -1, "follower-1");
snapshotManager.persist(new byte[]{}, Runtime.getRuntime().totalMemory());
@Test
public void testRollbackBeforePersist() {
// when replicatedToAllIndex = -1
- snapshotManager.captureToInstall(new MockRaftActorContext.MockReplicatedLogEntry(6, 9,
+ snapshotManager.captureToInstall(new SimpleReplicatedLogEntry(9, 6,
new MockRaftActorContext.MockPayload()), -1, "follower-1");
snapshotManager.rollback();
@Test
public void testCallingRollbackMultipleTimesCausesNoHarm() {
// when replicatedToAllIndex = -1
- snapshotManager.captureToInstall(new MockRaftActorContext.MockReplicatedLogEntry(6, 9,
+ snapshotManager.captureToInstall(new SimpleReplicatedLogEntry(9, 6,
new MockRaftActorContext.MockPayload()), -1, "follower-1");
snapshotManager.persist(new byte[]{}, Runtime.getRuntime().totalMemory());
@Test
public void testTrimLogAfterCapture() {
- boolean capture = snapshotManager.capture(new MockRaftActorContext.MockReplicatedLogEntry(1,9,
+ boolean capture = snapshotManager.capture(new SimpleReplicatedLogEntry(9, 1,
new MockRaftActorContext.MockPayload()), 9);
assertTrue(capture);
@Test
public void testTrimLogAfterCaptureToInstall() {
- boolean capture = snapshotManager.captureToInstall(new MockRaftActorContext.MockReplicatedLogEntry(1,9,
+ boolean capture = snapshotManager.captureToInstall(new SimpleReplicatedLogEntry(9, 1,
new MockRaftActorContext.MockPayload()), 9, "follower-1");
assertTrue(capture);
doReturn(4L).when(mockReplicatedLog).getSnapshotTerm();
doReturn(7L).when(mockReplicatedLog).getSnapshotIndex();
- ReplicatedLogEntry lastLogEntry = new MockRaftActorContext.MockReplicatedLogEntry(6L, 9L,
+ ReplicatedLogEntry lastLogEntry = new SimpleReplicatedLogEntry(9L, 6L,
new MockRaftActorContext.MockPayload());
// No followers and valid lastLogEntry
assertEquals("getIndex", -1L, reader.getIndex());
// Followers and valid originalIndex entry
- doReturn(new MockRaftActorContext.MockReplicatedLogEntry(5L, 8L,
+ doReturn(new SimpleReplicatedLogEntry(8L, 5L,
new MockRaftActorContext.MockPayload())).when(mockReplicatedLog).get(8L);
reader.init(mockReplicatedLog, 8L, lastLogEntry, true);