Search in sources :

Example 1 with SaveSnapshotFailure

use of akka.persistence.SaveSnapshotFailure in project controller by opendaylight.

the class RaftActorTest method testRaftActorForwardsToRaftActorSnapshotMessageSupport.

@Test
public void testRaftActorForwardsToRaftActorSnapshotMessageSupport() {
    String persistenceId = factory.generateActorId("leader-");
    DefaultConfigParamsImpl config = new DefaultConfigParamsImpl();
    config.setHeartBeatInterval(new FiniteDuration(1, TimeUnit.DAYS));
    RaftActorSnapshotMessageSupport mockSupport = mock(RaftActorSnapshotMessageSupport.class);
    TestActorRef<MockRaftActor> mockActorRef = factory.createTestActor(MockRaftActor.builder().id(persistenceId).config(config).snapshotMessageSupport(mockSupport).props());
    MockRaftActor mockRaftActor = mockActorRef.underlyingActor();
    // Wait for akka's recovery to complete so it doesn't interfere.
    mockRaftActor.waitForRecoveryComplete();
    ApplySnapshot applySnapshot = new ApplySnapshot(mock(Snapshot.class));
    doReturn(true).when(mockSupport).handleSnapshotMessage(same(applySnapshot), any(ActorRef.class));
    mockRaftActor.handleCommand(applySnapshot);
    CaptureSnapshotReply captureSnapshotReply = new CaptureSnapshotReply(ByteState.empty(), java.util.Optional.empty());
    doReturn(true).when(mockSupport).handleSnapshotMessage(same(captureSnapshotReply), any(ActorRef.class));
    mockRaftActor.handleCommand(captureSnapshotReply);
    SaveSnapshotSuccess saveSnapshotSuccess = new SaveSnapshotSuccess(new SnapshotMetadata("", 0L, 0L));
    doReturn(true).when(mockSupport).handleSnapshotMessage(same(saveSnapshotSuccess), any(ActorRef.class));
    mockRaftActor.handleCommand(saveSnapshotSuccess);
    SaveSnapshotFailure saveSnapshotFailure = new SaveSnapshotFailure(new SnapshotMetadata("", 0L, 0L), new Throwable());
    doReturn(true).when(mockSupport).handleSnapshotMessage(same(saveSnapshotFailure), any(ActorRef.class));
    mockRaftActor.handleCommand(saveSnapshotFailure);
    doReturn(true).when(mockSupport).handleSnapshotMessage(same(RaftActorSnapshotMessageSupport.COMMIT_SNAPSHOT), any(ActorRef.class));
    mockRaftActor.handleCommand(RaftActorSnapshotMessageSupport.COMMIT_SNAPSHOT);
    doReturn(true).when(mockSupport).handleSnapshotMessage(same(GetSnapshot.INSTANCE), any(ActorRef.class));
    mockRaftActor.handleCommand(GetSnapshot.INSTANCE);
    verify(mockSupport).handleSnapshotMessage(same(applySnapshot), any(ActorRef.class));
    verify(mockSupport).handleSnapshotMessage(same(captureSnapshotReply), any(ActorRef.class));
    verify(mockSupport).handleSnapshotMessage(same(saveSnapshotSuccess), any(ActorRef.class));
    verify(mockSupport).handleSnapshotMessage(same(saveSnapshotFailure), any(ActorRef.class));
    verify(mockSupport).handleSnapshotMessage(same(RaftActorSnapshotMessageSupport.COMMIT_SNAPSHOT), any(ActorRef.class));
    verify(mockSupport).handleSnapshotMessage(same(GetSnapshot.INSTANCE), any(ActorRef.class));
}
Also used : CaptureSnapshotReply(org.opendaylight.controller.cluster.raft.base.messages.CaptureSnapshotReply) ApplySnapshot(org.opendaylight.controller.cluster.raft.base.messages.ApplySnapshot) ActorRef(akka.actor.ActorRef) TestActorRef(akka.testkit.TestActorRef) FiniteDuration(scala.concurrent.duration.FiniteDuration) ByteString(com.google.protobuf.ByteString) SaveSnapshotFailure(akka.persistence.SaveSnapshotFailure) ApplySnapshot(org.opendaylight.controller.cluster.raft.base.messages.ApplySnapshot) Snapshot(org.opendaylight.controller.cluster.raft.persisted.Snapshot) GetSnapshot(org.opendaylight.controller.cluster.raft.client.messages.GetSnapshot) SnapshotMetadata(akka.persistence.SnapshotMetadata) SaveSnapshotSuccess(akka.persistence.SaveSnapshotSuccess) Test(org.junit.Test)

Example 2 with SaveSnapshotFailure

use of akka.persistence.SaveSnapshotFailure in project controller by opendaylight.

the class RaftActorSnapshotMessageSupportTest method testOnSaveSnapshotFailure.

@Test
public void testOnSaveSnapshotFailure() {
    sendMessageToSupport(new SaveSnapshotFailure(new SnapshotMetadata("foo", 100, 1234L), new Throwable("mock")));
    verify(mockSnapshotManager).rollback();
}
Also used : SnapshotMetadata(akka.persistence.SnapshotMetadata) SaveSnapshotFailure(akka.persistence.SaveSnapshotFailure) Test(org.junit.Test)

Aggregations

SaveSnapshotFailure (akka.persistence.SaveSnapshotFailure)2 SnapshotMetadata (akka.persistence.SnapshotMetadata)2 Test (org.junit.Test)2 ActorRef (akka.actor.ActorRef)1 SaveSnapshotSuccess (akka.persistence.SaveSnapshotSuccess)1 TestActorRef (akka.testkit.TestActorRef)1 ByteString (com.google.protobuf.ByteString)1 ApplySnapshot (org.opendaylight.controller.cluster.raft.base.messages.ApplySnapshot)1 CaptureSnapshotReply (org.opendaylight.controller.cluster.raft.base.messages.CaptureSnapshotReply)1 GetSnapshot (org.opendaylight.controller.cluster.raft.client.messages.GetSnapshot)1 Snapshot (org.opendaylight.controller.cluster.raft.persisted.Snapshot)1 FiniteDuration (scala.concurrent.duration.FiniteDuration)1