Search in sources :

Example 26 with SimpleReplicatedLogEntry

use of org.opendaylight.controller.cluster.raft.persisted.SimpleReplicatedLogEntry in project controller by opendaylight.

the class SnapshotManagerTest method testTrimLogAfterCaptureToInstall.

@Test
public void testTrimLogAfterCaptureToInstall() {
    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(10, 5);
    verify(mockReplicatedLog, never()).snapshotCommit();
}
Also used : SimpleReplicatedLogEntry(org.opendaylight.controller.cluster.raft.persisted.SimpleReplicatedLogEntry) SimpleReplicatedLogEntry(org.opendaylight.controller.cluster.raft.persisted.SimpleReplicatedLogEntry) Test(org.junit.Test)

Example 27 with SimpleReplicatedLogEntry

use of org.opendaylight.controller.cluster.raft.persisted.SimpleReplicatedLogEntry in project controller by opendaylight.

the class SnapshotManagerTest method testPersistWhenReplicatedLogDataSizeGreaterThanThreshold.

@Test
public void testPersistWhenReplicatedLogDataSizeGreaterThanThreshold() {
    doReturn(Integer.MAX_VALUE).when(mockReplicatedLog).dataSize();
    // when replicatedToAllIndex = -1
    snapshotManager.capture(new SimpleReplicatedLogEntry(9, 6, new MockRaftActorContext.MockPayload()), -1);
    snapshotManager.persist(ByteState.empty(), Optional.empty(), Runtime.getRuntime().totalMemory());
    verify(mockDataPersistenceProvider).saveSnapshot(any(Snapshot.class));
    verify(mockReplicatedLog).snapshotPreCommit(9L, 6L);
    verify(mockRaftActorBehavior, never()).setReplicatedToAllIndex(anyLong());
}
Also used : CaptureSnapshot(org.opendaylight.controller.cluster.raft.base.messages.CaptureSnapshot) SendInstallSnapshot(org.opendaylight.controller.cluster.raft.base.messages.SendInstallSnapshot) Snapshot(org.opendaylight.controller.cluster.raft.persisted.Snapshot) SimpleReplicatedLogEntry(org.opendaylight.controller.cluster.raft.persisted.SimpleReplicatedLogEntry) Test(org.junit.Test)

Example 28 with SimpleReplicatedLogEntry

use of org.opendaylight.controller.cluster.raft.persisted.SimpleReplicatedLogEntry in project controller by opendaylight.

the class SnapshotManagerTest method testPersistWhenReplicatedToAllIndexMinusOne.

@Test
public void testPersistWhenReplicatedToAllIndexMinusOne() throws Exception {
    doReturn(7L).when(mockReplicatedLog).getSnapshotIndex();
    doReturn(1L).when(mockReplicatedLog).getSnapshotTerm();
    doReturn(true).when(mockRaftActorContext).hasFollowers();
    doReturn(8L).when(mockRaftActorContext).getLastApplied();
    ReplicatedLogEntry lastLogEntry = new SimpleReplicatedLogEntry(9L, 3L, 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);
    // when replicatedToAllIndex = -1
    snapshotManager.capture(lastLogEntry, -1);
    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", 3L, snapshot.getLastTerm());
    assertEquals("getLastIndex", 9L, snapshot.getLastIndex());
    assertEquals("getLastAppliedTerm", 2L, snapshot.getLastAppliedTerm());
    assertEquals("getLastAppliedIndex", 8L, snapshot.getLastAppliedIndex());
    assertEquals("getState", snapshotState, snapshot.getState());
    assertEquals("getUnAppliedEntries", Arrays.asList(lastLogEntry), snapshot.getUnAppliedEntries());
    assertEquals("electionTerm", mockElectionTerm.getCurrentTerm(), snapshot.getElectionTerm());
    assertEquals("electionVotedFor", mockElectionTerm.getVotedFor(), snapshot.getElectionVotedFor());
    verify(mockReplicatedLog).snapshotPreCommit(7L, 1L);
}
Also used : CaptureSnapshot(org.opendaylight.controller.cluster.raft.base.messages.CaptureSnapshot) SendInstallSnapshot(org.opendaylight.controller.cluster.raft.base.messages.SendInstallSnapshot) Snapshot(org.opendaylight.controller.cluster.raft.persisted.Snapshot) SimpleReplicatedLogEntry(org.opendaylight.controller.cluster.raft.persisted.SimpleReplicatedLogEntry) SimpleReplicatedLogEntry(org.opendaylight.controller.cluster.raft.persisted.SimpleReplicatedLogEntry) ByteState(org.opendaylight.controller.cluster.raft.persisted.ByteState) Test(org.junit.Test)

Example 29 with SimpleReplicatedLogEntry

use of org.opendaylight.controller.cluster.raft.persisted.SimpleReplicatedLogEntry in project controller by opendaylight.

the class RaftActorRecoverySupportTest method testDataRecoveredWithPersistenceDisabled.

@Test
public void testDataRecoveredWithPersistenceDisabled() {
    doNothing().when(mockCohort).applyRecoverySnapshot(anyObject());
    doReturn(false).when(mockPersistence).isRecoveryApplicable();
    doReturn(10L).when(mockPersistentProvider).getLastSequenceNumber();
    Snapshot snapshot = Snapshot.create(new MockSnapshotState(Arrays.asList(new MockPayload("1"))), Collections.<ReplicatedLogEntry>emptyList(), 3, 1, 3, 1, -1, null, null);
    SnapshotOffer snapshotOffer = new SnapshotOffer(new SnapshotMetadata("test", 6, 12345), snapshot);
    sendMessageToSupport(snapshotOffer);
    sendMessageToSupport(new UpdateElectionTerm(5, "member2"));
    sendMessageToSupport(new SimpleReplicatedLogEntry(4, 1, new MockRaftActorContext.MockPayload("4")));
    sendMessageToSupport(new SimpleReplicatedLogEntry(5, 1, new MockRaftActorContext.MockPayload("5")));
    sendMessageToSupport(new ApplyJournalEntries(4));
    sendMessageToSupport(new DeleteEntries(5));
    assertEquals("Journal log size", 0, context.getReplicatedLog().size());
    assertEquals("Last index", -1, context.getReplicatedLog().lastIndex());
    assertEquals("Last applied", -1, context.getLastApplied());
    assertEquals("Commit index", -1, context.getCommitIndex());
    assertEquals("Snapshot term", -1, context.getReplicatedLog().getSnapshotTerm());
    assertEquals("Snapshot index", -1, context.getReplicatedLog().getSnapshotIndex());
    assertEquals("Current term", 5, context.getTermInformation().getCurrentTerm());
    assertEquals("Voted For", "member2", context.getTermInformation().getVotedFor());
    sendMessageToSupport(RecoveryCompleted.getInstance(), true);
    verify(mockCohort, never()).applyRecoverySnapshot(anyObject());
    verify(mockCohort, never()).getRestoreFromSnapshot();
    verifyNoMoreInteractions(mockCohort);
    verify(mockPersistentProvider).deleteMessages(10L);
}
Also used : MockSnapshotState(org.opendaylight.controller.cluster.raft.MockRaftActor.MockSnapshotState) Snapshot(org.opendaylight.controller.cluster.raft.persisted.Snapshot) SnapshotMetadata(akka.persistence.SnapshotMetadata) SimpleReplicatedLogEntry(org.opendaylight.controller.cluster.raft.persisted.SimpleReplicatedLogEntry) ApplyJournalEntries(org.opendaylight.controller.cluster.raft.persisted.ApplyJournalEntries) SnapshotOffer(akka.persistence.SnapshotOffer) DeleteEntries(org.opendaylight.controller.cluster.raft.persisted.DeleteEntries) UpdateElectionTerm(org.opendaylight.controller.cluster.raft.persisted.UpdateElectionTerm) MockPayload(org.opendaylight.controller.cluster.raft.MockRaftActorContext.MockPayload) Test(org.junit.Test)

Example 30 with SimpleReplicatedLogEntry

use of org.opendaylight.controller.cluster.raft.persisted.SimpleReplicatedLogEntry in project controller by opendaylight.

the class RaftActorRecoverySupportTest method testOnDeleteEntries.

@Test
public void testOnDeleteEntries() {
    ReplicatedLog replicatedLog = context.getReplicatedLog();
    replicatedLog.append(new SimpleReplicatedLogEntry(0, 1, new MockRaftActorContext.MockPayload("0")));
    replicatedLog.append(new SimpleReplicatedLogEntry(1, 1, new MockRaftActorContext.MockPayload("1")));
    replicatedLog.append(new SimpleReplicatedLogEntry(2, 1, new MockRaftActorContext.MockPayload("2")));
    sendMessageToSupport(new DeleteEntries(1));
    assertEquals("Journal log size", 1, context.getReplicatedLog().size());
    assertEquals("Last index", 0, context.getReplicatedLog().lastIndex());
}
Also used : SimpleReplicatedLogEntry(org.opendaylight.controller.cluster.raft.persisted.SimpleReplicatedLogEntry) DeleteEntries(org.opendaylight.controller.cluster.raft.persisted.DeleteEntries) MockPayload(org.opendaylight.controller.cluster.raft.MockRaftActorContext.MockPayload) Test(org.junit.Test)

Aggregations

SimpleReplicatedLogEntry (org.opendaylight.controller.cluster.raft.persisted.SimpleReplicatedLogEntry)75 Test (org.junit.Test)64 MockPayload (org.opendaylight.controller.cluster.raft.MockRaftActorContext.MockPayload)32 Snapshot (org.opendaylight.controller.cluster.raft.persisted.Snapshot)17 ApplyJournalEntries (org.opendaylight.controller.cluster.raft.persisted.ApplyJournalEntries)15 UpdateElectionTerm (org.opendaylight.controller.cluster.raft.persisted.UpdateElectionTerm)12 FiniteDuration (scala.concurrent.duration.FiniteDuration)12 ByteString (com.google.protobuf.ByteString)11 ApplyState (org.opendaylight.controller.cluster.raft.base.messages.ApplyState)11 CaptureSnapshot (org.opendaylight.controller.cluster.raft.base.messages.CaptureSnapshot)11 ServerConfigurationPayload (org.opendaylight.controller.cluster.raft.persisted.ServerConfigurationPayload)11 ServerInfo (org.opendaylight.controller.cluster.raft.persisted.ServerInfo)11 ActorRef (akka.actor.ActorRef)10 TestActorRef (akka.testkit.TestActorRef)9 ApplySnapshot (org.opendaylight.controller.cluster.raft.base.messages.ApplySnapshot)8 ByteState (org.opendaylight.controller.cluster.raft.persisted.ByteState)8 ArrayList (java.util.ArrayList)7 MockRaftActorContext (org.opendaylight.controller.cluster.raft.MockRaftActorContext)7 CaptureSnapshotReply (org.opendaylight.controller.cluster.raft.base.messages.CaptureSnapshotReply)7 DisableElectionsRaftPolicy (org.opendaylight.controller.cluster.raft.policy.DisableElectionsRaftPolicy)7