use of org.neo4j.time.FakeClock in project neo4j by neo4j.
the class LeaseManagerTest method shouldNotBarfWhenAnotherThreadOrRetrieveRevokesTheLease.
@Test
public void shouldNotBarfWhenAnotherThreadOrRetrieveRevokesTheLease() throws Exception {
FakeClock fakeClock = Clocks.fakeClock();
LeaseManager manager = new LeaseManager(fakeClock);
Lease leaseA = manager.createLease(SIXTY_SECONDS, mock(PagedTraverser.class));
Lease leaseB = manager.createLease(SIXTY_SECONDS * 3, mock(PagedTraverser.class));
fakeClock.forward(2, TimeUnit.MINUTES);
assertNotNull(manager.getLeaseById(leaseB.getId()));
assertNull(manager.getLeaseById(leaseA.getId()));
}
use of org.neo4j.time.FakeClock in project neo4j by neo4j.
the class LeaseManagerTest method shouldNotRetrieveALeaseAfterItExpired.
@Test
public void shouldNotRetrieveALeaseAfterItExpired() throws Exception {
FakeClock fakeClock = Clocks.fakeClock();
LeaseManager manager = new LeaseManager(fakeClock);
Lease lease = manager.createLease(SIXTY_SECONDS, mock(PagedTraverser.class));
fakeClock.forward(2, TimeUnit.MINUTES);
assertNull(manager.getLeaseById(lease.getId()));
}
use of org.neo4j.time.FakeClock in project neo4j by neo4j.
the class LeaseTest method shouldNotAllowLeasesInThePast.
@Test(expected = LeaseAlreadyExpiredException.class)
public void shouldNotAllowLeasesInThePast() throws Exception {
FakeClock clock = Clocks.fakeClock();
new Lease(mock(PagedTraverser.class), oneMinuteInThePast(), clock);
}
use of org.neo4j.time.FakeClock in project neo4j by neo4j.
the class CatchupGoalTest method goalAchievedWhenCatchupRoundDurationLessThanTarget.
@Test
public void goalAchievedWhenCatchupRoundDurationLessThanTarget() throws Exception {
FakeClock clock = Clocks.fakeClock();
long electionTimeout = 15;
StubLog log = new StubLog();
log.setAppendIndex(10);
CatchupGoal goal = new CatchupGoal(log, clock, electionTimeout);
log.setAppendIndex(20);
clock.forward(10, MILLISECONDS);
assertFalse(goal.achieved(new FollowerState()));
log.setAppendIndex(30);
clock.forward(10, MILLISECONDS);
assertFalse(goal.achieved(new FollowerState().onSuccessResponse(10)));
log.setAppendIndex(40);
clock.forward(10, MILLISECONDS);
assertTrue(goal.achieved(new FollowerState().onSuccessResponse(30)));
}
use of org.neo4j.time.FakeClock in project neo4j by neo4j.
the class CatchupGoalTrackerTest method shouldNotAchieveGoalIfBeyondRoundTimeout.
@Test
public void shouldNotAchieveGoalIfBeyondRoundTimeout() throws Exception {
FakeClock clock = Clocks.fakeClock();
StubLog log = new StubLog();
log.setAppendIndex(10);
CatchupGoalTracker catchupGoalTracker = new CatchupGoalTracker(log, clock, ROUND_TIMEOUT, CATCHUP_TIMEOUT);
clock.forward(ROUND_TIMEOUT + 5, TimeUnit.MILLISECONDS);
catchupGoalTracker.updateProgress(new FollowerState().onSuccessResponse(10));
assertFalse(catchupGoalTracker.isGoalAchieved());
assertFalse(catchupGoalTracker.isFinished());
}
Aggregations