Search in sources :

Example 1 with InvalidTransactionId

use of org.neo4j.server.rest.transactional.error.InvalidTransactionId in project neo4j by neo4j.

the class TransactionHandleRegistryTest method acquiringANonExistentTransactionShouldThrowErrorInvalidTransactionId.

@Test
public void acquiringANonExistentTransactionShouldThrowErrorInvalidTransactionId() throws Exception {
    // Given
    AssertableLogProvider logProvider = new AssertableLogProvider();
    TransactionHandleRegistry registry = new TransactionHandleRegistry(Clocks.fakeClock(), 0, logProvider);
    long madeUpTransactionId = 1337;
    // When
    try {
        registry.acquire(madeUpTransactionId);
        fail("Should have thrown exception");
    } catch (InvalidTransactionId e) {
    // expected
    }
    // then
    logProvider.assertNoLoggingOccurred();
}
Also used : InvalidTransactionId(org.neo4j.server.rest.transactional.error.InvalidTransactionId) AssertableLogProvider(org.neo4j.logging.AssertableLogProvider) Test(org.junit.Test)

Example 2 with InvalidTransactionId

use of org.neo4j.server.rest.transactional.error.InvalidTransactionId 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)

Aggregations

Test (org.junit.Test)2 AssertableLogProvider (org.neo4j.logging.AssertableLogProvider)2 InvalidTransactionId (org.neo4j.server.rest.transactional.error.InvalidTransactionId)2 FakeClock (org.neo4j.time.FakeClock)1