use of org.opendaylight.controller.cluster.raft.MockRaftActorContext.MockPayload in project controller by opendaylight.
the class ReplicatedLogImplTest method testRemoveFromAndPersist.
@Test
public void testRemoveFromAndPersist() throws Exception {
ReplicatedLog log = ReplicatedLogImpl.newInstance(context);
log.append(new SimpleReplicatedLogEntry(0, 1, new MockPayload("0")));
log.append(new SimpleReplicatedLogEntry(1, 1, new MockPayload("1")));
log.append(new SimpleReplicatedLogEntry(2, 1, new MockPayload("2")));
log.removeFromAndPersist(1);
DeleteEntries deleteEntries = new DeleteEntries(1);
verifyPersist(deleteEntries, match(deleteEntries), false);
assertEquals("size", 1, log.size());
reset(mockPersistence);
log.removeFromAndPersist(1);
verifyNoMoreInteractions(mockPersistence);
}
use of org.opendaylight.controller.cluster.raft.MockRaftActorContext.MockPayload in project controller by opendaylight.
the class ReplicatedLogImplTest method testAppendAndPersisWithDuplicateEntry.
@SuppressWarnings("unchecked")
@Test
public void testAppendAndPersisWithDuplicateEntry() throws Exception {
ReplicatedLog log = ReplicatedLogImpl.newInstance(context);
Procedure<ReplicatedLogEntry> mockCallback = Mockito.mock(Procedure.class);
ReplicatedLogEntry logEntry = new SimpleReplicatedLogEntry(1, 1, new MockPayload("1"));
log.appendAndPersist(logEntry, mockCallback, true);
verifyPersist(logEntry);
assertEquals("size", 1, log.size());
reset(mockPersistence, mockCallback);
log.appendAndPersist(logEntry, mockCallback, true);
verifyNoMoreInteractions(mockPersistence, mockCallback);
assertEquals("size", 1, log.size());
}
use of org.opendaylight.controller.cluster.raft.MockRaftActorContext.MockPayload in project controller by opendaylight.
the class ReplicationAndSnapshotsWithLaggingFollowerIntegrationTest method sendInitialPayloadsReplicatedToAllFollowers.
private void sendInitialPayloadsReplicatedToAllFollowers(String... data) {
// Send the payloads.
for (String d : data) {
expSnapshotState.add(sendPayloadData(leaderActor, d));
}
int numEntries = data.length;
// Verify the leader got consensus and applies each log entry even though follower 2 didn't respond.
List<ApplyState> applyStates = MessageCollectorActor.expectMatching(leaderCollectorActor, ApplyState.class, numEntries);
for (int i = 0; i < expSnapshotState.size(); i++) {
MockPayload payload = expSnapshotState.get(i);
verifyApplyState(applyStates.get(i), leaderCollectorActor, payload.toString(), currentTerm, i, payload);
}
// Verify follower 1 applies each log entry.
applyStates = MessageCollectorActor.expectMatching(follower1CollectorActor, ApplyState.class, numEntries);
for (int i = 0; i < expSnapshotState.size(); i++) {
MockPayload payload = expSnapshotState.get(i);
verifyApplyState(applyStates.get(i), null, null, currentTerm, i, payload);
}
// Verify follower 2 applies each log entry.
applyStates = MessageCollectorActor.expectMatching(follower2CollectorActor, ApplyState.class, numEntries);
for (int i = 0; i < expSnapshotState.size(); i++) {
MockPayload payload = expSnapshotState.get(i);
verifyApplyState(applyStates.get(i), null, null, currentTerm, i, payload);
}
// Ensure there's at least 1 more heartbeat.
MessageCollectorActor.clearMessages(leaderCollectorActor);
MessageCollectorActor.expectFirstMatching(leaderCollectorActor, AppendEntriesReply.class);
// The leader should have performed fake snapshots to trim the log to the last index replicated to
// all followers.
verifyLeadersTrimmedLog(numEntries - 1);
MessageCollectorActor.clearMessages(leaderCollectorActor);
MessageCollectorActor.clearMessages(follower1CollectorActor);
MessageCollectorActor.clearMessages(follower2CollectorActor);
}
use of org.opendaylight.controller.cluster.raft.MockRaftActorContext.MockPayload in project controller by opendaylight.
the class ReplicationAndSnapshotsWithLaggingFollowerIntegrationTest method testLeaderSnapshotWithLaggingFollowerCaughtUpViaInstallSnapshot.
/**
* Send payloads to trigger a leader snapshot due to snapshotBatchCount reached with follower 2
* lagging where the leader trims its log from the last applied index. Follower 2's log
* will be behind by several entries and, when it is resumed, it should be caught up via a snapshot
* installed by the leader.
*/
@Test
public void testLeaderSnapshotWithLaggingFollowerCaughtUpViaInstallSnapshot() throws Exception {
testLog.info("testLeaderSnapshotWithLaggingFollowerCaughtUpViaInstallSnapshot starting");
setup();
sendInitialPayloadsReplicatedToAllFollowers("zero", "one");
// Configure follower 2 to drop messages and lag.
follower2Actor.underlyingActor().startDropMessages(AppendEntries.class);
// Sleep for at least the election timeout interval so follower 2 is deemed inactive by the leader.
Uninterruptibles.sleepUninterruptibly(leaderConfigParams.getElectionTimeOutInterval().toMillis() + 5, TimeUnit.MILLISECONDS);
// Send 5 payloads - the second should cause a leader snapshot.
final MockPayload payload2 = sendPayloadData(leaderActor, "two");
final MockPayload payload3 = sendPayloadData(leaderActor, "three");
final MockPayload payload4 = sendPayloadData(leaderActor, "four");
final MockPayload payload5 = sendPayloadData(leaderActor, "five");
final MockPayload payload6 = sendPayloadData(leaderActor, "six");
MessageCollectorActor.expectFirstMatching(leaderCollectorActor, SaveSnapshotSuccess.class);
// Verify the leader got consensus and applies each log entry even though follower 2 didn't respond.
List<ApplyState> applyStates = MessageCollectorActor.expectMatching(leaderCollectorActor, ApplyState.class, 5);
verifyApplyState(applyStates.get(0), leaderCollectorActor, payload2.toString(), currentTerm, 2, payload2);
verifyApplyState(applyStates.get(2), leaderCollectorActor, payload4.toString(), currentTerm, 4, payload4);
verifyApplyState(applyStates.get(4), leaderCollectorActor, payload6.toString(), currentTerm, 6, payload6);
MessageCollectorActor.clearMessages(leaderCollectorActor);
testLog.info("testLeaderSnapshotWithLaggingFollowerCaughtUpViaInstallSnapshot: " + "sending 1 more payload to trigger second snapshot");
// Send another payload to trigger a second leader snapshot.
MockPayload payload7 = sendPayloadData(leaderActor, "seven");
MessageCollectorActor.expectFirstMatching(leaderCollectorActor, SaveSnapshotSuccess.class);
ApplyState applyState = MessageCollectorActor.expectFirstMatching(leaderCollectorActor, ApplyState.class);
verifyApplyState(applyState, leaderCollectorActor, payload7.toString(), currentTerm, 7, payload7);
// Verify follower 1 applies each log entry.
applyStates = MessageCollectorActor.expectMatching(follower1CollectorActor, ApplyState.class, 6);
verifyApplyState(applyStates.get(0), null, null, currentTerm, 2, payload2);
verifyApplyState(applyStates.get(2), null, null, currentTerm, 4, payload4);
verifyApplyState(applyStates.get(5), null, null, currentTerm, 7, payload7);
// The snapshot should have caused the leader to advanced the snapshot index to the leader's last
// applied index (6) since the log size should have exceed the snapshot batch count (4).
// replicatedToAllIndex should remain at 1 since follower 2 is lagging.
verifyLeadersTrimmedLog(7, 1);
expSnapshotState.add(payload2);
expSnapshotState.add(payload3);
expSnapshotState.add(payload4);
expSnapshotState.add(payload5);
expSnapshotState.add(payload6);
MessageCollectorActor.clearMessages(leaderCollectorActor);
MessageCollectorActor.clearMessages(follower1CollectorActor);
// Send a server config change to test that the install snapshot includes the server config.
ServerConfigurationPayload serverConfig = new ServerConfigurationPayload(Arrays.asList(new ServerInfo(leaderId, true), new ServerInfo(follower1Id, false), new ServerInfo(follower2Id, false)));
leaderContext.updatePeerIds(serverConfig);
((AbstractLeader) leader).updateMinReplicaCount();
leaderActor.tell(serverConfig, ActorRef.noSender());
applyState = MessageCollectorActor.expectFirstMatching(leaderCollectorActor, ApplyState.class);
verifyApplyState(applyState, leaderCollectorActor, "serverConfig", currentTerm, 8, serverConfig);
applyState = MessageCollectorActor.expectFirstMatching(follower1CollectorActor, ApplyState.class);
verifyApplyState(applyState, null, null, currentTerm, 8, serverConfig);
// Verify the leader's persisted snapshot.
List<Snapshot> persistedSnapshots = InMemorySnapshotStore.getSnapshots(leaderId, Snapshot.class);
assertEquals("Persisted snapshots size", 1, persistedSnapshots.size());
verifySnapshot("Persisted", persistedSnapshots.get(0), currentTerm, 6, currentTerm, 7);
List<ReplicatedLogEntry> unAppliedEntry = persistedSnapshots.get(0).getUnAppliedEntries();
assertEquals("Persisted Snapshot getUnAppliedEntries size", 1, unAppliedEntry.size());
verifyReplicatedLogEntry(unAppliedEntry.get(0), currentTerm, 7, payload7);
expSnapshotState.add(payload7);
verifyInstallSnapshotToLaggingFollower(8, serverConfig);
testLog.info("testLeaderSnapshotWithLaggingFollowerCaughtUpViaInstallSnapshot complete");
}
use of org.opendaylight.controller.cluster.raft.MockRaftActorContext.MockPayload in project controller by opendaylight.
the class ReplicationAndSnapshotsWithLaggingFollowerIntegrationTest method verifyNoSubsequentSnapshotAfterMemoryThresholdExceededSnapshot.
/**
* Send another payload to verify another snapshot is not done since the last snapshot trimmed the
* first log entry so the memory threshold should not be exceeded.
*/
private void verifyNoSubsequentSnapshotAfterMemoryThresholdExceededSnapshot() throws Exception {
ApplyState applyState;
CaptureSnapshot captureSnapshot;
MockPayload payload3 = sendPayloadData(leaderActor, "three");
// Verify the leader applies the state.
applyState = MessageCollectorActor.expectFirstMatching(leaderCollectorActor, ApplyState.class);
verifyApplyState(applyState, leaderCollectorActor, payload3.toString(), currentTerm, 3, payload3);
captureSnapshot = MessageCollectorActor.getFirstMatching(leaderCollectorActor, CaptureSnapshot.class);
Assert.assertNull("Leader received unexpected CaptureSnapshot", captureSnapshot);
// Verify the follower 1 applies the state.
applyState = MessageCollectorActor.expectFirstMatching(follower1CollectorActor, ApplyState.class);
verifyApplyState(applyState, null, null, currentTerm, 3, payload3);
// Verify the follower 2 applies the state.
applyState = MessageCollectorActor.expectFirstMatching(follower2CollectorActor, ApplyState.class);
verifyApplyState(applyState, null, null, currentTerm, 3, payload3);
// Verify the leader's state.
verifyLeadersTrimmedLog(3);
// Verify follower 1's state.
verifyFollowersTrimmedLog(1, follower1Actor, 3);
// Verify follower 2's state.
verifyFollowersTrimmedLog(2, follower2Actor, 3);
// Revert back to JVM total memory.
leaderActor.underlyingActor().setMockTotalMemory(0);
MessageCollectorActor.clearMessages(leaderCollectorActor);
MessageCollectorActor.clearMessages(follower1CollectorActor);
MessageCollectorActor.clearMessages(follower2CollectorActor);
expSnapshotState.add(payload3);
}
Aggregations