Do not reset datasize after a fake snapshot
[controller.git] / opendaylight / md-sal / sal-akka-raft / src / test / java / org / opendaylight / controller / cluster / raft / SnapshotManagerTest.java
index 44f8f8041f86f2d7c9ec1bbde52cede5bfa9d7da..4cdec8ca672c87fb091f176185e18837c52e0a4f 100644 (file)
@@ -12,9 +12,8 @@ import static org.junit.Assert.assertArrayEquals;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.anyLong;
-import static org.mockito.Matchers.anyObject;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyLong;
 import static org.mockito.Mockito.doNothing;
 import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.doThrow;
@@ -195,12 +194,12 @@ public class SnapshotManagerTest extends AbstractActorTest {
         CaptureSnapshot captureSnapshot = snapshotManager.getCaptureSnapshot();
 
         // LastIndex and LastTerm are picked up from the lastLogEntry
-        assertEquals(-1L, captureSnapshot.getLastIndex());
-        assertEquals(-1L, captureSnapshot.getLastTerm());
+        assertEquals(0, captureSnapshot.getLastIndex());
+        assertEquals(0, captureSnapshot.getLastTerm());
 
         // Since the actor does not have any followers (no peer addresses) lastApplied will be from lastLogEntry
-        assertEquals(-1L, captureSnapshot.getLastAppliedIndex());
-        assertEquals(-1L, captureSnapshot.getLastAppliedTerm());
+        assertEquals(0, captureSnapshot.getLastAppliedIndex());
+        assertEquals(0, captureSnapshot.getLastAppliedTerm());
 
         //
         assertEquals(-1L, captureSnapshot.getReplicatedToAllIndex());
@@ -210,7 +209,7 @@ public class SnapshotManagerTest extends AbstractActorTest {
 
     @Test
     public void testCaptureWithCreateProcedureError() {
-        doThrow(new RuntimeException("mock")).when(mockProcedure).accept(anyObject());
+        doThrow(new RuntimeException("mock")).when(mockProcedure).accept(any());
 
         boolean capture = snapshotManager.capture(new SimpleReplicatedLogEntry(9, 1,
                 new MockRaftActorContext.MockPayload()), 9);
@@ -219,7 +218,7 @@ public class SnapshotManagerTest extends AbstractActorTest {
 
         assertEquals(false, snapshotManager.isCapturing());
 
-        verify(mockProcedure).accept(anyObject());
+        verify(mockProcedure).accept(any());
     }
 
     @SuppressWarnings("unchecked")
@@ -230,7 +229,7 @@ public class SnapshotManagerTest extends AbstractActorTest {
 
         assertTrue(capture);
 
-        verify(mockProcedure).accept(anyObject());
+        verify(mockProcedure).accept(any());
 
         reset(mockProcedure);
 
@@ -240,7 +239,7 @@ public class SnapshotManagerTest extends AbstractActorTest {
 
         assertFalse(capture);
 
-        verify(mockProcedure, never()).accept(anyObject());
+        verify(mockProcedure, never()).accept(any());
     }
 
     @Test
@@ -361,7 +360,7 @@ public class SnapshotManagerTest extends AbstractActorTest {
     @Test
     public void testPersistSendInstallSnapshot() throws Exception {
         doReturn(Integer.MAX_VALUE).when(mockReplicatedLog).dataSize();
-        doNothing().when(mockProcedure).accept(anyObject());
+        doNothing().when(mockProcedure).accept(any());
 
         // when replicatedToAllIndex = -1
         boolean capture = snapshotManager.captureToInstall(new SimpleReplicatedLogEntry(9, 6,
@@ -449,7 +448,7 @@ public class SnapshotManagerTest extends AbstractActorTest {
 
         verify(mockDataPersistenceProvider).deleteSnapshots(criteriaCaptor.capture());
 
-        assertEquals(100L, criteriaCaptor.getValue().maxSequenceNr());
+        assertEquals(Long.MAX_VALUE, criteriaCaptor.getValue().maxSequenceNr());
         assertEquals(1233L, criteriaCaptor.getValue().maxTimestamp());
 
         MessageCollectorActor.expectFirstMatching(actorRef, SnapshotComplete.class);
@@ -561,7 +560,7 @@ public class SnapshotManagerTest extends AbstractActorTest {
         assertEquals("return index", 10L, retIndex);
 
         verify(mockReplicatedLog).snapshotPreCommit(10, 5);
-        verify(mockReplicatedLog).snapshotCommit();
+        verify(mockReplicatedLog).snapshotCommit(false);
 
         verify(mockRaftActorBehavior, never()).setReplicatedToAllIndex(anyLong());
     }
@@ -579,7 +578,7 @@ public class SnapshotManagerTest extends AbstractActorTest {
         assertEquals("return index", -1L, retIndex);
 
         verify(mockReplicatedLog, never()).snapshotPreCommit(anyLong(), anyLong());
-        verify(mockReplicatedLog, never()).snapshotCommit();
+        verify(mockReplicatedLog, never()).snapshotCommit(false);
 
         verify(mockRaftActorBehavior, never()).setReplicatedToAllIndex(anyLong());
     }
@@ -597,7 +596,7 @@ public class SnapshotManagerTest extends AbstractActorTest {
         assertEquals("return index", -1L, retIndex);
 
         verify(mockReplicatedLog, never()).snapshotPreCommit(anyLong(), anyLong());
-        verify(mockReplicatedLog, never()).snapshotCommit();
+        verify(mockReplicatedLog, never()).snapshotCommit(false);
 
         verify(mockRaftActorBehavior, never()).setReplicatedToAllIndex(anyLong());
     }
@@ -612,7 +611,7 @@ public class SnapshotManagerTest extends AbstractActorTest {
         assertEquals("return index", -1L, retIndex);
 
         verify(mockReplicatedLog, never()).snapshotPreCommit(anyLong(), anyLong());
-        verify(mockReplicatedLog, never()).snapshotCommit();
+        verify(mockReplicatedLog, never()).snapshotCommit(false);
 
         // Trim index is greater than replicatedToAllIndex so should update it.
         verify(mockRaftActorBehavior).setReplicatedToAllIndex(10L);
@@ -636,8 +635,7 @@ public class SnapshotManagerTest extends AbstractActorTest {
         snapshotManager.trimLog(10);
 
         verify(mockReplicatedLog, never()).snapshotPreCommit(anyLong(), anyLong());
-        verify(mockReplicatedLog, never()).snapshotCommit();
-
+        verify(mockReplicatedLog, never()).snapshotCommit(false);
     }
 
     @Test
@@ -659,7 +657,6 @@ public class SnapshotManagerTest extends AbstractActorTest {
 
         verify(mockReplicatedLog, never()).snapshotPreCommit(10, 5);
         verify(mockReplicatedLog, never()).snapshotCommit();
-
     }
 
     @Test