Search in sources :

Example 6 with FakeClock

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."));
}
Also used : FakeClock(org.neo4j.time.FakeClock) InvalidTransactionId(org.neo4j.server.rest.transactional.error.InvalidTransactionId) AssertableLogProvider(org.neo4j.logging.AssertableLogProvider) Test(org.junit.Test)

Example 7 with FakeClock

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

Example 8 with FakeClock

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);
}
Also used : FakeClock(org.neo4j.time.FakeClock) FunctionalTestHelper(org.neo4j.server.helpers.FunctionalTestHelper) BeforeClass(org.junit.BeforeClass)

Example 9 with FakeClock

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

Example 10 with FakeClock

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

Aggregations

FakeClock (org.neo4j.time.FakeClock)87 Test (org.junit.Test)85 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 AssertableLogProvider (org.neo4j.logging.AssertableLogProvider)14 ExecutingQuery (org.neo4j.kernel.api.query.ExecutingQuery)9 QueryLogger (org.neo4j.kernel.impl.query.QueryLoggerKernelExtension.QueryLogger)9 FollowerState (org.neo4j.causalclustering.core.consensus.roles.follower.FollowerState)7 Channel (org.jboss.netty.channel.Channel)5 User (org.neo4j.kernel.impl.security.User)5 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 RaftMachine (org.neo4j.causalclustering.core.consensus.RaftMachine)3 RaftMachineBuilder (org.neo4j.causalclustering.core.consensus.RaftMachineBuilder)3 TestMessageBuilders.voteRequest (org.neo4j.causalclustering.core.consensus.TestMessageBuilders.voteRequest)3 File (java.io.File)2 Clock (java.time.Clock)2