You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by ok...@apache.org on 2015/05/12 00:45:30 UTC
incubator-tinkerpop git commit: GraphComputerTest now tests property
manipulation in MapReduce jobs.
Repository: incubator-tinkerpop
Updated Branches:
refs/heads/master 6a846abaa -> 61af2e760
GraphComputerTest now tests property manipulation in MapReduce jobs.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/commit/61af2e76
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/61af2e76
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/61af2e76
Branch: refs/heads/master
Commit: 61af2e7605a871e580dca4b0f09666e1f3a8c767
Parents: 6a846ab
Author: Marko A. Rodriguez <ok...@gmail.com>
Authored: Mon May 11 16:45:24 2015 -0600
Committer: Marko A. Rodriguez <ok...@gmail.com>
Committed: Mon May 11 16:45:24 2015 -0600
----------------------------------------------------------------------
.../gremlin/process/computer/GraphComputer.java | 24 ++++-----
.../process/computer/util/ComputerGraph.java | 8 +++
.../util/detached/DetachedElement.java | 2 +-
.../process/computer/GraphComputerTest.java | 56 +++++++++++++++-----
4 files changed, 65 insertions(+), 25 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/61af2e76/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/GraphComputer.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/GraphComputer.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/GraphComputer.java
index 13b6a5e..dc6df81 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/GraphComputer.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/GraphComputer.java
@@ -192,16 +192,16 @@ public interface GraphComputer {
private Exceptions() {
}
- public static IllegalStateException adjacentVertexLabelsCanNotBeRead() {
- return new IllegalStateException("The label of an adjacent vertex can not be read");
+ public static UnsupportedOperationException adjacentVertexLabelsCanNotBeRead() {
+ return new UnsupportedOperationException("The label of an adjacent vertex can not be read");
}
- public static IllegalStateException adjacentVertexPropertiesCanNotBeReadOrUpdated() {
- return new IllegalStateException("The properties of an adjacent vertex can not be read or updated");
+ public static UnsupportedOperationException adjacentVertexPropertiesCanNotBeReadOrUpdated() {
+ return new UnsupportedOperationException("The properties of an adjacent vertex can not be read or updated");
}
- public static IllegalStateException adjacentVertexEdgesAndVerticesCanNotBeReadOrUpdated() {
- return new IllegalStateException("The edges and vertices of an adjacent vertex can not be read or updated");
+ public static UnsupportedOperationException adjacentVertexEdgesAndVerticesCanNotBeReadOrUpdated() {
+ return new UnsupportedOperationException("The edges and vertices of an adjacent vertex can not be read or updated");
}
public static IllegalArgumentException providedKeyIsNotAnElementComputeKey(final String key) {
@@ -212,10 +212,6 @@ public interface GraphComputer {
return new IllegalArgumentException("The provided key is not a memory compute key: " + key);
}
- public static IllegalStateException adjacentVerticesCanNotBeQueried() {
- return new IllegalStateException("It is not possible to query an adjacent vertex in a vertex program");
- }
-
public static IllegalArgumentException isolationNotSupported(final Isolation isolation) {
return new IllegalArgumentException("The provided isolation is not supported by this graph computer: " + isolation);
}
@@ -232,8 +228,12 @@ public interface GraphComputer {
return new IllegalStateException("The computer has no vertex program or map reducers to execute");
}
- public static IllegalStateException incidentAndAdjacentElementsCanNotBeAccessedInMapReduce() {
- return new IllegalStateException("The computer is in MapReduce mode and a vertex's incident and adjacent elements can not be accessed");
+ public static UnsupportedOperationException incidentAndAdjacentElementsCanNotBeAccessedInMapReduce() {
+ return new UnsupportedOperationException("The computer is in MapReduce mode and a vertex's incident and adjacent elements can not be accessed");
+ }
+
+ public static UnsupportedOperationException vertexPropertiesCanNotBeUpdatedInMapReduce() {
+ return new UnsupportedOperationException("The computer is in MapReduce mode and a vertex's properties can not be updated");
}
}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/61af2e76/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/util/ComputerGraph.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/util/ComputerGraph.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/util/ComputerGraph.java
index e57a021..8186a74 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/util/ComputerGraph.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/util/ComputerGraph.java
@@ -156,6 +156,8 @@ public final class ComputerGraph implements Graph {
@Override
public <V> Property<V> property(final String key, final V value) {
+ if (state.equals(State.MAP_REDUCE))
+ throw GraphComputer.Exceptions.vertexPropertiesCanNotBeUpdatedInMapReduce();
return new ComputerProperty<>(this.element.property(key, value));
}
@@ -216,6 +218,8 @@ public final class ComputerGraph implements Graph {
@Override
public <V> VertexProperty<V> property(final String key, final V value) {
+ if (state.equals(State.MAP_REDUCE))
+ throw GraphComputer.Exceptions.vertexPropertiesCanNotBeUpdatedInMapReduce();
if (!computeKeys.contains(key))
throw GraphComputer.Exceptions.providedKeyIsNotAnElementComputeKey(key);
return new ComputerVertexProperty<>(this.getBaseVertex().property(key, value));
@@ -223,6 +227,8 @@ public final class ComputerGraph implements Graph {
@Override
public <V> VertexProperty<V> property(final String key, final V value, final Object... keyValues) {
+ if (state.equals(State.MAP_REDUCE))
+ throw GraphComputer.Exceptions.vertexPropertiesCanNotBeUpdatedInMapReduce();
if (!computeKeys.contains(key))
throw GraphComputer.Exceptions.providedKeyIsNotAnElementComputeKey(key);
return new ComputerVertexProperty<>(this.getBaseVertex().property(key, value, keyValues));
@@ -230,6 +236,8 @@ public final class ComputerGraph implements Graph {
@Override
public <V> VertexProperty<V> property(final VertexProperty.Cardinality cardinality, final String key, final V value, final Object... keyValues) {
+ if (state.equals(State.MAP_REDUCE))
+ throw GraphComputer.Exceptions.vertexPropertiesCanNotBeUpdatedInMapReduce();
if (!computeKeys.contains(key))
throw GraphComputer.Exceptions.providedKeyIsNotAnElementComputeKey(key);
return new ComputerVertexProperty<>(this.getBaseVertex().property(cardinality, key, value, keyValues));
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/61af2e76/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/detached/DetachedElement.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/detached/DetachedElement.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/detached/DetachedElement.java
index 19c80cc..f9c8c73 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/detached/DetachedElement.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/detached/DetachedElement.java
@@ -50,7 +50,7 @@ public abstract class DetachedElement<E> implements Element, Serializable, Attac
this.id = element.id();
try {
this.label = element.label();
- } catch (IllegalStateException e) {
+ } catch (final UnsupportedOperationException e) { // ghetto.
this.label = Vertex.DEFAULT_LABEL;
}
}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/61af2e76/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/computer/GraphComputerTest.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/computer/GraphComputerTest.java b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/computer/GraphComputerTest.java
index 98fd101..db3bf33 100644
--- a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/computer/GraphComputerTest.java
+++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/computer/GraphComputerTest.java
@@ -60,8 +60,8 @@ import static org.junit.Assert.*;
"adjacentVertexLabelsCanNotBeRead",
"adjacentVertexPropertiesCanNotBeReadOrUpdated",
"adjacentVertexEdgesAndVerticesCanNotBeReadOrUpdated",
- "adjacentVerticesCanNotBeQueried",
- "resultGraphPersistCombinationNotSupported" // TODO: NOT TRUE!
+ "resultGraphPersistCombinationNotSupported",
+ "vertexPropertiesCanNotBeUpdatedInMapReduce"// TODO: NOT TRUE!
})
@ExceptionCoverage(exceptionClass = Graph.Exceptions.class, methods = {
"graphDoesNotSupportProvidedGraphComputer",
@@ -845,7 +845,7 @@ public class GraphComputerTest extends AbstractGremlinProcessTest {
/////////////////////////////////////////////
@Test
@LoadGraphWith(MODERN)
- public void shouldNotAllowEdgeAccessInMapReduce() throws Exception {
+ public void shouldOnlyAllowReadingVertexPropertiesInMapReduce() throws Exception {
graph.compute(graphComputerClass.get()).mapReduce(new MapReduceC()).submit().get();
}
@@ -861,21 +861,35 @@ public class GraphComputerTest extends AbstractGremlinProcessTest {
try {
vertex.edges(Direction.OUT);
fail("Edges should not be accessible in MapReduce.map()");
- } catch (final IllegalStateException e) {
+ } catch (final UnsupportedOperationException e) {
assertEquals(GraphComputer.Exceptions.incidentAndAdjacentElementsCanNotBeAccessedInMapReduce().getMessage(), e.getMessage());
}
try {
vertex.edges(Direction.IN);
fail("Edges should not be accessible in MapReduce.map()");
- } catch (final IllegalStateException e) {
+ } catch (final UnsupportedOperationException e) {
assertEquals(GraphComputer.Exceptions.incidentAndAdjacentElementsCanNotBeAccessedInMapReduce().getMessage(), e.getMessage());
}
try {
vertex.edges(Direction.BOTH);
fail("Edges should not be accessible in MapReduce.map()");
- } catch (final IllegalStateException e) {
+ } catch (final UnsupportedOperationException e) {
assertEquals(GraphComputer.Exceptions.incidentAndAdjacentElementsCanNotBeAccessedInMapReduce().getMessage(), e.getMessage());
}
+ ////
+ try {
+ vertex.property("name", "bob");
+ fail("Vertex properties should be immutable in MapReduce.map()");
+ } catch (final UnsupportedOperationException e) {
+ assertEquals(GraphComputer.Exceptions.vertexPropertiesCanNotBeUpdatedInMapReduce().getMessage(), e.getMessage());
+ }
+ try {
+ vertex.property("name").property("test", 1);
+ fail("Vertex properties should be immutable in MapReduce.map()");
+ } catch (final UnsupportedOperationException e) {
+ assertEquals(GraphComputer.Exceptions.vertexPropertiesCanNotBeUpdatedInMapReduce().getMessage(), e.getMessage());
+ }
+
}
@Override
@@ -913,7 +927,7 @@ public class GraphComputerTest extends AbstractGremlinProcessTest {
try {
vertex.vertices(Direction.OUT).forEachRemaining(Vertex::label);
fail("Adjacent vertex labels should not be accessible in VertexProgram.execute()");
- } catch (IllegalStateException e) {
+ } catch (UnsupportedOperationException e) {
assertEquals(GraphComputer.Exceptions.adjacentVertexLabelsCanNotBeRead().getMessage(), e.getMessage());
}
}
@@ -921,7 +935,7 @@ public class GraphComputerTest extends AbstractGremlinProcessTest {
try {
vertex.vertices(Direction.IN).forEachRemaining(Vertex::label);
fail("Adjacent vertex labels should not be accessible in VertexProgram.execute()");
- } catch (IllegalStateException e) {
+ } catch (UnsupportedOperationException e) {
assertEquals(GraphComputer.Exceptions.adjacentVertexLabelsCanNotBeRead().getMessage(), e.getMessage());
}
}
@@ -929,7 +943,7 @@ public class GraphComputerTest extends AbstractGremlinProcessTest {
try {
vertex.vertices(Direction.BOTH).forEachRemaining(Vertex::label);
fail("Adjacent vertex labels should not be accessible in VertexProgram.execute()");
- } catch (IllegalStateException e) {
+ } catch (UnsupportedOperationException e) {
assertEquals(GraphComputer.Exceptions.adjacentVertexLabelsCanNotBeRead().getMessage(), e.getMessage());
}
}
@@ -938,7 +952,7 @@ public class GraphComputerTest extends AbstractGremlinProcessTest {
try {
vertex.vertices(Direction.OUT).forEachRemaining(v -> v.property("name"));
fail("Adjacent vertex properties should not be accessible in VertexProgram.execute()");
- } catch (IllegalStateException e) {
+ } catch (UnsupportedOperationException e) {
assertEquals(GraphComputer.Exceptions.adjacentVertexPropertiesCanNotBeReadOrUpdated().getMessage(), e.getMessage());
}
}
@@ -946,7 +960,7 @@ public class GraphComputerTest extends AbstractGremlinProcessTest {
try {
vertex.vertices(Direction.IN).forEachRemaining(v -> v.property("name"));
fail("Adjacent vertex properties should not be accessible in VertexProgram.execute()");
- } catch (IllegalStateException e) {
+ } catch (UnsupportedOperationException e) {
assertEquals(GraphComputer.Exceptions.adjacentVertexPropertiesCanNotBeReadOrUpdated().getMessage(), e.getMessage());
}
}
@@ -954,10 +968,28 @@ public class GraphComputerTest extends AbstractGremlinProcessTest {
try {
vertex.vertices(Direction.BOTH).forEachRemaining(v -> v.property("name"));
fail("Adjacent vertex properties should not be accessible in VertexProgram.execute()");
- } catch (IllegalStateException e) {
+ } catch (UnsupportedOperationException e) {
assertEquals(GraphComputer.Exceptions.adjacentVertexPropertiesCanNotBeReadOrUpdated().getMessage(), e.getMessage());
}
}
+ ////////////////////
+ if (vertex.vertices(Direction.BOTH).hasNext()) {
+ try {
+ vertex.vertices(Direction.BOTH).forEachRemaining(v -> v.edges(Direction.BOTH));
+ fail("Adjacent vertex edges should not be accessible in VertexProgram.execute()");
+ } catch (UnsupportedOperationException e) {
+ assertEquals(GraphComputer.Exceptions.adjacentVertexEdgesAndVerticesCanNotBeReadOrUpdated().getMessage(), e.getMessage());
+ }
+ }
+ if (vertex.vertices(Direction.BOTH).hasNext()) {
+ try {
+ vertex.vertices(Direction.BOTH).forEachRemaining(v -> v.vertices(Direction.BOTH));
+ fail("Adjacent vertex vertices should not be accessible in VertexProgram.execute()");
+ } catch (UnsupportedOperationException e) {
+ assertEquals(GraphComputer.Exceptions.adjacentVertexEdgesAndVerticesCanNotBeReadOrUpdated().getMessage(), e.getMessage());
+ }
+ }
+
}
@Override