Search in sources :

Example 31 with MemberId

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

the class MemberIdMarshalTest method shouldSerializeAndDeserialize.

@Test
public void shouldSerializeAndDeserialize() throws Exception {
    // given
    MemberId.Marshal marshal = new MemberId.Marshal();
    final MemberId member = new MemberId(UUID.randomUUID());
    // when
    ByteBuf buffer = Unpooled.buffer(1_000);
    marshal.marshal(member, new NetworkFlushableChannelNetty4(buffer));
    final MemberId recovered = marshal.unmarshal(new NetworkReadableClosableChannelNetty4(buffer));
    // then
    assertEquals(member, recovered);
}
Also used : MemberId(org.neo4j.causalclustering.identity.MemberId) NetworkFlushableChannelNetty4(org.neo4j.causalclustering.messaging.NetworkFlushableChannelNetty4) ByteBuf(io.netty.buffer.ByteBuf) NetworkReadableClosableChannelNetty4(org.neo4j.causalclustering.messaging.NetworkReadableClosableChannelNetty4) Test(org.junit.Test)

Example 32 with MemberId

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

the class RaftGroupMembershipTest method shouldNotFormGroupWithoutAnyBootstrapping.

@Test
public void shouldNotFormGroupWithoutAnyBootstrapping() throws Exception {
    // given
    DirectNetworking net = new DirectNetworking();
    final MemberId[] ids = { member(0), member(1), member(2) };
    RaftTestFixture fixture = new RaftTestFixture(net, 3, ids);
    fixture.members().setTargetMembershipSet(new RaftTestGroup(ids).getMembers());
    fixture.members().invokeTimeout(ELECTION);
    // when
    net.processMessages();
    // then
    assertThat(fixture.members(), hasCurrentMembers(new RaftTestGroup(new int[0])));
    assertEquals(0, fixture.members().withRole(LEADER).size());
    assertEquals(3, fixture.members().withRole(FOLLOWER).size());
}
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 33 with MemberId

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

the class RaftGroupMembershipTest method shouldAddMultipleInstancesToExistingRaftGroup.

@Test
public void shouldAddMultipleInstancesToExistingRaftGroup() throws Exception {
    // given
    DirectNetworking net = new DirectNetworking();
    final MemberId leader = member(0);
    final MemberId stable1 = member(1);
    final MemberId stable2 = member(2);
    final MemberId toBeAdded1 = member(3);
    final MemberId toBeAdded2 = member(4);
    final MemberId toBeAdded3 = member(5);
    final MemberId[] initialMembers = { leader, stable1, stable2 };
    final MemberId[] finalMembers = { leader, stable1, stable2, toBeAdded1, toBeAdded2, toBeAdded3 };
    RaftTestFixture fixture = new RaftTestFixture(net, 3, finalMembers);
    fixture.bootstrap(initialMembers);
    fixture.members().withId(leader).timeoutService().invokeTimeout(ELECTION);
    net.processMessages();
    // when
    fixture.members().setTargetMembershipSet(new RaftTestGroup(finalMembers).getMembers());
    net.processMessages();
    // We need a heartbeat for every member we add. It is necessary to have the new members report their state
    // so their membership change can be processed. We can probably do better here.
    fixture.members().withId(leader).timeoutService().invokeTimeout(HEARTBEAT);
    net.processMessages();
    fixture.members().withId(leader).timeoutService().invokeTimeout(HEARTBEAT);
    net.processMessages();
    fixture.members().withId(leader).timeoutService().invokeTimeout(HEARTBEAT);
    net.processMessages();
    // then
    assertThat(fixture.members().withIds(finalMembers), hasCurrentMembers(new RaftTestGroup(finalMembers)));
    assertEquals(1, fixture.members().withRole(LEADER).size());
    assertEquals(5, fixture.members().withRole(FOLLOWER).size());
}
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 34 with MemberId

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

the class RaftGroupMembershipTest method shouldHandleMixedChangeToExistingRaftGroup.

@Test
public void shouldHandleMixedChangeToExistingRaftGroup() throws Exception {
    DirectNetworking net = new DirectNetworking();
    // given
    final MemberId leader = member(0);
    final MemberId stable = member(1);
    final MemberId toBeRemoved1 = member(2);
    final MemberId toBeRemoved2 = member(3);
    final MemberId toBeAdded1 = member(4);
    final MemberId toBeAdded2 = member(5);
    final MemberId[] everyone = { leader, stable, toBeRemoved1, toBeRemoved2, toBeAdded1, toBeAdded2 };
    final MemberId[] initialMembers = { leader, stable, toBeRemoved1, toBeRemoved2 };
    final MemberId[] finalMembers = { leader, stable, toBeAdded1, toBeAdded2 };
    RaftTestFixture fixture = new RaftTestFixture(net, 3, everyone);
    fixture.bootstrap(initialMembers);
    fixture.members().withId(leader).timeoutService().invokeTimeout(ELECTION);
    net.processMessages();
    // when
    fixture.members().withId(leader).raftInstance().setTargetMembershipSet(new RaftTestGroup(finalMembers).getMembers());
    net.processMessages();
    fixture.members().withId(leader).timeoutService().invokeTimeout(HEARTBEAT);
    net.processMessages();
    fixture.members().withId(leader).timeoutService().invokeTimeout(HEARTBEAT);
    net.processMessages();
    fixture.members().withId(leader).timeoutService().invokeTimeout(HEARTBEAT);
    net.processMessages();
    // then
    assertThat(fixture.members().withIds(finalMembers), hasCurrentMembers(new RaftTestGroup(finalMembers)));
    assertEquals(1, fixture.members().withIds(finalMembers).withRole(LEADER).size());
    assertEquals(3, fixture.members().withIds(finalMembers).withRole(FOLLOWER).size());
}
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 35 with MemberId

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

the class RaftGroupMembershipTest method shouldRemoveSingleInstanceFromExistingRaftGroup.

@Test
public void shouldRemoveSingleInstanceFromExistingRaftGroup() throws Exception {
    DirectNetworking net = new DirectNetworking();
    // given
    final MemberId leader = member(0);
    final MemberId stable = member(1);
    final MemberId toBeRemoved = member(2);
    final MemberId[] initialMembers = { leader, stable, toBeRemoved };
    final MemberId[] finalMembers = { leader, stable };
    RaftTestFixture fixture = new RaftTestFixture(net, 2, initialMembers);
    fixture.bootstrap(initialMembers);
    fixture.members().withId(leader).timeoutService().invokeTimeout(ELECTION);
    // when
    fixture.members().setTargetMembershipSet(new RaftTestGroup(finalMembers).getMembers());
    net.processMessages();
    // then
    assertThat(fixture.members().withIds(finalMembers), hasCurrentMembers(new RaftTestGroup(finalMembers)));
    assertEquals(1, fixture.members().withIds(finalMembers).withRole(LEADER).size());
    assertEquals(1, fixture.members().withIds(finalMembers).withRole(FOLLOWER).size());
}
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)

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