tinkerpop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From spmalle...@apache.org
Subject [07/12] tinkerpop git commit: TINKERPOP-887 Convert FastNoSuchElementExceptions in to regular NoSuchElementExceptions when exiting a traversal for top level traversals.
Date Thu, 03 Nov 2016 11:57:56 GMT
TINKERPOP-887 Convert FastNoSuchElementExceptions in to regular NoSuchElementExceptions when
exiting a traversal for top level traversals.


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

Branch: refs/heads/TINKERPOP-1434
Commit: fe7c422621c46564add54558efdd07d671e751fa
Parents: 1eac35b
Author: BrynCooke <bryncooke@gmail.com>
Authored: Wed Nov 2 16:54:46 2016 +0000
Committer: BrynCooke <bryncooke@gmail.com>
Committed: Wed Nov 2 16:54:46 2016 +0000

----------------------------------------------------------------------
 CHANGELOG.asciidoc                              |  1 +
 .../upgrade/release-3.2.x-incubating.asciidoc   | 12 +++++++
 .../traversal/util/DefaultTraversal.java        | 21 +++++++++---
 .../process/traversal/CoreTraversalTest.java    | 35 ++++++++++++++++++++
 .../PartitionStrategyProcessTest.java           |  3 +-
 5 files changed, 65 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/fe7c4226/CHANGELOG.asciidoc
----------------------------------------------------------------------
diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc
index cf8c007..246244e 100644
--- a/CHANGELOG.asciidoc
+++ b/CHANGELOG.asciidoc
@@ -33,6 +33,7 @@ TinkerPop 3.2.4 (Release Date: NOT OFFICIALLY RELEASED YET)
 * Added `Pick.none` and `Pick.any` to the serializers and importers.
 * Added a class loader to `TraversalStrategies.GlobalCache` which guarantees strategies are
registered prior to `GlobalCache.getStrategies()`.
 * Fixed a severe bug where `GraphComputer` strategies are not being loaded until the second
use of the traversal source.
+* Traversals now throw regular NoSuchElementException instead of FastNoSuchElementException.
 
 [[release-3-2-3]]
 TinkerPop 3.2.3 (Release Date: October 17, 2016)

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/fe7c4226/docs/src/upgrade/release-3.2.x-incubating.asciidoc
----------------------------------------------------------------------
diff --git a/docs/src/upgrade/release-3.2.x-incubating.asciidoc b/docs/src/upgrade/release-3.2.x-incubating.asciidoc
index 30daae1..1602600 100644
--- a/docs/src/upgrade/release-3.2.x-incubating.asciidoc
+++ b/docs/src/upgrade/release-3.2.x-incubating.asciidoc
@@ -29,6 +29,18 @@ TinkerPop 3.2.4
 
 Please see the link:https://github.com/apache/tinkerpop/blob/3.2.4/CHANGELOG.asciidoc#release-3-2-4[changelog]
for a complete list of all the modifications that are part of this release.
 
+Upgrading for Users
+~~~~~~~~~~~~~~~~~~~
+
+FastNoSuchElementException converted to regular NoSuchElementException
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+In gremlin 3.2.x a call to Traversal#next() that did not have a result would throw a FastNoSuchElementException.
+This has been changed to a regular NoSuchElementException that includes the stack trace.
Code that explicitly catches
+FastNoSuchElementException should be converted to NoSuchElementException.
+
+See: link:https://issues.apache.org/jira/browse/TINKERPOP-1330[TINKERPOP-1330]
+
 Upgrading for Providers
 ~~~~~~~~~~~~~~~~~~~~~~~
 

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/fe7c4226/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/DefaultTraversal.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/DefaultTraversal.java
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/DefaultTraversal.java
index 5bd01da..a1d21fb 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/DefaultTraversal.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/DefaultTraversal.java
@@ -40,6 +40,7 @@ import java.util.Collections;
 import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
+import java.util.NoSuchElementException;
 import java.util.Optional;
 import java.util.Set;
 
@@ -181,11 +182,21 @@ public class DefaultTraversal<S, E> implements Traversal.Admin<S,
E> {
 
     @Override
     public E next() {
-        if (!this.locked) this.applyStrategies();
-        if (this.lastTraverser.bulk() == 0L)
-            this.lastTraverser = this.finalEndStep.next();
-        this.lastTraverser.setBulk(this.lastTraverser.bulk() - 1L);
-        return this.lastTraverser.get();
+        try {
+            if (!this.locked) this.applyStrategies();
+            if (this.lastTraverser.bulk() == 0L)
+                this.lastTraverser = this.finalEndStep.next();
+            this.lastTraverser.setBulk(this.lastTraverser.bulk() - 1L);
+            return this.lastTraverser.get();
+        }
+        catch(FastNoSuchElementException e) {
+            if(parent == EmptyStep.instance()) {
+                throw new NoSuchElementException();
+            }
+            else {
+                throw e;
+            }
+        }
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/fe7c4226/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 bf3acf3..68f8217 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
@@ -23,7 +23,9 @@ import org.apache.tinkerpop.gremlin.FeatureRequirement;
 import org.apache.tinkerpop.gremlin.LoadGraphWith;
 import org.apache.tinkerpop.gremlin.process.AbstractGremlinProcessTest;
 import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal;
+import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__;
 import org.apache.tinkerpop.gremlin.process.traversal.step.util.BulkSet;
+import org.apache.tinkerpop.gremlin.process.traversal.util.FastNoSuchElementException;
 import org.apache.tinkerpop.gremlin.structure.Edge;
 import org.apache.tinkerpop.gremlin.structure.Graph;
 import org.apache.tinkerpop.gremlin.structure.Transaction;
@@ -35,6 +37,7 @@ import org.junit.Test;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
+import java.util.NoSuchElementException;
 import java.util.Random;
 import java.util.Set;
 import java.util.stream.Collectors;
@@ -272,4 +275,36 @@ public class CoreTraversalTest extends AbstractGremlinProcessTest {
         assertEquals(1, IteratorUtils.count(t));
         g.tx().rollback();
     }
+
+    @Test
+    @LoadGraphWith(MODERN)
+    public void shouldNotThrowFastNoSuchElementException() {
+        //FastNoSuchElement exceptions don't have a stack trace.
+        //They should be converted to regular exceptions before returning to the the user.
+        try {
+            g.V().has("foo").next();
+        } catch (NoSuchElementException e) {
+            assertEquals(NoSuchElementException.class, e.getClass());
+        }
+    }
+
+    @Test
+    @LoadGraphWith(MODERN)
+    public void shouldThrowFastNoSuchElementExceptionInNestedTraversals() {
+        //The nested traversal should throw a regular FastNoSuchElementException
+
+        GraphTraversal<Object, Object> nestedTraversal = __.has("name", "foo");
+        GraphTraversal<Vertex, Object> traversal = g.V().has("name", "marko").branch(nestedTraversal);
+
+        GraphTraversal.Admin<Object, Object> nestedTraversalAdmin = nestedTraversal.asAdmin();
+        nestedTraversalAdmin.reset();
+        nestedTraversalAdmin.addStart(nestedTraversalAdmin.getTraverserGenerator().generate(g.V().has("name",
"marko").next(), (Step)traversal.asAdmin().getStartStep(), 1l));
+
+        try {
+            nestedTraversal.next();
+        } catch (NoSuchElementException e) {
+            assertEquals(FastNoSuchElementException.class, e.getClass());
+        }
+
+    }
 }

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/fe7c4226/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/decoration/PartitionStrategyProcessTest.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/decoration/PartitionStrategyProcessTest.java
b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/decoration/PartitionStrategyProcessTest.java
index af81542..d1928cd 100644
--- a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/decoration/PartitionStrategyProcessTest.java
+++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/decoration/PartitionStrategyProcessTest.java
@@ -393,8 +393,7 @@ public class PartitionStrategyProcessTest extends AbstractGremlinProcessTest
{
             sourceA.E(e.id()).next();
             fail("Edge should not be in this partition");
         } catch (Exception ex) {
-            final Exception expected = FastNoSuchElementException.instance();
-            assertEquals(expected.getClass(), ex.getClass());
+            assertEquals(NoSuchElementException.class, ex.getClass());
         }
     }
 


Mime
View raw message