Search in sources :

Example 11 with FakeClock

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()));
}
Also used : FakeClock(org.neo4j.time.FakeClock) Test(org.junit.Test)

Example 12 with FakeClock

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()));
}
Also used : FakeClock(org.neo4j.time.FakeClock) Test(org.junit.Test)

Example 13 with FakeClock

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);
}
Also used : FakeClock(org.neo4j.time.FakeClock) Test(org.junit.Test)

Example 14 with FakeClock

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)));
}
Also used : FakeClock(org.neo4j.time.FakeClock) FollowerState(org.neo4j.causalclustering.core.consensus.roles.follower.FollowerState) Test(org.junit.Test)

Example 15 with FakeClock

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());
}
Also used : FakeClock(org.neo4j.time.FakeClock) FollowerState(org.neo4j.causalclustering.core.consensus.roles.follower.FollowerState) Test(org.junit.Test)

Aggregations

FakeClock (org.neo4j.time.FakeClock)87 Test (org.junit.Test)85 ControlledRenewableTimeoutService (org.neo4j.causalclustering.core.consensus.schedule.ControlledRenewableTimeoutService)17 MembershipEntry (org.neo4j.causalclustering.core.consensus.membership.MembershipEntry)16 RaftCoreState (org.neo4j.causalclustering.core.state.snapshot.RaftCoreState)16 AssertableLogProvider (org.neo4j.logging.AssertableLogProvider)14 ExecutingQuery (org.neo4j.kernel.api.query.ExecutingQuery)9 QueryLogger (org.neo4j.kernel.impl.query.QueryLoggerKernelExtension.QueryLogger)9 FollowerState (org.neo4j.causalclustering.core.consensus.roles.follower.FollowerState)7 Channel (org.jboss.netty.channel.Channel)5 User (org.neo4j.kernel.impl.security.User)5 CountDownLatch (java.util.concurrent.CountDownLatch)4 Response (javax.ws.rs.core.Response)4 Matchers.containsString (org.hamcrest.Matchers.containsString)4 InputStream (java.io.InputStream)3 RaftMachine (org.neo4j.causalclustering.core.consensus.RaftMachine)3 RaftMachineBuilder (org.neo4j.causalclustering.core.consensus.RaftMachineBuilder)3 TestMessageBuilders.voteRequest (org.neo4j.causalclustering.core.consensus.TestMessageBuilders.voteRequest)3 File (java.io.File)2 Clock (java.time.Clock)2