Search in sources :

Example 1 with FabricTransactionInfo

use of org.neo4j.fabric.transaction.FabricTransactionInfo in project neo4j by neo4j.

the class CommunityEditionEndToEndTest method testRollbackOnStatementFailure.

@Test
void testRollbackOnStatementFailure() {
    // this is intentionally not using the driver, because the driver closes transactions on any failure
    // and this test verifies that the server does the same (we should not rely on the drivers with this behaviour
    // as all the drivers might not come from us)
    var dependencyResolver = graphDatabase.getDependencyResolver();
    var transactionManager = dependencyResolver.resolveDependency(TransactionManager.class);
    var fabricExecutor = dependencyResolver.resolveDependency(FabricExecutor.class);
    var transactionInfo = new FabricTransactionInfo(org.neo4j.bolt.runtime.AccessMode.READ, AUTH_DISABLED, EMBEDDED_CONNECTION, DatabaseIdFactory.from("mega", UUID.randomUUID()), false, Duration.ZERO, Map.of(), new RoutingContext(false, Map.of()));
    var bookmarkManager = mock(TransactionBookmarkManager.class);
    var tx1 = transactionManager.begin(transactionInfo, bookmarkManager);
    var tx2 = transactionManager.begin(transactionInfo, bookmarkManager);
    assertEquals(2, transactionManager.getOpenTransactions().size());
    var query1 = joinAsLines("USE neo4j", "RETURN 1/0 AS res");
    assertThrows(org.neo4j.exceptions.ArithmeticException.class, () -> fabricExecutor.run(tx1, query1, MapValue.EMPTY).records().collectList().block());
    var query2 = joinAsLines("USE neo4j", "UNWIND [1, 0] AS a", "RETURN 1/a AS res");
    assertThrows(org.neo4j.exceptions.ArithmeticException.class, () -> fabricExecutor.run(tx2, query2, MapValue.EMPTY).records().collectList().block());
    assertTrue(transactionManager.getOpenTransactions().isEmpty());
}
Also used : RoutingContext(org.neo4j.bolt.v41.messaging.RoutingContext) FabricTransactionInfo(org.neo4j.fabric.transaction.FabricTransactionInfo) Test(org.junit.jupiter.api.Test)

Example 2 with FabricTransactionInfo

use of org.neo4j.fabric.transaction.FabricTransactionInfo in project neo4j by neo4j.

the class BoltFabricDatabaseService method beginTransaction.

@Override
public BoltTransaction beginTransaction(KernelTransaction.Type type, LoginContext loginContext, ClientConnectionInfo clientInfo, List<Bookmark> bookmarks, Duration txTimeout, AccessMode accessMode, Map<String, Object> txMetadata, RoutingContext routingContext) {
    memoryTracker.allocateHeap(BOLT_TRANSACTION_SHALLOW_SIZE);
    if (txTimeout == null) {
        txTimeout = config.getTransactionTimeout();
    }
    FabricTransactionInfo transactionInfo = new FabricTransactionInfo(accessMode, loginContext, clientInfo, namedDatabaseId, KernelTransaction.Type.IMPLICIT == type, txTimeout, txMetadata, TestOverrides.routingContext(routingContext));
    var transactionBookmarkManager = transactionBookmarkManagerFactory.createTransactionBookmarkManager(transactionIdTracker);
    transactionBookmarkManager.processSubmittedByClient(bookmarks);
    FabricTransaction fabricTransaction = transactionManager.begin(transactionInfo, transactionBookmarkManager);
    return new BoltTransactionImpl(transactionInfo, fabricTransaction);
}
Also used : FabricTransactionInfo(org.neo4j.fabric.transaction.FabricTransactionInfo) FabricTransaction(org.neo4j.fabric.transaction.FabricTransaction)

Aggregations

FabricTransactionInfo (org.neo4j.fabric.transaction.FabricTransactionInfo)2 Test (org.junit.jupiter.api.Test)1 RoutingContext (org.neo4j.bolt.v41.messaging.RoutingContext)1 FabricTransaction (org.neo4j.fabric.transaction.FabricTransaction)1