use of org.neo4j.causalclustering.core.consensus.RaftMessages.NewEntry.Request in project neo4j by neo4j.
the class CatchUpTest method newMemberWithNoLogShouldCatchUpFromPeers.
@Test
public void newMemberWithNoLogShouldCatchUpFromPeers() throws Throwable {
DirectNetworking net = new DirectNetworking();
// given
final MemberId leaderId = member(0);
final MemberId sleepyId = member(2);
final MemberId[] awakeMembers = { leaderId, member(1) };
final MemberId[] allMembers = { leaderId, member(1), sleepyId };
RaftTestFixture fixture = new RaftTestFixture(net, 3, allMembers);
fixture.bootstrap(allMembers);
fixture.members().withId(leaderId).raftInstance().installCoreState(new RaftCoreState(new MembershipEntry(0, new HashSet<>(Arrays.asList(allMembers)))));
fixture.members().withId(leaderId).timeoutService().invokeTimeout(RaftMachine.Timeouts.ELECTION);
net.processMessages();
final MemberId leader = fixture.members().withId(leaderId).member();
net.disconnect(sleepyId);
// when
fixture.members().withId(leaderId).raftInstance().handle(new Request(leader, valueOf(10)));
fixture.members().withId(leaderId).raftInstance().handle(new Request(leader, valueOf(20)));
fixture.members().withId(leaderId).raftInstance().handle(new Request(leader, valueOf(30)));
fixture.members().withId(leaderId).raftInstance().handle(new Request(leader, valueOf(40)));
net.processMessages();
// then
for (MemberId awakeMember : awakeMembers) {
assertThat(integerValues(fixture.members().withId(awakeMember).raftLog()), hasItems(10, 20, 30, 40));
}
assertThat(integerValues(fixture.members().withId(sleepyId).raftLog()), empty());
// when
net.reconnect(sleepyId);
// TODO: This needs an injectable/controllable timeout service for the log shipper.
Thread.sleep(500);
net.processMessages();
// then
assertThat(integerValues(fixture.members().withId(sleepyId).raftLog()), hasItems(10, 20, 30, 40));
}
use of org.neo4j.causalclustering.core.consensus.RaftMessages.NewEntry.Request in project neo4j by neo4j.
the class CatchUpTest method happyClusterPropagatesUpdates.
@Test
public void happyClusterPropagatesUpdates() throws Throwable {
DirectNetworking net = new DirectNetworking();
// given
final MemberId leader = member(0);
final MemberId[] allMembers = { leader, member(1), member(2) };
final RaftTestFixture fixture = new RaftTestFixture(net, 3, allMembers);
fixture.bootstrap(allMembers);
final MemberId leaderMember = fixture.members().withId(leader).member();
// when
fixture.members().withId(leader).timeoutService().invokeTimeout(RaftMachine.Timeouts.ELECTION);
net.processMessages();
fixture.members().withId(leader).raftInstance().handle(new Request(leaderMember, valueOf(42)));
net.processMessages();
// then
for (MemberId aMember : allMembers) {
assertThat(integerValues(fixture.members().withId(aMember).raftLog()), hasItems(42));
}
}
Aggregations