Skip to content

Instantly share code, notes, and snippets.

@sarmbruster
Last active August 29, 2015 14:22
Show Gist options
  • Save sarmbruster/35f6da569757b970aab7 to your computer and use it in GitHub Desktop.
Save sarmbruster/35f6da569757b970aab7 to your computer and use it in GitHub Desktop.
@Grab(group = "org.neo4j", module = "neo4j-kernel", version = "1.9.9")
@Grab(group = "org.neo4j", module = "neo4j-lucene-index", version = "1.9.9")
import org.neo4j.graphdb.DynamicRelationshipType
import org.neo4j.graphdb.GraphDatabaseService
import org.neo4j.graphdb.factory.GraphDatabaseFactory
import org.neo4j.tooling.GlobalGraphOperations
def graphDbDir = "/tmp/dummy"
new File(graphDbDir).deleteDir()
GraphDatabaseService graphDatabaseService = new GraphDatabaseFactory().newEmbeddedDatabase("/tmp/dummy")
def now = new Date().time
def tx
try {
tx = graphDatabaseService.beginTx()
for (int i = 0; i < 65536; i++) {
if (i % 5000 == 0) {
println "${new Date().time - now} created $i rels/rel types"
tx.success()
tx.finish()
tx = graphDatabaseService.beginTx()
}
def node1 = graphDatabaseService.createNode()
def node2 = graphDatabaseService.createNode()
node1.createRelationshipTo(node2, DynamicRelationshipType.withName("rel_$i"))
}
tx.success()
} finally {
tx.finish()
}
tx = graphDatabaseService.beginTx()
try {
def ggo = GlobalGraphOperations.at(graphDatabaseService);
// check how many reltypes we can find
def count = 0;
for (r in ggo.allRelationshipTypes) {
count++
}
println "total: $count rel types (according to ggo.getAllRelationshipTypes())"
// check if a relationship type is used only once at most
count = 0
def reltypes = []
for (r in ggo.allRelationships) {
count++
def type = r.type.name()
assert !reltypes.contains(type)
reltypes << type
}
println "total: $count rels"
tx.success()
} finally {
tx.finish()
}
graphDatabaseService.shutdown()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment