forked from mpollmeier/gremlin-scala-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIndexSpec.scala
54 lines (47 loc) · 1.92 KB
/
IndexSpec.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
import gremlin.scala._
import org.apache.tinkerpop.gremlin.neo4j.structure.Neo4jGraph
import org.apache.tinkerpop.gremlin.process.traversal.Path
import org.neo4j.graphdb.DynamicLabel
import scala.util.Random
import collection.JavaConversions._
import org.scalatest._
// indices have to be set directly in neo4j nowadays...
// http://tinkerpop.incubator.apache.org/docs/3.0.0-incubating/#_indices
// inspired by https://github.com/tinkerpop/tinkerpop3/issues/359#event-197211058
class IndexSpec extends FlatSpec with Matchers {
"Gremlin-Scala" should "create some vertices with properties" ignore {
// val dbPath = "target/indexspec"
// FileUtils.removeAll(dbPath)
// val graph: Neo4jGraph = Neo4jGraph.open(dbPath)
// val gs = GremlinScala(graph)
// graph.tx.open
// val l = DynamicLabel.label("Person")
// val s = graph.getBaseGraph.schema
// s.indexFor(l).on("name").create
// graph.tx.close
// val vertexCount = 10000
// (1 to vertexCount) foreach { i ⇒
// val name = i.toString
// val nonIndexedString = i.toString
// val vertex = s.addVertex(label = "Person")
// vertex.setProperty("name", name)
// vertex.setProperty("nonIndexedString", nonIndexedString)
// }
// def timeLookups(propertyName: String): Long = {
// val t0 = System.currentTimeMillis
// (1 to 100).foreach { _ ⇒
// val i = Random.nextInt(vertexCount)
// val v = gs.V.has(T.label, "Person").has(propertyName, i.toString).headOption
// assert(v.isDefined)
// }
// val t1 = System.currentTimeMillis
// t1 - t0
// }
// val timeNonIndexed = timeLookups("nonIndexedString")
// val timeIndexed = timeLookups("name")
// println(s"time for lookups of non-indexed vertices: ${timeNonIndexed}ms")
// println(s"time for lookups of indexed vertices: ${timeIndexed}ms")
// timeIndexed should be < timeNonIndexed
// graph.close
}
}