You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by sp...@apache.org on 2019/07/31 15:34:19 UTC

[tinkerpop] 02/04: Explicitly closed traversal on interruption.

This is an automated email from the ASF dual-hosted git repository.

spmallette pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/tinkerpop.git

commit df2055e791444a10e166dcb87410d3ec7dabe832
Author: Stephen Mallette <sp...@genoprime.com>
AuthorDate: Wed Jul 31 11:32:25 2019 -0400

    Explicitly closed traversal on interruption.
    
    This seems to make sense even though it wasn't causing problems really. A traversal might not release resources on its own without an explicit close if the traversal does not complete iteration. Since we have an interruption of the traversal, an explicit close() seems like the right move here. CTR
---
 .../traversal/TraversalInterruptionTest.java       | 44 +++++++++++++---------
 1 file changed, 27 insertions(+), 17 deletions(-)

diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/TraversalInterruptionTest.java b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/TraversalInterruptionTest.java
index 1fb54d4..6588a6b 100644
--- a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/TraversalInterruptionTest.java
+++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/TraversalInterruptionTest.java
@@ -27,6 +27,8 @@ import org.hamcrest.CoreMatchers;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.junit.runners.Parameterized;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import java.util.Arrays;
 import java.util.concurrent.CountDownLatch;
@@ -43,6 +45,7 @@ import static org.junit.Assert.assertThat;
  */
 @RunWith(Parameterized.class)
 public class TraversalInterruptionTest extends AbstractGremlinProcessTest {
+    private static final Logger logger = LoggerFactory.getLogger(TraversalInterruptionTest.class);
 
     @Parameterized.Parameters(name = "expectInterruption({0})")
     public static Iterable<Object[]> data() {
@@ -75,27 +78,34 @@ public class TraversalInterruptionTest extends AbstractGremlinProcessTest {
         final AtomicBoolean exceptionThrown = new AtomicBoolean(false);
         final CountDownLatch startedIterating = new CountDownLatch(1);
         final Thread t = new Thread(() -> {
-            try {
-                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();
+            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();
@@ -110,4 +120,4 @@ public class TraversalInterruptionTest extends AbstractGremlinProcessTest {
         // ensure that some but not all of the traversal was iterated and that the right exception was tossed
         assertThat(exceptionThrown.get(), CoreMatchers.is(true));
     }
-}
+}
\ No newline at end of file