Skip to content

Commit

Permalink
added integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
Valentyn Kahamlyk authored and Valentyn Kahamlyk committed May 22, 2024
1 parent f3679f1 commit 06fcf77
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,15 @@
*/
package org.apache.tinkerpop.gremlin.console


import org.apache.tinkerpop.gremlin.console.jsr223.AbstractGremlinServerIntegrationTest
import org.apache.tinkerpop.gremlin.structure.io.Storage
import org.apache.tinkerpop.gremlin.util.TestSupport
import org.codehaus.groovy.tools.shell.IO
import org.junit.Test

import java.nio.file.Files

import static org.junit.Assert.assertTrue;

class GremlinGroovyshTest extends AbstractGremlinServerIntegrationTest {
private IO testio
Expand All @@ -37,6 +43,33 @@ class GremlinGroovyshTest extends AbstractGremlinServerIntegrationTest {
shell = new GremlinGroovysh(new Mediator(null), testio)
}

@Test
void shouldGetResultFromRemote() {
final File configFile = TestSupport.generateTempFileFromResource(AbstractGremlinServerIntegrationTest.class, "remote.yaml", "")
final File file = File.createTempFile("remote-graph", ".properties")

try {
// create temporary config file
Files.deleteIfExists(file.toPath())
Files.createFile(file.toPath())
try (PrintStream out = new PrintStream(new FileOutputStream(file.toPath().toString()))) {
out.print("gremlin.remote.remoteConnectionClass=org.apache.tinkerpop.gremlin.driver.remote.DriverRemoteConnection\n")
out.print("gremlin.remote.driver.clusterFile=" + Storage.toPath(configFile))
out.print("\ngremlin.remote.driver.sourceName=g\n")
}

shell.execute("import static org.apache.tinkerpop.gremlin.process.traversal.AnonymousTraversalSource.traversal")
shell.execute("g = traversal().with('" + Storage.toPath(file) + "')")
out.reset()
shell.execute("g.V().count().next()")

// 6 vertices in modern graph
assertTrue(out.toString().endsWith("6\r\n"))
} finally {
Files.deleteIfExists(file.toPath())
}
}

@Override
void tearDown() {
super.tearDown()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

import java.io.InputStream;
import java.nio.file.Paths;
import java.util.Collections;

/**
* Starts and stops an instance for each executed test.
Expand All @@ -48,8 +49,12 @@ public void setUp() throws Exception {
final Settings settings = Settings.read(stream);

final Settings overridenSettings = overrideSettings(settings);
String prop = Paths.get(AbstractGremlinServerIntegrationTest.class.getResource("tinkergraph-empty.properties").toURI()).toString();
final String prop = Paths.get(AbstractGremlinServerIntegrationTest.class.getResource("tinkergraph-empty.properties").toURI()).toString();
overridenSettings.graphs.put("graph", prop);
final String script = Paths.get(AbstractGremlinServerIntegrationTest.class.getResource("generate.groovy").toURI()).toString();
overridenSettings.scriptEngines.get("gremlin-groovy").plugins
.get("org.apache.tinkerpop.gremlin.jsr223.ScriptFileGremlinPlugin")
.put("files", Collections.singletonList(script));

this.server = new GremlinServer(overridenSettings);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* 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.
*/

// an init script that returns a Map allows explicit setting of global bindings.
def globals = [:]

// Generates the modern graph into an "empty" TinkerGraph via LifeCycleHook.
// Note that the name of the key in the "global" map is unimportant.
globals << [hook : [
onStartUp: { ctx ->
ctx.logger.info("Loading 'modern' graph data.")
org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerFactory.generateModern(graph)
}
] as LifeCycleHook]

// define the default TraversalSource to bind queries to - this one will be named "g".
globals << [g : traversal().withEmbedded(graph)]
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ scriptEngines: {
gremlin-groovy: {
plugins: { org.apache.tinkerpop.gremlin.server.jsr223.GremlinServerGremlinPlugin: {},
org.apache.tinkerpop.gremlin.tinkergraph.jsr223.TinkerGraphGremlinPlugin: {},
org.apache.tinkerpop.gremlin.jsr223.ImportGremlinPlugin: {classImports: [java.lang.Math], methodImports: [java.lang.Math#*]}}}}
org.apache.tinkerpop.gremlin.jsr223.ImportGremlinPlugin: {classImports: [java.lang.Math], methodImports: [java.lang.Math#*]},
org.apache.tinkerpop.gremlin.jsr223.ScriptFileGremlinPlugin: {}}}}
serializers:
- { className: org.apache.tinkerpop.gremlin.util.ser.GraphBinaryMessageSerializerV4} # application/vnd.graphbinary-v4.0
metrics: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@
##############################################################

gremlin.remote.remoteConnectionClass=org.apache.tinkerpop.gremlin.driver.remote.DriverRemoteConnection
gremlin.remote.driver.clusterFile=conf/remote.yaml
gremlin.remote.driver.clusterFile=remote.yaml
gremlin.remote.driver.sourceName=g
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public T with(final RemoteConnection remoteConnection) {
*/
public T with(final String configFile) throws Exception {
final Configurations configs = new Configurations();
return with(configs.properties((configFile)));
return with(configs.properties(configFile));
}

/**
Expand Down

0 comments on commit 06fcf77

Please sign in to comment.