-
Notifications
You must be signed in to change notification settings - Fork 2.3k
/
MergeNodeAcceptanceTest.scala
96 lines (84 loc) · 3.85 KB
/
MergeNodeAcceptanceTest.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/*
* Copyright (c) 2002-2018 "Neo Technology,"
* Network Engine for Objects in Lund AB [http://neotechnology.com]
*
* This file is part of Neo4j.
*
* Neo4j is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.neo4j.internal.cypher.acceptance
import org.neo4j.cypher.{ExecutionEngineFunSuite, QueryStatisticsTestSupport}
import org.neo4j.graphdb.Relationship
import org.neo4j.internal.cypher.acceptance.CypherComparisonSupport._
class MergeNodeAcceptanceTest extends ExecutionEngineFunSuite with QueryStatisticsTestSupport
with CypherComparisonSupport {
// TODO: Reflect something like this in the TCK
test("multiple merges after each other") {
1 to 100 foreach { prop =>
val result = executeWith(Configs.Interpreted - Configs.Cost2_3, s"merge (a:Label {prop: $prop}) return a.prop")
assertStats(result, nodesCreated = 1, propertiesWritten = 1, labelsAdded = 1)
}
}
test("should not accidentally create relationship between wrong nodes after merge") {
// Given
val query =
"""
|MERGE (a:A)
|MERGE (b:B)
|MERGE (c:C)
|WITH a, b, c
|CREATE (b)-[r:R]->(c)
|RETURN r
""".stripMargin
// When
val result = graph.execute(s"CYPHER runtime=slotted $query")
// Then
val row = result.next
val r = row.get("r").asInstanceOf[Relationship]
graph.inTx {
val labelB = r.getStartNode.getLabels.iterator().next()
val labelC = r.getEndNode.getLabels.iterator().next()
labelB.name() shouldEqual ("B")
labelC.name() shouldEqual ("C")
}
}
private val supportMerge = Configs.Interpreted - Configs.Cost2_3
// TODO: Change this setting when the bugfix #10771 merged to earlier 3.x versions is included as a dependency
private val doNotYetHaveBugFix = Configs.Cost3_1
test("Merging with self loop and relationship uniqueness") {
graph.execute("CREATE (a) CREATE (a)-[:X]->(a)")
val result = executeWith(supportMerge, "MERGE (a)-[:X]->(b)-[:X]->(c) RETURN 42")
assertStats(result, relationshipsCreated = 2, nodesCreated = 3)
}
test("Merging with self loop and relationship uniqueness - no stats") {
graph.execute("CREATE (a) CREATE (a)-[:X]->(a)")
val result = executeWith(supportMerge, "MERGE (a)-[r1:X]->(b)-[r2:X]->(c) RETURN id(r1) = id(r2) as sameEdge",
expectedDifferentResults = doNotYetHaveBugFix)
result.columnAs[Boolean]("sameEdge").toList should equal(List(false))
}
test("Merging with self loop and relationship uniqueness - no stats - reverse direction") {
graph.execute("CREATE (a) CREATE (a)-[:X]->(a)")
val result = executeWith(supportMerge, "MERGE (a)-[r1:X]->(b)<-[r2:X]-(c) RETURN id(r1) = id(r2) as sameEdge",
expectedDifferentResults = doNotYetHaveBugFix)
result.columnAs[Boolean]("sameEdge").toList should equal(List(false))
}
test("Merging with non-self-loop but require relationship uniqueness") {
val a = createLabeledNode(Map("name" -> "a"), "A")
val b = createLabeledNode(Map("name" -> "b"), "B")
relate(a, b, "X")
val result = executeWith(supportMerge, "MERGE (a)-[r1:X]->(b)<-[r2:X]-(c) RETURN id(r1) = id(r2) as sameEdge, c.name as name",
expectedDifferentResults = doNotYetHaveBugFix)
result.toList should equal(List(Map("sameEdge" -> false, "name" -> null)))
}
}