TINKERPOP-1996 Used g.io() in tests by default
Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/81870168 Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/81870168 Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/81870168 Branch: refs/heads/TINKERPOP-1996 Commit: 8187016886b8b699ff107c9b6a7dfe95deb7e4a1 Parents: 5bf19e2 Author: Stephen Mallette <[email protected]> Authored: Mon Jul 16 12:10:02 2018 -0400 Committer: Stephen Mallette <[email protected]> Committed: Thu Jul 19 13:41:01 2018 -0400 ---------------------------------------------------------------------- CHANGELOG.asciidoc | 5 ++-- .../gremlin/AbstractGraphProvider.java | 8 +++---- .../apache/tinkerpop/gremlin/TestHelper.java | 24 ++++++++++++++------ 3 files changed, 24 insertions(+), 13 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/81870168/CHANGELOG.asciidoc ---------------------------------------------------------------------- diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc index 1add03c..1848421 100644 --- a/CHANGELOG.asciidoc +++ b/CHANGELOG.asciidoc @@ -25,11 +25,12 @@ image::https://raw.githubusercontent.com/apache/tinkerpop/master/docs/static/ima This release also includes changes from <<release-3-3-3, 3.3.3>>. -* Bumped to Netty 4.1.25. -* Bumped to Spark 2.3.1. +* `AbstractGraphProvider` uses `g.io()` for loading test data. * Added the `io()` start step and `read()` and `write()` termination steps to the Gremlin language. * Added `GraphFeatures.supportsIoRead()` and `GraphFeatures.supportsIoWrite()`. * Deprecated `Graph.io()` and related infrastructure. +* Bumped to Netty 4.1.25. +* Bumped to Spark 2.3.1. * Moved `Parameterizing` interface to the `org.apache.tinkerpop.gremlin.process.traversal.step` package with other marker interfaces of its type. * Replaced `Parameterizing.addPropertyMutations()` with `Configuring.configure()`. * Changed interface hierarchy for `Parameterizing` and `Mutating` interfaces as they are tightly related. http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/81870168/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/AbstractGraphProvider.java ---------------------------------------------------------------------- diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/AbstractGraphProvider.java b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/AbstractGraphProvider.java index 75d033b..b6fc43c 100644 --- a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/AbstractGraphProvider.java +++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/AbstractGraphProvider.java @@ -25,6 +25,7 @@ import org.apache.tinkerpop.gremlin.structure.io.gryo.GryoIo; import org.apache.tinkerpop.gremlin.structure.io.gryo.GryoReader; import org.apache.commons.configuration.BaseConfiguration; import org.apache.commons.configuration.Configuration; +import org.apache.tinkerpop.gremlin.structure.io.gryo.GryoResourceAccess; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -142,9 +143,8 @@ public abstract class AbstractGraphProvider implements GraphProvider { * @param path the path to the file to load into the graph */ protected void readIntoGraph(final Graph graph, final String path) throws IOException { - final GraphReader reader = GryoReader.build().create(); - try (final InputStream stream = AbstractGremlinTest.class.getResourceAsStream(path)) { - reader.readGraph(stream, graph); - } + final String dataFile = TestHelper.generateTempFileFromResource(graph.getClass(), + GryoResourceAccess.class, path.substring(path.lastIndexOf(File.separator) + 1), "", false).getAbsolutePath(); + graph.traversal().io(dataFile).read(); } } http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/81870168/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/TestHelper.java ---------------------------------------------------------------------- diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/TestHelper.java b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/TestHelper.java index 38d9a25..cda32e2 100644 --- a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/TestHelper.java +++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/TestHelper.java @@ -152,17 +152,27 @@ public final class TestHelper { * {@link TestHelper#makeTestDataPath} in a subdirectory called {@code temp/resources}. */ public static File generateTempFileFromResource(final Class graphClass, final Class resourceClass, final String resourceName, final String extension) throws IOException { + return generateTempFileFromResource(graphClass, resourceClass, resourceName, extension, true); + } + + /** + * Copies a file stored as part of a resource to the file system in the path returned from + * {@link TestHelper#makeTestDataPath} in a subdirectory called {@code temp/resources}. + */ + public static File generateTempFileFromResource(final Class graphClass, final Class resourceClass, final String resourceName, final String extension, final boolean overwrite) throws IOException { final File temp = makeTestDataPath(graphClass, "resources"); if (!temp.exists()) temp.mkdirs(); final File tempFile = new File(temp, resourceName + extension); - final FileOutputStream outputStream = new FileOutputStream(tempFile); - int data; - final InputStream inputStream = resourceClass.getResourceAsStream(resourceName); - while ((data = inputStream.read()) != -1) { - outputStream.write(data); + if (!tempFile.exists() || overwrite) { + try (final FileOutputStream outputStream = new FileOutputStream(tempFile)) { + int data; + try (final InputStream inputStream = resourceClass.getResourceAsStream(resourceName)) { + while ((data = inputStream.read()) != -1) { + outputStream.write(data); + } + } + } } - outputStream.close(); - inputStream.close(); return tempFile; }
