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/04/22 21:50:23 UTC
incubator-tinkerpop git commit: StarGraphTest tweaks. Now
serialization is tested for all vendors.
Repository: incubator-tinkerpop
Updated Branches:
refs/heads/master e13f4889c -> df393c074
StarGraphTest tweaks. Now serialization is tested for all vendors.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/commit/df393c07
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/df393c07
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/df393c07
Branch: refs/heads/master
Commit: df393c07497c246bd99a2203c7ad6c33cd535df6
Parents: e13f488
Author: Marko A. Rodriguez <ok...@gmail.com>
Authored: Wed Apr 22 13:50:18 2015 -0600
Committer: Marko A. Rodriguez <ok...@gmail.com>
Committed: Wed Apr 22 13:50:18 2015 -0600
----------------------------------------------------------------------
.../gremlin/structure/util/star/StarGraph.java | 1 -
.../util/star/StarGraphSerializer.java | 8 +--
.../structure/util/star/StarGraphTest.java | 68 +++++++++++++++++---
.../tinkergraph/structure/TinkerGraphTest.java | 49 --------------
4 files changed, 63 insertions(+), 63 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/df393c07/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/star/StarGraph.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/star/StarGraph.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/star/StarGraph.java
index ad745d3..46b658e 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/star/StarGraph.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/star/StarGraph.java
@@ -59,7 +59,6 @@ public final class StarGraph implements Graph, Serializable {
}
protected Long nextId = 0l;
-
protected StarVertex starVertex = null;
protected Map<Object, Map<String, Object>> edgeProperties = null;
protected Map<Object, Map<String, Object>> metaProperties = null;
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/df393c07/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/star/StarGraphSerializer.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/star/StarGraphSerializer.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/star/StarGraphSerializer.java
index 38c1f01..38cdbe9 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/star/StarGraphSerializer.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/star/StarGraphSerializer.java
@@ -50,8 +50,8 @@ public final class StarGraphSerializer extends Serializer<StarGraph> {
kryo.writeObject(output, starGraph.nextId);
kryo.writeObjectOrNull(output, starGraph.edgeProperties, HashMap.class);
kryo.writeObjectOrNull(output, starGraph.metaProperties, HashMap.class);
- kryo.writeClassAndObject(output, starGraph.starVertex.id());
- kryo.writeObject(output, starGraph.starVertex.label());
+ kryo.writeClassAndObject(output, starGraph.starVertex.id);
+ kryo.writeObject(output, starGraph.starVertex.label);
writeEdges(kryo, output, starGraph.starVertex.inEdges, Direction.IN);
writeEdges(kryo, output, starGraph.starVertex.outEdges, Direction.OUT);
kryo.writeObject(output, null != starGraph.starVertex.vertexProperties);
@@ -74,9 +74,7 @@ public final class StarGraphSerializer extends Serializer<StarGraph> {
starGraph.nextId = kryo.readObject(input, Long.class);
starGraph.edgeProperties = kryo.readObjectOrNull(input, HashMap.class);
starGraph.metaProperties = kryo.readObjectOrNull(input, HashMap.class);
- final Object starVertexId = kryo.readClassAndObject(input);
- final String starVertexLabel = kryo.readObject(input, String.class);
- starGraph.addVertex(T.id, starVertexId, T.label, starVertexLabel);
+ starGraph.addVertex(T.id, kryo.readClassAndObject(input), T.label, kryo.readObject(input, String.class));
readEdges(kryo, input, starGraph, Direction.IN);
readEdges(kryo, input, starGraph, Direction.OUT);
if (kryo.readObject(input, Boolean.class)) {
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/df393c07/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/util/star/StarGraphTest.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/util/star/StarGraphTest.java b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/util/star/StarGraphTest.java
index 464d7c6..7c77756 100644
--- a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/util/star/StarGraphTest.java
+++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/util/star/StarGraphTest.java
@@ -22,13 +22,17 @@
package org.apache.tinkerpop.gremlin.structure.util.star;
import org.apache.tinkerpop.gremlin.AbstractGremlinTest;
+import org.apache.tinkerpop.gremlin.FeatureRequirement;
import org.apache.tinkerpop.gremlin.LoadGraphWith;
import org.apache.tinkerpop.gremlin.structure.Direction;
import org.apache.tinkerpop.gremlin.structure.Edge;
+import org.apache.tinkerpop.gremlin.structure.Graph;
import org.apache.tinkerpop.gremlin.structure.Vertex;
+import org.apache.tinkerpop.gremlin.structure.VertexProperty;
import org.apache.tinkerpop.gremlin.structure.io.gryo.GryoReader;
import org.apache.tinkerpop.gremlin.structure.io.gryo.GryoWriter;
import org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils;
+import org.javatuples.Pair;
import org.junit.Test;
import java.io.ByteArrayInputStream;
@@ -36,16 +40,25 @@ import java.io.ByteArrayOutputStream;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
+import java.util.Random;
import java.util.Set;
+import java.util.UUID;
import java.util.concurrent.atomic.AtomicInteger;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
/**
* @author Marko A. Rodriguez (http://markorodriguez.com)
*/
public class StarGraphTest extends AbstractGremlinTest {
+ private static Pair<StarGraph, Integer> serializeDeserialize(final StarGraph starGraph) {
+ final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
+ GryoWriter.build().create().writeObject(outputStream, starGraph);
+ return Pair.with(GryoReader.build().create().readObject(new ByteArrayInputStream(outputStream.toByteArray())), outputStream.size());
+ }
+
@Test
@LoadGraphWith(LoadGraphWith.GraphData.CREW)
public void shouldHashAndEqualsCorrectly() {
@@ -69,13 +82,52 @@ public class StarGraphTest extends AbstractGremlinTest {
@Test
@LoadGraphWith(LoadGraphWith.GraphData.CREW)
public void shouldSerializeCorrectlyUsingGryo() {
- g.V().forEachRemaining(vertex -> {
- StarGraph starGraph = StarGraph.of(vertex);
- final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
- GryoWriter.build().create().writeObject(outputStream, starGraph);
- starGraph = GryoReader.build().create().readObject(new ByteArrayInputStream(outputStream.toByteArray()));
- validateVertex(vertex, starGraph.getStarVertex());
- });
+ g.V().forEachRemaining(vertex -> validateVertex(vertex, serializeDeserialize(StarGraph.of(vertex)).getValue0().getStarVertex()));
+ }
+
+ @Test
+ @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES)
+ @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_PROPERTY)
+ @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_META_PROPERTIES)
+ @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_MULTI_PROPERTIES)
+ @FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_ADD_EDGES)
+ @FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_ADD_PROPERTY)
+ public void shouldHaveSizeOfStarGraphLessThanDetached() throws Exception {
+ final Random random = new Random();
+ final Vertex vertex = graph.addVertex("person");
+ for (int i = 0; i < 100; i++) { // vertex properties and meta properties
+ vertex.property(VertexProperty.Cardinality.list, UUID.randomUUID().toString(), random.nextDouble(),
+ "acl", random.nextBoolean() ? "public" : "private",
+ "created", random.nextLong());
+ }
+ for (int i = 0; i < 50000; i++) { // edges and edge properties
+ vertex.addEdge("knows", graph.addVertex("person"), "since", random.nextLong(), "acl", random.nextBoolean() ? "public" : "private");
+ graph.addVertex("software").addEdge("createdBy", vertex, "date", random.nextLong());
+ graph.addVertex("group").addEdge("hasMember", vertex);
+ }
+ ///////////////
+ Pair<StarGraph, Integer> pair = serializeDeserialize(StarGraph.of(vertex));
+ int starGraphSize = pair.getValue1();
+ validateVertex(vertex, pair.getValue0().getStarVertex());
+ ///
+ pair = serializeDeserialize(pair.getValue0());
+ assertEquals(starGraphSize, pair.getValue1().intValue());
+ starGraphSize = pair.getValue1();
+ validateVertex(vertex, pair.getValue0().getStarVertex());
+ ///
+ pair = serializeDeserialize(pair.getValue0());
+ assertEquals(starGraphSize, pair.getValue1().intValue());
+ starGraphSize = pair.getValue1();
+ validateVertex(vertex, pair.getValue0().getStarVertex());
+ ///
+ final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
+ GryoWriter.build().create().writeVertex(outputStream, vertex, Direction.BOTH);
+ final int detachedVertexSize = outputStream.size();
+ assertTrue(starGraphSize < detachedVertexSize);
+
+ System.out.println("Size of star graph: " + starGraphSize);
+ System.out.println("Size of detached vertex: " + detachedVertexSize);
+ System.out.println("Size reduction: " + (float) detachedVertexSize / (float) starGraphSize);
}
private void validateVertex(final Vertex originalVertex, final StarGraph.StarVertex starVertex) {
@@ -136,7 +188,7 @@ public class StarGraphTest extends AbstractGremlinTest {
});
});
assertEquals(originalPropertyCounter.get(), starPropertyCounter.get());
- assertEquals(originalMetaPropertyCounter.get(),starMetaPropertyCounter.get());
+ assertEquals(originalMetaPropertyCounter.get(), starMetaPropertyCounter.get());
//////////////// VALIDATE EDGES
assertEquals(originalVertex, starVertex);
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/df393c07/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraphTest.java
----------------------------------------------------------------------
diff --git a/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraphTest.java b/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraphTest.java
index 52febd7..3be3883 100644
--- a/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraphTest.java
+++ b/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraphTest.java
@@ -177,55 +177,6 @@ public class TinkerGraphTest {
}
@Test
- public void shouldHaveSizeOfStarGraphLessThanDetached() throws Exception {
- final Graph graph = TinkerGraph.open();
- final Random random = new Random();
- final Vertex vertex = graph.addVertex("person");
- for(int i=0;i<100000;i++) {
- vertex.addEdge("knows",graph.addVertex("person"),"since",random.nextLong(),"created","blah");
- }
-
- StarGraph starGraph = StarGraph.of(vertex);
- ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
- GryoWriter.build().create().writeObject(outputStream, starGraph);
- outputStream.flush();
- final int starGraph1 = outputStream.size();
- System.out.println("Size of star graph (1): " + starGraph1);
- ///
- starGraph = GryoReader.build().create().readObject(new ByteArrayInputStream(outputStream.toByteArray()));
- outputStream = new ByteArrayOutputStream();
- GryoWriter.build().create().writeObject(outputStream, starGraph);
- outputStream.flush();
- final int starGraph2 = outputStream.size();
- System.out.println("Size of star graph (2): " + starGraph2);
-
- assertEquals(starGraph1, starGraph2);
-
- //
- starGraph = GryoReader.build().create().readObject(new ByteArrayInputStream(outputStream.toByteArray()));
- outputStream = new ByteArrayOutputStream();
- GryoWriter.build().create().writeObject(outputStream, starGraph);
- outputStream.flush();
- final int starGraph3 = outputStream.size();
- System.out.println("Size of star graph (3): " + starGraph3);
-
- assertEquals(starGraph1, starGraph3);
- assertEquals(starGraph2, starGraph3);
-
- //starGraph.getStarVertex().edges(Direction.OUT).forEachRemaining(System.out::println);
-
- /////////
-
- outputStream = new ByteArrayOutputStream();
- GryoWriter.build().create().writeVertex(outputStream, vertex, Direction.BOTH);
- outputStream.flush();
- final int detached = outputStream.size();
- System.out.println("Size of detached vertex (1): " + detached);
-
- assertTrue(starGraph1 < detached);
- }
-
- @Test
@Ignore
public void testPlayDK() throws Exception {
GraphTraversalSource g = TinkerFactory.createModern().traversal();