use of org.neo4j.graphdb.Relationship in project neo4j by neo4j.
the class RelationshipProxyTest method shouldPrintCypherEsqueRelationshipToString.
@Test
public void shouldPrintCypherEsqueRelationshipToString() throws Exception {
// GIVEN
Node start, end;
RelationshipType type = RelationshipType.withName("NICE");
Relationship relationship;
try (Transaction tx = db.beginTx()) {
// GIVEN
start = db.createNode();
end = db.createNode();
relationship = start.createRelationshipTo(end, type);
tx.success();
// WHEN
String toString = relationship.toString();
// THEN
assertEquals("(" + start.getId() + ")-[" + type + "," + relationship.getId() + "]->(" + end.getId() + ")", toString);
}
}
use of org.neo4j.graphdb.Relationship in project neo4j by neo4j.
the class TestDenseNodeRelChainPositionIT method givenDenseNodeWhenAskForWrongDirectionThenIncorrectNrOfRelsReturned.
/*
* Tests for a particular bug with dense nodes. It used to be that if a dense node had relationships
* for only one direction, if a request for relationships of the other direction was made, no relationships
* would be returned, ever.
*/
@Test
public void givenDenseNodeWhenAskForWrongDirectionThenIncorrectNrOfRelsReturned() throws Exception {
// Given
final int denseNodeThreshold = Integer.parseInt(GraphDatabaseSettings.dense_node_threshold.getDefaultValue()) + // We must be over the dense node threshold for the bug to manifest
1;
Node node1;
try (Transaction tx = db.beginTx()) {
node1 = db.createNode();
Node node2 = db.createNode();
for (int i = 0; i < denseNodeThreshold; i++) {
node1.createRelationshipTo(node2, RelationshipType.withName("FOO"));
}
tx.success();
}
// When/Then
try (Transaction ignored = db.beginTx()) {
Node node1b = db.getNodeById(node1.getId());
Iterable<Relationship> rels = node1b.getRelationships(Direction.INCOMING);
assertEquals(0, Iterables.count(rels));
Iterable<Relationship> rels2 = node1b.getRelationships(Direction.OUTGOING);
assertEquals(denseNodeThreshold, Iterables.count(rels2));
}
}
use of org.neo4j.graphdb.Relationship in project neo4j by neo4j.
the class TestExceptionTypeOnInvalidIds method getRelationshipById.
private void getRelationshipById(long index) {
Relationship value = graphdb.getRelationshipById(index);
fail(String.format("Returned Relationship [0x%x] for index 0x%x (int value: 0x%x)", value.getId(), index, (int) index));
}
use of org.neo4j.graphdb.Relationship in project neo4j by neo4j.
the class SubGraphExporter method appendRelationships.
private long appendRelationships(PrintWriter out) {
long relationships = 0;
for (Node node : graph.getNodes()) {
for (Relationship rel : node.getRelationships(Direction.OUTGOING)) {
appendRelationship(out, rel);
relationships++;
}
}
return relationships;
}
use of org.neo4j.graphdb.Relationship in project neo4j by neo4j.
the class DeleteRelationshipStressIT method setup.
@Before
public void setup() {
for (int i = 0; i < 100; i++) {
try (Transaction tx = db.beginTx()) {
Node prev = null;
for (int j = 0; j < 100; j++) {
Node node = db.createNode(label("L"));
if (prev != null) {
Relationship rel = prev.createRelationshipTo(node, DynamicRelationshipType.withName("T"));
rel.setProperty("prop", i + j);
}
prev = node;
}
tx.success();
}
}
}
Aggregations