Search in sources :

Example 16 with CoreTopology

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

the class UpstreamDatabaseStrategySelectorTest method shouldUseSpecifiedStrategyInPreferenceToDefault.

@Test
public void shouldUseSpecifiedStrategyInPreferenceToDefault() throws Exception {
    // given
    TopologyService topologyService = mock(TopologyService.class);
    MemberId memberId = new MemberId(UUID.randomUUID());
    when(topologyService.coreServers()).thenReturn(new CoreTopology(new ClusterId(UUID.randomUUID()), false, mapOf(memberId, mock(CoreServerInfo.class))));
    ConnectToRandomCoreServerStrategy shouldNotUse = new ConnectToRandomCoreServerStrategy();
    UpstreamDatabaseSelectionStrategy mockStrategy = mock(UpstreamDatabaseSelectionStrategy.class);
    when(mockStrategy.upstreamDatabase()).thenReturn(Optional.of(new MemberId(UUID.randomUUID())));
    UpstreamDatabaseStrategySelector selector = new UpstreamDatabaseStrategySelector(shouldNotUse, iterable(mockStrategy), null, NullLogProvider.getInstance());
    // when
    selector.bestUpstreamDatabase();
    // then
    verify(mockStrategy, times(2)).upstreamDatabase();
}
Also used : MemberId(org.neo4j.causalclustering.identity.MemberId) ClusterId(org.neo4j.causalclustering.identity.ClusterId) CoreServerInfo(org.neo4j.causalclustering.discovery.CoreServerInfo) CoreTopology(org.neo4j.causalclustering.discovery.CoreTopology) TopologyService(org.neo4j.causalclustering.discovery.TopologyService) Test(org.junit.Test)

Example 17 with CoreTopology

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

the class ClusterOverviewProcedureTest method shouldProvideOverviewOfCoreServersAndReadReplicas.

@Test
public void shouldProvideOverviewOfCoreServersAndReadReplicas() throws Exception {
    // given
    final CoreTopologyService topologyService = mock(CoreTopologyService.class);
    Map<MemberId, CoreServerInfo> coreMembers = new HashMap<>();
    MemberId theLeader = new MemberId(UUID.randomUUID());
    MemberId follower1 = new MemberId(UUID.randomUUID());
    MemberId follower2 = new MemberId(UUID.randomUUID());
    coreMembers.put(theLeader, adressesForCore(0));
    coreMembers.put(follower1, adressesForCore(1));
    coreMembers.put(follower2, adressesForCore(2));
    Map<MemberId, ReadReplicaInfo> replicaMembers = new HashMap<>();
    MemberId replica4 = new MemberId(UUID.randomUUID());
    MemberId replica5 = new MemberId(UUID.randomUUID());
    replicaMembers.put(replica4, addressesForReadReplica(4));
    replicaMembers.put(replica5, addressesForReadReplica(5));
    when(topologyService.coreServers()).thenReturn(new CoreTopology(null, false, coreMembers));
    when(topologyService.readReplicas()).thenReturn(new ReadReplicaTopology(replicaMembers));
    LeaderLocator leaderLocator = mock(LeaderLocator.class);
    when(leaderLocator.getLeader()).thenReturn(theLeader);
    ClusterOverviewProcedure procedure = new ClusterOverviewProcedure(topologyService, leaderLocator, NullLogProvider.getInstance());
    // when
    final RawIterator<Object[], ProcedureException> members = procedure.apply(null, new Object[0]);
    assertThat(members.next(), new IsRecord(theLeader.getUuid(), 5000, Role.LEADER, asSet("core", "core0")));
    assertThat(members.next(), new IsRecord(follower1.getUuid(), 5001, Role.FOLLOWER, asSet("core", "core1")));
    assertThat(members.next(), new IsRecord(follower2.getUuid(), 5002, Role.FOLLOWER, asSet("core", "core2")));
    assertThat(members.next(), new IsRecord(replica4.getUuid(), 6004, Role.READ_REPLICA, asSet("replica", "replica4")));
    assertThat(members.next(), new IsRecord(replica5.getUuid(), 6005, Role.READ_REPLICA, asSet("replica", "replica5")));
    assertFalse(members.hasNext());
}
Also used : ReadReplicaInfo(org.neo4j.causalclustering.discovery.ReadReplicaInfo) 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) ProcedureException(org.neo4j.kernel.api.exceptions.ProcedureException) ReadReplicaTopology(org.neo4j.causalclustering.discovery.ReadReplicaTopology) Test(org.junit.Test)

Example 18 with CoreTopology

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

the class GetServersProcedureV1Test method shouldProvideReaderAndRouterForSingleCoreSetup.

@Test
public void shouldProvideReaderAndRouterForSingleCoreSetup() throws Exception {
    // given
    final CoreTopologyService coreTopologyService = mock(CoreTopologyService.class);
    LeaderLocator leaderLocator = mock(LeaderLocator.class);
    Map<MemberId, CoreServerInfo> coreMembers = new HashMap<>();
    coreMembers.put(member(0), adressesForCore(0));
    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
    ClusterView clusterView = run(proc);
    // 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 19 with CoreTopology

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

the class GetServersProcedureV1Test method shouldReturnCoreServersWithRouteAllCoresButLeaderAsReadAndSingleWriteActions.

@Test
public void shouldReturnCoreServersWithRouteAllCoresButLeaderAsReadAndSingleWriteActions() 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
    ClusterView clusterView = run(proc);
    // then
    ClusterView.Builder builder = new ClusterView.Builder();
    builder.writeAddress(adressesForCore(0).connectors().boltAddress());
    builder.readAddress(adressesForCore(1).connectors().boltAddress());
    builder.readAddress(adressesForCore(2).connectors().boltAddress());
    builder.routeAddress(adressesForCore(0).connectors().boltAddress());
    builder.routeAddress(adressesForCore(1).connectors().boltAddress());
    builder.routeAddress(adressesForCore(2).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 20 with CoreTopology

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

the class GetServersProcedureV1Test method shouldReturnSelfIfOnlyMemberOfTheCluster.

@Test
public void shouldReturnSelfIfOnlyMemberOfTheCluster() 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));
    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
    ClusterView clusterView = run(proc);
    // 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

CoreTopology (org.neo4j.causalclustering.discovery.CoreTopology)22 MemberId (org.neo4j.causalclustering.identity.MemberId)16 Test (org.junit.Test)15 CoreServerInfo (org.neo4j.causalclustering.discovery.CoreServerInfo)15 CoreTopologyService (org.neo4j.causalclustering.discovery.CoreTopologyService)13 LeaderLocator (org.neo4j.causalclustering.core.consensus.LeaderLocator)12 ReadReplicaTopology (org.neo4j.causalclustering.discovery.ReadReplicaTopology)12 HashMap (java.util.HashMap)10 TopologyService (org.neo4j.causalclustering.discovery.TopologyService)4 Optional (java.util.Optional)3 Set (java.util.Set)3 NoLeaderFoundException (org.neo4j.causalclustering.core.consensus.NoLeaderFoundException)3 ClusterId (org.neo4j.causalclustering.identity.ClusterId)3 List (java.util.List)2 Map (java.util.Map)2 TimeoutException (java.util.concurrent.TimeoutException)2 Collectors (java.util.stream.Collectors)2 CausalClusteringSettings (org.neo4j.causalclustering.core.CausalClusteringSettings)2 CoreSnapshot (org.neo4j.causalclustering.core.state.snapshot.CoreSnapshot)2 ClientConnectorAddresses (org.neo4j.causalclustering.discovery.ClientConnectorAddresses)2