Use new server start groovy scripts - Use new server start/stop groovy scripts - Support different traversal sources at connection level - Avoid destructuring syntax (not support on Node.js v4)
Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/b5d15801 Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/b5d15801 Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/b5d15801 Branch: refs/heads/TINKERPOP-1489 Commit: b5d15801fea6361288caaa31dd5b411805774221 Parents: cecfdf8 Author: Jorge Bay Gondra <jorgebaygon...@gmail.com> Authored: Thu Nov 23 10:20:19 2017 +0100 Committer: Jorge Bay Gondra <jorgebaygon...@gmail.com> Committed: Mon Jan 8 11:30:46 2018 +0100 ---------------------------------------------------------------------- gremlin-javascript/glv/PackageJson.template | 4 +- gremlin-javascript/pom.xml | 67 +++++++++++--------- .../lib/driver/driver-remote-connection.js | 6 +- .../javascript/gremlin-javascript/package.json | 4 +- .../test/cucumber/feature-steps.js | 29 +++++---- .../gremlin-javascript/test/cucumber/world.js | 12 +++- .../gremlin-javascript/test/helper.js | 29 +++++++++ .../test/integration/remote-connection-tests.js | 18 ++---- .../test/integration/traversal-test.js | 16 ++--- 9 files changed, 111 insertions(+), 74 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/b5d15801/gremlin-javascript/glv/PackageJson.template ---------------------------------------------------------------------- diff --git a/gremlin-javascript/glv/PackageJson.template b/gremlin-javascript/glv/PackageJson.template index 3ff17af..52d2c1d 100644 --- a/gremlin-javascript/glv/PackageJson.template +++ b/gremlin-javascript/glv/PackageJson.template @@ -47,8 +47,8 @@ "url": "https://issues.apache.org/jira/browse/TINKERPOP" }, "scripts": { - "test": "./node_modules/.bin/mocha test --recursive -t 5000", - "features": "./node_modules/.bin/cucumber.js ../../../../../gremlin-test/features/", + "test": "./node_modules/.bin/mocha test/unit test/integration -t 5000", + "features": "./node_modules/.bin/cucumber.js --require test/cucumber ../../../../../gremlin-test/features/map/Count.feature", "unit-test": "./node_modules/.bin/mocha test/unit" }, "engines": { http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/b5d15801/gremlin-javascript/pom.xml ---------------------------------------------------------------------- diff --git a/gremlin-javascript/pom.xml b/gremlin-javascript/pom.xml index 871fd7a..830052b 100644 --- a/gremlin-javascript/pom.xml +++ b/gremlin-javascript/pom.xml @@ -202,26 +202,30 @@ packageJsonFile.newWriter().withWriter{ it << packageJsonTemplate } <goal>execute</goal> </goals> <configuration> + <properties> + <property> + <name>skipTests</name> + <value>${skipTests}</value> + </property> + <property> + <name>python</name> + <value>false</value> + </property> + <property> + <name>gremlinServerDir</name> + <value>${gremlin.server.dir}</value> + </property> + <property> + <name>settingsFile</name> + <value>${gremlin.server.dir}/src/test/resources/org/apache/tinkerpop/gremlin/driver/remote/gremlin-server-integration.yaml</value> + </property> + <property> + <name>executionName</name> + <value>${project.name}</value> + </property> + </properties> <scripts> - <script> - <![CDATA[ -import org.apache.tinkerpop.gremlin.server.GremlinServer -import org.apache.tinkerpop.gremlin.server.Settings -import org.apache.tinkerpop.gremlin.server.Settings.ScriptEngineSettings -import org.apache.tinkerpop.gremlin.server.op.session.Session - -if (${skipIntegrationTests}) return -log.info("Starting Gremlin Server instances for native testing of gremlin-javascript") -def settings = Settings.read("${gremlin.server.dir}/conf/gremlin-server-modern.yaml") -settings.graphs.graph = "${gremlin.server.dir}/conf/tinkergraph-empty.properties" -settings.scriptEngines["gremlin-groovy"].scripts = ["${gremlin.server.dir}/scripts/generate-modern.groovy"] -settings.port = 45950 -def server = new GremlinServer(settings) -server.start().join() -project.setContextValue("gremlin.javascript.server", server) -log.info("Gremlin Server started on port 45950") -]]> - </script> + <script>${gremlin.server.dir}/src/test/scripts/test-server-start.groovy</script> </scripts> </configuration> </execution> @@ -232,19 +236,18 @@ log.info("Gremlin Server started on port 45950") <goal>execute</goal> </goals> <configuration> + <properties> + <property> + <name>skipTests</name> + <value>${skipTests}</value> + </property> + <property> + <name>executionName</name> + <value>${project.name}</value> + </property> + </properties> <scripts> - <script> - <![CDATA[ -import org.apache.tinkerpop.gremlin.server.GremlinServer -import org.apache.tinkerpop.gremlin.server.op.session.Session - -if (${skipIntegrationTests}) return -log.info("Tests for native gremlin-javascript complete") -def server = project.getContextValue("gremlin.javascript.server") -log.info("Shutting down $server") -server.stop().join() -]]> - </script> + <script>${gremlin.server.dir}/src/test/scripts/test-server-stop.groovy</script> </scripts> </configuration> </execution> @@ -292,6 +295,7 @@ server.stop().join() </goals> <configuration> <arguments>test</arguments> + <failOnError>true</failOnError> </configuration> </execution> <execution> @@ -302,6 +306,7 @@ server.stop().join() </goals> <configuration> <arguments>run-script features</arguments> + <failOnError>true</failOnError> </configuration> </execution> </executions> http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/b5d15801/gremlin-javascript/src/main/javascript/gremlin-javascript/lib/driver/driver-remote-connection.js ---------------------------------------------------------------------- diff --git a/gremlin-javascript/src/main/javascript/gremlin-javascript/lib/driver/driver-remote-connection.js b/gremlin-javascript/src/main/javascript/gremlin-javascript/lib/driver/driver-remote-connection.js index 0d6d507..18c551c 100644 --- a/gremlin-javascript/src/main/javascript/gremlin-javascript/lib/driver/driver-remote-connection.js +++ b/gremlin-javascript/src/main/javascript/gremlin-javascript/lib/driver/driver-remote-connection.js @@ -41,6 +41,7 @@ var responseStatusCode = { * Creates a new instance of DriverRemoteConnection. * @param {String} url The resource uri. * @param {Object} [options] The connection options. + * @param {String} [options.traversalSource] The traversal source. Defaults to: 'g'. * @param {Array} [options.ca] Trusted certificates. * @param {String|Array|Buffer} [options.cert] The certificate key. * @param {String|Buffer} [options.pfx] The private key, certificate, and CA certs. @@ -71,6 +72,7 @@ function DriverRemoteConnection(url, options) { this._responseHandlers = {}; this._reader = options.reader || new serializer.GraphSONReader(); this._writer = options.writer || new serializer.GraphSONWriter(); + this._traversalSource = options.traversalSource || 'g'; this._openPromise = null; this._openCallback = null; this._closePromise = null; @@ -125,7 +127,7 @@ DriverRemoteConnection.prototype._getRequest = function (id, bytecode) { 'processor': 'traversal', 'args': { 'gremlin': this._writer.adaptObject(bytecode), - 'aliases': { 'g': 'g'} + 'aliases': { 'g': this._traversalSource } } }); }; @@ -193,7 +195,7 @@ function getUuid() { hex.substr(20, 12)); } -var bufferFromString = Buffer.from || function newBuffer(text) { +const bufferFromString = (Int8Array.from !== Buffer.from && Buffer.from) || function newBuffer(text) { return new Buffer(text, 'utf8'); }; http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/b5d15801/gremlin-javascript/src/main/javascript/gremlin-javascript/package.json ---------------------------------------------------------------------- diff --git a/gremlin-javascript/src/main/javascript/gremlin-javascript/package.json b/gremlin-javascript/src/main/javascript/gremlin-javascript/package.json index dfbaff2..43cf35f 100644 --- a/gremlin-javascript/src/main/javascript/gremlin-javascript/package.json +++ b/gremlin-javascript/src/main/javascript/gremlin-javascript/package.json @@ -28,8 +28,8 @@ "url": "https://issues.apache.org/jira/browse/TINKERPOP" }, "scripts": { - "test": "./node_modules/.bin/mocha test --recursive -t 5000", - "features": "./node_modules/.bin/cucumber.js ../../../../../gremlin-test/features/", + "test": "./node_modules/.bin/mocha test/unit test/integration -t 5000", + "features": "./node_modules/.bin/cucumber.js --require test/cucumber ../../../../../gremlin-test/features/map/Count.feature", "unit-test": "./node_modules/.bin/mocha test/unit" }, "engines": { http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/b5d15801/gremlin-javascript/src/main/javascript/gremlin-javascript/test/cucumber/feature-steps.js ---------------------------------------------------------------------- diff --git a/gremlin-javascript/src/main/javascript/gremlin-javascript/test/cucumber/feature-steps.js b/gremlin-javascript/src/main/javascript/gremlin-javascript/test/cucumber/feature-steps.js index 10680b7..bea7321 100644 --- a/gremlin-javascript/src/main/javascript/gremlin-javascript/test/cucumber/feature-steps.js +++ b/gremlin-javascript/src/main/javascript/gremlin-javascript/test/cucumber/feature-steps.js @@ -22,34 +22,37 @@ */ 'use strict'; -const {defineSupportCode} = require('cucumber'); +const defineSupportCode = require('cucumber').defineSupportCode; const vm = require('vm'); -defineSupportCode(function({Given, When, Then}) { - Given(/^the (.+) graph$/, function (graphName) { +defineSupportCode(function(methods) { + methods.Given(/^the (.+) graph$/, function (graphName) { //TODO: Set context g }); - // Given('the graph initializer of'); - Given('an unsupported test', () => {}); + methods.Given('the graph initializer of', function () { + //TODO + }); + + methods.Given('an unsupported test', () => {}); - Given('the traversal of', function (traversalText) { + methods.Given('the traversal of', function (traversalText) { //TODO: make traversal }); - Given(/^$/, function (paramName, stringValue) { + methods.Given(/^$/, function (paramName, stringValue) { //TODO: Add parameter }); - When('iterated to list', function () { + methods.When('iterated to list', function () { //TODO }); - When('iterated next', function () { + methods.When('iterated next', function () { //TODO }); - Then(/^the result should be (\w+)$/, function (characterizedAs, resultTable) { + methods.Then(/^the result should be (\w+)$/, function (characterizedAs, resultTable) { //TODO //console.log('--resultTable', resultTable.rows()); if (typeof resultTable === 'function'){ @@ -57,13 +60,13 @@ defineSupportCode(function({Given, When, Then}) { } }); - Then(/^the graph should return (\d+) for count of (.+)$/, function (stringCount, traversalString) { + methods.Then(/^the graph should return (\d+) for count of (.+)$/, function (stringCount, traversalString) { }); - Then(/^the result should have a count of (\d+)$/, function (stringCount) { + methods.Then(/^the result should have a count of (\d+)$/, function (stringCount) { }); - Then('nothing should happen because', () => {}); + methods.Then('nothing should happen because', () => {}); }); \ No newline at end of file http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/b5d15801/gremlin-javascript/src/main/javascript/gremlin-javascript/test/cucumber/world.js ---------------------------------------------------------------------- diff --git a/gremlin-javascript/src/main/javascript/gremlin-javascript/test/cucumber/world.js b/gremlin-javascript/src/main/javascript/gremlin-javascript/test/cucumber/world.js index f1cd7a6..2e4f6e1 100644 --- a/gremlin-javascript/src/main/javascript/gremlin-javascript/test/cucumber/world.js +++ b/gremlin-javascript/src/main/javascript/gremlin-javascript/test/cucumber/world.js @@ -22,12 +22,18 @@ */ 'use strict'; -const {defineSupportCode} = require('cucumber'); +const defineSupportCode = require('cucumber').defineSupportCode; -defineSupportCode(function ({setWorldConstructor}) { +defineSupportCode(function (methods) { function TinkerPopWorld(){ this.g = null; this.traversal = null; } - setWorldConstructor(TinkerPopWorld); + methods.setWorldConstructor(TinkerPopWorld); + methods.BeforeAll(function () { + // load all traversals + }); + methods.Before(function () { + + }); }); \ No newline at end of file http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/b5d15801/gremlin-javascript/src/main/javascript/gremlin-javascript/test/helper.js ---------------------------------------------------------------------- diff --git a/gremlin-javascript/src/main/javascript/gremlin-javascript/test/helper.js b/gremlin-javascript/src/main/javascript/gremlin-javascript/test/helper.js new file mode 100644 index 0000000..546840e --- /dev/null +++ b/gremlin-javascript/src/main/javascript/gremlin-javascript/test/helper.js @@ -0,0 +1,29 @@ +/* + * 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. + */ + +/** + * @author Jorge Bay Gondra + */ +'use strict'; + +const DriverRemoteConnection = require('../lib/driver/driver-remote-connection'); + +exports.getConnection = function getConnection(traversalSource) { + return new DriverRemoteConnection('ws://localhost:45940/gremlin', { traversalSource: traversalSource }); +}; \ No newline at end of file http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/b5d15801/gremlin-javascript/src/main/javascript/gremlin-javascript/test/integration/remote-connection-tests.js ---------------------------------------------------------------------- diff --git a/gremlin-javascript/src/main/javascript/gremlin-javascript/test/integration/remote-connection-tests.js b/gremlin-javascript/src/main/javascript/gremlin-javascript/test/integration/remote-connection-tests.js index df813ad..268773c 100644 --- a/gremlin-javascript/src/main/javascript/gremlin-javascript/test/integration/remote-connection-tests.js +++ b/gremlin-javascript/src/main/javascript/gremlin-javascript/test/integration/remote-connection-tests.js @@ -22,16 +22,16 @@ */ 'use strict'; -var assert = require('assert'); -var Bytecode = require('../../lib/process/bytecode'); -var DriverRemoteConnection = require('../../lib/driver/driver-remote-connection'); -var graphModule = require('../../lib/structure/graph'); +const assert = require('assert'); +const Bytecode = require('../../lib/process/bytecode'); +const graphModule = require('../../lib/structure/graph'); +const helper = require('../helper'); var connection; describe('DriverRemoteConnection', function () { before(function () { - connection = new DriverRemoteConnection('ws://localhost:45950/gremlin'); + connection = helper.getConnection(); return connection.open(); }); after(function () { @@ -55,10 +55,4 @@ describe('DriverRemoteConnection', function () { }); }); }); -}); - -function delay(ms) { - return new Promise(function (resolve) { - setTimeout(resolve, ms); - }); -} \ No newline at end of file +}); \ No newline at end of file http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/b5d15801/gremlin-javascript/src/main/javascript/gremlin-javascript/test/integration/traversal-test.js ---------------------------------------------------------------------- diff --git a/gremlin-javascript/src/main/javascript/gremlin-javascript/test/integration/traversal-test.js b/gremlin-javascript/src/main/javascript/gremlin-javascript/test/integration/traversal-test.js index 90afced..96de7c7 100644 --- a/gremlin-javascript/src/main/javascript/gremlin-javascript/test/integration/traversal-test.js +++ b/gremlin-javascript/src/main/javascript/gremlin-javascript/test/integration/traversal-test.js @@ -22,20 +22,18 @@ */ 'use strict'; -var assert = require('assert'); -var graphModule = require('../../lib/structure/graph'); -var Graph = graphModule.Graph; -var Vertex = graphModule.Vertex; -var utils = require('../../lib/utils'); -var t = require('../../lib/process/traversal'); -var TraversalStrategies = require('../../lib/process/traversal-strategy').TraversalStrategies; -var DriverRemoteConnection = require('../../lib/driver/driver-remote-connection'); +const assert = require('assert'); +const graphModule = require('../../lib/structure/graph'); +const Graph = graphModule.Graph; +const Vertex = graphModule.Vertex; +const utils = require('../../lib/utils'); +const helper = require('../helper'); var connection; describe('Traversal', function () { before(function () { - connection = new DriverRemoteConnection('ws://localhost:45950/gremlin'); + connection = helper.getConnection(); return connection.open(); }); after(function () {