Search in sources :

Example 11 with CoreTopologyService

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

the class ClusterBinderTest method shouldFailToPublishMismatchingStoredClusterId.

@Test
public void shouldFailToPublishMismatchingStoredClusterId() throws Throwable {
    // given
    ClusterId previouslyBoundClusterId = new ClusterId(UUID.randomUUID());
    CoreTopologyService topologyService = mock(CoreTopologyService.class);
    when(topologyService.setClusterId(previouslyBoundClusterId)).thenReturn(false);
    StubClusterIdStorage clusterIdStorage = new StubClusterIdStorage();
    clusterIdStorage.writeState(previouslyBoundClusterId);
    ClusterBinder binder = new ClusterBinder(clusterIdStorage, topologyService, NullLogProvider.getInstance(), clock, () -> clock.forward(1, TimeUnit.SECONDS), 3_000, coreBootstrapper);
    // when
    try {
        binder.bindToCluster(null);
        fail("Should have thrown exception");
    } catch (BindingException e) {
    // expected
    }
}
Also used : CoreTopologyService(org.neo4j.causalclustering.discovery.CoreTopologyService) Test(org.junit.Test)

Example 12 with CoreTopologyService

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

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

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

Example 15 with CoreTopologyService

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

the class GetServersProcedureV1Test method shouldReturnTheCoreLeaderForWriteAndReadReplicasAndCoresForReads.

@Test
public void shouldReturnTheCoreLeaderForWriteAndReadReplicasAndCoresForReads() 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(readReplicaInfoMap(1)));
    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());
    if (expectFollowersAsReadEndPoints) {
        builder.readAddress(adressesForCore(0).connectors().boltAddress());
    }
    builder.readAddress(addressesForReadReplica(1).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

Test (org.junit.Test)16 CoreTopologyService (org.neo4j.causalclustering.discovery.CoreTopologyService)16 CoreTopology (org.neo4j.causalclustering.discovery.CoreTopology)13 LeaderLocator (org.neo4j.causalclustering.core.consensus.LeaderLocator)10 ReadReplicaTopology (org.neo4j.causalclustering.discovery.ReadReplicaTopology)10 MemberId (org.neo4j.causalclustering.identity.MemberId)10 HashMap (java.util.HashMap)9 CoreServerInfo (org.neo4j.causalclustering.discovery.CoreServerInfo)9 TimeoutException (java.util.concurrent.TimeoutException)1 NoLeaderFoundException (org.neo4j.causalclustering.core.consensus.NoLeaderFoundException)1 CoreSnapshot (org.neo4j.causalclustering.core.state.snapshot.CoreSnapshot)1 HazelcastDiscoveryServiceFactory (org.neo4j.causalclustering.discovery.HazelcastDiscoveryServiceFactory)1 ReadReplicaInfo (org.neo4j.causalclustering.discovery.ReadReplicaInfo)1 ProcedureException (org.neo4j.kernel.api.exceptions.ProcedureException)1 BoltConnector (org.neo4j.kernel.configuration.BoltConnector)1 Config (org.neo4j.kernel.configuration.Config)1 HttpConnector (org.neo4j.kernel.configuration.HttpConnector)1 Neo4jJobScheduler (org.neo4j.kernel.impl.util.Neo4jJobScheduler)1 AssertableLogProvider (org.neo4j.logging.AssertableLogProvider)1