-
Notifications
You must be signed in to change notification settings - Fork 2.3k
/
MorselRuntimeAcceptanceTest.scala
169 lines (134 loc) · 5.54 KB
/
MorselRuntimeAcceptanceTest.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
/*
* 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
import org.neo4j.graphdb.config.Setting
import org.neo4j.graphdb.factory.GraphDatabaseSettings
import scala.collection.Map
class MorselRuntimeAcceptanceTest extends ExecutionEngineFunSuite {
test("should not use morsel by default") {
//Given
val result = graph.execute("MATCH (n) RETURN n")
// When (exhaust result)
result.resultAsString()
//Then
result.getExecutionPlanDescription.getArguments.get("runtime") should not equal "MORSEL"
}
test("should be able to ask for morsel") {
//Given
val result = graph.execute("CYPHER runtime=morsel MATCH (n) RETURN n")
// When (exhaust result)
result.resultAsString()
//Then
result.getExecutionPlanDescription.getArguments.get("runtime") should equal("MORSEL")
}
test("should fallback if morsel doesn't support query") {
//Given
val result = graph.execute("CYPHER runtime=morsel MATCH (n)-[*]->(m) RETURN n")
// When (exhaust result)
result.resultAsString()
//Then
result.getExecutionPlanDescription.getArguments.get("runtime") should not equal "MORSEL"
}
test("should warn that morsels are experimental") {
//Given
import scala.collection.JavaConverters._
val result = graph.execute("CYPHER runtime=morsel EXPLAIN MATCH (n) RETURN n")
// When (exhaust result)
val notifications = result.getNotifications.asScala.toSet
//Then
notifications.head.getDescription should equal("You are using an experimental feature (use the morsel runtime at " +
"your own peril, not recommended to be run on production systems)")
}
test("should support count with no grouping") {
//Given
createNode("prop" -> "foo")
createNode()
createNode()
createNode("prop" -> "foo")
createNode("prop" -> "foo")
createNode("prop" -> "foo")
//When
val result = graph.execute("CYPHER runtime=morsel MATCH (n) RETURN count(n.prop)")
//Then
result.next().get("count(n.prop)") should equal(4)
result.getExecutionPlanDescription.getArguments.get("runtime") should equal("MORSEL")
}
test("should support multiple counts with no grouping") {
//Given
relate(createNode("prop" -> "foo"),createNode())
relate(createNode(), createNode("prop" -> "foo"))
relate(createNode("prop" -> "foo"), createNode("prop" -> "foo"))
//When
val result = graph.execute("CYPHER runtime=morsel MATCH (n)-->(m) RETURN count(n.prop), count(m.prop)")
//Then
val next = result.next()
next.get("count(n.prop)") should equal(2)
next.get("count(m.prop)") should equal(2)
result.getExecutionPlanDescription.getArguments.get("runtime") should equal("MORSEL")
}
test("should support count with grouping") {
//Given
createNode("prop" -> "foo", "count" -> 1)
createNode("prop" -> "foo", "count" -> 1)
createNode("prop" -> "bar")
createNode("prop" -> "bar", "count" -> 1)
createNode()
//When
val result = graph.execute("CYPHER runtime=morsel MATCH (n) RETURN n.prop,count(n.count)")
//Then
var next = result.next()
next.get("n.prop") should equal("foo")
next.get("count(n.count)") should equal(2)
next = result.next()
next.get("n.prop") shouldBe null
next.get("count(n.count)") should equal(0)
next = result.next()
next.get("n.prop") should equal("bar")
next.get("count(n.count)") should equal(1)
result.hasNext shouldBe false
result.getExecutionPlanDescription.getArguments.get("runtime") should equal("MORSEL")
}
test("should support average") {
//Given
10 to 100 by 10 foreach(i => createNode("prop" -> i))
//When
val result = graph.execute("CYPHER runtime=morsel MATCH (n) RETURN avg(n.prop)")
//Then
result.next().get("avg(n.prop)") should equal(55.0)
result.getExecutionPlanDescription.getArguments.get("runtime") should equal("MORSEL")
}
test("should support average with grouping") {
//Given
10 to 100 by 10 foreach(i => createNode("prop" -> i, "group" -> (if (i > 50) "FOO" else "BAR")))
//When
val result = graph.execute("CYPHER runtime=morsel MATCH (n) RETURN n.group, avg(n.prop)")
//Then
val first = result.next()
first.get("n.group") should equal("FOO")
first.get("avg(n.prop)") should equal(80.0)
val second = result.next()
second.get("n.group") should equal("BAR")
second.get("avg(n.prop)") should equal(30.0)
result.getExecutionPlanDescription.getArguments.get("runtime") should equal("MORSEL")
}
//we use a ridiculously small morsel size in order to trigger as many morsel overflows as possible
override def databaseConfig(): Map[Setting[_], String] = Map(GraphDatabaseSettings.cypher_morsel_size -> "4")
}