Search in sources :

Example 51 with FakeClock

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);
}
Also used : Path(java.nio.file.Path) FakeClock(org.neo4j.time.FakeClock) Test(org.junit.jupiter.api.Test)

Example 52 with FakeClock

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);
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) FakeClock(org.neo4j.time.FakeClock) Semaphore(java.util.concurrent.Semaphore) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 53 with FakeClock

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");
}
Also used : Log(org.neo4j.logging.Log) FakeClock(org.neo4j.time.FakeClock) AssertableLogProvider(org.neo4j.logging.AssertableLogProvider) Test(org.junit.jupiter.api.Test)

Example 54 with FakeClock

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);
}
Also used : User(org.neo4j.kernel.impl.security.User) FakeClock(org.neo4j.time.FakeClock) Test(org.junit.jupiter.api.Test)

Example 55 with FakeClock

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