Search in sources :

Example 1 with FilteringIterable

use of org.neo4j.helpers.collection.FilteringIterable in project neo4j by neo4j.

the class DisconnectLeaderScenario method oneIteration.

private long oneIteration(long leaderStabilityMaxTimeMillis) throws InterruptedException, TimeoutException {
    List<RaftMachine> rafts = fixture.rafts.stream().map(Fixture.RaftFixture::raftMachine).collect(toList());
    MemberId oldLeader = ElectionUtil.waitForLeaderAgreement(rafts, leaderStabilityMaxTimeMillis);
    long startTime = System.currentTimeMillis();
    fixture.net.disconnect(oldLeader);
    MemberId newLeader = ElectionUtil.waitForLeaderAgreement(new FilteringIterable<>(rafts, raft -> !raft.identity().equals(oldLeader)), leaderStabilityMaxTimeMillis);
    // this should be guaranteed by the waitForLeaderAgreement call
    assert !newLeader.equals(oldLeader);
    return System.currentTimeMillis() - startTime;
}
Also used : List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) TimeoutException(java.util.concurrent.TimeoutException) MemberId(org.neo4j.causalclustering.identity.MemberId) FilteringIterable(org.neo4j.helpers.collection.FilteringIterable) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) RaftMachine(org.neo4j.causalclustering.core.consensus.RaftMachine) RaftMachine(org.neo4j.causalclustering.core.consensus.RaftMachine) MemberId(org.neo4j.causalclustering.identity.MemberId)

Aggregations

ArrayList (java.util.ArrayList)1 List (java.util.List)1 ThreadLocalRandom (java.util.concurrent.ThreadLocalRandom)1 TimeoutException (java.util.concurrent.TimeoutException)1 Collectors (java.util.stream.Collectors)1 Collectors.toList (java.util.stream.Collectors.toList)1 RaftMachine (org.neo4j.causalclustering.core.consensus.RaftMachine)1 MemberId (org.neo4j.causalclustering.identity.MemberId)1 FilteringIterable (org.neo4j.helpers.collection.FilteringIterable)1