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()));
}
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());
}
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());
}
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()));
}
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));
}
Aggregations