Search in sources :

Example 1 with FakeClock

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

the class RotationTimerFactoryTest method testTimer.

@Test
public void testTimer() throws Exception {
    // GIVEN
    Clock fixedClock = Clock.fixed(Instant.ofEpochMilli(10000), ZoneOffset.UTC);
    // WHEN
    RotationTimerFactory timerFactory = new RotationTimerFactory(fixedClock, 1000);
    RotationTimerFactory.RotationTimer timer = timerFactory.createTimer();
    RotationTimerFactory.RotationTimer anotherTimer = timerFactory.createTimer();
    // THEN
    Assert.assertFalse(timer.isTimedOut());
    Assert.assertEquals(0, timer.getElapsedTimeMillis());
    Assert.assertNotSame("Factory should construct different timers", timer, anotherTimer);
    // WHEN
    FakeClock fakeClock = Clocks.fakeClock();
    RotationTimerFactory fakeTimerFactory = new RotationTimerFactory(fakeClock, 1000);
    RotationTimerFactory.RotationTimer fakeTimer = fakeTimerFactory.createTimer();
    fakeClock.forward(1001, TimeUnit.MILLISECONDS);
    Assert.assertTrue(fakeTimer.isTimedOut());
    Assert.assertEquals(1001, fakeTimer.getElapsedTimeMillis());
}
Also used : FakeClock(org.neo4j.time.FakeClock) FakeClock(org.neo4j.time.FakeClock) Clock(java.time.Clock) Test(org.junit.Test)

Example 2 with FakeClock

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

the class UnknownAddressMonitorTest method shouldResumeLoggingAfterQuietPeriod.

@Test
public void shouldResumeLoggingAfterQuietPeriod() throws Exception {
    // given
    Log log = mock(Log.class);
    FakeClock clock = testClock();
    UnknownAddressMonitor logger = new UnknownAddressMonitor(log, clock, 1000);
    MemberId to = member(0);
    // when
    logger.logAttemptToSendToMemberWithNoKnownAddress(to);
    clock.forward(20001, MILLISECONDS);
    logger.logAttemptToSendToMemberWithNoKnownAddress(to);
    clock.forward(80001, MILLISECONDS);
    logger.logAttemptToSendToMemberWithNoKnownAddress(to);
    // then
    verify(log, times(3)).info(format("No address found for %s, probably because the member has been shut " + "down.", to));
}
Also used : MemberId(org.neo4j.causalclustering.identity.MemberId) Log(org.neo4j.logging.Log) FakeClock(org.neo4j.time.FakeClock) Test(org.junit.Test)

Example 3 with FakeClock

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

the class UnknownAddressMonitorTest method shouldThrottleLogging.

@Test
public void shouldThrottleLogging() throws Exception {
    // given
    Log log = mock(Log.class);
    FakeClock clock = testClock();
    UnknownAddressMonitor logger = new UnknownAddressMonitor(log, clock, 1000);
    MemberId to = member(0);
    // when
    logger.logAttemptToSendToMemberWithNoKnownAddress(to);
    clock.forward(1, MILLISECONDS);
    logger.logAttemptToSendToMemberWithNoKnownAddress(to);
    // then
    verify(log, times(1)).info(format("No address found for %s, probably because the member has been shut " + "down.", to));
}
Also used : MemberId(org.neo4j.causalclustering.identity.MemberId) Log(org.neo4j.logging.Log) FakeClock(org.neo4j.time.FakeClock) Test(org.junit.Test)

Example 4 with FakeClock

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

the class TransactionHandleRegistryTest method gettingInterruptHandlerForUnknownIdShouldThrowErrorInvalidTransactionId.

@Test(expected = InvalidTransactionId.class)
public void gettingInterruptHandlerForUnknownIdShouldThrowErrorInvalidTransactionId() throws TransactionLifecycleException {
    // Given
    AssertableLogProvider logProvider = new AssertableLogProvider();
    FakeClock clock = Clocks.fakeClock();
    int timeoutLength = 123;
    TransactionHandleRegistry registry = new TransactionHandleRegistry(clock, timeoutLength, logProvider);
    // When
    registry.terminate(456);
}
Also used : FakeClock(org.neo4j.time.FakeClock) AssertableLogProvider(org.neo4j.logging.AssertableLogProvider) Test(org.junit.Test)

Example 5 with FakeClock

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

the class TransactionHandleRegistryTest method shouldProvideInterruptHandlerForSuspendedTransaction.

@Test
public void shouldProvideInterruptHandlerForSuspendedTransaction() throws TransactionLifecycleException {
    // Given
    AssertableLogProvider logProvider = new AssertableLogProvider();
    FakeClock clock = Clocks.fakeClock();
    int timeoutLength = 123;
    TransactionHandleRegistry registry = new TransactionHandleRegistry(clock, timeoutLength, logProvider);
    TransactionHandle handle = mock(TransactionHandle.class);
    // Suspended Tx in Registry
    long id = registry.begin(handle);
    registry.release(id, handle);
    // When
    registry.terminate(id);
    // Then
    verify(handle, times(1)).terminate();
    verifyNoMoreInteractions(handle);
}
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