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()));
}
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));
}
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);
}
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);
}
}
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);
}
Aggregations