Search in sources :

Example 11 with KernelTransaction

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

the class TopLevelTransactionTest method shouldThrowTransactionExceptionOnTransientKernelException.

@Test
public void shouldThrowTransactionExceptionOnTransientKernelException() throws Exception {
    // GIVEN
    KernelTransaction kernelTransaction = mock(KernelTransaction.class);
    when(kernelTransaction.isOpen()).thenReturn(true);
    doThrow(new RuntimeException("Just a random failure")).when(kernelTransaction).close();
    ThreadToStatementContextBridge bridge = new ThreadToStatementContextBridge();
    TopLevelTransaction transaction = new TopLevelTransaction(kernelTransaction, bridge);
    // WHEN
    transaction.success();
    try {
        transaction.close();
        fail("Should have failed");
    } catch (org.neo4j.graphdb.TransactionFailureException e) {
    // THEN Good
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) ThreadToStatementContextBridge(org.neo4j.kernel.impl.core.ThreadToStatementContextBridge) TopLevelTransaction(org.neo4j.kernel.impl.coreapi.TopLevelTransaction) Test(org.junit.Test)

Example 12 with KernelTransaction

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

the class TopLevelTransactionTest method shouldLetThroughTransientFailureException.

@Test
public void shouldLetThroughTransientFailureException() throws Exception {
    // GIVEN
    KernelTransaction kernelTransaction = mock(KernelTransaction.class);
    when(kernelTransaction.isOpen()).thenReturn(true);
    doThrow(new TransientDatabaseFailureException("Just a random failure")).when(kernelTransaction).close();
    ThreadToStatementContextBridge bridge = new ThreadToStatementContextBridge();
    TopLevelTransaction transaction = new TopLevelTransaction(kernelTransaction, bridge);
    // WHEN
    transaction.success();
    try {
        transaction.close();
        fail("Should have failed");
    } catch (TransientFailureException e) {
    // THEN Good
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) TransientFailureException(org.neo4j.graphdb.TransientFailureException) ThreadToStatementContextBridge(org.neo4j.kernel.impl.core.ThreadToStatementContextBridge) TransientDatabaseFailureException(org.neo4j.graphdb.TransientDatabaseFailureException) TopLevelTransaction(org.neo4j.kernel.impl.coreapi.TopLevelTransaction) Test(org.junit.Test)

Example 13 with KernelTransaction

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

the class IndexProceduresTest method closeStatementOnClose.

@Test
public void closeStatementOnClose() throws Exception {
    KernelTransaction kernelTransaction = mock(KernelTransaction.class);
    Statement statement = mock(Statement.class);
    when(kernelTransaction.acquireStatement()).thenReturn(statement);
    //noinspection EmptyTryBlock
    try (IndexProcedures ignored = new IndexProcedures(kernelTransaction, null)) {
    }
    verify(statement).close();
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) Statement(org.neo4j.kernel.api.Statement) Test(org.junit.Test)

Example 14 with KernelTransaction

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

the class ConstraintIndexCreator method dropUniquenessConstraintIndex.

/**
     * You MUST hold a schema write lock before you call this method.
     */
public void dropUniquenessConstraintIndex(NewIndexDescriptor descriptor) throws TransactionFailureException, DropIndexFailureException {
    try (KernelTransaction transaction = kernelSupplier.get().newTransaction(KernelTransaction.Type.implicit, AUTH_DISABLED);
        Statement statement = transaction.acquireStatement()) {
        // NOTE: This creates the index (obviously) but it DOES NOT grab a schema
        // write lock. It is assumed that the transaction that invoked this "inner" transaction
        // holds a schema write lock, and that it will wait for this inner transaction to do its
        // work.
        // TODO (Ben+Jake): The Transactor is really part of the kernel internals, so it needs access to the
        // internal implementation of Statement. However it is currently used by the external
        // RemoveOrphanConstraintIndexesOnStartup job. This needs revisiting.
        ((KernelStatement) statement).txState().indexDoDrop(descriptor);
        transaction.success();
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) Statement(org.neo4j.kernel.api.Statement) KernelStatement(org.neo4j.kernel.impl.api.KernelStatement)

Example 15 with KernelTransaction

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

the class ConstraintIndexCreator method createConstraintIndex.

public NewIndexDescriptor createConstraintIndex(final LabelSchemaDescriptor schema) {
    try (KernelTransaction transaction = kernelSupplier.get().newTransaction(KernelTransaction.Type.implicit, AUTH_DISABLED);
        Statement statement = transaction.acquireStatement()) {
        // NOTE: This creates the index (obviously) but it DOES NOT grab a schema
        // write lock. It is assumed that the transaction that invoked this "inner" transaction
        // holds a schema write lock, and that it will wait for this inner transaction to do its
        // work.
        // TODO (Ben+Jake): The Transactor is really part of the kernel internals, so it needs access to the
        // internal implementation of Statement. However it is currently used by the external
        // RemoveOrphanConstraintIndexesOnStartup job. This needs revisiting.
        NewIndexDescriptor index = NewIndexDescriptorFactory.uniqueForSchema(schema);
        ((KernelStatement) statement).txState().indexRuleDoAdd(index);
        transaction.success();
        return index;
    } catch (TransactionFailureException e) {
        throw new RuntimeException(e);
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) TransactionFailureException(org.neo4j.kernel.api.exceptions.TransactionFailureException) NewIndexDescriptor(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor) Statement(org.neo4j.kernel.api.Statement) KernelStatement(org.neo4j.kernel.impl.api.KernelStatement)

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