Search in sources :

Example 1 with ClusterId

use of org.neo4j.causalclustering.identity.ClusterId in project neo4j by neo4j.

the class CoreTopologyTest method identicalTopologiesShouldHaveNoDifference.

@Test
public void identicalTopologiesShouldHaveNoDifference() throws Exception {
    // given
    UUID one = UUID.randomUUID();
    UUID two = UUID.randomUUID();
    Map<MemberId, CoreServerInfo> coreMembers = new HashMap<>();
    coreMembers.put(new MemberId(one), mock(CoreServerInfo.class));
    coreMembers.put(new MemberId(two), mock(CoreServerInfo.class));
    CoreTopology topology = new CoreTopology(new ClusterId(UUID.randomUUID()), true, coreMembers);
    // when
    TopologyDifference diff = topology.difference(topology);
    // then
    assertThat(diff.added().size(), Matchers.equalTo(0));
    assertThat(diff.removed().size(), Matchers.equalTo(0));
}
Also used : MemberId(org.neo4j.causalclustering.identity.MemberId) HashMap(java.util.HashMap) ClusterId(org.neo4j.causalclustering.identity.ClusterId) UUID(java.util.UUID) Test(org.junit.Test)

Example 2 with ClusterId

use of org.neo4j.causalclustering.identity.ClusterId in project neo4j by neo4j.

the class CoreTopologyTest method shouldDetectAddedAndRemovedMembers.

@Test
public void shouldDetectAddedAndRemovedMembers() throws Exception {
    // given
    Map<MemberId, CoreServerInfo> initialMembers = new HashMap<>();
    initialMembers.put(new MemberId(UUID.randomUUID()), mock(CoreServerInfo.class));
    initialMembers.put(new MemberId(UUID.randomUUID()), mock(CoreServerInfo.class));
    Map<MemberId, CoreServerInfo> newMembers = new HashMap<>();
    newMembers.put(new MemberId(UUID.randomUUID()), mock(CoreServerInfo.class));
    newMembers.put(new MemberId(UUID.randomUUID()), mock(CoreServerInfo.class));
    CoreTopology topology = new CoreTopology(new ClusterId(UUID.randomUUID()), true, initialMembers);
    // when
    TopologyDifference diff = topology.difference(new CoreTopology(new ClusterId(UUID.randomUUID()), true, newMembers));
    // then
    assertThat(diff.added().size(), Matchers.equalTo(2));
    assertThat(diff.removed().size(), Matchers.equalTo(2));
}
Also used : MemberId(org.neo4j.causalclustering.identity.MemberId) HashMap(java.util.HashMap) ClusterId(org.neo4j.causalclustering.identity.ClusterId) Test(org.junit.Test)

Example 3 with ClusterId

use of org.neo4j.causalclustering.identity.ClusterId in project neo4j by neo4j.

the class ConnectToRandomCoreServerStrategyTest method fakeCoreTopology.

static CoreTopology fakeCoreTopology(MemberId... memberIds) {
    assert memberIds.length > 0;
    ClusterId clusterId = new ClusterId(UUID.randomUUID());
    Map<MemberId, CoreServerInfo> coreMembers = new HashMap<>();
    int offset = 0;
    for (MemberId memberId : memberIds) {
        coreMembers.put(memberId, new CoreServerInfo(new AdvertisedSocketAddress("localhost", 5000 + offset), new AdvertisedSocketAddress("localhost", 6000 + offset), new ClientConnectorAddresses(singletonList(new ClientConnectorAddresses.ConnectorUri(ClientConnectorAddresses.Scheme.bolt, new AdvertisedSocketAddress("localhost", 7000 + offset)))), asSet("core")));
        offset++;
    }
    return new CoreTopology(clusterId, false, coreMembers);
}
Also used : MemberId(org.neo4j.causalclustering.identity.MemberId) ClusterId(org.neo4j.causalclustering.identity.ClusterId) HashMap(java.util.HashMap) CoreServerInfo(org.neo4j.causalclustering.discovery.CoreServerInfo) AdvertisedSocketAddress(org.neo4j.helpers.AdvertisedSocketAddress) ClientConnectorAddresses(org.neo4j.causalclustering.discovery.ClientConnectorAddresses) CoreTopology(org.neo4j.causalclustering.discovery.CoreTopology)

Example 4 with ClusterId

use of org.neo4j.causalclustering.identity.ClusterId in project neo4j by neo4j.

the class UpstreamDatabaseStrategySelectorTest method shouldDefaultToRandomCoreServerIfNoOtherStrategySpecified.

@Test
public void shouldDefaultToRandomCoreServerIfNoOtherStrategySpecified() 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 defaultStrategy = new ConnectToRandomCoreServerStrategy();
    defaultStrategy.setTopologyService(topologyService);
    UpstreamDatabaseStrategySelector selector = new UpstreamDatabaseStrategySelector(defaultStrategy);
    // when
    MemberId instance = selector.bestUpstreamDatabase();
    // then
    assertEquals(memberId, instance);
}
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 5 with ClusterId

use of org.neo4j.causalclustering.identity.ClusterId in project neo4j by neo4j.

the class ClusterBindingIT method changeClusterId.

private void changeClusterId(CoreClusterMember coreMember) throws IOException {
    SimpleStorage<ClusterId> clusterIdStorage = new SimpleFileStorage<>(fs, coreMember.clusterStateDirectory(), CLUSTER_ID_NAME, new ClusterId.Marshal(), NullLogProvider.getInstance());
    clusterIdStorage.writeState(new ClusterId(UUID.randomUUID()));
}
Also used : SimpleFileStorage(org.neo4j.causalclustering.core.state.storage.SimpleFileStorage) ClusterId(org.neo4j.causalclustering.identity.ClusterId)

Aggregations

ClusterId (org.neo4j.causalclustering.identity.ClusterId)15 MemberId (org.neo4j.causalclustering.identity.MemberId)10 Test (org.junit.Test)6 HashMap (java.util.HashMap)5 UUID (java.util.UUID)4 CoreServerInfo (org.neo4j.causalclustering.discovery.CoreServerInfo)4 RaftMessages (org.neo4j.causalclustering.core.consensus.RaftMessages)3 CoreTopology (org.neo4j.causalclustering.discovery.CoreTopology)3 RaftLogEntry (org.neo4j.causalclustering.core.consensus.log.RaftLogEntry)2 TopologyService (org.neo4j.causalclustering.discovery.TopologyService)2 Member (com.hazelcast.core.Member)1 ClusterIdAwareMessage (org.neo4j.causalclustering.core.consensus.RaftMessages.ClusterIdAwareMessage)1 RaftMessage (org.neo4j.causalclustering.core.consensus.RaftMessages.RaftMessage)1 ConsensusOutcome (org.neo4j.causalclustering.core.consensus.outcome.ConsensusOutcome)1 ReplicatedContent (org.neo4j.causalclustering.core.replication.ReplicatedContent)1 SimpleFileStorage (org.neo4j.causalclustering.core.state.storage.SimpleFileStorage)1 ClientConnectorAddresses (org.neo4j.causalclustering.discovery.ClientConnectorAddresses)1 NetworkFlushableByteBuf (org.neo4j.causalclustering.messaging.NetworkFlushableByteBuf)1 NetworkReadableClosableChannelNetty4 (org.neo4j.causalclustering.messaging.NetworkReadableClosableChannelNetty4)1 AdvertisedSocketAddress (org.neo4j.helpers.AdvertisedSocketAddress)1