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