use of org.neo4j.causalclustering.core.consensus.DirectNetworking in project neo4j by neo4j.
the class RaftGroupMembershipTest method shouldAddSingleInstanceToExistingRaftGroup.
@Test
public void shouldAddSingleInstanceToExistingRaftGroup() throws Exception {
// given
DirectNetworking net = new DirectNetworking();
final MemberId leader = member(0);
final MemberId stable1 = member(1);
final MemberId stable2 = member(2);
final MemberId toBeAdded = member(3);
final MemberId[] initialMembers = { leader, stable1, stable2 };
final MemberId[] finalMembers = { leader, stable1, stable2, toBeAdded };
RaftTestFixture fixture = new RaftTestFixture(net, 3, finalMembers);
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();
// then
assertThat(fixture.members().withIds(finalMembers), hasCurrentMembers(new RaftTestGroup(finalMembers)));
assertEquals(1, fixture.members().withRole(LEADER).size());
assertEquals(3, fixture.members().withRole(FOLLOWER).size());
}
use of org.neo4j.causalclustering.core.consensus.DirectNetworking in project neo4j by neo4j.
the class RaftGroupMembershipTest method shouldRemoveMultipleInstancesFromExistingRaftGroup.
@Test
public void shouldRemoveMultipleInstancesFromExistingRaftGroup() 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 toBeRemoved3 = member(4);
final MemberId[] initialMembers = { leader, stable, toBeRemoved1, toBeRemoved2, toBeRemoved3 };
final MemberId[] finalMembers = { leader, stable };
RaftTestFixture fixture = new RaftTestFixture(net, 2, initialMembers);
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();
// 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());
}
use of org.neo4j.causalclustering.core.consensus.DirectNetworking in project neo4j by neo4j.
the class RaftGroupMembershipTest method shouldRemoveLeaderFromExistingRaftGroupAndActivelyTransferLeadership.
@Test
public void shouldRemoveLeaderFromExistingRaftGroupAndActivelyTransferLeadership() throws Exception {
DirectNetworking net = new DirectNetworking();
// given
final MemberId leader = member(0);
final MemberId stable1 = member(1);
final MemberId stable2 = member(2);
final MemberId[] initialMembers = { leader, stable1, stable2 };
final MemberId[] finalMembers = { stable1, stable2 };
RaftTestFixture fixture = new RaftTestFixture(net, 2, initialMembers);
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(stable1).timeoutService().invokeTimeout(ELECTION);
net.processMessages();
// then
assertThat(fixture.members().withIds(finalMembers), hasCurrentMembers(new RaftTestGroup(finalMembers)));
assertTrue(fixture.members().withId(stable1).raftInstance().isLeader() || fixture.members().withId(stable2).raftInstance().isLeader());
}
use of org.neo4j.causalclustering.core.consensus.DirectNetworking 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)));
}
use of org.neo4j.causalclustering.core.consensus.DirectNetworking 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)));
}
Aggregations