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 2015/02/13 21:14:13 UTC

incubator-tinkerpop git commit: Catch the different method of traversal interruption exception in hadoop-gremlin.

Repository: incubator-tinkerpop
Updated Branches:
  refs/heads/master 1c7a362f2 -> 84c1632a1


Catch the different method of traversal interruption exception in hadoop-gremlin.

Had to convert a a generic IllegalStateException into a TraversalInterruptedException so that tests would pass.


Project: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/commit/84c1632a
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/84c1632a
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/84c1632a

Branch: refs/heads/master
Commit: 84c1632a14ca5776e537f16e57fd44f71acc2ab2
Parents: 1c7a362
Author: Stephen Mallette <sp...@apache.org>
Authored: Fri Feb 13 15:13:06 2015 -0500
Committer: Stephen Mallette <sp...@apache.org>
Committed: Fri Feb 13 15:13:06 2015 -0500

----------------------------------------------------------------------
 .../process/TraversalInterruptedException.java    | 18 ++++++++++++++----
 .../process/traversal/CoreTraversalTest.java      | 11 +++++------
 .../structure/hdfs/HadoopElementIterator.java     |  6 ++++++
 3 files changed, 25 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/84c1632a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/TraversalInterruptedException.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/TraversalInterruptedException.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/TraversalInterruptedException.java
index bff1e33..dc1f803 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/TraversalInterruptedException.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/TraversalInterruptedException.java
@@ -20,21 +20,31 @@ package org.apache.tinkerpop.gremlin.process;
 
 import org.apache.tinkerpop.gremlin.util.InterruptedRuntimeException;
 
+import java.util.Optional;
+
 /**
  * An unchecked exception thrown when the current thread processing a {@link Traversal} is interrupted.
  *
  * @author Stephen Mallette (http://stephen.genoprime.com)
  */
 public class TraversalInterruptedException extends InterruptedRuntimeException {
-    private final Traversal interruptedTraversal;
+    private final Optional<Traversal> interruptedTraversal;
+
+    public TraversalInterruptedException(final Throwable t) {
+        this(null, t);
+    }
 
     public TraversalInterruptedException(final Traversal interruptedTraversal) {
+        this(interruptedTraversal, null);
+    }
+
+    public TraversalInterruptedException(final Traversal interruptedTraversal, final Throwable cause) {
         super(String.format("The %s thread received interruption notification while iterating %s - it did not complete",
-                Thread.currentThread().getName(), interruptedTraversal));
-        this.interruptedTraversal = interruptedTraversal;
+                Thread.currentThread().getName(), null == interruptedTraversal ? "" : interruptedTraversal), cause);
+        this.interruptedTraversal = Optional.ofNullable(interruptedTraversal);
     }
 
-    public Traversal getInterruptedTraversal() {
+    public Optional<Traversal> getInterruptedTraversal() {
         return interruptedTraversal;
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/84c1632a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/CoreTraversalTest.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/CoreTraversalTest.java b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/CoreTraversalTest.java
index 5747198..863347a 100644
--- a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/CoreTraversalTest.java
+++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/CoreTraversalTest.java
@@ -209,7 +209,6 @@ public class CoreTraversalTest extends AbstractGremlinProcessTest {
         g.tx().rollback();
     }
 
-    @org.junit.Ignore
     @Test
     @LoadGraphWith(GRATEFUL)
     public void shouldTimeoutOnTraversalWhereIterateHasStarted() throws Exception {
@@ -226,7 +225,7 @@ public class CoreTraversalTest extends AbstractGremlinProcessTest {
 
         t.start();
 
-        Thread.sleep(1000);
+        Thread.sleep(500);
         t.interrupt();
         t.join();
 
@@ -249,14 +248,13 @@ public class CoreTraversalTest extends AbstractGremlinProcessTest {
 
         t.start();
 
-        Thread.sleep(1000);
+        Thread.sleep(500);
         t.interrupt();
         t.join();
 
         assertTrue(interrupted.get());
     }
 
-    @org.junit.Ignore
     @Test
     @LoadGraphWith(GRATEFUL)
     public void shouldTimeoutOnTraversalWhereNextingStarted() throws Exception {
@@ -267,13 +265,14 @@ public class CoreTraversalTest extends AbstractGremlinProcessTest {
                 g.V().out().out().out().out().out().out().out().out().out().out().out().next(Integer.MAX_VALUE);
                 fail("No way this should have completed in any reasonable time");
             } catch (Exception ex) {
+                ex.printStackTrace();
                 interrupted.set(ex.getClass().equals(TraversalInterruptedException.class));
             }
         });
 
         t.start();
 
-        Thread.sleep(1000);
+        Thread.sleep(500);
         t.interrupt();
         t.join();
 
@@ -296,7 +295,7 @@ public class CoreTraversalTest extends AbstractGremlinProcessTest {
 
         t.start();
 
-        Thread.sleep(1000);
+        Thread.sleep(500);
         t.interrupt();
         t.join();
 

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/84c1632a/hadoop-gremlin/src/main/java/org/apache/tinkerpop/gremlin/hadoop/structure/hdfs/HadoopElementIterator.java
----------------------------------------------------------------------
diff --git a/hadoop-gremlin/src/main/java/org/apache/tinkerpop/gremlin/hadoop/structure/hdfs/HadoopElementIterator.java b/hadoop-gremlin/src/main/java/org/apache/tinkerpop/gremlin/hadoop/structure/hdfs/HadoopElementIterator.java
index 1951b93..5449c78 100644
--- a/hadoop-gremlin/src/main/java/org/apache/tinkerpop/gremlin/hadoop/structure/hdfs/HadoopElementIterator.java
+++ b/hadoop-gremlin/src/main/java/org/apache/tinkerpop/gremlin/hadoop/structure/hdfs/HadoopElementIterator.java
@@ -22,6 +22,7 @@ import org.apache.tinkerpop.gremlin.hadoop.Constants;
 import org.apache.tinkerpop.gremlin.hadoop.structure.HadoopGraph;
 import org.apache.tinkerpop.gremlin.hadoop.structure.io.VertexWritable;
 import org.apache.tinkerpop.gremlin.hadoop.structure.util.ConfUtil;
+import org.apache.tinkerpop.gremlin.process.TraversalInterruptedException;
 import org.apache.tinkerpop.gremlin.structure.Element;
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.fs.FileStatus;
@@ -35,6 +36,7 @@ import org.apache.hadoop.mapreduce.TaskAttemptID;
 import org.apache.hadoop.mapreduce.lib.input.FileSplit;
 
 import java.io.IOException;
+import java.nio.channels.ClosedByInterruptException;
 import java.util.Iterator;
 import java.util.LinkedList;
 import java.util.Queue;
@@ -67,6 +69,10 @@ public abstract class HadoopElementIterator<E extends Element> implements Iterat
                     this.readers.add(inputFormat.createRecordReader(new FileSplit(status.getPath(), 0, Integer.MAX_VALUE, new String[]{}), new TaskAttemptContext(configuration, new TaskAttemptID())));
                 }
             }
+        } catch (ClosedByInterruptException cbie) {
+            // this is the exception that seems to rise when a Traversal interrupt occurs.  Convert it to the
+            // common exception expected.
+            throw new TraversalInterruptedException(cbie);
         } catch (Exception e) {
             throw new IllegalStateException(e.getMessage(), e);
         }