tinkerpop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From spmalle...@apache.org
Subject [03/11] incubator-tinkerpop git commit: updates
Date Tue, 24 Nov 2015 00:13:44 GMT
updates


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

Branch: refs/heads/master
Commit: c6626dac29c4d26503c13da2b7d12b662fd13908
Parents: 16faa85
Author: Kushal <kushal@foodinhood.com>
Authored: Tue Nov 10 17:23:31 2015 -0800
Committer: Kushal <kushal@foodinhood.com>
Committed: Tue Nov 10 17:23:31 2015 -0800

----------------------------------------------------------------------
 docs/src/implementations.asciidoc               |  5 +-
 .../tinkerpop/gremlin/structure/io/IoCore.java  |  6 ++
 .../tinkergraph/structure/TinkerGraph.java      | 16 +++--
 .../tinkergraph/structure/TinkerGraphTest.java  | 69 +++++++++++++++++++-
 4 files changed, 84 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/c6626dac/docs/src/implementations.asciidoc
----------------------------------------------------------------------
diff --git a/docs/src/implementations.asciidoc b/docs/src/implementations.asciidoc
index 66e2738..1a58ef9 100755
--- a/docs/src/implementations.asciidoc
+++ b/docs/src/implementations.asciidoc
@@ -630,8 +630,9 @@ TinkerGraph has several settings that can be provided on creation via
`Configura
 value is specified here, the the `gremlin.tinkergraph.graphFormat` should also be specified.
 If this value is not
 included (default), then the graph will stay in-memory and not be loaded/persisted to disk.
 |gremlin.tinkergraph.graphFormat |The format to use to serialize the graph which may be one
of the following:
-`graphml`, `graphson`, gryo`, or a fully qualified class name that implements Io.Builder
interface.
-If a value is specified here, the the `gremlin.tinkergraph.graphLocation` should
+`graphml`, `graphson`, `gryo`, or a fully qualified class name that implements Io.Builder
interface (which allows for
+external third party graph reader/writer formats to be used for persistence).
+If a value is specified here, then the `gremlin.tinkergraph.graphLocation` should
 also be specified.  If this value is not included (default), then the graph will stay in-memory
and not be
 loaded/persisted to disk.
 |=========================================================

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/c6626dac/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/IoCore.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/IoCore.java
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/IoCore.java
old mode 100644
new mode 100755
index a22dd28..9295269
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/IoCore.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/IoCore.java
@@ -52,4 +52,10 @@ public final class IoCore {
     public static Io.Builder<GryoIo> gryo() {
         return GryoIo.build();
     }
+
+    public static Io.Builder createIoBuilder(String graphFormat) throws ClassNotFoundException,
IllegalAccessException, InstantiationException {
+        Class<Io.Builder> ioBuilderClass = (Class<Io.Builder>) Class.forName(graphFormat);
+        Io.Builder ioBuilder = ioBuilderClass.newInstance();
+        return ioBuilder;
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/c6626dac/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 5c17ac6..35e268e 100755
--- 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
@@ -283,12 +283,10 @@ public final class TinkerGraph implements Graph {
                 } else if (graphFormat.equals("gryo")) {
                     io(IoCore.gryo()).readGraph(graphLocation);
                 } else {
-                    Class<Io.Builder> ioBuilderClass = (Class<Io.Builder>) Class.forName(graphFormat);
//If graphFormat is not a fully qualified class, get ClassNotFoundException.  Will this be
clear enough to user? currently they will just RuntimeException at end of method
-                    Io.Builder ioBuilder = ioBuilderClass.newInstance();  //If graphFormat
is class not derived from Io.Builder, get ClassCastdException.  Will this be clear enough
to user?
-                    io(ioBuilder).readGraph(graphLocation);
+                    io(IoCore.createIoBuilder(graphFormat)).readGraph(graphLocation);
                 }
-            } catch (Exception exc) {
-                throw new RuntimeException(String.format("Could not load graph at %s with
%s", graphLocation, graphFormat));
+            } catch (Exception ex) {
+                throw new RuntimeException(String.format("Could not load graph at %s with
%s", graphLocation, graphFormat), ex);
             }
         }
     }
@@ -311,12 +309,16 @@ public final class TinkerGraph implements Graph {
                 io(IoCore.graphson()).writeGraph(graphLocation);
             } else if (graphFormat.equals("gryo")) {
                 io(IoCore.gryo()).writeGraph(graphLocation);
+            } else {
+                io(IoCore.createIoBuilder(graphFormat)).writeGraph(graphLocation);
             }
-        } catch (IOException ioe) {
-            throw new RuntimeException(String.format("Could not save graph at %s with %s",
graphLocation, graphFormat));
+        } catch (Exception ex) {
+            throw new RuntimeException(String.format("Could not save graph at %s with %s",
graphLocation, graphFormat), ex);
         }
     }
 
+
+
     private <T extends Element> Iterator<T> createElementIterator(final Class<T>
clazz, final Map<Object, T> elements,
                                                                   final IdManager idManager,
                                                                   final Object... ids) {

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/c6626dac/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
old mode 100644
new mode 100755
index b3dc64e..1f627fc
--- 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
@@ -23,19 +23,21 @@ import org.apache.commons.configuration.Configuration;
 import org.apache.tinkerpop.gremlin.TestHelper;
 import org.apache.tinkerpop.gremlin.process.traversal.P;
 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.io.Io;
 import org.apache.tinkerpop.gremlin.structure.io.IoCore;
+import org.apache.tinkerpop.gremlin.structure.io.IoRegistry;
 import org.apache.tinkerpop.gremlin.structure.io.IoTest;
 import org.junit.Ignore;
 import org.junit.Test;
 
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.File;
+import java.io.*;
 import java.util.Set;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.mock;
 
 /**
  * @author Marko A. Rodriguez (http://markorodriguez.com)
@@ -382,4 +384,65 @@ public class TinkerGraphTest {
         IoTest.assertModernGraph(reloadedGraph, true, false);
         reloadedGraph.close();
     }
+
+    @Test
+    public void shouldPersistToAnyGraphFormat() {
+        final String graphLocation = TestHelper.makeTestDataPath(TinkerGraphTest.class, "temp").getAbsolutePath()
+ "shouldPersistToAnyGraphFormat.dat";
+        final File f = new File(graphLocation);
+        if (f.exists() && f.isFile()) f.delete();
+
+        final Configuration conf = new BaseConfiguration();
+        conf.setProperty(TinkerGraph.GREMLIN_TINKERGRAPH_GRAPH_FORMAT, TestIoBuilder.class.getName());
+        conf.setProperty(TinkerGraph.GREMLIN_TINKERGRAPH_GRAPH_LOCATION, graphLocation);
+        final TinkerGraph graph = TinkerGraph.open(conf);
+        TinkerFactory.generateModern(graph);
+
+        //Test write graph
+        graph.close();
+        assertEquals(TestIoBuilder.calledRegistry, 1);
+        assertEquals(TestIoBuilder.calledGraph, 1);
+        assertEquals(TestIoBuilder.calledCreate, 1);
+
+        try (BufferedOutputStream os = new BufferedOutputStream(new FileOutputStream(f))){
+            os.write("dummy string".getBytes());
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+
+        //Test read graph
+        final TinkerGraph readGraph = TinkerGraph.open(conf);
+        assertEquals(TestIoBuilder.calledRegistry, 1);
+        assertEquals(TestIoBuilder.calledGraph, 1);
+        assertEquals(TestIoBuilder.calledCreate, 1);
+    }
+
+    public static class TestIoBuilder implements Io.Builder{
+
+        static int calledRegistry, calledGraph, calledCreate;
+
+        public TestIoBuilder(){
+            //Looks awkward to reset static vars inside a constructor, but makes sense from
testing perspective
+            calledRegistry=0;
+            calledGraph=0;
+            calledCreate=0;
+        }
+
+        @Override
+        public Io.Builder<? extends Io> registry(IoRegistry registry) {
+            calledRegistry++;
+            return this;
+        }
+
+        @Override
+        public Io.Builder<? extends Io> graph(Graph graph) {
+            calledGraph++;
+            return this;
+        }
+
+        @Override
+        public Io create() {
+            calledCreate++;
+            return mock(Io.class);
+        }
+    }
 }


Mime
View raw message