Search in sources :

Example 71 with KernelTransaction

use of org.neo4j.kernel.api.KernelTransaction in project neo4j by neo4j.

the class IndexPopulationJobTest method getPropertyKeyForName.

private int getPropertyKeyForName(String name) throws TransactionFailureException {
    try (KernelTransaction tx = kernel.newTransaction(KernelTransaction.Type.implicit, AnonymousContext.read());
        Statement statement = tx.acquireStatement()) {
        int result = statement.readOperations().propertyKeyGetForName(name);
        tx.success();
        return result;
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) Statement(org.neo4j.kernel.api.Statement)

Example 72 with KernelTransaction

use of org.neo4j.kernel.api.KernelTransaction in project neo4j by neo4j.

the class KernelIT method txReturnsCorrectIdWhenRolledBack.

@Test
public void txReturnsCorrectIdWhenRolledBack() throws Exception {
    executeDummyTxs(db, 42);
    KernelTransaction tx = kernel.newTransaction(KernelTransaction.Type.implicit, AUTH_DISABLED);
    try (Statement statement = tx.acquireStatement()) {
        statement.dataWriteOperations().nodeCreate();
    }
    tx.failure();
    assertEquals(KernelTransaction.ROLLBACK, tx.closeTransaction());
    assertFalse(tx.isOpen());
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) Statement(org.neo4j.kernel.api.Statement) Test(org.junit.Test)

Example 73 with KernelTransaction

use of org.neo4j.kernel.api.KernelTransaction in project neo4j by neo4j.

the class KernelIT method shouldKillTransactionsOnShutdown.

@Test
public void shouldKillTransactionsOnShutdown() throws Throwable {
    // Given
    assumeThat(kernel, instanceOf(Kernel.class));
    // Then
    try (KernelTransaction tx = kernel.newTransaction(KernelTransaction.Type.implicit, AnonymousContext.read())) {
        ((Kernel) kernel).stop();
        tx.acquireStatement().readOperations().nodeExists(0L);
        fail("Should have been terminated.");
    } catch (TransactionTerminatedException e) {
    // Success
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) TransactionTerminatedException(org.neo4j.graphdb.TransactionTerminatedException) Kernel(org.neo4j.kernel.impl.api.Kernel) Test(org.junit.Test)

Example 74 with KernelTransaction

use of org.neo4j.kernel.api.KernelTransaction in project neo4j by neo4j.

the class KernelIT method txReturnsCorrectIdWhenCommitted.

@Test
public void txReturnsCorrectIdWhenCommitted() throws Exception {
    executeDummyTxs(db, 42);
    KernelTransaction tx = kernel.newTransaction(KernelTransaction.Type.implicit, AUTH_DISABLED);
    try (Statement statement = tx.acquireStatement()) {
        statement.dataWriteOperations().nodeCreate();
    }
    tx.success();
    long previousCommittedTxId = lastCommittedTxId(db);
    assertEquals(previousCommittedTxId + 1, tx.closeTransaction());
    assertFalse(tx.isOpen());
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) Statement(org.neo4j.kernel.api.Statement) Test(org.junit.Test)

Example 75 with KernelTransaction

use of org.neo4j.kernel.api.KernelTransaction in project neo4j by neo4j.

the class KernelIT method txReturnsCorrectIdWhenFailedlAndMarkedForTermination.

@Test
public void txReturnsCorrectIdWhenFailedlAndMarkedForTermination() throws Exception {
    executeDummyTxs(db, 42);
    KernelTransaction tx = kernel.newTransaction(KernelTransaction.Type.implicit, AUTH_DISABLED);
    try (Statement statement = tx.acquireStatement()) {
        statement.dataWriteOperations().nodeCreate();
    }
    tx.failure();
    tx.markForTermination(Status.Transaction.Terminated);
    assertEquals(KernelTransaction.ROLLBACK, tx.closeTransaction());
    assertFalse(tx.isOpen());
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) Statement(org.neo4j.kernel.api.Statement) Test(org.junit.Test)

Aggregations

KernelTransaction (org.neo4j.kernel.api.KernelTransaction)77 Test (org.junit.Test)37 Statement (org.neo4j.kernel.api.Statement)30 TransactionFailureException (org.neo4j.kernel.api.exceptions.TransactionFailureException)14 ThreadToStatementContextBridge (org.neo4j.kernel.impl.core.ThreadToStatementContextBridge)14 KernelAPI (org.neo4j.kernel.api.KernelAPI)9 TopLevelTransaction (org.neo4j.kernel.impl.coreapi.TopLevelTransaction)8 NewIndexDescriptor (org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor)7 TransactionTerminatedException (org.neo4j.graphdb.TransactionTerminatedException)6 InternalTransaction (org.neo4j.kernel.impl.coreapi.InternalTransaction)6 QueryRegistryOperations (org.neo4j.kernel.api.QueryRegistryOperations)4 SecurityContext (org.neo4j.kernel.api.security.SecurityContext)4 KernelStatement (org.neo4j.kernel.impl.api.KernelStatement)4 RemoteException (java.rmi.RemoteException)3 ExpectedException (org.junit.rules.ExpectedException)3 DependencyResolver (org.neo4j.graphdb.DependencyResolver)3 GraphDatabaseQueryService (org.neo4j.kernel.GraphDatabaseQueryService)3 ShellException (org.neo4j.shell.ShellException)3 File (java.io.File)2 ArrayList (java.util.ArrayList)2