use of org.neo4j.kernel.api.exceptions.EntityNotFoundException 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);
}
}
use of org.neo4j.kernel.api.exceptions.EntityNotFoundException in project neo4j by neo4j.
the class TwoPhaseNodeForRelationshipLockingTest method returnRelationships.
static void returnRelationships(EntityReadOperations ops, KernelStatement state, long nodeId, final boolean skipFirst, final RelationshipData... relIds) throws EntityNotFoundException {
NodeItem nodeItem = mock(NodeItem.class);
when(ops.nodeGetRelationships(state, nodeItem, Direction.BOTH)).thenAnswer(new Answer<Cursor<RelationshipItem>>() {
private boolean first = skipFirst;
@Override
public Cursor<RelationshipItem> answer(InvocationOnMock invocation) throws Throwable {
try {
return new Cursor<RelationshipItem>() {
private int i = first ? 1 : 0;
private RelationshipData relationshipData = null;
@Override
public boolean next() {
boolean next = i < relIds.length;
relationshipData = next ? relIds[i++] : null;
return next;
}
@Override
public RelationshipItem get() {
if (relationshipData == null) {
throw new NoSuchElementException();
}
return relationshipData.asRelationshipItem();
}
@Override
public void close() {
}
};
} finally {
first = false;
}
}
});
when(ops.nodeCursorById(state, nodeId)).thenAnswer(invocationOnMock -> {
Cursor<NodeItem> cursor = new Cursor<NodeItem>() {
private int i = 0;
@Override
public boolean next() {
return i++ == 0;
}
@Override
public NodeItem get() {
if (i != 1) {
throw new NoSuchElementException();
}
return nodeItem;
}
@Override
public void close() {
}
};
if (!cursor.next()) {
throw new EntityNotFoundException(EntityType.NODE, nodeId);
}
return cursor;
});
}
use of org.neo4j.kernel.api.exceptions.EntityNotFoundException in project neo4j by neo4j.
the class PropertyIT method shouldNotAllowModifyingPropertiesOnDeletedRelationship.
@Test
public void shouldNotAllowModifyingPropertiesOnDeletedRelationship() throws Exception {
// given
Statement statement = statementInNewTransaction(AnonymousContext.writeToken());
int prop1 = statement.tokenWriteOperations().propertyKeyGetOrCreateForName("prop1");
int type = statement.tokenWriteOperations().relationshipTypeGetOrCreateForName("RELATED");
long startNodeId = statement.dataWriteOperations().nodeCreate();
long endNodeId = statement.dataWriteOperations().nodeCreate();
long rel = statement.dataWriteOperations().relationshipCreate(type, startNodeId, endNodeId);
statement.dataWriteOperations().relationshipSetProperty(rel, stringProperty(prop1, "As"));
statement.dataWriteOperations().relationshipDelete(rel);
// When
try {
statement.dataWriteOperations().relationshipRemoveProperty(rel, prop1);
fail("Should have failed.");
} catch (EntityNotFoundException e) {
assertThat(e.getMessage(), equalTo("Unable to load RELATIONSHIP with id " + rel + "."));
}
}
use of org.neo4j.kernel.api.exceptions.EntityNotFoundException in project neo4j by neo4j.
the class PropertyIT method shouldNotAllowModifyingPropertiesOnDeletedNode.
@Test
public void shouldNotAllowModifyingPropertiesOnDeletedNode() throws Exception {
// given
Statement statement = statementInNewTransaction(AnonymousContext.writeToken());
int prop1 = statement.tokenWriteOperations().propertyKeyGetOrCreateForName("prop1");
long node = statement.dataWriteOperations().nodeCreate();
statement.dataWriteOperations().nodeSetProperty(node, stringProperty(prop1, "As"));
statement.dataWriteOperations().nodeDelete(node);
// When
try {
statement.dataWriteOperations().nodeRemoveProperty(node, prop1);
fail("Should have failed.");
} catch (EntityNotFoundException e) {
assertThat(e.getMessage(), equalTo("Unable to load NODE with id " + node + "."));
}
}
use of org.neo4j.kernel.api.exceptions.EntityNotFoundException in project neo4j by neo4j.
the class KernelIT method changesInTransactionContextShouldBeRolledBackWhenTxIsRolledBack.
@Test
public void changesInTransactionContextShouldBeRolledBackWhenTxIsRolledBack() throws Exception {
// GIVEN
Node node;
int labelId;
try (Transaction tx = db.beginTx()) {
Statement statement = statementContextSupplier.get();
// WHEN
node = db.createNode();
labelId = statement.tokenWriteOperations().labelGetOrCreateForName("labello");
statement.dataWriteOperations().nodeAddLabel(node.getId(), labelId);
statement.close();
}
// THEN
try (Transaction tx = db.beginTx()) {
try (Statement statement = statementContextSupplier.get()) {
statement.readOperations().nodeHasLabel(node.getId(), labelId);
fail("should have thrown exception");
} catch (EntityNotFoundException e) {
// Yay!
}
}
}
Aggregations