use of org.opendaylight.controller.cluster.raft.persisted.DeleteEntries in project controller by opendaylight.
the class RaftActorTest method testRaftActorForwardsToRaftActorRecoverySupport.
@Test
public void testRaftActorForwardsToRaftActorRecoverySupport() {
String persistenceId = factory.generateActorId("leader-");
DefaultConfigParamsImpl config = new DefaultConfigParamsImpl();
config.setHeartBeatInterval(new FiniteDuration(1, TimeUnit.DAYS));
TestActorRef<MockRaftActor> mockActorRef = factory.createTestActor(MockRaftActor.props(persistenceId, Collections.<String, String>emptyMap(), config), persistenceId);
MockRaftActor mockRaftActor = mockActorRef.underlyingActor();
// Wait for akka's recovery to complete so it doesn't interfere.
mockRaftActor.waitForRecoveryComplete();
RaftActorRecoverySupport mockSupport = mock(RaftActorRecoverySupport.class);
mockRaftActor.setRaftActorRecoverySupport(mockSupport);
Snapshot snapshot = Snapshot.create(ByteState.of(new byte[] { 1 }), Collections.<ReplicatedLogEntry>emptyList(), 3, 1, 3, 1, -1, null, null);
SnapshotOffer snapshotOffer = new SnapshotOffer(new SnapshotMetadata("test", 6, 12345), snapshot);
mockRaftActor.handleRecover(snapshotOffer);
ReplicatedLogEntry logEntry = new SimpleReplicatedLogEntry(1, 1, new MockRaftActorContext.MockPayload("1", 5));
mockRaftActor.handleRecover(logEntry);
ApplyJournalEntries applyJournalEntries = new ApplyJournalEntries(2);
mockRaftActor.handleRecover(applyJournalEntries);
DeleteEntries deleteEntries = new DeleteEntries(1);
mockRaftActor.handleRecover(deleteEntries);
UpdateElectionTerm updateElectionTerm = new UpdateElectionTerm(5, "member2");
mockRaftActor.handleRecover(updateElectionTerm);
verify(mockSupport).handleRecoveryMessage(same(snapshotOffer), any(PersistentDataProvider.class));
verify(mockSupport).handleRecoveryMessage(same(logEntry), any(PersistentDataProvider.class));
verify(mockSupport).handleRecoveryMessage(same(applyJournalEntries), any(PersistentDataProvider.class));
verify(mockSupport).handleRecoveryMessage(same(deleteEntries), any(PersistentDataProvider.class));
verify(mockSupport).handleRecoveryMessage(same(updateElectionTerm), any(PersistentDataProvider.class));
}
use of org.opendaylight.controller.cluster.raft.persisted.DeleteEntries 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.persisted.DeleteEntries in project controller by opendaylight.
the class RaftActorRecoverySupportTest method testDataRecoveredWithPersistenceDisabled.
@Test
public void testDataRecoveredWithPersistenceDisabled() {
doNothing().when(mockCohort).applyRecoverySnapshot(anyObject());
doReturn(false).when(mockPersistence).isRecoveryApplicable();
doReturn(10L).when(mockPersistentProvider).getLastSequenceNumber();
Snapshot snapshot = Snapshot.create(new MockSnapshotState(Arrays.asList(new MockPayload("1"))), Collections.<ReplicatedLogEntry>emptyList(), 3, 1, 3, 1, -1, null, null);
SnapshotOffer snapshotOffer = new SnapshotOffer(new SnapshotMetadata("test", 6, 12345), snapshot);
sendMessageToSupport(snapshotOffer);
sendMessageToSupport(new UpdateElectionTerm(5, "member2"));
sendMessageToSupport(new SimpleReplicatedLogEntry(4, 1, new MockRaftActorContext.MockPayload("4")));
sendMessageToSupport(new SimpleReplicatedLogEntry(5, 1, new MockRaftActorContext.MockPayload("5")));
sendMessageToSupport(new ApplyJournalEntries(4));
sendMessageToSupport(new DeleteEntries(5));
assertEquals("Journal log size", 0, context.getReplicatedLog().size());
assertEquals("Last index", -1, context.getReplicatedLog().lastIndex());
assertEquals("Last applied", -1, context.getLastApplied());
assertEquals("Commit index", -1, context.getCommitIndex());
assertEquals("Snapshot term", -1, context.getReplicatedLog().getSnapshotTerm());
assertEquals("Snapshot index", -1, context.getReplicatedLog().getSnapshotIndex());
assertEquals("Current term", 5, context.getTermInformation().getCurrentTerm());
assertEquals("Voted For", "member2", context.getTermInformation().getVotedFor());
sendMessageToSupport(RecoveryCompleted.getInstance(), true);
verify(mockCohort, never()).applyRecoverySnapshot(anyObject());
verify(mockCohort, never()).getRestoreFromSnapshot();
verifyNoMoreInteractions(mockCohort);
verify(mockPersistentProvider).deleteMessages(10L);
}
use of org.opendaylight.controller.cluster.raft.persisted.DeleteEntries in project controller by opendaylight.
the class RaftActorRecoverySupportTest method testOnDeleteEntries.
@Test
public void testOnDeleteEntries() {
ReplicatedLog replicatedLog = context.getReplicatedLog();
replicatedLog.append(new SimpleReplicatedLogEntry(0, 1, new MockRaftActorContext.MockPayload("0")));
replicatedLog.append(new SimpleReplicatedLogEntry(1, 1, new MockRaftActorContext.MockPayload("1")));
replicatedLog.append(new SimpleReplicatedLogEntry(2, 1, new MockRaftActorContext.MockPayload("2")));
sendMessageToSupport(new DeleteEntries(1));
assertEquals("Journal log size", 1, context.getReplicatedLog().size());
assertEquals("Last index", 0, context.getReplicatedLog().lastIndex());
}
Aggregations