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
}
}
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);
}
}
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
}
}
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());
}
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);
}
}
Aggregations