@Test
    public void shouldOverrideTimeoutWithinScript() throws Exception {
        final TinkerGraph graph = TinkerFactory.createModern();
        final GraphTraversalSource g = graph.traversal();

        final ExecutorService evalExecutor = Executors.newSingleThreadExecutor(testingThreadFactory);
        final GremlinExecutor gremlinExecutor = GremlinExecutor.build()
                .evaluationTimeout(60000)
                .afterSuccess(b -> {
                    final GraphTraversalSource ig = (GraphTraversalSource) b.get("g");
                    if (ig.getGraph().features().graph().supportsTransactions())
                        ig.tx().commit();
                })
                .executorService(evalExecutor).create();

        final Map<String,Object> bindings = new HashMap<>();
        bindings.put("g", g);

        try {
            gremlinExecutor.eval("g.with('evaluationTimeout',100).V().repeat(both()).toList()", bindings).get();
            fail("Should have timed out");
        } catch (ExecutionException ex) {
            // should die in 100ms not 60000
            assertThat(ex.getCause().getMessage(), startsWith("Evaluation exceeded the configured 'evaluationTimeout' threshold of 100 ms"));
        }
    }
@author Stephen Mallette (http://stephen.genoprime.com)
gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/engine/GremlinExecutorOverGraphTest.java