Search in sources :

Example 1 with ReadReplicaTopology

use of org.neo4j.causalclustering.discovery.ReadReplicaTopology 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 2 with ReadReplicaTopology

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

the class GetServersProcedureV1Test method ttlShouldBeInSeconds.

@Test
public void ttlShouldBeInSeconds() throws Exception {
    // given
    final CoreTopologyService coreTopologyService = mock(CoreTopologyService.class);
    LeaderLocator leaderLocator = mock(LeaderLocator.class);
    final CoreTopology clusterTopology = new CoreTopology(clusterId, false, new HashMap<>());
    when(coreTopologyService.coreServers()).thenReturn(clusterTopology);
    when(coreTopologyService.readReplicas()).thenReturn(new ReadReplicaTopology(emptyMap()));
    // set the TTL in minutes
    config = config.augment(stringMap(cluster_routing_ttl.name(), "10m"));
    final LegacyGetServersProcedure proc = new LegacyGetServersProcedure(coreTopologyService, leaderLocator, config, getInstance());
    // when
    List<Object[]> results = asList(proc.apply(null, new Object[0]));
    // then
    Object[] rows = results.get(0);
    long ttlInSeconds = (long) rows[0];
    assertEquals(600, ttlInSeconds);
}
Also used : LeaderLocator(org.neo4j.causalclustering.core.consensus.LeaderLocator) CoreTopologyService(org.neo4j.causalclustering.discovery.CoreTopologyService) ReadReplicaTopology(org.neo4j.causalclustering.discovery.ReadReplicaTopology) CoreTopology(org.neo4j.causalclustering.discovery.CoreTopology) Test(org.junit.Test)

Example 3 with ReadReplicaTopology

use of org.neo4j.causalclustering.discovery.ReadReplicaTopology 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)

Example 4 with ReadReplicaTopology

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

the class GetServersProcedureV1Test method shouldReturnNoWriteEndpointsIfThereIsNoLeader.

@Test
public void shouldReturnNoWriteEndpointsIfThereIsNoLeader() 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()).thenThrow(new NoLeaderFoundException());
    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 : NoLeaderFoundException(org.neo4j.causalclustering.core.consensus.NoLeaderFoundException) HashMap(java.util.HashMap) CoreTopology(org.neo4j.causalclustering.discovery.CoreTopology) MemberId(org.neo4j.causalclustering.identity.MemberId) LeaderLocator(org.neo4j.causalclustering.core.consensus.LeaderLocator) CoreTopologyService(org.neo4j.causalclustering.discovery.CoreTopologyService) CoreServerInfo(org.neo4j.causalclustering.discovery.CoreServerInfo) ReadReplicaTopology(org.neo4j.causalclustering.discovery.ReadReplicaTopology) Test(org.junit.Test)

Example 5 with ReadReplicaTopology

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

the class UserDefinedConfigurationStrategyTest method fakeReadReplicaTopology.

private ReadReplicaTopology fakeReadReplicaTopology(MemberId[] readReplicaIds, NoEastGroupGenerator groupGenerator) {
    assert readReplicaIds.length > 0;
    Map<MemberId, ReadReplicaInfo> readReplicas = new HashMap<>();
    int offset = 0;
    for (MemberId memberId : readReplicaIds) {
        readReplicas.put(memberId, new ReadReplicaInfo(new ClientConnectorAddresses(singletonList(new ClientConnectorAddresses.ConnectorUri(ClientConnectorAddresses.Scheme.bolt, new AdvertisedSocketAddress("localhost", 11000 + offset)))), new AdvertisedSocketAddress("localhost", 10000 + offset), groupGenerator.get(memberId)));
        offset++;
    }
    return new ReadReplicaTopology(readReplicas);
}
Also used : MemberId(org.neo4j.causalclustering.identity.MemberId) ReadReplicaInfo(org.neo4j.causalclustering.discovery.ReadReplicaInfo) HashMap(java.util.HashMap) AdvertisedSocketAddress(org.neo4j.helpers.AdvertisedSocketAddress) ClientConnectorAddresses(org.neo4j.causalclustering.discovery.ClientConnectorAddresses) ReadReplicaTopology(org.neo4j.causalclustering.discovery.ReadReplicaTopology)

Aggregations

ReadReplicaTopology (org.neo4j.causalclustering.discovery.ReadReplicaTopology)14 CoreTopology (org.neo4j.causalclustering.discovery.CoreTopology)12 MemberId (org.neo4j.causalclustering.identity.MemberId)12 HashMap (java.util.HashMap)11 LeaderLocator (org.neo4j.causalclustering.core.consensus.LeaderLocator)11 Test (org.junit.Test)10 CoreServerInfo (org.neo4j.causalclustering.discovery.CoreServerInfo)10 CoreTopologyService (org.neo4j.causalclustering.discovery.CoreTopologyService)10 ReadReplicaInfo (org.neo4j.causalclustering.discovery.ReadReplicaInfo)3 NoLeaderFoundException (org.neo4j.causalclustering.core.consensus.NoLeaderFoundException)2 ClientConnectorAddresses (org.neo4j.causalclustering.discovery.ClientConnectorAddresses)2 LoadBalancingResult (org.neo4j.causalclustering.load_balancing.LoadBalancingResult)2 AdvertisedSocketAddress (org.neo4j.helpers.AdvertisedSocketAddress)2 Collections.emptyList (java.util.Collections.emptyList)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 CausalClusteringSettings (org.neo4j.causalclustering.core.CausalClusteringSettings)1