Search in sources :

Example 6 with CoreTopologyService

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

the class ClusterBinderTest method shouldTimeoutWhenNotBootrappableAndNobodyElsePublishesClusterId.

@Test
public void shouldTimeoutWhenNotBootrappableAndNobodyElsePublishesClusterId() throws Throwable {
    // given
    CoreTopology unboundTopology = new CoreTopology(null, false, emptyMap());
    CoreTopologyService topologyService = mock(CoreTopologyService.class);
    when(topologyService.coreServers()).thenReturn(unboundTopology);
    ClusterBinder binder = new ClusterBinder(new StubClusterIdStorage(), topologyService, NullLogProvider.getInstance(), clock, () -> clock.forward(1, TimeUnit.SECONDS), 3_000, coreBootstrapper);
    try {
        // when
        binder.bindToCluster(null);
        fail("Should have timed out");
    } catch (TimeoutException e) {
    // expected
    }
    // then
    verify(topologyService, atLeast(2)).coreServers();
}
Also used : CoreTopologyService(org.neo4j.causalclustering.discovery.CoreTopologyService) CoreTopology(org.neo4j.causalclustering.discovery.CoreTopology) TimeoutException(java.util.concurrent.TimeoutException) Test(org.junit.Test)

Example 7 with CoreTopologyService

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

the class ClusterBinderTest method shouldBootstrapWhenBootstrappable.

@Test
public void shouldBootstrapWhenBootstrappable() throws Throwable {
    // given
    CoreTopology bootstrappableTopology = new CoreTopology(null, true, emptyMap());
    CoreTopologyService topologyService = mock(CoreTopologyService.class);
    when(topologyService.coreServers()).thenReturn(bootstrappableTopology);
    when(topologyService.setClusterId(any())).thenReturn(true);
    ClusterBinder binder = new ClusterBinder(new StubClusterIdStorage(), topologyService, NullLogProvider.getInstance(), clock, () -> clock.forward(1, TimeUnit.SECONDS), 3_000, coreBootstrapper);
    ThrowingConsumer<CoreSnapshot, Throwable> snapshotInstaller = mock(ThrowingConsumer.class);
    // when
    binder.bindToCluster(snapshotInstaller);
    // then
    verify(coreBootstrapper).bootstrap(any());
    Optional<ClusterId> clusterId = binder.get();
    assertTrue(clusterId.isPresent());
    verify(topologyService).setClusterId(clusterId.get());
    verify(snapshotInstaller).accept(any());
}
Also used : CoreSnapshot(org.neo4j.causalclustering.core.state.snapshot.CoreSnapshot) CoreTopologyService(org.neo4j.causalclustering.discovery.CoreTopologyService) CoreTopology(org.neo4j.causalclustering.discovery.CoreTopology) Test(org.junit.Test)

Example 8 with CoreTopologyService

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

the class ConnectionInfoIT method hzTest.

@Test
public void hzTest() throws Throwable {
    // given
    testSocket = bindPort("0.0.0.0", 4243);
    //when
    AssertableLogProvider logProvider = new AssertableLogProvider();
    AssertableLogProvider userLogProvider = new AssertableLogProvider();
    HazelcastDiscoveryServiceFactory hzFactory = new HazelcastDiscoveryServiceFactory();
    Config config = embeddedDefaults(stringMap(discovery_listen_address.name(), ":" + testSocket.getLocalPort(), CausalClusteringSettings.initial_discovery_members.name(), "localhost:" + testSocket.getLocalPort(), new BoltConnector("bolt").enabled.name(), "true", new HttpConnector("http").enabled.name(), "true"));
    Neo4jJobScheduler jobScheduler = new Neo4jJobScheduler();
    jobScheduler.init();
    CoreTopologyService coreTopologyService = hzFactory.coreTopologyService(config, new MemberId(UUID.randomUUID()), jobScheduler, logProvider, userLogProvider);
    try {
        coreTopologyService.init();
        coreTopologyService.start();
    }//then
     catch (Throwable throwable) {
    //expected
    }
    logProvider.assertContainsMessageContaining("Hazelcast was unable to start with setting");
    userLogProvider.assertContainsMessageContaining("Hazelcast was unable to start with setting");
}
Also used : Neo4jJobScheduler(org.neo4j.kernel.impl.util.Neo4jJobScheduler) MemberId(org.neo4j.causalclustering.identity.MemberId) HttpConnector(org.neo4j.kernel.configuration.HttpConnector) HazelcastDiscoveryServiceFactory(org.neo4j.causalclustering.discovery.HazelcastDiscoveryServiceFactory) CoreTopologyService(org.neo4j.causalclustering.discovery.CoreTopologyService) BoltConnector(org.neo4j.kernel.configuration.BoltConnector) Config(org.neo4j.kernel.configuration.Config) AssertableLogProvider(org.neo4j.logging.AssertableLogProvider) Test(org.junit.Test)

Example 9 with CoreTopologyService

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

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

the class ClusterBinderTest method shouldPublishStoredClusterIdIfPreviouslyBound.

@Test
public void shouldPublishStoredClusterIdIfPreviouslyBound() throws Throwable {
    // given
    ClusterId previouslyBoundClusterId = new ClusterId(UUID.randomUUID());
    CoreTopologyService topologyService = mock(CoreTopologyService.class);
    when(topologyService.setClusterId(previouslyBoundClusterId)).thenReturn(true);
    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
    binder.bindToCluster(null);
    // then
    verify(topologyService).setClusterId(previouslyBoundClusterId);
    Optional<ClusterId> clusterId = binder.get();
    assertTrue(clusterId.isPresent());
    assertEquals(previouslyBoundClusterId, clusterId.get());
}
Also used : CoreTopologyService(org.neo4j.causalclustering.discovery.CoreTopologyService) 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