@Test
    @LoadGraphWith(GRATEFUL)
    public void shouldRespectThreadInterruptionInVertexStep() throws Exception {
        final AtomicBoolean exceptionThrown = new AtomicBoolean(false);
        final CountDownLatch startedIterating = new CountDownLatch(1);
        final Thread t = new Thread(() -> {
            try {
                final Traversal traversal = traversalMaker.apply(g).sideEffect(traverser -> {
                    startedIterating.countDown();
                    try {
                        // artificially slow down the traversal execution so that
                        // this test has a chance to interrupt it before it finishes
                        Thread.sleep(100);
                    } catch (InterruptedException e) {
                        // if the traversal is interrupted while in this
                        // sleep, reassert the interrupt so that the thread is
                        // re-marked as interrupted and correctly handled as
                        // an interrupted traversal
                        Thread.currentThread().interrupt();
                    }
                });
                traversal.iterate();
            } catch (Exception ex) {
                exceptionThrown.set(ex instanceof TraversalInterruptedException);
            }
        }, name);

        t.start();

        // total time for test should not exceed 5 seconds - this prevents the test from just hanging and allows
        // it to finish with failure
        assertThat(startedIterating.await(5000, TimeUnit.MILLISECONDS), CoreMatchers.is(true));

        t.interrupt();
        t.join();

        // ensure that some but not all of the traversal was iterated and that the right exception was tossed
        assertThat(exceptionThrown.get(), CoreMatchers.is(true));
    }
@author Stephen Mallette (http://stephen.genoprime.com)
gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/TraversalInterruptionComputerTest.java