Search in sources :

Example 76 with RaftLogEntry

use of org.neo4j.causalclustering.core.consensus.log.RaftLogEntry in project neo4j by neo4j.

the class CommandApplicationProcessTest method shouldIncreaseLastAppliedForOtherCommands.

@Test
public void shouldIncreaseLastAppliedForOtherCommands() throws Exception {
    // given
    applicationProcess.start();
    // when
    raftLog.append(new RaftLogEntry(0, new NewLeaderBarrier()));
    raftLog.append(new RaftLogEntry(0, new NewLeaderBarrier()));
    raftLog.append(new RaftLogEntry(0, new NewLeaderBarrier()));
    applicationProcess.notifyCommitted(2);
    applier.sync(false);
    // then
    assertEquals(2, applicationProcess.lastApplied());
}
Also used : NewLeaderBarrier(org.neo4j.causalclustering.core.consensus.NewLeaderBarrier) RaftLogEntry(org.neo4j.causalclustering.core.consensus.log.RaftLogEntry) Test(org.junit.Test)

Example 77 with RaftLogEntry

use of org.neo4j.causalclustering.core.consensus.log.RaftLogEntry in project neo4j by neo4j.

the class CommandApplicationProcessTest method shouldPanicIfUnableToApply.

@Test
public void shouldPanicIfUnableToApply() throws Throwable {
    // given
    doThrow(IllegalStateException.class).when(commandDispatcher).dispatch(any(ReplicatedTransaction.class), anyLong(), anyCallback());
    applicationProcess.start();
    raftLog.append(new RaftLogEntry(0, operation(nullTx)));
    // when
    assertEquals(true, dbHealth.isHealthy());
    applicationProcess.notifyCommitted(0);
    applier.sync(false);
    // then
    assertEquals(false, dbHealth.isHealthy());
}
Also used : ReplicatedTransaction(org.neo4j.causalclustering.core.state.machines.tx.ReplicatedTransaction) RaftLogEntry(org.neo4j.causalclustering.core.consensus.log.RaftLogEntry) Test(org.junit.Test)

Example 78 with RaftLogEntry

use of org.neo4j.causalclustering.core.consensus.log.RaftLogEntry in project neo4j by neo4j.

the class CommandApplicationProcessTest method entriesThatAreNotStateMachineCommandsShouldStillIncreaseCommandIndex.

@Test
public void entriesThatAreNotStateMachineCommandsShouldStillIncreaseCommandIndex() throws Throwable {
    // given
    applicationProcess.start();
    // when
    raftLog.append(new RaftLogEntry(0, new NewLeaderBarrier()));
    raftLog.append(new RaftLogEntry(0, operation(nullTx)));
    applicationProcess.notifyCommitted(1);
    applier.sync(false);
    InOrder inOrder = inOrder(coreStateMachines, commandDispatcher);
    // then
    inOrder.verify(coreStateMachines).commandDispatcher();
    inOrder.verify(commandDispatcher).dispatch(eq(nullTx), eq(1L), anyCallback());
    inOrder.verify(commandDispatcher).close();
}
Also used : InOrder(org.mockito.InOrder) NewLeaderBarrier(org.neo4j.causalclustering.core.consensus.NewLeaderBarrier) RaftLogEntry(org.neo4j.causalclustering.core.consensus.log.RaftLogEntry) Test(org.junit.Test)

Example 79 with RaftLogEntry

use of org.neo4j.causalclustering.core.consensus.log.RaftLogEntry in project neo4j by neo4j.

the class CommandApplicationProcessTest method shouldApplyToLogFromCache.

@Test
public void shouldApplyToLogFromCache() throws Throwable {
    //given n things to apply in the cache, check that they are actually applied.
    // given
    applicationProcess.start();
    inFlightMap.put(0L, new RaftLogEntry(1, operation(nullTx)));
    //when
    applicationProcess.notifyCommitted(0);
    applier.sync(false);
    //then the cache should have had it's get method called.
    verify(inFlightMap, times(1)).get(0L);
    verifyZeroInteractions(raftLog);
}
Also used : RaftLogEntry(org.neo4j.causalclustering.core.consensus.log.RaftLogEntry) Test(org.junit.Test)

Example 80 with RaftLogEntry

use of org.neo4j.causalclustering.core.consensus.log.RaftLogEntry in project neo4j by neo4j.

the class CommandApplicationProcessTest method cacheEntryShouldBePurgedWhenApplied.

@Test
public void cacheEntryShouldBePurgedWhenApplied() throws Throwable {
    //given a cache in submitApplyJob, the contents of the cache should only contain unapplied "things"
    applicationProcess.start();
    inFlightMap.put(0L, new RaftLogEntry(0, operation(nullTx)));
    inFlightMap.put(1L, new RaftLogEntry(0, operation(nullTx)));
    inFlightMap.put(2L, new RaftLogEntry(0, operation(nullTx)));
    //when
    applicationProcess.notifyCommitted(0);
    applier.sync(false);
    //then the cache should have had its get method called.
    assertNull(inFlightMap.get(0L));
    assertNotNull(inFlightMap.get(1L));
    assertNotNull(inFlightMap.get(2L));
}
Also used : RaftLogEntry(org.neo4j.causalclustering.core.consensus.log.RaftLogEntry) Test(org.junit.Test)

Aggregations

RaftLogEntry (org.neo4j.causalclustering.core.consensus.log.RaftLogEntry)87 Test (org.junit.Test)69 Outcome (org.neo4j.causalclustering.core.consensus.outcome.Outcome)27 InMemoryRaftLog (org.neo4j.causalclustering.core.consensus.log.InMemoryRaftLog)25 RaftState (org.neo4j.causalclustering.core.consensus.state.RaftState)20 RaftMessages (org.neo4j.causalclustering.core.consensus.RaftMessages)12 RaftLog (org.neo4j.causalclustering.core.consensus.log.RaftLog)10 ReadableRaftState (org.neo4j.causalclustering.core.consensus.state.ReadableRaftState)10 AppendLogEntry (org.neo4j.causalclustering.core.consensus.outcome.AppendLogEntry)8 NewLeaderBarrier (org.neo4j.causalclustering.core.consensus.NewLeaderBarrier)7 AppendEntries (org.neo4j.causalclustering.core.consensus.RaftMessages.AppendEntries)7 MemberId (org.neo4j.causalclustering.identity.MemberId)7 InOrder (org.mockito.InOrder)6 RaftLogCursor (org.neo4j.causalclustering.core.consensus.log.RaftLogCursor)6 ReadableRaftLog (org.neo4j.causalclustering.core.consensus.log.ReadableRaftLog)5 RaftTestGroup (org.neo4j.causalclustering.core.consensus.membership.RaftTestGroup)5 BatchAppendLogEntries (org.neo4j.causalclustering.core.consensus.outcome.BatchAppendLogEntries)5 ShipCommand (org.neo4j.causalclustering.core.consensus.outcome.ShipCommand)5 TruncateLogCommand (org.neo4j.causalclustering.core.consensus.outcome.TruncateLogCommand)5 File (java.io.File)4