@Test
@LoadGraphWith(LoadGraphWith.GraphData.CLASSIC)
public void shouldEvalGlobalClosuresEvenAfterEvictionOfClass() throws ScriptException {
final GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine();
final Bindings bindings = engine.createBindings();
bindings.put("g", g);
// strong referenced global closure
engine.eval("def isVadas(v){v.value('name')=='vadas'}", bindings);
assertEquals(true, engine.eval("isVadas(g.v(2))", bindings));
// phantom referenced global closure
bindings.put(GremlinGroovyScriptEngine.KEY_REFERENCE_TYPE, GremlinGroovyScriptEngine.REFERENCE_TYPE_PHANTOM);
engine.eval("def isMarko(v){v.value('name')=='marko'}", bindings);
try {
engine.eval("isMarko(g.v(1))", bindings);
fail("the isMarko function should not be present");
} catch (Exception ex) {
}
assertEquals(true, engine.eval("def isMarko(v){v.value('name')=='marko'}; isMarko(g.v(1))", bindings));
try {
engine.eval("isMarko(g.v(1))", bindings);
fail("the isMarko function should not be present");
} catch (Exception ex) {
}
bindings.remove(GremlinGroovyScriptEngine.KEY_REFERENCE_TYPE);
// isVadas class was a hard reference so it should still be hanging about
assertEquals(true, engine.eval("isVadas(g.v(2))", bindings));
}