Search in sources :

Example 21 with SimpleReplicatedLogEntry

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());
}
Also used : SimpleReplicatedLogEntry(org.opendaylight.controller.cluster.raft.persisted.SimpleReplicatedLogEntry) Test(org.junit.Test)

Example 22 with SimpleReplicatedLogEntry

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();
}
Also used : SimpleReplicatedLogEntry(org.opendaylight.controller.cluster.raft.persisted.SimpleReplicatedLogEntry) SimpleReplicatedLogEntry(org.opendaylight.controller.cluster.raft.persisted.SimpleReplicatedLogEntry) Test(org.junit.Test)

Example 23 with SimpleReplicatedLogEntry

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();
}
Also used : SimpleReplicatedLogEntry(org.opendaylight.controller.cluster.raft.persisted.SimpleReplicatedLogEntry) Test(org.junit.Test)

Example 24 with SimpleReplicatedLogEntry

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);
}
Also used : Optional(java.util.Optional) SimpleReplicatedLogEntry(org.opendaylight.controller.cluster.raft.persisted.SimpleReplicatedLogEntry) CaptureSnapshot(org.opendaylight.controller.cluster.raft.base.messages.CaptureSnapshot) Test(org.junit.Test)

Example 25 with SimpleReplicatedLogEntry

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);
}
Also used : Optional(java.util.Optional) SimpleReplicatedLogEntry(org.opendaylight.controller.cluster.raft.persisted.SimpleReplicatedLogEntry) CaptureSnapshot(org.opendaylight.controller.cluster.raft.base.messages.CaptureSnapshot) 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