Search in sources :

Example 16 with CoreServerInfo

use of org.neo4j.causalclustering.discovery.CoreServerInfo in project neo4j by neo4j.

the class GetServersProcedureV1Test method shouldReturnCoreMemberAsReadServerIfNoReadReplicasAvailable.

@Test
public void shouldReturnCoreMemberAsReadServerIfNoReadReplicasAvailable() throws Exception {
    // given
    final CoreTopologyService topologyService = mock(CoreTopologyService.class);
    Map<MemberId, CoreServerInfo> coreMembers = new HashMap<>();
    MemberId theLeader = member(0);
    coreMembers.put(theLeader, 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(theLeader);
    LegacyGetServersProcedure procedure = new LegacyGetServersProcedure(topologyService, leaderLocator, config, getInstance());
    // when
    ClusterView clusterView = run(procedure);
    // then
    ClusterView.Builder builder = new ClusterView.Builder();
    builder.writeAddress(adressesForCore(0).connectors().boltAddress());
    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

CoreServerInfo (org.neo4j.causalclustering.discovery.CoreServerInfo)16 CoreTopology (org.neo4j.causalclustering.discovery.CoreTopology)13 MemberId (org.neo4j.causalclustering.identity.MemberId)13 LeaderLocator (org.neo4j.causalclustering.core.consensus.LeaderLocator)11 HashMap (java.util.HashMap)10 ReadReplicaTopology (org.neo4j.causalclustering.discovery.ReadReplicaTopology)10 Test (org.junit.Test)9 CoreTopologyService (org.neo4j.causalclustering.discovery.CoreTopologyService)9 Optional (java.util.Optional)3 Set (java.util.Set)3 NoLeaderFoundException (org.neo4j.causalclustering.core.consensus.NoLeaderFoundException)3 AdvertisedSocketAddress (org.neo4j.helpers.AdvertisedSocketAddress)3 List (java.util.List)2 Map (java.util.Map)2 Collectors (java.util.stream.Collectors)2 CausalClusteringSettings (org.neo4j.causalclustering.core.CausalClusteringSettings)2 ClientConnectorAddresses (org.neo4j.causalclustering.discovery.ClientConnectorAddresses)2 ReadReplicaInfo (org.neo4j.causalclustering.discovery.ReadReplicaInfo)2 TopologyService (org.neo4j.causalclustering.discovery.TopologyService)2 ClusterId (org.neo4j.causalclustering.identity.ClusterId)2