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();
}
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());
}
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");
}
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());
}
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());
}
Aggregations