use of org.neo4j.time.FakeClock in project neo4j by neo4j.
the class PagingTraversalTest method shouldRespondWith404WhenTraversalHasExpired.
@Test
public void shouldRespondWith404WhenTraversalHasExpired() {
Response response = createAPagedTraverser();
((FakeClock) leaseManager.getClock()).forward(enoughMinutesToExpireTheTraversal(), TimeUnit.MINUTES);
String traverserId = parseTraverserIdFromLocationUri(response);
response = service.pagedTraverse(traverserId, TraverserReturnType.node);
assertEquals(404, response.getStatus());
}
use of org.neo4j.time.FakeClock in project neo4j by neo4j.
the class PagingTraversalTest method shouldRenewLeaseAtEachTraversal.
@Test
public void shouldRenewLeaseAtEachTraversal() {
Response response = createAPagedTraverser();
String traverserId = parseTraverserIdFromLocationUri(response);
((FakeClock) leaseManager.getClock()).forward(30, TimeUnit.SECONDS);
response = service.pagedTraverse(traverserId, TraverserReturnType.node);
assertEquals(200, response.getStatus());
((FakeClock) leaseManager.getClock()).forward(30, TimeUnit.SECONDS);
response = service.pagedTraverse(traverserId, TraverserReturnType.node);
assertEquals(200, response.getStatus());
((FakeClock) leaseManager.getClock()).forward(this.enoughMinutesToExpireTheTraversal(), TimeUnit.MINUTES);
response = service.pagedTraverse(traverserId, TraverserReturnType.node);
assertEquals(404, response.getStatus());
}
use of org.neo4j.time.FakeClock in project neo4j by neo4j.
the class CountsTrackerTest method shouldNotEndUpInBrokenStateAfterRotationFailure.
@Test
@Resources.Life(STARTED)
public void shouldNotEndUpInBrokenStateAfterRotationFailure() throws Exception {
// GIVEN
FakeClock clock = Clocks.fakeClock();
CountsTracker tracker = resourceManager.managed(newTracker(clock));
int labelId = 1;
try (CountsAccessor.Updater tx = tracker.apply(2).get()) {
// now at 1
tx.incrementNodeCount(labelId, 1);
}
// WHEN
Predicate<Thread> arrived = thread -> stackTraceContains(thread, all(classNameContains("Rotation"), methodIs("rotate")));
Future<Object> rotation = threading.executeAndAwait(t -> t.rotate(4), tracker, arrived, 100, MILLISECONDS);
try (CountsAccessor.Updater tx = tracker.apply(3).get()) {
// now at 2
tx.incrementNodeCount(labelId, 1);
}
clock.forward(Config.empty().get(GraphDatabaseSettings.counts_store_rotation_timeout) * 2, MILLISECONDS);
try {
rotation.get();
fail("Should've failed rotation due to timeout");
} catch (ExecutionException e) {
// good
assertTrue(e.getCause() instanceof RotationTimeoutException);
}
// THEN
Register.DoubleLongRegister register = Registers.newDoubleLongRegister();
tracker.get(CountsKeyFactory.nodeKey(labelId), register);
assertEquals(2, register.readSecond());
// and WHEN later attempting rotation again
try (CountsAccessor.Updater tx = tracker.apply(4).get()) {
// now at 3
tx.incrementNodeCount(labelId, 1);
}
tracker.rotate(4);
// THEN
tracker.get(CountsKeyFactory.nodeKey(labelId), register);
assertEquals(3, register.readSecond());
}
use of org.neo4j.time.FakeClock in project neo4j by neo4j.
the class BufferingIdGeneratorFactoryTest method shouldDelayFreeingOfAggressivelyReusedIdsConsideringTimeAsWell.
@Test
public void shouldDelayFreeingOfAggressivelyReusedIdsConsideringTimeAsWell() throws Exception {
// GIVEN
MockedIdGeneratorFactory actual = new MockedIdGeneratorFactory();
final FakeClock clock = Clocks.fakeClock();
final long safeZone = MINUTES.toMillis(1);
ControllableSnapshotSupplier boundaries = new ControllableSnapshotSupplier();
BufferingIdGeneratorFactory bufferingIdGeneratorFactory = new BufferingIdGeneratorFactory(actual, boundaries, t -> clock.millis() - t.snapshotTime() >= safeZone, new CommunityIdTypeConfigurationProvider());
IdGenerator idGenerator = bufferingIdGeneratorFactory.open(new File("doesnt-matter"), 10, IdType.STRING_BLOCK, 0, Integer.MAX_VALUE);
// WHEN
idGenerator.freeId(7);
verifyNoMoreInteractions(actual.get(IdType.STRING_BLOCK));
// after some maintenance and transaction still not closed
bufferingIdGeneratorFactory.maintenance();
verifyNoMoreInteractions(actual.get(IdType.STRING_BLOCK));
// although after transactions have all closed
boundaries.setMostRecentlyReturnedSnapshotToAllClosed();
bufferingIdGeneratorFactory.maintenance();
// ... the clock would still say "nope" so no interaction
verifyNoMoreInteractions(actual.get(IdType.STRING_BLOCK));
// then finally after time has passed as well
clock.forward(70, SECONDS);
bufferingIdGeneratorFactory.maintenance();
// THEN
verify(actual.get(IdType.STRING_BLOCK)).freeId(7);
}
use of org.neo4j.time.FakeClock in project neo4j by neo4j.
the class TransportWriteThrottleTest method shouldAllocateMemoryUponInstall.
@Test
void shouldAllocateMemoryUponInstall() throws InterruptedException {
var lock = newThrottleLockMock();
FakeClock clock = Clocks.fakeClock(1, TimeUnit.SECONDS);
var throttle = newThrottle(lock, clock, Duration.ofSeconds(5));
var memoryTracker = mock(MemoryTracker.class);
throttle.install(channel, memoryTracker);
verify(memoryTracker).allocateHeap(anyLong());
}
Aggregations