use of org.neo4j.time.FakeClock in project neo4j by neo4j.
the class CatchupGoalTrackerTest method shouldFailToAchieveGoalDueToRoundExhaustion.
@Test
public void shouldFailToAchieveGoalDueToRoundExhaustion() throws Exception {
FakeClock clock = Clocks.fakeClock();
StubLog log = new StubLog();
long appendIndex = 10;
log.setAppendIndex(appendIndex);
CatchupGoalTracker catchupGoalTracker = new CatchupGoalTracker(log, clock, ROUND_TIMEOUT, CATCHUP_TIMEOUT);
for (int i = 0; i < CatchupGoalTracker.MAX_ROUNDS; i++) {
appendIndex += 10;
log.setAppendIndex(appendIndex);
clock.forward(ROUND_TIMEOUT + 1, TimeUnit.MILLISECONDS);
catchupGoalTracker.updateProgress(new FollowerState().onSuccessResponse(appendIndex));
}
// then
assertFalse(catchupGoalTracker.isGoalAchieved());
assertTrue(catchupGoalTracker.isFinished());
}
use of org.neo4j.time.FakeClock in project neo4j by neo4j.
the class RaftMachineTest method shouldVoteFalseForCandidateInOldTerm.
@Test
public void shouldVoteFalseForCandidateInOldTerm() throws Exception {
// Given
FakeClock fakeClock = Clocks.fakeClock();
ControlledRenewableTimeoutService timeouts = new ControlledRenewableTimeoutService(fakeClock);
OutboundMessageCollector messages = new OutboundMessageCollector();
RaftMachine raft = new RaftMachineBuilder(myself, 3, RaftTestMemberSetBuilder.INSTANCE).timeoutService(timeouts).clock(fakeClock).outbound(messages).build();
raft.installCoreState(new RaftCoreState(new MembershipEntry(0, asSet(myself, member1, member2))));
raft.startTimers();
// When
raft.handle(voteRequest().from(member1).term(-1).candidate(member1).lastLogIndex(0).lastLogTerm(-1).build());
// Then
assertThat(messages.sentTo(member1).size(), equalTo(1));
assertThat(messages.sentTo(member1), hasItem(voteResponse().from(myself).term(0).deny().build()));
}
use of org.neo4j.time.FakeClock in project neo4j by neo4j.
the class RaftMachineTest method shouldNotBecomeLeaderWhenVotingOnItself.
@Test
public void shouldNotBecomeLeaderWhenVotingOnItself() throws Exception {
// Given
FakeClock fakeClock = Clocks.fakeClock();
ControlledRenewableTimeoutService timeouts = new ControlledRenewableTimeoutService(fakeClock);
RaftMachine raft = new RaftMachineBuilder(myself, 3, RaftTestMemberSetBuilder.INSTANCE).timeoutService(timeouts).clock(fakeClock).build();
raft.installCoreState(new RaftCoreState(new MembershipEntry(0, asSet(myself, member1, member2))));
raft.startTimers();
timeouts.invokeTimeout(ELECTION);
// When
raft.handle(voteResponse().from(myself).term(1).grant().build());
// Then
assertThat(raft.isLeader(), is(false));
}
use of org.neo4j.time.FakeClock in project neo4j by neo4j.
the class CappedLoggerTest method unsettingTimeLimitMustLetMessagesThrough.
@Test
public void unsettingTimeLimitMustLetMessagesThrough() throws Exception {
FakeClock clock = getDefaultFakeClock();
logger.setTimeLimit(1, TimeUnit.MILLISECONDS, clock);
logMethod.log(logger, "### AAA ###");
logMethod.log(logger, "### BBB ###");
clock.forward(1, TimeUnit.MILLISECONDS);
logMethod.log(logger, "### CCC ###");
logMethod.log(logger, "### DDD ###");
// Note that we are not advancing the clock!
logger.unsetTimeLimit();
logMethod.log(logger, "### EEE ###");
logProvider.assertContainsMessageMatching(containsString("### AAA ###"));
logProvider.assertNone(currentLog(inLog(CappedLogger.class), containsString("### BBB ###")));
logProvider.assertContainsMessageMatching(containsString("### CCC ###"));
logProvider.assertNone(currentLog(inLog(CappedLogger.class), containsString("### DDD ###")));
logProvider.assertContainsMessageMatching(containsString("### EEE ###"));
}
use of org.neo4j.time.FakeClock in project neo4j by neo4j.
the class CappedLoggerTest method mustNotLogMessagesWithinConfiguredTimeLimit.
@Test
public void mustNotLogMessagesWithinConfiguredTimeLimit() throws Exception {
FakeClock clock = getDefaultFakeClock();
logger.setTimeLimit(1, TimeUnit.MILLISECONDS, clock);
logMethod.log(logger, "### AAA ###");
logMethod.log(logger, "### BBB ###");
clock.forward(1, TimeUnit.MILLISECONDS);
logMethod.log(logger, "### CCC ###");
logProvider.assertContainsMessageMatching(containsString("### AAA ###"));
logProvider.assertNone(currentLog(inLog(CappedLogger.class), containsString("### BBB ###")));
logProvider.assertContainsMessageMatching(containsString("### CCC ###"));
}
Aggregations