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