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;
import akka.actor.ActorRef;
import akka.persistence.SnapshotSelectionCriteria;
-import akka.testkit.TestActorRef;
import java.io.OutputStream;
import java.util.Arrays;
import java.util.Optional;
private TestActorFactory factory;
- private TestActorRef<MessageCollectorActor> actorRef;
+ private ActorRef actorRef;
@Before
public void setUp() {
snapshotManager = new SnapshotManager(mockRaftActorContext, LoggerFactory.getLogger(this.getClass()));
factory = new TestActorFactory(getSystem());
- actorRef = factory.createTestActor(MessageCollectorActor.props(), factory.generateActorId("test-"));
+ actorRef = factory.createActor(MessageCollectorActor.props(), factory.generateActorId("test-"));
doReturn(actorRef).when(mockRaftActorContext).getActor();
snapshotManager.setCreateSnapshotConsumer(mockProcedure);
@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
- public void testCaptureToInstall() throws Exception {
+ public void testCaptureToInstall() {
// Force capturing toInstall = true
snapshotManager.captureToInstall(new SimpleReplicatedLogEntry(0, 1,
//
assertEquals(-1L, captureSnapshot.getReplicatedToAllIndex());
assertEquals(-1L, captureSnapshot.getReplicatedToAllTerm());
- actorRef.underlyingActor().clear();
+ MessageCollectorActor.clearMessages(actorRef);
}
@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
- public void testCapture() throws Exception {
+ public void testCapture() {
boolean capture = snapshotManager.capture(new SimpleReplicatedLogEntry(9, 1,
new MockRaftActorContext.MockPayload()), 9);
assertEquals(-1L, captureSnapshot.getReplicatedToAllIndex());
assertEquals(-1L, captureSnapshot.getReplicatedToAllTerm());
- actorRef.underlyingActor().clear();
-
+ MessageCollectorActor.clearMessages(actorRef);
}
@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
- public void testCaptureWithNullLastLogEntry() throws Exception {
+ public void testCaptureWithNullLastLogEntry() {
boolean capture = snapshotManager.capture(null, 1);
assertTrue(capture);
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());
assertEquals(-1L, captureSnapshot.getReplicatedToAllTerm());
- actorRef.underlyingActor().clear();
-
+ MessageCollectorActor.clearMessages(actorRef);
}
@Test
- public void testCaptureWithCreateProcedureError() throws Exception {
- doThrow(new RuntimeException("mock")).when(mockProcedure).accept(anyObject());
+ public void testCaptureWithCreateProcedureError() {
+ doThrow(new RuntimeException("mock")).when(mockProcedure).accept(any());
boolean capture = snapshotManager.capture(new SimpleReplicatedLogEntry(9, 1,
new MockRaftActorContext.MockPayload()), 9);
assertEquals(false, snapshotManager.isCapturing());
- verify(mockProcedure).accept(anyObject());
+ verify(mockProcedure).accept(any());
}
@SuppressWarnings("unchecked")
@Test
- public void testIllegalCapture() throws Exception {
+ public void testIllegalCapture() {
boolean capture = snapshotManager.capture(new SimpleReplicatedLogEntry(9, 1,
new MockRaftActorContext.MockPayload()), 9);
assertTrue(capture);
- verify(mockProcedure).accept(anyObject());
+ verify(mockProcedure).accept(any());
reset(mockProcedure);
assertFalse(capture);
- verify(mockProcedure, never()).accept(anyObject());
+ verify(mockProcedure, never()).accept(any());
}
@Test
- public void testPersistWhenReplicatedToAllIndexMinusOne() throws Exception {
+ public void testPersistWhenReplicatedToAllIndexMinusOne() {
doReturn(7L).when(mockReplicatedLog).getSnapshotIndex();
doReturn(1L).when(mockReplicatedLog).getSnapshotTerm();
}
@Test
- public void testPersistWhenReplicatedToAllIndexNotMinus() throws Exception {
+ public void testPersistWhenReplicatedToAllIndexNotMinus() {
doReturn(45L).when(mockReplicatedLog).getSnapshotIndex();
doReturn(6L).when(mockReplicatedLog).getSnapshotTerm();
ReplicatedLogEntry replicatedLogEntry = mock(ReplicatedLogEntry.class);
@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,
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);
assertEquals("return index", 10L, retIndex);
verify(mockReplicatedLog).snapshotPreCommit(10, 5);
- verify(mockReplicatedLog).snapshotCommit();
+ verify(mockReplicatedLog).snapshotCommit(false);
verify(mockRaftActorBehavior, never()).setReplicatedToAllIndex(anyLong());
}
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());
}
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());
}
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);
snapshotManager.trimLog(10);
verify(mockReplicatedLog, never()).snapshotPreCommit(anyLong(), anyLong());
- verify(mockReplicatedLog, never()).snapshotCommit();
-
+ verify(mockReplicatedLog, never()).snapshotCommit(false);
}
@Test
verify(mockReplicatedLog, never()).snapshotPreCommit(10, 5);
verify(mockReplicatedLog, never()).snapshotCommit();
-
}
@Test