Search in sources :

Example 6 with SnapshotMetadata

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

the class RaftActorRecoverySupportTest method testOnSnapshotOfferWithServerConfiguration.

@Test
public void testOnSnapshotOfferWithServerConfiguration() {
    long electionTerm = 2;
    String electionVotedFor = "member-2";
    ServerConfigurationPayload serverPayload = new ServerConfigurationPayload(Arrays.asList(new ServerInfo(localId, true), new ServerInfo("follower1", true), new ServerInfo("follower2", true)));
    MockSnapshotState snapshotState = new MockSnapshotState(Arrays.asList(new MockPayload("1")));
    Snapshot snapshot = Snapshot.create(snapshotState, Collections.<ReplicatedLogEntry>emptyList(), -1, -1, -1, -1, electionTerm, electionVotedFor, serverPayload);
    SnapshotMetadata metadata = new SnapshotMetadata("test", 6, 12345);
    SnapshotOffer snapshotOffer = new SnapshotOffer(metadata, snapshot);
    sendMessageToSupport(snapshotOffer);
    assertEquals("Journal log size", 0, context.getReplicatedLog().size());
    assertEquals("Election term", electionTerm, context.getTermInformation().getCurrentTerm());
    assertEquals("Election votedFor", electionVotedFor, context.getTermInformation().getVotedFor());
    assertTrue("Dynamic server configuration", context.isDynamicServerConfigurationInUse());
    assertEquals("Peer List", Sets.newHashSet("follower1", "follower2"), Sets.newHashSet(context.getPeerIds()));
}
Also used : MockSnapshotState(org.opendaylight.controller.cluster.raft.MockRaftActor.MockSnapshotState) Snapshot(org.opendaylight.controller.cluster.raft.persisted.Snapshot) ServerConfigurationPayload(org.opendaylight.controller.cluster.raft.persisted.ServerConfigurationPayload) SnapshotMetadata(akka.persistence.SnapshotMetadata) ServerInfo(org.opendaylight.controller.cluster.raft.persisted.ServerInfo) SnapshotOffer(akka.persistence.SnapshotOffer) MockPayload(org.opendaylight.controller.cluster.raft.MockRaftActorContext.MockPayload) Test(org.junit.Test)

Example 7 with SnapshotMetadata

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

the class RaftActorSnapshotMessageSupportTest method testOnSaveSnapshotSuccess.

@Test
public void testOnSaveSnapshotSuccess() {
    long sequenceNumber = 100;
    long timeStamp = 1234L;
    sendMessageToSupport(new SaveSnapshotSuccess(new SnapshotMetadata("foo", sequenceNumber, timeStamp)));
    verify(mockSnapshotManager).commit(eq(sequenceNumber), eq(timeStamp));
}
Also used : SnapshotMetadata(akka.persistence.SnapshotMetadata) SaveSnapshotSuccess(akka.persistence.SaveSnapshotSuccess) Test(org.junit.Test)

Example 8 with SnapshotMetadata

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

the class ActorBehaviorTest method testRecoveryAfterRestartFrontendIdMismatch.

@Test
public void testRecoveryAfterRestartFrontendIdMismatch() throws Exception {
    system.stop(mockedActor);
    // start actor again
    mockedActor = system.actorOf(MockedActor.props(id, initialBehavior));
    probe.expectMsgClass(MockedSnapshotStore.LoadRequest.class);
    // offer snapshot with incorrect client id
    final SnapshotMetadata metadata = saveRequest.getMetadata();
    final FrontendIdentifier anotherFrontend = FrontendIdentifier.create(MemberName.forName("another"), FrontendType.forName("type-2"));
    final ClientIdentifier incorrectClientId = ClientIdentifier.create(anotherFrontend, 0);
    probe.watch(mockedActor);
    probe.reply(Optional.of(new SelectedSnapshot(metadata, incorrectClientId)));
    // actor should be stopped
    probe.expectTerminated(mockedActor, TIMEOUT);
}
Also used : ClientIdentifier(org.opendaylight.controller.cluster.access.concepts.ClientIdentifier) SelectedSnapshot(akka.persistence.SelectedSnapshot) SnapshotMetadata(akka.persistence.SnapshotMetadata) FrontendIdentifier(org.opendaylight.controller.cluster.access.concepts.FrontendIdentifier) Test(org.junit.Test)

Example 9 with SnapshotMetadata

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

the class LocalSnapshotStore method doLoad.

private Optional<SelectedSnapshot> doLoad(final Deque<SnapshotMetadata> metadatas) throws IOException {
    SnapshotMetadata metadata = metadatas.removeFirst();
    File file = toSnapshotFile(metadata);
    LOG.debug("doLoad {}", file);
    try {
        Object data = deserialize(file);
        LOG.debug("deserialized data: {}", data);
        return Optional.of(new SelectedSnapshot(metadata, data));
    } catch (IOException e) {
        LOG.error("Error loading snapshot file {}, remaining attempts: {}", file, metadatas.size(), e);
        if (metadatas.isEmpty()) {
            throw e;
        }
        return doLoad(metadatas);
    }
}
Also used : SelectedSnapshot(akka.persistence.SelectedSnapshot) SnapshotMetadata(akka.persistence.SnapshotMetadata) IOException(java.io.IOException) File(java.io.File)

Example 10 with SnapshotMetadata

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

the class RaftActorRecoverySupportTest method testOnSnapshotOffer.

@Test
public void testOnSnapshotOffer() {
    ReplicatedLog replicatedLog = context.getReplicatedLog();
    replicatedLog.append(new SimpleReplicatedLogEntry(1, 1, new MockRaftActorContext.MockPayload("1")));
    replicatedLog.append(new SimpleReplicatedLogEntry(2, 1, new MockRaftActorContext.MockPayload("2")));
    replicatedLog.append(new SimpleReplicatedLogEntry(3, 1, new MockRaftActorContext.MockPayload("3")));
    ReplicatedLogEntry unAppliedEntry1 = new SimpleReplicatedLogEntry(4, 1, new MockRaftActorContext.MockPayload("4", 4));
    ReplicatedLogEntry unAppliedEntry2 = new SimpleReplicatedLogEntry(5, 1, new MockRaftActorContext.MockPayload("5", 5));
    long lastAppliedDuringSnapshotCapture = 3;
    long lastIndexDuringSnapshotCapture = 5;
    long electionTerm = 2;
    String electionVotedFor = "member-2";
    MockSnapshotState snapshotState = new MockSnapshotState(Arrays.asList(new MockPayload("1")));
    Snapshot snapshot = Snapshot.create(snapshotState, Arrays.asList(unAppliedEntry1, unAppliedEntry2), lastIndexDuringSnapshotCapture, 1, lastAppliedDuringSnapshotCapture, 1, electionTerm, electionVotedFor, null);
    SnapshotMetadata metadata = new SnapshotMetadata("test", 6, 12345);
    SnapshotOffer snapshotOffer = new SnapshotOffer(metadata, snapshot);
    sendMessageToSupport(snapshotOffer);
    assertEquals("Journal log size", 2, context.getReplicatedLog().size());
    assertEquals("Journal data size", 9, context.getReplicatedLog().dataSize());
    assertEquals("Last index", lastIndexDuringSnapshotCapture, context.getReplicatedLog().lastIndex());
    assertEquals("Last applied", lastAppliedDuringSnapshotCapture, context.getLastApplied());
    assertEquals("Commit index", lastAppliedDuringSnapshotCapture, context.getCommitIndex());
    assertEquals("Snapshot term", 1, context.getReplicatedLog().getSnapshotTerm());
    assertEquals("Snapshot index", lastAppliedDuringSnapshotCapture, context.getReplicatedLog().getSnapshotIndex());
    assertEquals("Election term", electionTerm, context.getTermInformation().getCurrentTerm());
    assertEquals("Election votedFor", electionVotedFor, context.getTermInformation().getVotedFor());
    assertFalse("Dynamic server configuration", context.isDynamicServerConfigurationInUse());
    verify(mockCohort).applyRecoverySnapshot(snapshotState);
}
Also used : MockSnapshotState(org.opendaylight.controller.cluster.raft.MockRaftActor.MockSnapshotState) Snapshot(org.opendaylight.controller.cluster.raft.persisted.Snapshot) SimpleReplicatedLogEntry(org.opendaylight.controller.cluster.raft.persisted.SimpleReplicatedLogEntry) SimpleReplicatedLogEntry(org.opendaylight.controller.cluster.raft.persisted.SimpleReplicatedLogEntry) SnapshotMetadata(akka.persistence.SnapshotMetadata) SnapshotOffer(akka.persistence.SnapshotOffer) MockPayload(org.opendaylight.controller.cluster.raft.MockRaftActorContext.MockPayload) MockPayload(org.opendaylight.controller.cluster.raft.MockRaftActorContext.MockPayload) Test(org.junit.Test)

Aggregations

SnapshotMetadata (akka.persistence.SnapshotMetadata)12 Test (org.junit.Test)11 SelectedSnapshot (akka.persistence.SelectedSnapshot)5 Snapshot (org.opendaylight.controller.cluster.raft.persisted.Snapshot)5 SnapshotOffer (akka.persistence.SnapshotOffer)4 MockPayload (org.opendaylight.controller.cluster.raft.MockRaftActorContext.MockPayload)4 LoadSnapshot (akka.persistence.SnapshotProtocol.LoadSnapshot)3 LoadSnapshotResult (akka.persistence.SnapshotProtocol.LoadSnapshotResult)3 TestKit (akka.testkit.javadsl.TestKit)3 File (java.io.File)3 MockSnapshotState (org.opendaylight.controller.cluster.raft.MockRaftActor.MockSnapshotState)3 SimpleReplicatedLogEntry (org.opendaylight.controller.cluster.raft.persisted.SimpleReplicatedLogEntry)3 SaveSnapshotFailure (akka.persistence.SaveSnapshotFailure)2 SaveSnapshotSuccess (akka.persistence.SaveSnapshotSuccess)2 ByteString (com.google.protobuf.ByteString)2 ApplySnapshot (org.opendaylight.controller.cluster.raft.base.messages.ApplySnapshot)2 GetSnapshot (org.opendaylight.controller.cluster.raft.client.messages.GetSnapshot)2 ApplyJournalEntries (org.opendaylight.controller.cluster.raft.persisted.ApplyJournalEntries)2 DeleteEntries (org.opendaylight.controller.cluster.raft.persisted.DeleteEntries)2 UpdateElectionTerm (org.opendaylight.controller.cluster.raft.persisted.UpdateElectionTerm)2