You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by dk...@apache.org on 2015/05/11 13:43:35 UTC

[04/50] [abbrv] incubator-tinkerpop git commit: Added structure "integration" tests to the test suite.

Added structure "integration" tests to the test suite.


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

Branch: refs/heads/TINKERPOP3-666
Commit: 330363ab61a00264fe1534204f8b64c5ff900c23
Parents: 665ce51
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Fri May 8 07:59:42 2015 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Fri May 8 07:59:42 2015 -0400

----------------------------------------------------------------------
 .../tinkerpop/gremlin/structure/Graph.java      |   1 +
 .../structure/StructureIntegrateSuite.java      |  52 +++++++++
 .../gremlin/structure/io/IoIntegrateTest.java   | 107 +++++++++++++++++++
 .../tinkergraph/structure/TinkerGraph.java      |   1 +
 .../TinkerGraphStructureIntegrateTest.java      |  36 +++++++
 5 files changed, 197 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/330363ab/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/Graph.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/Graph.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/Graph.java
index 6765524..1b514cc 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/Graph.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/Graph.java
@@ -1014,6 +1014,7 @@ public interface Graph extends AutoCloseable, Host {
     @Inherited
     public @interface OptIn {
         public static String SUITE_STRUCTURE_STANDARD = "org.apache.tinkerpop.gremlin.structure.StructureStandardSuite";
+        public static String SUITE_STRUCTURE_INTEGRATE = "org.apache.tinkerpop.gremlin.structure.StructureIntegrateSuite";
         public static String SUITE_STRUCTURE_PERFORMANCE = "org.apache.tinkerpop.gremlin.structure.StructurePerformanceSuite";
         public static String SUITE_PROCESS_COMPUTER = "org.apache.tinkerpop.gremlin.process.ProcessComputerSuite";
         public static String SUITE_PROCESS_STANDARD = "org.apache.tinkerpop.gremlin.process.ProcessStandardSuite";

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/330363ab/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/StructureIntegrateSuite.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/StructureIntegrateSuite.java b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/StructureIntegrateSuite.java
new file mode 100644
index 0000000..e071f4a
--- /dev/null
+++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/StructureIntegrateSuite.java
@@ -0,0 +1,52 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tinkerpop.gremlin.structure;
+
+import org.apache.tinkerpop.gremlin.AbstractGremlinSuite;
+import org.apache.tinkerpop.gremlin.process.traversal.TraversalEngine;
+import org.apache.tinkerpop.gremlin.structure.io.IoIntegrateTest;
+import org.junit.runners.model.InitializationError;
+import org.junit.runners.model.RunnerBuilder;
+
+/**
+ * The {@code StructureIntegrationSuite} is a JUnit test runner that executes the Gremlin Test Suite over a
+ * {@link Graph} implementation. This suite contains "long-run" tests that enforce various behaviors and
+ * expectations of a vendor implementation of {@link Graph}. Its usage is optional to vendors as the tests are
+ * somewhat redundant to those found elsewhere in other required test suites.
+ * <p/>
+ * For more information on the usage of this suite, please see {@link StructureStandardSuite}.
+ *
+ * @author Stephen Mallette (http://stephen.genoprime.com)
+ */
+public class StructureIntegrateSuite extends AbstractGremlinSuite {
+
+    /**
+     * This list of tests in the suite that will be executed.  Gremlin developers should add to this list
+     * as needed to enforce tests upon implementations.
+     */
+    private static final Class<?>[] allTests = new Class<?>[]{
+            IoIntegrateTest.class
+    };
+
+    public StructureIntegrateSuite(final Class<?> klass, final RunnerBuilder builder) throws InitializationError {
+        super(klass, builder, allTests, null, false, TraversalEngine.Type.STANDARD);
+    }
+
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/330363ab/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/io/IoIntegrateTest.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/io/IoIntegrateTest.java b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/io/IoIntegrateTest.java
new file mode 100644
index 0000000..0026e67
--- /dev/null
+++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/io/IoIntegrateTest.java
@@ -0,0 +1,107 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tinkerpop.gremlin.structure.io;
+
+import org.apache.tinkerpop.gremlin.AbstractGremlinTest;
+import org.apache.tinkerpop.gremlin.FeatureRequirement;
+import org.apache.tinkerpop.gremlin.TestHelper;
+import org.apache.tinkerpop.gremlin.structure.Direction;
+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.GryoWriter;
+import org.apache.tinkerpop.gremlin.structure.util.detached.DetachedFactory;
+import org.apache.tinkerpop.gremlin.structure.util.star.StarGraph;
+import org.javatuples.Pair;
+import org.junit.Test;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.util.Random;
+import java.util.UUID;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * @author Stephen Mallette (http://stephen.genoprime.com)
+ */
+public class IoIntegrateTest extends AbstractGremlinTest {
+    @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(95746498l);
+        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();
+        TestHelper.validateEquality(vertex, pair.getValue0().getStarVertex());
+        ///
+        pair = serializeDeserialize(pair.getValue0());
+        assertEquals(starGraphSize, pair.getValue1().intValue());
+        starGraphSize = pair.getValue1();
+        TestHelper.validateEquality(vertex, pair.getValue0().getStarVertex());
+        ///
+        pair = serializeDeserialize(pair.getValue0());
+        assertEquals(starGraphSize, pair.getValue1().intValue());
+        starGraphSize = pair.getValue1();
+        TestHelper.validateEquality(vertex, pair.getValue0().getStarVertex());
+        ///
+        // this is a rough approximation of "detached" serialization of all vertices and edges.
+        // now that writeVertex in gryo writes StarGraph that approach can't be used anymore to test
+        // serialization size of detached.
+        final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
+        final GryoWriter writer = graph.io(IoCore.gryo()).writer().create();
+        writer.writeObject(outputStream, DetachedFactory.detach(vertex, true));
+        vertex.edges(Direction.BOTH).forEachRemaining(e -> writer.writeObject(outputStream, DetachedFactory.detach(e, true)));
+        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 Pair<StarGraph, Integer> serializeDeserialize(final StarGraph starGraph) {
+        final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
+        try {
+            graph.io(IoCore.gryo()).writer().create().writeObject(outputStream, starGraph);
+            return Pair.with(graph.io(IoCore.gryo()).reader().create().readObject(new ByteArrayInputStream(outputStream.toByteArray()), StarGraph.class), outputStream.size());
+        } catch (IOException ioe) {
+            throw new RuntimeException(ioe);
+        }
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/330363ab/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraph.java
----------------------------------------------------------------------
diff --git a/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraph.java b/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraph.java
index e9058a8..cfe7f73 100644
--- a/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraph.java
+++ b/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraph.java
@@ -53,6 +53,7 @@ import java.util.stream.Stream;
  * @author Stephen Mallette (http://stephen.genoprime.com)
  */
 @Graph.OptIn(Graph.OptIn.SUITE_STRUCTURE_STANDARD)
+@Graph.OptIn(Graph.OptIn.SUITE_STRUCTURE_INTEGRATE)
 @Graph.OptIn(Graph.OptIn.SUITE_STRUCTURE_PERFORMANCE)
 @Graph.OptIn(Graph.OptIn.SUITE_PROCESS_STANDARD)
 @Graph.OptIn(Graph.OptIn.SUITE_PROCESS_COMPUTER)

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/330363ab/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraphStructureIntegrateTest.java
----------------------------------------------------------------------
diff --git a/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraphStructureIntegrateTest.java b/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraphStructureIntegrateTest.java
new file mode 100644
index 0000000..04d93e0
--- /dev/null
+++ b/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraphStructureIntegrateTest.java
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tinkerpop.gremlin.tinkergraph.structure;
+
+import org.apache.tinkerpop.gremlin.structure.StructureIntegrateSuite;
+import org.apache.tinkerpop.gremlin.structure.StructurePerformanceSuite;
+import org.apache.tinkerpop.gremlin.structure.StructureStandardSuite;
+import org.apache.tinkerpop.gremlin.tinkergraph.TinkerGraphProvider;
+import org.junit.runner.RunWith;
+
+/**
+ * Executes the Gremlin Structure Performance Test Suite using TinkerGraph.
+ *
+ * @author Stephen Mallette (http://stephen.genoprime.com)
+ */
+@RunWith(StructureIntegrateSuite.class)
+@StructureIntegrateSuite.GraphProviderClass(provider = TinkerGraphProvider.class, graph = TinkerGraph.class)
+public class TinkerGraphStructureIntegrateTest {
+
+}
\ No newline at end of file