use of org.neo4j.kernel.impl.coreapi.TransactionImpl in project neo4j by neo4j.
the class DeleteNodeWithRelationshipsIT method shouldDeleteDenseNodeIfContainingEmptyGroupsFromPreviousContendedRelationshipDeletions.
@Test
void shouldDeleteDenseNodeIfContainingEmptyGroupsFromPreviousContendedRelationshipDeletions() throws ExecutionException, InterruptedException {
// given
long nodeId;
RelationshipType typeA = RelationshipType.withName("A");
RelationshipType typeB = RelationshipType.withName("B");
try (Transaction tx = db.beginTx()) {
Node node = tx.createNode();
nodeId = node.getId();
for (int i = 0; i < 200; i++) {
node.createRelationshipTo(tx.createNode(), i % 2 == 0 ? typeA : typeB);
}
tx.commit();
}
// when starting a transaction that creates a relationship of type B and halting it before apply
Barrier.Control barrier;
try (OtherThreadExecutor t2 = new OtherThreadExecutor("T2")) {
barrier = new Barrier.Control();
Future<Object> t2Future = t2.executeDontWait(() -> {
try (TransactionImpl tx = (TransactionImpl) db.beginTx()) {
tx.getNodeById(nodeId).createRelationshipTo(tx.createNode(), typeB);
tx.commit(barrier::reached);
}
return null;
});
barrier.awaitUninterruptibly();
// and another transaction which deletes all relationships of type A, and let it commit
try (Transaction tx = db.beginTx()) {
tx.getNodeById(nodeId).getRelationships(typeA).forEach(Relationship::delete);
tx.commit();
}
// and letting the first transaction complete
barrier.release();
t2Future.get();
}
// then deleting the node should remove the empty group A, even if it's only deleting relationships of type B
try (Transaction tx = db.beginTx()) {
Node node = tx.getNodeById(nodeId);
node.getRelationships().forEach(relationship -> {
assertThat(relationship.isType(typeB)).isTrue();
relationship.delete();
});
node.delete();
tx.commit();
}
}
use of org.neo4j.kernel.impl.coreapi.TransactionImpl in project neo4j by neo4j.
the class DeleteNodeWithRelationshipsIT method shouldDeleteDenseNodeIfContainingEmptyGroups.
@Test
void shouldDeleteDenseNodeIfContainingEmptyGroups() throws Exception {
// given
long nodeId;
RelationshipType typeA = RelationshipType.withName("A");
RelationshipType typeB = RelationshipType.withName("B");
try (Transaction tx = db.beginTx()) {
Node node = tx.createNode();
nodeId = node.getId();
node.createRelationshipTo(tx.createNode(), typeA);
for (int i = 0; i < 200; i++) {
// Type A is created first and will get a lower type ID
node.createRelationshipTo(tx.createNode(), typeA);
}
tx.getNodeById(nodeId).createRelationshipTo(tx.createNode(), typeB);
tx.commit();
}
// when starting a transaction that creates a relationship of type A and halting it before apply
Barrier.Control barrier;
try (OtherThreadExecutor t2 = new OtherThreadExecutor("T2")) {
barrier = new Barrier.Control();
Future<Object> t2Future = t2.executeDontWait(() -> {
try (TransactionImpl tx = (TransactionImpl) db.beginTx()) {
tx.getNodeById(nodeId).createRelationshipTo(tx.createNode(), typeA);
tx.commit(barrier::reached);
}
return null;
});
barrier.awaitUninterruptibly();
// and another transaction which deletes all relationships of type B, and let it commit
try (Transaction tx = db.beginTx()) {
tx.getNodeById(nodeId).getRelationships(typeB).forEach(Relationship::delete);
// This will fail to delete the group B since it can not get exlusive locks
tx.commit();
}
// and letting the first transaction complete
barrier.release();
t2Future.get();
// then removing the remaining relationships of A
try (Transaction tx = db.beginTx()) {
tx.getNodeById(nodeId).getRelationships(typeA).forEach(Relationship::delete);
// this should only delete group A since B has a higher typeId than A (later in group-chain)
tx.commit();
}
}
// then deleting the node should also remove the empty group B
try (Transaction tx = db.beginTx()) {
tx.getNodeById(nodeId).delete();
assertThatCode(tx::commit).doesNotThrowAnyException();
}
}
use of org.neo4j.kernel.impl.coreapi.TransactionImpl in project neo4j by neo4j.
the class SystemGraphComponent method executeWithFullAccess.
static void executeWithFullAccess(GraphDatabaseService system, ThrowingConsumer<Transaction, Exception> consumer) throws Exception {
try (TransactionImpl tx = (TransactionImpl) system.beginTx();
KernelTransaction.Revertable ignore = tx.kernelTransaction().overrideWith(SecurityContext.AUTH_DISABLED)) {
consumer.accept(tx);
tx.commit();
}
}
use of org.neo4j.kernel.impl.coreapi.TransactionImpl in project neo4j by neo4j.
the class TransactionImplTest method shouldShowTransactionTerminatedExceptionAsTransient.
@Test
void shouldShowTransactionTerminatedExceptionAsTransient() throws Exception {
KernelTransaction kernelTransaction = mock(KernelTransaction.class);
doReturn(true).when(kernelTransaction).isOpen();
RuntimeException error = new TransactionTerminatedException(Status.Transaction.Terminated);
doThrow(error).when(kernelTransaction).close();
TransactionImpl transaction = new TransactionImpl(tokenHolders, contextFactory, availabilityGuard, engine, kernelTransaction, null, null);
transaction.commit();
}
use of org.neo4j.kernel.impl.coreapi.TransactionImpl in project neo4j by neo4j.
the class TransactionImplTest method shouldLetThroughTransientFailureException.
@Test
void shouldLetThroughTransientFailureException() throws Exception {
// GIVEN
KernelTransaction kernelTransaction = mock(KernelTransaction.class);
when(kernelTransaction.isOpen()).thenReturn(true);
doThrow(new TransientFailureException("Just a random failure") {
// @Override
public Status status() {
return null;
}
}).when(kernelTransaction).close();
TransactionImpl transaction = new TransactionImpl(tokenHolders, contextFactory, availabilityGuard, engine, kernelTransaction, null, null);
// WHEN
transaction.commit();
}
Aggregations