use of org.opendaylight.controller.cluster.raft.persisted.SimpleReplicatedLogEntry in project controller by opendaylight.
the class AbstractReplicatedLogImplTest method testSnapshotPreCommit.
@Test
public void testSnapshotPreCommit() {
// add 4 more entries
replicatedLogImpl.append(new SimpleReplicatedLogEntry(4, 2, new MockPayload("E")));
replicatedLogImpl.append(new SimpleReplicatedLogEntry(5, 2, new MockPayload("F")));
replicatedLogImpl.append(new SimpleReplicatedLogEntry(6, 3, new MockPayload("G")));
replicatedLogImpl.append(new SimpleReplicatedLogEntry(7, 3, new MockPayload("H")));
// sending negative values should not cause any changes
replicatedLogImpl.snapshotPreCommit(-1, -1);
assertEquals(8, replicatedLogImpl.size());
assertEquals(-1, replicatedLogImpl.getSnapshotIndex());
assertEquals(-1, replicatedLogImpl.getSnapshotTerm());
replicatedLogImpl.snapshotPreCommit(4, 2);
assertEquals(3, replicatedLogImpl.size());
assertEquals(4, replicatedLogImpl.getSnapshotIndex());
assertEquals(2, replicatedLogImpl.getSnapshotTerm());
replicatedLogImpl.snapshotPreCommit(6, 3);
assertEquals(1, replicatedLogImpl.size());
assertEquals(6, replicatedLogImpl.getSnapshotIndex());
assertEquals(3, replicatedLogImpl.getSnapshotTerm());
replicatedLogImpl.snapshotPreCommit(7, 3);
assertEquals(0, replicatedLogImpl.size());
assertEquals(7, replicatedLogImpl.getSnapshotIndex());
assertEquals(3, replicatedLogImpl.getSnapshotTerm());
// running it again on an empty list should not throw exception
replicatedLogImpl.snapshotPreCommit(7, 3);
assertEquals(0, replicatedLogImpl.size());
assertEquals(7, replicatedLogImpl.getSnapshotIndex());
assertEquals(3, replicatedLogImpl.getSnapshotTerm());
}
use of org.opendaylight.controller.cluster.raft.persisted.SimpleReplicatedLogEntry in project controller by opendaylight.
the class AbstractReplicatedLogImplTest method setUp.
@Before
public void setUp() {
replicatedLogImpl = new MockAbstractReplicatedLogImpl();
// create a set of initial entries in the in-memory log
replicatedLogImpl.append(new SimpleReplicatedLogEntry(0, 1, new MockPayload("A")));
replicatedLogImpl.append(new SimpleReplicatedLogEntry(1, 1, new MockPayload("B")));
replicatedLogImpl.append(new SimpleReplicatedLogEntry(2, 1, new MockPayload("C")));
replicatedLogImpl.append(new SimpleReplicatedLogEntry(3, 2, new MockPayload("D")));
}
use of org.opendaylight.controller.cluster.raft.persisted.SimpleReplicatedLogEntry in project controller by opendaylight.
the class MigratedMessagesTest method testNoSnapshotAfterStartupWithNoMigratedMessages.
@Test
public void testNoSnapshotAfterStartupWithNoMigratedMessages() {
TEST_LOG.info("testNoSnapshotAfterStartupWithNoMigratedMessages starting");
String id = factory.generateActorId("test-actor-");
InMemoryJournal.addEntry(id, 1, new UpdateElectionTerm(1, id));
InMemoryJournal.addEntry(id, 2, new SimpleReplicatedLogEntry(0, 1, new MockRaftActorContext.MockPayload("A")));
InMemoryJournal.addEntry(id, 3, new ApplyJournalEntries(0));
DefaultConfigParamsImpl config = new DefaultConfigParamsImpl();
config.setCustomRaftPolicyImplementationClass(DisableElectionsRaftPolicy.class.getName());
RaftActorSnapshotCohort snapshotCohort = new RaftActorSnapshotCohort() {
@Override
public void createSnapshot(ActorRef actorRef, java.util.Optional<OutputStream> installSnapshotStream) {
actorRef.tell(new CaptureSnapshotReply(ByteState.empty(), installSnapshotStream), actorRef);
}
@Override
public void applySnapshot(Snapshot.State snapshotState) {
}
@Override
public State deserializeSnapshot(ByteSource snapshotBytes) {
throw new UnsupportedOperationException();
}
};
TestActorRef<MockRaftActor> raftActorRef = factory.createTestActor(MockRaftActor.builder().id(id).config(config).snapshotCohort(snapshotCohort).persistent(Optional.of(true)).props().withDispatcher(Dispatchers.DefaultDispatcherId()), id);
MockRaftActor mockRaftActor = raftActorRef.underlyingActor();
mockRaftActor.waitForRecoveryComplete();
Uninterruptibles.sleepUninterruptibly(750, TimeUnit.MILLISECONDS);
List<Snapshot> snapshots = InMemorySnapshotStore.getSnapshots(id, Snapshot.class);
assertEquals("Snapshots", 0, snapshots.size());
TEST_LOG.info("testNoSnapshotAfterStartupWithNoMigratedMessages ending");
}
use of org.opendaylight.controller.cluster.raft.persisted.SimpleReplicatedLogEntry in project controller by opendaylight.
the class SnapshotManagerTest method testPersistWhenReplicatedToAllIndexNotMinus.
@Test
public void testPersistWhenReplicatedToAllIndexNotMinus() throws Exception {
doReturn(45L).when(mockReplicatedLog).getSnapshotIndex();
doReturn(6L).when(mockReplicatedLog).getSnapshotTerm();
ReplicatedLogEntry replicatedLogEntry = mock(ReplicatedLogEntry.class);
doReturn(replicatedLogEntry).when(mockReplicatedLog).get(9);
doReturn(6L).when(replicatedLogEntry).getTerm();
doReturn(9L).when(replicatedLogEntry).getIndex();
// when replicatedToAllIndex != -1
snapshotManager.capture(new SimpleReplicatedLogEntry(9, 6, new MockRaftActorContext.MockPayload()), 9);
ByteState snapshotState = ByteState.of(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 });
snapshotManager.persist(snapshotState, Optional.empty(), Runtime.getRuntime().totalMemory());
ArgumentCaptor<Snapshot> snapshotArgumentCaptor = ArgumentCaptor.forClass(Snapshot.class);
verify(mockDataPersistenceProvider).saveSnapshot(snapshotArgumentCaptor.capture());
Snapshot snapshot = snapshotArgumentCaptor.getValue();
assertEquals("getLastTerm", 6L, snapshot.getLastTerm());
assertEquals("getLastIndex", 9L, snapshot.getLastIndex());
assertEquals("getLastAppliedTerm", 6L, snapshot.getLastAppliedTerm());
assertEquals("getLastAppliedIndex", 9L, snapshot.getLastAppliedIndex());
assertEquals("getState", snapshotState, snapshot.getState());
assertEquals("getUnAppliedEntries size", 0, snapshot.getUnAppliedEntries().size());
verify(mockReplicatedLog).snapshotPreCommit(9L, 6L);
verify(mockRaftActorBehavior).setReplicatedToAllIndex(9);
}
use of org.opendaylight.controller.cluster.raft.persisted.SimpleReplicatedLogEntry in project controller by opendaylight.
the class SnapshotManagerTest method testCallingCommitMultipleTimesCausesNoHarm.
@Test
public void testCallingCommitMultipleTimesCausesNoHarm() {
doReturn(50L).when(mockDataPersistenceProvider).getLastSequenceNumber();
// when replicatedToAllIndex = -1
snapshotManager.capture(new SimpleReplicatedLogEntry(9, 6, new MockRaftActorContext.MockPayload()), -1);
snapshotManager.persist(ByteState.empty(), Optional.empty(), Runtime.getRuntime().totalMemory());
snapshotManager.commit(100L, 0);
snapshotManager.commit(100L, 0);
verify(mockReplicatedLog, times(1)).snapshotCommit();
verify(mockDataPersistenceProvider, times(1)).deleteMessages(50L);
verify(mockDataPersistenceProvider, times(1)).deleteSnapshots(any(SnapshotSelectionCriteria.class));
}
Aggregations