use of org.neo4j.server.rest.transactional.error.InvalidConcurrentTransactionAccess in project neo4j by neo4j.
the class ConcurrentTransactionAccessTest method shouldThrowSpecificExceptionOnConcurrentTransactionAccess.
@Test
public void shouldThrowSpecificExceptionOnConcurrentTransactionAccess() throws Exception {
// given
TransactionRegistry registry = new TransactionHandleRegistry(mock(Clock.class), 0, NullLogProvider.getInstance());
TransitionalPeriodTransactionMessContainer kernel = mock(TransitionalPeriodTransactionMessContainer.class);
GraphDatabaseQueryService queryService = mock(GraphDatabaseQueryService.class);
when(kernel.newTransaction(any(KernelTransaction.Type.class), any(SecurityContext.class), anyLong())).thenReturn(mock(TransitionalTxManagementKernelTransaction.class));
TransactionFacade actions = new TransactionFacade(kernel, null, queryService, registry, NullLogProvider.getInstance());
final TransactionHandle transactionHandle = actions.newTransactionHandle(new DisgustingUriScheme(), true, SecurityContext.AUTH_DISABLED, -1);
final DoubleLatch latch = new DoubleLatch();
final StatementDeserializer statements = mock(StatementDeserializer.class);
when(statements.hasNext()).thenAnswer(invocation -> {
latch.startAndWaitForAllToStartAndFinish();
return false;
});
new Thread(() -> {
// start and block until finish
transactionHandle.execute(statements, mock(ExecutionResultSerializer.class), mock(HttpServletRequest.class));
}).start();
latch.waitForAllToStart();
try {
// when
actions.findTransactionHandle(DisgustingUriScheme.parseTxId(transactionHandle.uri()));
fail("should have thrown exception");
} catch (InvalidConcurrentTransactionAccess neo4jError) {
// then we get here
} finally {
latch.finish();
}
}
use of org.neo4j.server.rest.transactional.error.InvalidConcurrentTransactionAccess in project neo4j by neo4j.
the class TransactionHandleRegistryTest method acquiringATransactionThatHasAlreadyBeenAcquiredShouldThrowInvalidConcurrentTransactionAccess.
@Test
public void acquiringATransactionThatHasAlreadyBeenAcquiredShouldThrowInvalidConcurrentTransactionAccess() throws Exception {
// Given
AssertableLogProvider logProvider = new AssertableLogProvider();
TransactionHandleRegistry registry = new TransactionHandleRegistry(Clocks.fakeClock(), 0, logProvider);
TransactionHandle handle = mock(TransactionHandle.class);
long id = registry.begin(handle);
registry.release(id, handle);
registry.acquire(id);
// When
try {
registry.acquire(id);
fail("Should have thrown exception");
} catch (InvalidConcurrentTransactionAccess e) {
// expected
}
// then
logProvider.assertNoLoggingOccurred();
}
Aggregations