Search in sources :

Example 91 with FakeClock

use of org.neo4j.time.FakeClock in project neo4j by neo4j.

the class LeaseManagerTest method shouldRetrieveAnExistingLeaseSomeTimeAfterCreation.

@Test
public void shouldRetrieveAnExistingLeaseSomeTimeAfterCreation() throws Exception {
    FakeClock fakeClock = Clocks.fakeClock();
    LeaseManager manager = new LeaseManager(fakeClock);
    Lease lease = manager.createLease(120, mock(PagedTraverser.class));
    fakeClock.forward(1, TimeUnit.MINUTES);
    assertNotNull(manager.getLeaseById(lease.getId()));
}
Also used : FakeClock(org.neo4j.time.FakeClock) Test(org.junit.Test)

Example 92 with FakeClock

use of org.neo4j.time.FakeClock in project neo4j by neo4j.

the class LeaseTest method leasesShouldExpire.

@Test
public void leasesShouldExpire() throws Exception {
    FakeClock clock = Clocks.fakeClock();
    Lease lease = new Lease(mock(PagedTraverser.class), SIXTY_SECONDS, clock);
    clock.forward(10, TimeUnit.MINUTES);
    assertTrue(lease.expired());
}
Also used : FakeClock(org.neo4j.time.FakeClock) Test(org.junit.Test)

Example 93 with FakeClock

use of org.neo4j.time.FakeClock in project neo4j by neo4j.

the class LeaseTest method shouldRenewLeaseForSamePeriod.

@Test
public void shouldRenewLeaseForSamePeriod() {
    FakeClock clock = Clocks.fakeClock();
    Lease lease = new Lease(mock(PagedTraverser.class), SIXTY_SECONDS, clock);
    clock.forward(30, TimeUnit.SECONDS);
    // has side effect of renewing the
    lease.getLeasedItemAndRenewLease();
    // lease
    clock.forward(30, TimeUnit.SECONDS);
    assertFalse(lease.expired());
    clock.forward(10, TimeUnit.MINUTES);
    assertTrue(lease.expired());
}
Also used : FakeClock(org.neo4j.time.FakeClock) Test(org.junit.Test)

Example 94 with FakeClock

use of org.neo4j.time.FakeClock in project neo4j by neo4j.

the class LeaseManagerTest method shouldRemoveALease.

@Test
public void shouldRemoveALease() {
    FakeClock fakeClock = Clocks.fakeClock();
    LeaseManager manager = new LeaseManager(fakeClock);
    Lease lease = manager.createLease(101L, mock(PagedTraverser.class));
    manager.remove(lease.getId());
    assertNull(manager.getLeaseById(lease.getId()));
}
Also used : FakeClock(org.neo4j.time.FakeClock) Test(org.junit.Test)

Example 95 with FakeClock

use of org.neo4j.time.FakeClock in project neo4j by neo4j.

the class TransactionHandleRegistryTest method expiryTimeShouldBeSetToCurrentTimePlusTimeout.

@Test
public void expiryTimeShouldBeSetToCurrentTimePlusTimeout() throws Exception {
    // Given
    AssertableLogProvider logProvider = new AssertableLogProvider();
    FakeClock clock = Clocks.fakeClock();
    int timeoutLength = 123;
    TransactionHandleRegistry registry = new TransactionHandleRegistry(clock, timeoutLength, logProvider);
    TransactionHandle handle = mock(TransactionHandle.class);
    long id = registry.begin(handle);
    // When
    long timesOutAt = registry.release(id, handle);
    // Then
    assertThat(timesOutAt, equalTo(clock.millis() + timeoutLength));
    // And when
    clock.forward(1337, TimeUnit.MILLISECONDS);
    registry.acquire(id);
    timesOutAt = registry.release(id, handle);
    // Then
    assertThat(timesOutAt, equalTo(clock.millis() + timeoutLength));
}
Also used : FakeClock(org.neo4j.time.FakeClock) AssertableLogProvider(org.neo4j.logging.AssertableLogProvider) Test(org.junit.Test)

Aggregations

FakeClock (org.neo4j.time.FakeClock)111 Test (org.junit.Test)82 Test (org.junit.jupiter.api.Test)21 AssertableLogProvider (org.neo4j.logging.AssertableLogProvider)20 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 ExecutingQuery (org.neo4j.kernel.api.query.ExecutingQuery)9 QueryLogger (org.neo4j.kernel.impl.query.QueryLoggerKernelExtension.QueryLogger)9 User (org.neo4j.kernel.impl.security.User)9 FollowerState (org.neo4j.causalclustering.core.consensus.roles.follower.FollowerState)7 Channel (org.jboss.netty.channel.Channel)5 Path (java.nio.file.Path)4 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 ExecutionException (java.util.concurrent.ExecutionException)3 BeforeEach (org.junit.jupiter.api.BeforeEach)3 RaftMachine (org.neo4j.causalclustering.core.consensus.RaftMachine)3