Search in sources :

Example 1 with InvalidConcurrentTransactionAccess

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();
    }
}
Also used : InvalidConcurrentTransactionAccess(org.neo4j.server.rest.transactional.error.InvalidConcurrentTransactionAccess) GraphDatabaseQueryService(org.neo4j.kernel.GraphDatabaseQueryService) Clock(java.time.Clock) SecurityContext(org.neo4j.kernel.api.security.SecurityContext) DoubleLatch(org.neo4j.test.DoubleLatch) Test(org.junit.Test)

Example 2 with InvalidConcurrentTransactionAccess

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

Aggregations

Test (org.junit.Test)2 InvalidConcurrentTransactionAccess (org.neo4j.server.rest.transactional.error.InvalidConcurrentTransactionAccess)2 Clock (java.time.Clock)1 GraphDatabaseQueryService (org.neo4j.kernel.GraphDatabaseQueryService)1 SecurityContext (org.neo4j.kernel.api.security.SecurityContext)1 AssertableLogProvider (org.neo4j.logging.AssertableLogProvider)1 DoubleLatch (org.neo4j.test.DoubleLatch)1