script in empty-sample.groovy is called twice

I have JanusGraph running as it's own process and remote to it from Gremlin. Since i'm learning, i create an in-memory graph in empty-sample.goovy when i start JanusGraph

g = graph.traversal()

rV = g.addV('r').property('name', 'r-name').next()
bV = g.addV('b').property('name', 'b-name').next()
lV = g.addV('l').property('name', 'l-name').next()

g.V(rV).addE('c').to(bV).property('name', 'r-b').next()
g.V(rV).addE('ht').to(lV).property('name', 'r-ht').next()

g.tx().commit()

System.out.println( ">>>>>> post tx commit" )
g.V().each( System.out::println )

This outputs 3 vertices as i would expect.

>>>>>> post tx commit
...
v[4224]
v[4256]
v[4272]

However, when i start Gremlin and :remote connect, it seems to run empty-sample.groovy again. Now i have duplicate vertices.

>>>>>> post tx commit
...
v[4224]
v[4256]
v[4272]
v[8368]
v[12464]
v[4296]

My yaml file has

scriptEngines: {
gremlin-groovy: {
plugins: { ...,
org.apache.tinkerpop.gremlin.jsr223.ScriptFileGremlinPlugin: {files: [scripts/empty-sample.groovy]}}}}

If this is expected behaviour - run the script on JanusGraph startup and then again on each(?) remote Gremlin connection - how would/where would one initialise an in-memory graph?

Thanks.
Was this page helpful?