Search in sources :

Example 1 with IntegerElectionCredentials

use of org.neo4j.cluster.protocol.election.IntegerElectionCredentials in project neo4j by neo4j.

the class DefaultWinnerStrategyTest method theWinnerShouldHaveTheBestVoteCredentials.

@Test
public void theWinnerShouldHaveTheBestVoteCredentials() throws Exception {
    // given
    InstanceId instanceOne = new InstanceId(1);
    InstanceId instanceTwo = new InstanceId(2);
    ClusterContext clusterContext = mock(ClusterContext.class);
    final Log log = mock(Log.class);
    LogProvider logProvider = new LogProvider() {

        @Override
        public Log getLog(Class loggingClass) {
            return log;
        }

        @Override
        public Log getLog(String name) {
            return log;
        }
    };
    when(clusterContext.getLog(DefaultWinnerStrategy.class)).thenReturn(logProvider.getLog(DefaultWinnerStrategy.class));
    // when
    Collection<Vote> votes = Arrays.asList(new Vote(instanceOne, new IntegerElectionCredentials(1)), new Vote(instanceTwo, new IntegerElectionCredentials(2)));
    DefaultWinnerStrategy strategy = new DefaultWinnerStrategy(clusterContext);
    org.neo4j.cluster.InstanceId winner = strategy.pickWinner(votes);
    // then
    assertEquals(instanceTwo, winner);
}
Also used : InstanceId(org.neo4j.cluster.InstanceId) InstanceId(org.neo4j.cluster.InstanceId) Log(org.neo4j.logging.Log) ClusterContext(org.neo4j.cluster.protocol.cluster.ClusterContext) IntegerElectionCredentials(org.neo4j.cluster.protocol.election.IntegerElectionCredentials) LogProvider(org.neo4j.logging.LogProvider) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)1 InstanceId (org.neo4j.cluster.InstanceId)1 ClusterContext (org.neo4j.cluster.protocol.cluster.ClusterContext)1 IntegerElectionCredentials (org.neo4j.cluster.protocol.election.IntegerElectionCredentials)1 Log (org.neo4j.logging.Log)1 LogProvider (org.neo4j.logging.LogProvider)1