You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by sp...@apache.org on 2018/07/16 16:11:02 UTC
tinkerpop git commit: TINKERPOP-1996 Used g.io() in tests by default
Repository: tinkerpop
Updated Branches:
refs/heads/TINKERPOP-1996 2216a50eb -> 5a4085b3f
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/5a4085b3
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/5a4085b3
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/5a4085b3
Branch: refs/heads/TINKERPOP-1996
Commit: 5a4085b3ff5130becb16767b407355f506b4929d
Parents: 2216a50
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Mon Jul 16 12:10:02 2018 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Mon Jul 16 12:10:02 2018 -0400
----------------------------------------------------------------------
CHANGELOG.asciidoc | 1 +
.../gremlin/AbstractGraphProvider.java | 8 +++----
.../apache/tinkerpop/gremlin/TestHelper.java | 24 ++++++++++++++------
3 files changed, 22 insertions(+), 11 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/5a4085b3/CHANGELOG.asciidoc
----------------------------------------------------------------------
diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc
index b4e957d..8dd009f 100644
--- a/CHANGELOG.asciidoc
+++ b/CHANGELOG.asciidoc
@@ -25,6 +25,7 @@ image::https://raw.githubusercontent.com/apache/tinkerpop/master/docs/static/ima
This release also includes changes from <<release-3-3-3, 3.3.3>>.
+* `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.
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/5a4085b3/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/5a4085b3/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 833a383..2940050 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
@@ -143,17 +143,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;
}