use of org.neo4j.time.FakeClock in project neo4j by neo4j.
the class TransactionHandleRegistryTest method transactionsShouldBeEvictedWhenUnusedLongerThanTimeout.
@Test
public void transactionsShouldBeEvictedWhenUnusedLongerThanTimeout() throws Exception {
// Given
FakeClock clock = Clocks.fakeClock();
AssertableLogProvider logProvider = new AssertableLogProvider();
TransactionHandleRegistry registry = new TransactionHandleRegistry(clock, 0, logProvider);
TransactionHandle oldTx = mock(TransactionHandle.class);
TransactionHandle newTx = mock(TransactionHandle.class);
TransactionHandle handle = mock(TransactionHandle.class);
long txId1 = registry.begin(handle);
long txId2 = registry.begin(handle);
// And given one transaction was stored one minute ago, and another was stored just now
registry.release(txId1, oldTx);
clock.forward(1, TimeUnit.MINUTES);
registry.release(txId2, newTx);
// When
registry.rollbackSuspendedTransactionsIdleSince(clock.millis() - 1000);
// Then
assertThat(registry.acquire(txId2), equalTo(newTx));
// And then the other should have been evicted
try {
registry.acquire(txId1);
fail("Should have thrown exception");
} catch (InvalidTransactionId e) {
// ok
}
logProvider.assertExactly(inLog(TransactionHandleRegistry.class).info("Transaction with id 1 has been automatically rolled " + "back due to transaction timeout."));
}
use of org.neo4j.time.FakeClock in project neo4j by neo4j.
the class TransactionHandleRegistryTest method shouldProvideInterruptHandlerForActiveTransaction.
@Test
public void shouldProvideInterruptHandlerForActiveTransaction() 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);
// Active Tx in Registry
long id = registry.begin(handle);
// When
registry.terminate(id);
// Then
verify(handle, times(1)).terminate();
verifyNoMoreInteractions(handle);
}
use of org.neo4j.time.FakeClock in project neo4j by neo4j.
the class EnterpriseVersionIT method setupServer.
@BeforeClass
public static void setupServer() throws Exception {
FakeClock clock = Clocks.fakeClock();
server = EnterpriseServerBuilder.server().usingDataDir(staticFolder.getRoot().getAbsolutePath()).withClock(clock).build();
suppressAll().call((Callable<Void>) () -> {
server.start();
return null;
});
functionalTestHelper = new FunctionalTestHelper(server);
}
use of org.neo4j.time.FakeClock in project neo4j by neo4j.
the class LeaseManagerTest method shouldRetrieveAnExistingLeaseImmediatelyAfterCreation.
@Test
public void shouldRetrieveAnExistingLeaseImmediatelyAfterCreation() throws Exception {
FakeClock fakeClock = Clocks.fakeClock();
LeaseManager manager = new LeaseManager(fakeClock);
Lease lease = manager.createLease(SIXTY_SECONDS, mock(PagedTraverser.class));
assertNotNull(manager.getLeaseById(lease.getId()));
}
use of org.neo4j.time.FakeClock in project neo4j by neo4j.
the class LeaseManagerTest method shouldNotAcceptLeasesWithNegativeTTL.
@Test
public void shouldNotAcceptLeasesWithNegativeTTL() throws Exception {
FakeClock fakeClock = Clocks.fakeClock();
LeaseManager manager = new LeaseManager(fakeClock);
assertNull(manager.createLease(-1L, mock(PagedTraverser.class)));
assertNull(manager.createLease(Long.MAX_VALUE + 1, mock(PagedTraverser.class)));
}
Aggregations