use of org.neo4j.unsafe.impl.batchimport.input.InputRelationship in project neo4j by neo4j.
the class CalculateDenseNodesStepTest method shouldCollectBadRelationships.
@Test
public void shouldCollectBadRelationships() throws Exception {
// GIVEN
NodeRelationshipCache cache = mock(NodeRelationshipCache.class);
Collector collector = mock(Collector.class);
try (CalculateDenseNodesStep step = new CalculateDenseNodesStep(mock(StageControl.class), DEFAULT, cache, collector)) {
step.processors(4);
step.start(0);
// WHEN
Batch<InputRelationship, RelationshipRecord> batch = batch(relationship(1, 5), relationship(3, 10), // <-- bad relationship with missing start node
relationship("a", 2, -1, 2), // <-- bad relationship with missing end node
relationship(2, "b", 2, -1), // <-- bad relationship with missing start and end node
relationship("c", "d", -1, -1));
step.receive(0, batch);
step.endOfUpstream();
while (!step.isCompleted()) {
//wait
}
// THEN
verify(collector, times(1)).collectBadRelationship(any(InputRelationship.class), eq("a"));
verify(collector, times(1)).collectBadRelationship(any(InputRelationship.class), eq("b"));
verify(collector, times(1)).collectBadRelationship(any(InputRelationship.class), eq("c"));
verify(collector, times(1)).collectBadRelationship(any(InputRelationship.class), eq("d"));
}
}
use of org.neo4j.unsafe.impl.batchimport.input.InputRelationship in project neo4j by neo4j.
the class CalculateDenseNodesStepTest method shouldNotProcessLoopsTwice.
@Test
public void shouldNotProcessLoopsTwice() throws Exception {
// GIVEN
NodeRelationshipCache cache = mock(NodeRelationshipCache.class);
try (CalculateDenseNodesStep step = new CalculateDenseNodesStep(mock(StageControl.class), DEFAULT, cache, mock(Collector.class))) {
step.processors(4);
step.start(0);
// WHEN
Batch<InputRelationship, RelationshipRecord> batch = batch(relationship(1, 5), relationship(3, 10), // <-- the loop
relationship(2, 2), relationship(4, 1));
step.receive(0, batch);
step.endOfUpstream();
while (!step.isCompleted()) {
// wait
}
// THEN
verify(cache, times(2)).incrementCount(eq(1L));
verify(cache, times(1)).incrementCount(eq(2L));
verify(cache, times(1)).incrementCount(eq(3L));
verify(cache, times(1)).incrementCount(eq(4L));
verify(cache, times(1)).incrementCount(eq(5L));
verify(cache, times(1)).incrementCount(eq(10L));
}
}
use of org.neo4j.unsafe.impl.batchimport.input.InputRelationship in project neo4j by neo4j.
the class CsvInputBatchImportIT method buildUpExpectedData.
private void buildUpExpectedData(List<InputNode> nodeData, List<InputRelationship> relationshipData, Map<String, InputNode> expectedNodes, Map<String, String[]> expectedNodeNames, Map<String, Map<String, Map<String, AtomicInteger>>> expectedRelationships, Map<String, AtomicLong> nodeCounts, Map<String, Map<String, Map<String, AtomicLong>>> relationshipCounts) {
for (InputNode node : nodeData) {
expectedNodes.put((String) node.id(), node);
expectedNodeNames.put(nameOf(node), node.labels());
countNodeLabels(nodeCounts, node.labels());
}
for (InputRelationship relationship : relationshipData) {
// Expected relationship counts per node, type and direction
InputNode startNode = expectedNodes.get(relationship.startNode());
InputNode endNode = expectedNodes.get(relationship.endNode());
{
expectedRelationships.get(nameOf(startNode)).get(nameOf(endNode)).get(relationship.type()).incrementAndGet();
}
// Expected counts per start/end node label ids
// Let's do what CountsState#addRelationship does, roughly
relationshipCounts.get(null).get(null).get(null).incrementAndGet();
relationshipCounts.get(null).get(relationship.type()).get(null).incrementAndGet();
for (String startNodeLabelName : asSet(startNode.labels())) {
Map<String, Map<String, AtomicLong>> startLabelCounts = relationshipCounts.get(startNodeLabelName);
startLabelCounts.get(null).get(null).incrementAndGet();
Map<String, AtomicLong> typeCounts = startLabelCounts.get(relationship.type());
typeCounts.get(null).incrementAndGet();
if (COMPUTE_DOUBLE_SIDED_RELATIONSHIP_COUNTS) {
for (String endNodeLabelName : asSet(endNode.labels())) {
startLabelCounts.get(null).get(endNodeLabelName).incrementAndGet();
typeCounts.get(endNodeLabelName).incrementAndGet();
}
}
}
for (String endNodeLabelName : asSet(endNode.labels())) {
relationshipCounts.get(null).get(null).get(endNodeLabelName).incrementAndGet();
relationshipCounts.get(null).get(relationship.type()).get(endNodeLabelName).incrementAndGet();
}
}
}
use of org.neo4j.unsafe.impl.batchimport.input.InputRelationship in project neo4j by neo4j.
the class CsvInputTest method shouldDoWithoutRelationshipTypeHeaderIfDefaultSupplied.
@Test
public void shouldDoWithoutRelationshipTypeHeaderIfDefaultSupplied() throws Exception {
// GIVEN relationship data w/o :TYPE header
String defaultType = "HERE";
DataFactory<InputRelationship> data = data(":START_ID,:END_ID,name\n" + "0,1,First\n" + "2,3,Second\n", defaultRelationshipType(defaultType));
Iterable<DataFactory<InputRelationship>> dataIterable = dataIterable(data);
Input input = new CsvInput(null, null, dataIterable, defaultFormatRelationshipFileHeader(), IdType.ACTUAL, config(COMMAS), silentBadCollector(0), getRuntime().availableProcessors());
// WHEN
try (ResourceIterator<InputRelationship> relationships = input.relationships().iterator()) {
// THEN
assertRelationship(relationships.next(), 0L, 1L, defaultType, properties("name", "First"));
assertRelationship(relationships.next(), 2L, 3L, defaultType, properties("name", "Second"));
assertFalse(relationships.hasNext());
}
}
use of org.neo4j.unsafe.impl.batchimport.input.InputRelationship in project neo4j by neo4j.
the class CsvInputTest method shouldIgnoreRelationshipEntriesMarkedIgnoreUsingHeader.
@Test
public void shouldIgnoreRelationshipEntriesMarkedIgnoreUsingHeader() throws Exception {
// GIVEN
Iterable<DataFactory<InputRelationship>> data = DataFactories.relationshipData(CsvInputTest.<InputRelationship>data(":START_ID,:TYPE,:END_ID,prop:IGNORE,other:int\n" + "1,KNOWS,2,Mattias,10\n" + "2,KNOWS,3,Johan,111\n" + "3,KNOWS,4,Emil,12"));
Input input = new CsvInput(null, null, data, defaultFormatRelationshipFileHeader(), IdType.INTEGER, config(COMMAS), silentBadCollector(0), getRuntime().availableProcessors());
// WHEN
try (InputIterator<InputRelationship> relationships = input.relationships().iterator()) {
assertRelationship(relationships.next(), 1L, 2L, "KNOWS", new Object[] { "other", 10 });
assertRelationship(relationships.next(), 2L, 3L, "KNOWS", new Object[] { "other", 111 });
assertRelationship(relationships.next(), 3L, 4L, "KNOWS", new Object[] { "other", 12 });
assertFalse(relationships.hasNext());
}
}
Aggregations