use of org.neo4j.time.FakeClock in project neo4j by neo4j.
the class LoggingIndexedIdGeneratorMonitorTest method shouldLogAndDumpAllTypesOfCalls.
@Test
void shouldLogAndDumpAllTypesOfCalls() throws IOException {
// given
Path file = directory.file("file");
FakeClock clock = Clocks.fakeClock();
int timeStep = 100;
try (LoggingIndexedIdGeneratorMonitor monitor = new LoggingIndexedIdGeneratorMonitor(fs, file, clock, 10, MebiByte, 1, DAYS)) {
// when (making all logging calls)
clock.forward(timeStep, MILLISECONDS);
monitor.opened(98, 99);
clock.forward(timeStep, MILLISECONDS);
monitor.allocatedFromHigh(1);
clock.forward(timeStep, MILLISECONDS);
monitor.allocatedFromReused(2);
clock.forward(timeStep, MILLISECONDS);
monitor.bridged(3);
clock.forward(timeStep, MILLISECONDS);
monitor.cached(4);
clock.forward(timeStep, MILLISECONDS);
monitor.checkpoint(5, 6);
clock.forward(timeStep, MILLISECONDS);
monitor.markedAsDeletedAndFree(7);
clock.forward(timeStep, MILLISECONDS);
monitor.markedAsUsed(8);
clock.forward(timeStep, MILLISECONDS);
monitor.markedAsDeleted(9);
clock.forward(timeStep, MILLISECONDS);
monitor.markedAsFree(10);
clock.forward(timeStep, MILLISECONDS);
monitor.markedAsReserved(11);
clock.forward(timeStep, MILLISECONDS);
monitor.markedAsUnreserved(12);
clock.forward(timeStep, MILLISECONDS);
monitor.normalized(13);
clock.forward(timeStep, MILLISECONDS);
monitor.clearingCache();
clock.forward(timeStep, MILLISECONDS);
monitor.clearedCache();
clock.forward(timeStep, MILLISECONDS);
}
// then
LoggingIndexedIdGeneratorMonitor.Dumper dumper = mock(LoggingIndexedIdGeneratorMonitor.Dumper.class);
LoggingIndexedIdGeneratorMonitor.dump(fs, file, dumper);
long time = 0;
verify(dumper).typeAndTwoIds(LoggingIndexedIdGeneratorMonitor.Type.OPENED, time += timeStep, 98, 99);
verify(dumper).typeAndId(LoggingIndexedIdGeneratorMonitor.Type.ALLOCATE_HIGH, time += timeStep, 1);
verify(dumper).typeAndId(LoggingIndexedIdGeneratorMonitor.Type.ALLOCATE_REUSED, time += timeStep, 2);
verify(dumper).typeAndId(LoggingIndexedIdGeneratorMonitor.Type.BRIDGED, time += timeStep, 3);
verify(dumper).typeAndId(LoggingIndexedIdGeneratorMonitor.Type.CACHED, time += timeStep, 4);
verify(dumper).typeAndTwoIds(LoggingIndexedIdGeneratorMonitor.Type.CHECKPOINT, time += timeStep, 5, 6);
verify(dumper).typeAndId(LoggingIndexedIdGeneratorMonitor.Type.MARK_DELETED_AND_FREE, time += timeStep, 7);
verify(dumper).typeAndId(LoggingIndexedIdGeneratorMonitor.Type.MARK_USED, time += timeStep, 8);
verify(dumper).typeAndId(LoggingIndexedIdGeneratorMonitor.Type.MARK_DELETED, time += timeStep, 9);
verify(dumper).typeAndId(LoggingIndexedIdGeneratorMonitor.Type.MARK_FREE, time += timeStep, 10);
verify(dumper).typeAndId(LoggingIndexedIdGeneratorMonitor.Type.MARK_RESERVED, time += timeStep, 11);
verify(dumper).typeAndId(LoggingIndexedIdGeneratorMonitor.Type.MARK_UNRESERVED, time += timeStep, 12);
verify(dumper).typeAndId(LoggingIndexedIdGeneratorMonitor.Type.NORMALIZED, time += timeStep, 13);
verify(dumper).type(LoggingIndexedIdGeneratorMonitor.Type.CLEARING_CACHE, time += timeStep);
verify(dumper).type(LoggingIndexedIdGeneratorMonitor.Type.CLEARED_CACHE, time += timeStep);
verify(dumper).type(LoggingIndexedIdGeneratorMonitor.Type.CLOSED, time += timeStep);
}
use of org.neo4j.time.FakeClock in project neo4j by neo4j.
the class TimeBasedTaskSchedulerTest method setUp.
@BeforeEach
void setUp() {
clock = new FakeClock();
FailedJobRunsStore failedJobRunsStore = new FailedJobRunsStore(10);
var idGenerator = new AtomicLong();
pools = new ThreadPoolManager(new ThreadGroup("TestPool"), clock, failedJobRunsStore, idGenerator::get);
scheduler = new TimeBasedTaskScheduler(clock, pools, failedJobRunsStore, idGenerator::get);
counter = new AtomicInteger();
semaphore = new Semaphore(0);
}
use of org.neo4j.time.FakeClock in project neo4j by neo4j.
the class VisibleMigrationProgressMonitorTest method shouldIncludeDurationInCompletionMessage.
@Test
void shouldIncludeDurationInCompletionMessage() {
// given
AssertableLogProvider logProvider = new AssertableLogProvider();
Log log = logProvider.getLog(getClass());
FakeClock clock = new FakeClock();
VisibleMigrationProgressMonitor monitor = new VisibleMigrationProgressMonitor(log, clock);
// when
monitor.started(1);
clock.forward(1500, TimeUnit.MILLISECONDS);
monitor.completed();
// then
assertThat(logProvider).containsMessages("took 1s 500ms");
}
use of org.neo4j.time.FakeClock in project neo4j by neo4j.
the class RateLimitedAuthenticationStrategyTest method shouldNotSlowRequestRateOnLessThanMaxFailedAttempts.
@Test
void shouldNotSlowRequestRateOnLessThanMaxFailedAttempts() {
// Given
FakeClock clock = getFakeClock();
AuthenticationStrategy authStrategy = newAuthStrategy(clock, 3);
User user = new User.Builder("user", credentialFor("right")).build();
// When we've failed two times
assertThat(authStrategy.authenticate(user, password("wrong"))).isEqualTo(AuthenticationResult.FAILURE);
assertThat(authStrategy.authenticate(user, password("wrong"))).isEqualTo(AuthenticationResult.FAILURE);
// Then
assertThat(authStrategy.authenticate(user, password("right"))).isEqualTo(AuthenticationResult.SUCCESS);
}
use of org.neo4j.time.FakeClock in project neo4j by neo4j.
the class MultiExecutionMonitorTest method shouldCheckMultipleMonitors.
@Test
void shouldCheckMultipleMonitors() {
// GIVEN
FakeClock clock = Clocks.fakeClock();
TestableMonitor first = new TestableMonitor(clock, 100, MILLISECONDS, "first");
TestableMonitor other = new TestableMonitor(clock, 250, MILLISECONDS, "other");
MultiExecutionMonitor multiMonitor = new MultiExecutionMonitor(clock, first, other);
// WHEN/THEN
clock.forward(110, MILLISECONDS);
expectCallsToCheck(multiMonitor, first, 1, other, 0);
clock.forward(100, MILLISECONDS);
expectCallsToCheck(multiMonitor, first, 2, other, 0);
clock.forward(45, MILLISECONDS);
expectCallsToCheck(multiMonitor, first, 2, other, 1);
}
Aggregations