Search in sources :

Example 1 with InFlightMap

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));
}
Also used : Log(org.neo4j.logging.Log) AssertableLogProvider.inLog(org.neo4j.logging.AssertableLogProvider.inLog) NullLog(org.neo4j.logging.NullLog) InFlightMap(org.neo4j.causalclustering.core.consensus.log.segmented.InFlightMap) AssertableLogProvider(org.neo4j.logging.AssertableLogProvider) RaftLogEntry(org.neo4j.causalclustering.core.consensus.log.RaftLogEntry) Test(org.junit.Test)

Example 2 with 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));
}
Also used : InFlightMap(org.neo4j.causalclustering.core.consensus.log.segmented.InFlightMap) RaftLogEntry(org.neo4j.causalclustering.core.consensus.log.RaftLogEntry) Test(org.junit.Test)

Example 3 with InFlightMap

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));
}
Also used : TruncateLogCommand(org.neo4j.causalclustering.core.consensus.outcome.TruncateLogCommand) LinkedList(java.util.LinkedList) RaftLogCommand(org.neo4j.causalclustering.core.consensus.outcome.RaftLogCommand) RaftLogEntry(org.neo4j.causalclustering.core.consensus.log.RaftLogEntry) InMemoryRaftLog(org.neo4j.causalclustering.core.consensus.log.InMemoryRaftLog) VoteState(org.neo4j.causalclustering.core.consensus.vote.VoteState) Outcome(org.neo4j.causalclustering.core.consensus.outcome.Outcome) AppendLogEntry(org.neo4j.causalclustering.core.consensus.outcome.AppendLogEntry) InFlightMap(org.neo4j.causalclustering.core.consensus.log.segmented.InFlightMap) TermState(org.neo4j.causalclustering.core.consensus.term.TermState) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)3 RaftLogEntry (org.neo4j.causalclustering.core.consensus.log.RaftLogEntry)3 InFlightMap (org.neo4j.causalclustering.core.consensus.log.segmented.InFlightMap)3 LinkedList (java.util.LinkedList)1 InMemoryRaftLog (org.neo4j.causalclustering.core.consensus.log.InMemoryRaftLog)1 AppendLogEntry (org.neo4j.causalclustering.core.consensus.outcome.AppendLogEntry)1 Outcome (org.neo4j.causalclustering.core.consensus.outcome.Outcome)1 RaftLogCommand (org.neo4j.causalclustering.core.consensus.outcome.RaftLogCommand)1 TruncateLogCommand (org.neo4j.causalclustering.core.consensus.outcome.TruncateLogCommand)1 TermState (org.neo4j.causalclustering.core.consensus.term.TermState)1 VoteState (org.neo4j.causalclustering.core.consensus.vote.VoteState)1 AssertableLogProvider (org.neo4j.logging.AssertableLogProvider)1 AssertableLogProvider.inLog (org.neo4j.logging.AssertableLogProvider.inLog)1 Log (org.neo4j.logging.Log)1 NullLog (org.neo4j.logging.NullLog)1