@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(() -> {
            final Traversal traversal = traversalAfterPause.apply(traversalBeforePause.apply(g).sideEffect(traverser -> {
                // let the first iteration flow through
                if (startedIterating.getCount() == 0) {
                    // ensure that the whole traversal doesn't iterate out before we get a chance to interrupt
                    // the next iteration should stop so we can force the interrupt to be handled by VertexStep
                    try {
                        Thread.sleep(3000);
                    } catch (Exception ignored) {
                        // make sure that the interrupt propagates in case the interrupt occurs during sleep.
                        // this should ensure VertexStep gets to try to throw the TraversalInterruptedException
                        Thread.currentThread().interrupt();
                    }
                } else {
                    startedIterating.countDown();
                }
            }));
            try {
                traversal.iterate();
            } catch (Exception ex) {
                exceptionThrown.set(ex instanceof TraversalInterruptedException);

                try {
                    traversal.close();
                } catch (Exception iex) {
                    logger.error("Error closing traversal after interruption", iex);
                }
            }

        }, 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/TraversalInterruptionTest.java