Search in sources :

Example 71 with MemberId

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

the class RaftGroupMembershipTest method shouldRemoveLeaderAndAddItBackIn.

@Test
public void shouldRemoveLeaderAndAddItBackIn() throws Exception {
    DirectNetworking net = new DirectNetworking();
    // given
    final MemberId leader1 = member(0);
    final MemberId leader2 = member(1);
    final MemberId stable1 = member(2);
    final MemberId stable2 = member(3);
    final MemberId[] allMembers = { leader1, leader2, stable1, stable2 };
    final MemberId[] fewerMembers = { leader2, stable1, stable2 };
    RaftTestFixture fixture = new RaftTestFixture(net, 3, allMembers);
    fixture.bootstrap(allMembers);
    // when
    fixture.members().withId(leader1).timeoutService().invokeTimeout(ELECTION);
    net.processMessages();
    fixture.members().withId(leader1).raftInstance().setTargetMembershipSet(new RaftTestGroup(fewerMembers).getMembers());
    net.processMessages();
    fixture.members().withId(leader2).timeoutService().invokeTimeout(ELECTION);
    net.processMessages();
    fixture.members().withId(leader2).raftInstance().setTargetMembershipSet(new RaftTestGroup(allMembers).getMembers());
    net.processMessages();
    fixture.members().withId(leader2).timeoutService().invokeTimeout(HEARTBEAT);
    net.processMessages();
    // then
    assertTrue(fixture.members().withId(leader2).raftInstance().isLeader());
    assertThat(fixture.members().withIds(allMembers), hasCurrentMembers(new RaftTestGroup(allMembers)));
}
Also used : MemberId(org.neo4j.causalclustering.identity.MemberId) RaftTestFixture(org.neo4j.causalclustering.core.consensus.RaftTestFixture) DirectNetworking(org.neo4j.causalclustering.core.consensus.DirectNetworking) Test(org.junit.Test)

Example 72 with MemberId

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

the class RaftGroupMembershipTest method shouldRemoveFollowerAndAddItBackIn.

@Test
public void shouldRemoveFollowerAndAddItBackIn() throws Exception {
    DirectNetworking net = new DirectNetworking();
    // given
    final MemberId leader = member(0);
    final MemberId unstable = member(1);
    final MemberId stable1 = member(2);
    final MemberId stable2 = member(3);
    final MemberId[] allMembers = { leader, unstable, stable1, stable2 };
    final MemberId[] fewerMembers = { leader, stable1, stable2 };
    RaftTestFixture fixture = new RaftTestFixture(net, 3, allMembers);
    fixture.bootstrap(allMembers);
    // when
    fixture.members().withId(leader).timeoutService().invokeTimeout(ELECTION);
    net.processMessages();
    fixture.members().withId(leader).raftInstance().setTargetMembershipSet(new RaftTestGroup(fewerMembers).getMembers());
    net.processMessages();
    assertTrue(fixture.members().withId(leader).raftInstance().isLeader());
    assertThat(fixture.members().withIds(fewerMembers), hasCurrentMembers(new RaftTestGroup(fewerMembers)));
    fixture.members().withId(leader).raftInstance().setTargetMembershipSet(new RaftTestGroup(allMembers).getMembers());
    net.processMessages();
    fixture.members().withId(leader).timeoutService().invokeTimeout(HEARTBEAT);
    net.processMessages();
    // then
    assertTrue(fixture.members().withId(leader).raftInstance().isLeader());
    assertThat(fixture.members().withIds(allMembers), hasCurrentMembers(new RaftTestGroup(allMembers)));
}
Also used : MemberId(org.neo4j.causalclustering.identity.MemberId) RaftTestFixture(org.neo4j.causalclustering.core.consensus.RaftTestFixture) DirectNetworking(org.neo4j.causalclustering.core.consensus.DirectNetworking) Test(org.junit.Test)

Example 73 with MemberId

use of org.neo4j.causalclustering.identity.MemberId 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 74 with MemberId

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

the class UserDefinedConfigurationStrategyTest method fakeReadReplicaTopology.

static ReadReplicaTopology fakeReadReplicaTopology(MemberId... readReplicaIds) {
    assert readReplicaIds.length > 0;
    Map<MemberId, ReadReplicaInfo> readReplicas = new HashMap<>();
    int offset = 0;
    for (MemberId memberId : readReplicaIds) {
        readReplicas.put(memberId, new ReadReplicaInfo(new ClientConnectorAddresses(singletonList(new ClientConnectorAddresses.ConnectorUri(ClientConnectorAddresses.Scheme.bolt, new AdvertisedSocketAddress("localhost", 11000 + offset)))), new AdvertisedSocketAddress("localhost", 10000 + offset)));
        offset++;
    }
    return new ReadReplicaTopology(readReplicas);
}
Also used : MemberId(org.neo4j.causalclustering.identity.MemberId) ReadReplicaInfo(org.neo4j.causalclustering.discovery.ReadReplicaInfo) HashMap(java.util.HashMap) AdvertisedSocketAddress(org.neo4j.helpers.AdvertisedSocketAddress) ClientConnectorAddresses(org.neo4j.causalclustering.discovery.ClientConnectorAddresses) ReadReplicaTopology(org.neo4j.causalclustering.discovery.ReadReplicaTopology)

Example 75 with MemberId

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

the class UserDefinedConfigurationStrategyTest method shouldPickTheFirstMatchingServer.

@Test
public void shouldPickTheFirstMatchingServer() throws Exception {
    // given
    MemberId theCoreMemberId = new MemberId(UUID.randomUUID());
    TopologyService topologyService = fakeTopologyService(fakeCoreTopology(theCoreMemberId), fakeReadReplicaTopology(memberIDs(100), new NoEastGroupGenerator()));
    UserDefinedConfigurationStrategy strategy = new UserDefinedConfigurationStrategy();
    Config config = Config.defaults().with(stringMap(CausalClusteringSettings.user_defined_upstream_selection_strategy.name(), "groups(east); groups(core); halt()"));
    strategy.setConfig(config);
    strategy.setTopologyService(topologyService);
    //when
    Optional<MemberId> memberId = strategy.upstreamDatabase();
    // then
    assertEquals(theCoreMemberId, memberId.get());
}
Also used : MemberId(org.neo4j.causalclustering.identity.MemberId) Config(org.neo4j.kernel.configuration.Config) TopologyService(org.neo4j.causalclustering.discovery.TopologyService) Test(org.junit.Test)

Aggregations

MemberId (org.neo4j.causalclustering.identity.MemberId)114 Test (org.junit.Test)83 HashMap (java.util.HashMap)26 CoreTopology (org.neo4j.causalclustering.discovery.CoreTopology)16 CoreServerInfo (org.neo4j.causalclustering.discovery.CoreServerInfo)15 LeaderLocator (org.neo4j.causalclustering.core.consensus.LeaderLocator)13 ReadReplicaTopology (org.neo4j.causalclustering.discovery.ReadReplicaTopology)12 DirectNetworking (org.neo4j.causalclustering.core.consensus.DirectNetworking)10 RaftTestFixture (org.neo4j.causalclustering.core.consensus.RaftTestFixture)10 CoreTopologyService (org.neo4j.causalclustering.discovery.CoreTopologyService)10 Log (org.neo4j.logging.Log)10 ClusterId (org.neo4j.causalclustering.identity.ClusterId)9 ArrayList (java.util.ArrayList)8 UUID (java.util.UUID)8 RaftMessages (org.neo4j.causalclustering.core.consensus.RaftMessages)8 TopologyService (org.neo4j.causalclustering.discovery.TopologyService)7 ByteBuf (io.netty.buffer.ByteBuf)6 File (java.io.File)6 RaftLogEntry (org.neo4j.causalclustering.core.consensus.log.RaftLogEntry)6 HashSet (java.util.HashSet)5