use of org.neo4j.causalclustering.core.consensus.log.segmented.InFlightMap in project neo4j by neo4j.
the class TruncateLogCommandTest method applyTo.
@Test
public void applyTo() throws Exception {
//Test that truncate commands correctly remove entries from the cache.
//given
AssertableLogProvider logProvider = new AssertableLogProvider();
Log log = logProvider.getLog(getClass());
long fromIndex = 2L;
TruncateLogCommand truncateLogCommand = new TruncateLogCommand(fromIndex);
InFlightMap<RaftLogEntry> inFlightMap = new InFlightMap<>();
inFlightMap.put(0L, new RaftLogEntry(0L, valueOf(0)));
inFlightMap.put(1L, new RaftLogEntry(1L, valueOf(1)));
inFlightMap.put(2L, new RaftLogEntry(2L, valueOf(2)));
inFlightMap.put(3L, new RaftLogEntry(3L, valueOf(3)));
//when
truncateLogCommand.applyTo(inFlightMap, log);
//then
assertNotNull(inFlightMap.get(0L));
assertNotNull(inFlightMap.get(1L));
assertNull(inFlightMap.get(2L));
assertNull(inFlightMap.get(3L));
logProvider.assertAtLeastOnce(inLog(getClass()).debug("Start truncating in-flight-map from index %d. Current map:%n%s", fromIndex, inFlightMap));
}
use of org.neo4j.causalclustering.core.consensus.log.segmented.InFlightMap in project neo4j by neo4j.
the class TruncateLogCommandTest method shouldTruncateWithGaps.
@Test
public void shouldTruncateWithGaps() throws Exception {
//given
long fromIndex = 1L;
TruncateLogCommand truncateLogCommand = new TruncateLogCommand(fromIndex);
InFlightMap<RaftLogEntry> inFlightMap = new InFlightMap<>();
inFlightMap.put(0L, new RaftLogEntry(0L, valueOf(0)));
inFlightMap.put(2L, new RaftLogEntry(1L, valueOf(1)));
inFlightMap.put(4L, new RaftLogEntry(2L, valueOf(2)));
truncateLogCommand.applyTo(inFlightMap, NullLog.getInstance());
inFlightMap.put(1L, new RaftLogEntry(3L, valueOf(1)));
inFlightMap.put(2L, new RaftLogEntry(4L, valueOf(2)));
assertNotNull(inFlightMap.get(0L));
assertNotNull(inFlightMap.get(1L));
assertNotNull(inFlightMap.get(2L));
}
use of org.neo4j.causalclustering.core.consensus.log.segmented.InFlightMap in project neo4j by neo4j.
the class RaftStateTest method shouldUpdateCacheState.
@Test
public void shouldUpdateCacheState() throws Exception {
//Test that updates applied to the raft state will be refelcted in the entry cache.
//given
InFlightMap<RaftLogEntry> cache = new InFlightMap<>();
RaftState raftState = new RaftState(member(0), new InMemoryStateStorage<>(new TermState()), new FakeMembership(), new InMemoryRaftLog(), new InMemoryStateStorage<>(new VoteState()), cache, NullLogProvider.getInstance());
List<RaftLogCommand> logCommands = new LinkedList<RaftLogCommand>() {
{
add(new AppendLogEntry(1, new RaftLogEntry(0L, valueOf(0))));
add(new AppendLogEntry(2, new RaftLogEntry(0L, valueOf(1))));
add(new AppendLogEntry(3, new RaftLogEntry(0L, valueOf(2))));
add(new AppendLogEntry(4, new RaftLogEntry(0L, valueOf(4))));
add(new TruncateLogCommand(3));
add(new AppendLogEntry(3, new RaftLogEntry(0L, valueOf(5))));
}
};
Outcome raftTestMemberOutcome = new Outcome(CANDIDATE, 0, null, -1, null, emptySet(), -1, initialFollowerStates(), true, logCommands, emptyOutgoingMessages(), emptySet(), -1, emptySet());
//when
raftState.update(raftTestMemberOutcome);
//then
assertNotNull(cache.get(1L));
assertNotNull(cache.get(2L));
assertNotNull(cache.get(3L));
assertEquals(valueOf(5), cache.get(3L).content());
assertNull(cache.get(4L));
}
Aggregations