Search in sources :

Example 6 with MemberId

use of org.neo4j.causalclustering.identity.MemberId in project neo4j by neo4j.

the class VoteStateTest method shouldNotUpdateVoteForSameTerm.

@Test
public void shouldNotUpdateVoteForSameTerm() throws Exception {
    // given
    VoteState voteState = new VoteState();
    MemberId member1 = new MemberId(UUID.randomUUID());
    MemberId member2 = new MemberId(UUID.randomUUID());
    voteState.update(member1, 0);
    try {
        // when
        voteState.update(member2, 0);
        Assert.fail("Should have thrown IllegalArgumentException");
    } catch (IllegalArgumentException expected) {
    // expected
    }
}
Also used : MemberId(org.neo4j.causalclustering.identity.MemberId) Test(org.junit.Test)

Example 7 with MemberId

use of org.neo4j.causalclustering.identity.MemberId in project neo4j by neo4j.

the class VoteStateTest method shouldNotClearVoteForSameTerm.

@Test
public void shouldNotClearVoteForSameTerm() throws Exception {
    // given
    VoteState voteState = new VoteState();
    MemberId member = new MemberId(UUID.randomUUID());
    voteState.update(member, 0);
    try {
        // when
        voteState.update(null, 0);
        Assert.fail("Should have thrown IllegalArgumentException");
    } catch (IllegalArgumentException expected) {
    // expected
    }
}
Also used : MemberId(org.neo4j.causalclustering.identity.MemberId) Test(org.junit.Test)

Example 8 with MemberId

use of org.neo4j.causalclustering.identity.MemberId in project neo4j by neo4j.

the class VoteStateTest method shouldClearVote.

@Test
public void shouldClearVote() throws Exception {
    // given
    VoteState voteState = new VoteState();
    MemberId member = new MemberId(UUID.randomUUID());
    voteState.update(member, 0);
    // when
    voteState.update(null, 1);
    // then
    Assert.assertNull(voteState.votedFor());
}
Also used : MemberId(org.neo4j.causalclustering.identity.MemberId) Test(org.junit.Test)

Example 9 with MemberId

use of org.neo4j.causalclustering.identity.MemberId in project neo4j by neo4j.

the class GetServersProcedureV1RoutingTest method shouldReturnEndpointsInDifferentOrders.

@Test
public void shouldReturnEndpointsInDifferentOrders() throws Exception {
    // given
    final CoreTopologyService coreTopologyService = mock(CoreTopologyService.class);
    LeaderLocator leaderLocator = mock(LeaderLocator.class);
    when(leaderLocator.getLeader()).thenReturn(member(0));
    Map<MemberId, CoreServerInfo> coreMembers = new HashMap<>();
    coreMembers.put(member(0), adressesForCore(0));
    coreMembers.put(member(1), adressesForCore(1));
    coreMembers.put(member(2), adressesForCore(2));
    final CoreTopology clusterTopology = new CoreTopology(clusterId, false, coreMembers);
    when(coreTopologyService.coreServers()).thenReturn(clusterTopology);
    when(coreTopologyService.readReplicas()).thenReturn(new ReadReplicaTopology(emptyMap()));
    final LegacyGetServersProcedure proc = new LegacyGetServersProcedure(coreTopologyService, leaderLocator, config, getInstance());
    // when
    Object[] endpoints = getEndpoints(proc);
    //then
    Object[] endpointsInDifferentOrder = getEndpoints(proc);
    for (int i = 0; i < 100; i++) {
        if (Arrays.deepEquals(endpointsInDifferentOrder, endpoints)) {
            endpointsInDifferentOrder = getEndpoints(proc);
        } else {
            //Different order of servers, no need to retry.
            break;
        }
    }
    assertFalse(Arrays.deepEquals(endpoints, endpointsInDifferentOrder));
}
Also used : MemberId(org.neo4j.causalclustering.identity.MemberId) LeaderLocator(org.neo4j.causalclustering.core.consensus.LeaderLocator) CoreTopologyService(org.neo4j.causalclustering.discovery.CoreTopologyService) HashMap(java.util.HashMap) CoreServerInfo(org.neo4j.causalclustering.discovery.CoreServerInfo) ReadReplicaTopology(org.neo4j.causalclustering.discovery.ReadReplicaTopology) CoreTopology(org.neo4j.causalclustering.discovery.CoreTopology) Test(org.junit.Test)

Example 10 with MemberId

use of org.neo4j.causalclustering.identity.MemberId in project neo4j by neo4j.

the class GetServersProcedureV1Test method shouldReturnNoWriteEndpointsIfThereIsNoAddressForTheLeader.

@Test
public void shouldReturnNoWriteEndpointsIfThereIsNoAddressForTheLeader() throws Exception {
    // given
    final CoreTopologyService topologyService = mock(CoreTopologyService.class);
    Map<MemberId, CoreServerInfo> coreMembers = new HashMap<>();
    coreMembers.put(member(0), adressesForCore(0));
    when(topologyService.coreServers()).thenReturn(new CoreTopology(clusterId, false, coreMembers));
    when(topologyService.readReplicas()).thenReturn(new ReadReplicaTopology(emptyMap()));
    LeaderLocator leaderLocator = mock(LeaderLocator.class);
    when(leaderLocator.getLeader()).thenReturn(member(1));
    LegacyGetServersProcedure procedure = new LegacyGetServersProcedure(topologyService, leaderLocator, config, getInstance());
    // when
    ClusterView clusterView = run(procedure);
    // then
    ClusterView.Builder builder = new ClusterView.Builder();
    builder.readAddress(adressesForCore(0).connectors().boltAddress());
    builder.routeAddress(adressesForCore(0).connectors().boltAddress());
    assertEquals(builder.build(), clusterView);
}
Also used : MemberId(org.neo4j.causalclustering.identity.MemberId) LeaderLocator(org.neo4j.causalclustering.core.consensus.LeaderLocator) CoreTopologyService(org.neo4j.causalclustering.discovery.CoreTopologyService) HashMap(java.util.HashMap) CoreServerInfo(org.neo4j.causalclustering.discovery.CoreServerInfo) ReadReplicaTopology(org.neo4j.causalclustering.discovery.ReadReplicaTopology) CoreTopology(org.neo4j.causalclustering.discovery.CoreTopology) Test(org.junit.Test)

Aggregations

MemberId (org.neo4j.causalclustering.identity.MemberId)114 Test (org.junit.Test)83 HashMap (java.util.HashMap)26 CoreTopology (org.neo4j.causalclustering.discovery.CoreTopology)16 CoreServerInfo (org.neo4j.causalclustering.discovery.CoreServerInfo)15 LeaderLocator (org.neo4j.causalclustering.core.consensus.LeaderLocator)13 ReadReplicaTopology (org.neo4j.causalclustering.discovery.ReadReplicaTopology)12 DirectNetworking (org.neo4j.causalclustering.core.consensus.DirectNetworking)10 RaftTestFixture (org.neo4j.causalclustering.core.consensus.RaftTestFixture)10 CoreTopologyService (org.neo4j.causalclustering.discovery.CoreTopologyService)10 Log (org.neo4j.logging.Log)10 ClusterId (org.neo4j.causalclustering.identity.ClusterId)9 ArrayList (java.util.ArrayList)8 UUID (java.util.UUID)8 RaftMessages (org.neo4j.causalclustering.core.consensus.RaftMessages)8 TopologyService (org.neo4j.causalclustering.discovery.TopologyService)7 ByteBuf (io.netty.buffer.ByteBuf)6 File (java.io.File)6 RaftLogEntry (org.neo4j.causalclustering.core.consensus.log.RaftLogEntry)6 HashSet (java.util.HashSet)5