use of org.neo4j.unsafe.batchinsert.BatchRelationship in project neo4j by neo4j.
the class BatchInsertTest method testMore.
@Test
public void testMore() throws Exception {
BatchInserter graphDb = globalInserter;
long startNode = graphDb.createNode(properties);
long[] endNodes = new long[25];
Set<Long> rels = new HashSet<>();
for (int i = 0; i < 25; i++) {
endNodes[i] = graphDb.createNode(properties);
rels.add(graphDb.createRelationship(startNode, endNodes[i], relTypeArray[i % 5], properties));
}
for (BatchRelationship rel : graphDb.getRelationships(startNode)) {
assertTrue(rels.contains(rel.getId()));
assertEquals(rel.getStartNode(), startNode);
}
graphDb.setNodeProperties(startNode, properties);
}
use of org.neo4j.unsafe.batchinsert.BatchRelationship in project neo4j by neo4j.
the class BatchInserterImpl method getRelationshipById.
@Override
public BatchRelationship getRelationshipById(long relId) {
RelationshipRecord record = getRelationshipRecord(relId).forReadingData();
RelationshipType type = (RelationshipType) relationshipTypeTokens.byId(record.getType());
return new BatchRelationship(record.getId(), record.getFirstNode(), record.getSecondNode(), type);
}
use of org.neo4j.unsafe.batchinsert.BatchRelationship in project neo4j by neo4j.
the class BatchInsertTest method testSimple.
@Test
public void testSimple() throws Exception {
BatchInserter graphDb = globalInserter;
long node1 = graphDb.createNode(null);
long node2 = graphDb.createNode(null);
long rel1 = graphDb.createRelationship(node1, node2, RelTypes.BATCH_TEST, null);
BatchRelationship rel = graphDb.getRelationshipById(rel1);
assertEquals(rel.getStartNode(), node1);
assertEquals(rel.getEndNode(), node2);
assertEquals(RelTypes.BATCH_TEST.name(), rel.getType().name());
}
use of org.neo4j.unsafe.batchinsert.BatchRelationship in project neo4j by neo4j.
the class BatchInsertTest method makeSureLoopsCanBeCreated.
@Test
public void makeSureLoopsCanBeCreated() throws Exception {
BatchInserter graphDb = newBatchInserter();
long startNode = graphDb.createNode(properties);
long otherNode = graphDb.createNode(properties);
long selfRelationship = graphDb.createRelationship(startNode, startNode, relTypeArray[0], properties);
long relationship = graphDb.createRelationship(startNode, otherNode, relTypeArray[0], properties);
for (BatchRelationship rel : graphDb.getRelationships(startNode)) {
if (rel.getId() == selfRelationship) {
assertEquals(startNode, rel.getStartNode());
assertEquals(startNode, rel.getEndNode());
} else if (rel.getId() == relationship) {
assertEquals(startNode, rel.getStartNode());
assertEquals(otherNode, rel.getEndNode());
} else {
fail("Unexpected relationship " + rel.getId());
}
}
GraphDatabaseService db = switchToEmbeddedGraphDatabaseService(graphDb);
try (Transaction ignored = db.beginTx()) {
Node realStartNode = db.getNodeById(startNode);
Relationship realSelfRelationship = db.getRelationshipById(selfRelationship);
Relationship realRelationship = db.getRelationshipById(relationship);
assertEquals(realSelfRelationship, realStartNode.getSingleRelationship(RelTypes.REL_TYPE1, Direction.INCOMING));
assertEquals(asSet(realSelfRelationship, realRelationship), Iterables.asSet(realStartNode.getRelationships(Direction.OUTGOING)));
assertEquals(asSet(realSelfRelationship, realRelationship), Iterables.asSet(realStartNode.getRelationships()));
} finally {
db.shutdown();
}
}
Aggregations