@Test
    public void shouldNotBlowTheHeapParameterized() throws ScriptException {
        final Graph graph = TinkerFactory.createModern();
        final GraphTraversalSource g = graph.traversal();
        final GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine();

        final String[] gremlins = new String[]{
                "g.V(xxx).out().toList()",
                "g.V(xxx).in().toList()",
                "g.V(xxx).out().out().out().toList()",
                "g.V(xxx).out().groupCount()"
        };

        long parameterizedStartTime = System.currentTimeMillis();
        logger.info("Try to blow the heap with parameterized Gremlin.");
        try {
            for (int ix = 0; ix < 50001; ix++) {
                final Bindings bindings = engine.createBindings();
                bindings.put("g", g);
                bindings.put("xxx", (ix % 4) + 1);
                engine.eval(gremlins[ix % 4], bindings);

                if (ix > 0 && ix % 5000 == 0) {
                    logger.info(String.format("%s scripts processed in %s (ms) - rate %s (ms/q).", ix, System.currentTimeMillis() - parameterizedStartTime, Double.valueOf(System.currentTimeMillis() - parameterizedStartTime) / Double.valueOf(ix)));
                }
            }
        } catch (OutOfMemoryError oome) {
            fail("Blew the heap - the cache should prevent this from happening.");
        }
    }
@author Stephen Mallette (http://stephen.genoprime.com)
gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngineIntegrateTest.java