use of org.opendaylight.controller.cluster.raft.persisted.SimpleReplicatedLogEntry in project controller by opendaylight.
the class SnapshotManagerTest method testCaptureWithCreateProcedureError.
@Test
public void testCaptureWithCreateProcedureError() throws Exception {
doThrow(new RuntimeException("mock")).when(mockProcedure).accept(anyObject());
boolean capture = snapshotManager.capture(new SimpleReplicatedLogEntry(9, 1, new MockRaftActorContext.MockPayload()), 9);
assertFalse(capture);
assertEquals(false, snapshotManager.isCapturing());
verify(mockProcedure).accept(anyObject());
}
use of org.opendaylight.controller.cluster.raft.persisted.SimpleReplicatedLogEntry in project controller by opendaylight.
the class SnapshotManagerTest method testTrimLogAfterCapture.
@Test
public void testTrimLogAfterCapture() {
boolean capture = snapshotManager.capture(new SimpleReplicatedLogEntry(9, 1, new MockRaftActorContext.MockPayload()), 9);
assertTrue(capture);
assertEquals(true, snapshotManager.isCapturing());
ReplicatedLogEntry replicatedLogEntry = mock(ReplicatedLogEntry.class);
doReturn(20L).when(mockRaftActorContext).getLastApplied();
doReturn(true).when(mockReplicatedLog).isPresent(10);
doReturn(replicatedLogEntry).when(mockReplicatedLog).get(10);
doReturn(5L).when(replicatedLogEntry).getTerm();
snapshotManager.trimLog(10);
verify(mockReplicatedLog, never()).snapshotPreCommit(anyLong(), anyLong());
verify(mockReplicatedLog, never()).snapshotCommit();
}
use of org.opendaylight.controller.cluster.raft.persisted.SimpleReplicatedLogEntry in project controller by opendaylight.
the class SnapshotManagerTest method testRollbackBeforePersist.
@Test
public void testRollbackBeforePersist() {
// when replicatedToAllIndex = -1
snapshotManager.capture(new SimpleReplicatedLogEntry(9, 6, new MockRaftActorContext.MockPayload()), -1);
snapshotManager.rollback();
verify(mockReplicatedLog, never()).snapshotRollback();
}
use of org.opendaylight.controller.cluster.raft.persisted.SimpleReplicatedLogEntry in project controller by opendaylight.
the class SnapshotManagerTest method testCapture.
@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void testCapture() throws Exception {
boolean capture = snapshotManager.capture(new SimpleReplicatedLogEntry(9, 1, new MockRaftActorContext.MockPayload()), 9);
assertTrue(capture);
assertEquals(true, snapshotManager.isCapturing());
ArgumentCaptor<Optional> outputStream = ArgumentCaptor.forClass(Optional.class);
verify(mockProcedure).accept(outputStream.capture());
assertEquals("isPresent", false, outputStream.getValue().isPresent());
CaptureSnapshot captureSnapshot = snapshotManager.getCaptureSnapshot();
// LastIndex and LastTerm are picked up from the lastLogEntry
assertEquals(9L, captureSnapshot.getLastIndex());
assertEquals(1L, captureSnapshot.getLastTerm());
// Since the actor does not have any followers (no peer addresses) lastApplied will be from lastLogEntry
assertEquals(9L, captureSnapshot.getLastAppliedIndex());
assertEquals(1L, captureSnapshot.getLastAppliedTerm());
//
assertEquals(-1L, captureSnapshot.getReplicatedToAllIndex());
assertEquals(-1L, captureSnapshot.getReplicatedToAllTerm());
MessageCollectorActor.clearMessages(actorRef);
}
use of org.opendaylight.controller.cluster.raft.persisted.SimpleReplicatedLogEntry in project controller by opendaylight.
the class SnapshotManagerTest method testCaptureToInstall.
@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void testCaptureToInstall() throws Exception {
// Force capturing toInstall = true
snapshotManager.captureToInstall(new SimpleReplicatedLogEntry(0, 1, new MockRaftActorContext.MockPayload()), 0, "follower-1");
assertEquals(true, snapshotManager.isCapturing());
ArgumentCaptor<Optional> outputStream = ArgumentCaptor.forClass(Optional.class);
verify(mockProcedure).accept(outputStream.capture());
assertEquals("isPresent", true, outputStream.getValue().isPresent());
CaptureSnapshot captureSnapshot = snapshotManager.getCaptureSnapshot();
// LastIndex and LastTerm are picked up from the lastLogEntry
assertEquals(0L, captureSnapshot.getLastIndex());
assertEquals(1L, captureSnapshot.getLastTerm());
// Since the actor does not have any followers (no peer addresses) lastApplied will be from lastLogEntry
assertEquals(0L, captureSnapshot.getLastAppliedIndex());
assertEquals(1L, captureSnapshot.getLastAppliedTerm());
//
assertEquals(-1L, captureSnapshot.getReplicatedToAllIndex());
assertEquals(-1L, captureSnapshot.getReplicatedToAllTerm());
MessageCollectorActor.clearMessages(actorRef);
}
Aggregations