Search in sources :

Example 21 with TransactionFailureException

use of org.neo4j.kernel.api.exceptions.TransactionFailureException in project neo4j by neo4j.

the class CommitProcessStateMachineCollaborationTest method shouldFailTransactionIfLockSessionChanges.

@Test
public void shouldFailTransactionIfLockSessionChanges() throws Exception {
    // given
    int initialLockSessionId = 23;
    TransactionToApply transactionToApply = new TransactionToApply(physicalTx(initialLockSessionId));
    int finalLockSessionId = 24;
    TransactionCommitProcess localCommitProcess = mock(TransactionCommitProcess.class);
    ReplicatedTransactionStateMachine stateMachine = new ReplicatedTransactionStateMachine(lockState(finalLockSessionId), 16, NullLogProvider.getInstance());
    stateMachine.installCommitProcess(localCommitProcess, -1L);
    DirectReplicator<ReplicatedTransaction> replicator = new DirectReplicator<>(stateMachine);
    ReplicatedTransactionCommitProcess commitProcess = new ReplicatedTransactionCommitProcess(replicator);
    // when
    try {
        commitProcess.commit(transactionToApply, NULL, EXTERNAL);
        fail("Should have thrown exception.");
    } catch (TransactionFailureException e) {
    // expected
    }
}
Also used : TransactionToApply(org.neo4j.kernel.impl.api.TransactionToApply) TransactionFailureException(org.neo4j.kernel.api.exceptions.TransactionFailureException) TransactionCommitProcess(org.neo4j.kernel.impl.api.TransactionCommitProcess) DirectReplicator(org.neo4j.causalclustering.core.replication.DirectReplicator) Test(org.junit.Test)

Example 22 with TransactionFailureException

use of org.neo4j.kernel.api.exceptions.TransactionFailureException in project neo4j by neo4j.

the class StateHandlingStatementOperations method uniquePropertyConstraintCreate.

@Override
public UniquenessConstraintDescriptor uniquePropertyConstraintCreate(KernelStatement state, LabelSchemaDescriptor descriptor) throws CreateConstraintFailureException {
    UniquenessConstraintDescriptor constraint = ConstraintDescriptorFactory.uniqueForSchema(descriptor);
    try {
        if (state.hasTxStateWithChanges() && // ..., DROP, *CREATE*
        state.txState().indexDoUnRemove(constraint.ownedIndexDescriptor())) {
            // creation is undoing a drop
            if (// CREATE, ..., DROP, *CREATE*
            !state.txState().constraintDoUnRemove(constraint)) {
                // ... the drop we are undoing did itself undo a prior create...
                state.txState().constraintDoAdd(constraint, state.txState().indexCreatedForConstraint(constraint));
            }
        } else // *CREATE*
        {
            // create from scratch
            Iterator<ConstraintDescriptor> it = storeLayer.constraintsGetForSchema(descriptor);
            while (it.hasNext()) {
                if (it.next().equals(constraint)) {
                    return constraint;
                }
            }
            long indexId = constraintIndexCreator.createUniquenessConstraintIndex(state, this, descriptor);
            state.txState().constraintDoAdd(constraint, indexId);
        }
        return constraint;
    } catch (UniquePropertyValueValidationException | DropIndexFailureException | TransactionFailureException e) {
        throw new CreateConstraintFailureException(constraint, e);
    }
}
Also used : UniquePropertyValueValidationException(org.neo4j.kernel.api.exceptions.schema.UniquePropertyValueValidationException) TransactionFailureException(org.neo4j.kernel.api.exceptions.TransactionFailureException) ConstraintDescriptor(org.neo4j.kernel.api.schema_new.constaints.ConstraintDescriptor) UniquenessConstraintDescriptor(org.neo4j.kernel.api.schema_new.constaints.UniquenessConstraintDescriptor) NodeExistenceConstraintDescriptor(org.neo4j.kernel.api.schema_new.constaints.NodeExistenceConstraintDescriptor) RelExistenceConstraintDescriptor(org.neo4j.kernel.api.schema_new.constaints.RelExistenceConstraintDescriptor) UniquenessConstraintDescriptor(org.neo4j.kernel.api.schema_new.constaints.UniquenessConstraintDescriptor) DropIndexFailureException(org.neo4j.kernel.api.exceptions.schema.DropIndexFailureException) CreateConstraintFailureException(org.neo4j.kernel.api.exceptions.schema.CreateConstraintFailureException)

Example 23 with TransactionFailureException

use of org.neo4j.kernel.api.exceptions.TransactionFailureException in project neo4j by neo4j.

the class TopLevelTransactionTest method shouldThrowTransientExceptionOnTransientKernelException.

@Test
public void shouldThrowTransientExceptionOnTransientKernelException() throws Exception {
    // GIVEN
    KernelTransaction kernelTransaction = mock(KernelTransaction.class);
    when(kernelTransaction.isOpen()).thenReturn(true);
    doThrow(new TransactionFailureException(Status.Transaction.ConstraintsChanged, "Proving that TopLevelTransaction does the right thing")).when(kernelTransaction).close();
    ThreadToStatementContextBridge bridge = new ThreadToStatementContextBridge();
    TopLevelTransaction transaction = new TopLevelTransaction(kernelTransaction, bridge);
    // WHEN
    transaction.success();
    try {
        transaction.close();
        fail("Should have failed");
    } catch (TransientTransactionFailureException e) {
    // THEN Good
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) TransientTransactionFailureException(org.neo4j.graphdb.TransientTransactionFailureException) TransactionFailureException(org.neo4j.kernel.api.exceptions.TransactionFailureException) ThreadToStatementContextBridge(org.neo4j.kernel.impl.core.ThreadToStatementContextBridge) TransientTransactionFailureException(org.neo4j.graphdb.TransientTransactionFailureException) TopLevelTransaction(org.neo4j.kernel.impl.coreapi.TopLevelTransaction) Test(org.junit.Test)

Example 24 with TransactionFailureException

use of org.neo4j.kernel.api.exceptions.TransactionFailureException in project neo4j by neo4j.

the class TransactionRepresentationCommitProcessTest method shouldCloseTransactionRegardlessOfWhetherOrNotItAppliedCorrectly.

@Test
public void shouldCloseTransactionRegardlessOfWhetherOrNotItAppliedCorrectly() throws Exception {
    // GIVEN
    TransactionIdStore transactionIdStore = mock(TransactionIdStore.class);
    TransactionAppender appender = new TestableTransactionAppender(transactionIdStore);
    long txId = 11;
    when(transactionIdStore.nextCommittingTransactionId()).thenReturn(txId);
    IOException rootCause = new IOException("Mock exception");
    StorageEngine storageEngine = mock(StorageEngine.class);
    doThrow(new IOException(rootCause)).when(storageEngine).apply(any(TransactionToApply.class), any(TransactionApplicationMode.class));
    TransactionCommitProcess commitProcess = new TransactionRepresentationCommitProcess(appender, storageEngine);
    TransactionToApply transaction = mockedTransaction();
    // WHEN
    try {
        commitProcess.commit(transaction, commitEvent, INTERNAL);
    } catch (TransactionFailureException e) {
        assertThat(e.getMessage(), containsString("Could not apply the transaction to the store"));
        assertTrue(contains(e, rootCause.getMessage(), rootCause.getClass()));
    }
    // THEN
    // we can't verify transactionCommitted since that's part of the TransactionAppender, which we have mocked
    verify(transactionIdStore, times(1)).transactionClosed(eq(txId), anyLong(), anyLong());
}
Also used : TransactionFailureException(org.neo4j.kernel.api.exceptions.TransactionFailureException) TransactionIdStore(org.neo4j.kernel.impl.transaction.log.TransactionIdStore) TestableTransactionAppender(org.neo4j.kernel.impl.transaction.log.TestableTransactionAppender) TestableTransactionAppender(org.neo4j.kernel.impl.transaction.log.TestableTransactionAppender) TransactionAppender(org.neo4j.kernel.impl.transaction.log.TransactionAppender) TransactionApplicationMode(org.neo4j.storageengine.api.TransactionApplicationMode) IOException(java.io.IOException) StorageEngine(org.neo4j.storageengine.api.StorageEngine) Test(org.junit.Test)

Example 25 with TransactionFailureException

use of org.neo4j.kernel.api.exceptions.TransactionFailureException in project neo4j by neo4j.

the class TestMigrateToDenseNodeSupport method verifyDenseRepresentation.

private void verifyDenseRepresentation(GraphDatabaseService db, Node node, boolean dense) {
    KernelAPI kernelAPI = ((GraphDatabaseAPI) db).getDependencyResolver().resolveDependency(KernelAPI.class);
    try (KernelTransaction tx = kernelAPI.newTransaction(KernelTransaction.Type.implicit, AnonymousContext.read());
        Statement statement = tx.acquireStatement()) {
        Cursor<NodeItem> nodeCursor = statement.readOperations().nodeCursorById(node.getId());
        assertEquals(dense, nodeCursor.get().isDense());
    } catch (TransactionFailureException | IllegalArgumentException | EntityNotFoundException e) {
        throw new RuntimeException(e);
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) TransactionFailureException(org.neo4j.kernel.api.exceptions.TransactionFailureException) NodeItem(org.neo4j.storageengine.api.NodeItem) Statement(org.neo4j.kernel.api.Statement) EntityNotFoundException(org.neo4j.kernel.api.exceptions.EntityNotFoundException) KernelAPI(org.neo4j.kernel.api.KernelAPI)

Aggregations

TransactionFailureException (org.neo4j.kernel.api.exceptions.TransactionFailureException)26 Test (org.junit.Test)11 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)10 IOException (java.io.IOException)5 TransientTransactionFailureException (org.neo4j.graphdb.TransientTransactionFailureException)4 TransactionToApply (org.neo4j.kernel.impl.api.TransactionToApply)4 CreateConstraintFailureException (org.neo4j.kernel.api.exceptions.schema.CreateConstraintFailureException)3 StorageEngine (org.neo4j.storageengine.api.StorageEngine)3 ArrayList (java.util.ArrayList)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 RequestContext (org.neo4j.com.RequestContext)2 Statement (org.neo4j.kernel.api.Statement)2 ConstraintValidationException (org.neo4j.kernel.api.exceptions.schema.ConstraintValidationException)2 TransactionCommitProcess (org.neo4j.kernel.impl.api.TransactionCommitProcess)2 TransactionRepresentation (org.neo4j.kernel.impl.transaction.TransactionRepresentation)2 StorageCommand (org.neo4j.storageengine.api.StorageCommand)2 ExecutionException (java.util.concurrent.ExecutionException)1 ThreadLocalRandom (java.util.concurrent.ThreadLocalRandom)1 AtomicReferenceArray (java.util.concurrent.atomic.AtomicReferenceArray)1 CatchupPollingProcess (org.neo4j.causalclustering.catchup.tx.CatchupPollingProcess)1