Return-Path: X-Original-To: apmail-ignite-commits-archive@minotaur.apache.org Delivered-To: apmail-ignite-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id BC5CC17FB1 for ; Mon, 8 Jun 2015 10:12:51 +0000 (UTC) Received: (qmail 11240 invoked by uid 500); 8 Jun 2015 10:12:51 -0000 Delivered-To: apmail-ignite-commits-archive@ignite.apache.org Received: (qmail 11209 invoked by uid 500); 8 Jun 2015 10:12:51 -0000 Mailing-List: contact commits-help@ignite.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@ignite.incubator.apache.org Delivered-To: mailing list commits@ignite.incubator.apache.org Received: (qmail 11200 invoked by uid 99); 8 Jun 2015 10:12:51 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 08 Jun 2015 10:12:51 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED,T_RP_MATCHES_RCVD X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO mail.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with SMTP; Mon, 08 Jun 2015 10:10:33 +0000 Received: (qmail 10342 invoked by uid 99); 8 Jun 2015 10:12:19 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 08 Jun 2015 10:12:19 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 8B0B0DFF60; Mon, 8 Jun 2015 10:12:19 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: sboikov@apache.org To: commits@ignite.incubator.apache.org Date: Mon, 08 Jun 2015 10:12:24 -0000 Message-Id: In-Reply-To: <45db4b432fcb4b64bc4416fbc57e611c@git.apache.org> References: <45db4b432fcb4b64bc4416fbc57e611c@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [6/9] incubator-ignite git commit: #nodejs: rename directories nodejs to js. X-Virus-Checked: Checked by ClamAV on apache.org #nodejs: rename directories nodejs to js. Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/0998c8be Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/0998c8be Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/0998c8be Branch: refs/heads/ignite-nodejs Commit: 0998c8be90587c906fe44da49ca8391e86b2f0a4 Parents: 15f07e1 Author: ivasilinets Authored: Mon Jun 8 13:00:42 2015 +0300 Committer: ivasilinets Committed: Mon Jun 8 13:00:42 2015 +0300 ---------------------------------------------------------------------- modules/nodejs/src/main/js/cache.js | 56 ++++++++++ modules/nodejs/src/main/js/ignition.js | 50 +++++++++ modules/nodejs/src/main/js/server.js | 97 +++++++++++++++++ modules/nodejs/src/main/nodejs/cache.js | 56 ---------- modules/nodejs/src/main/nodejs/ignition.js | 50 --------- modules/nodejs/src/main/nodejs/server.js | 97 ----------------- modules/nodejs/src/test/js/rest-jetty.xml | 53 +++++++++ modules/nodejs/src/test/js/test-node.xml | 97 +++++++++++++++++ modules/nodejs/src/test/js/test.js | 99 +++++++++++++++++ modules/nodejs/src/test/js/test_ignition.js | 32 ++++++ modules/nodejs/src/test/js/test_runner.js | 29 +++++ modules/nodejs/src/test/js/test_utils.js | 109 +++++++++++++++++++ modules/nodejs/src/test/nodejs/rest-jetty.xml | 53 --------- modules/nodejs/src/test/nodejs/test-node.xml | 97 ----------------- modules/nodejs/src/test/nodejs/test.js | 99 ----------------- modules/nodejs/src/test/nodejs/test_ignition.js | 32 ------ modules/nodejs/src/test/nodejs/test_runner.js | 29 ----- modules/nodejs/src/test/nodejs/test_utils.js | 109 ------------------- 18 files changed, 622 insertions(+), 622 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/0998c8be/modules/nodejs/src/main/js/cache.js ---------------------------------------------------------------------- diff --git a/modules/nodejs/src/main/js/cache.js b/modules/nodejs/src/main/js/cache.js new file mode 100644 index 0000000..59c8ece --- /dev/null +++ b/modules/nodejs/src/main/js/cache.js @@ -0,0 +1,56 @@ +/** + * Creates an instance of Cache + * + * @constructor + * @this {Cache} + * @param {Server} server Server class + * @param {string} cacheName Cache name + */ +function Cache(server, cacheName) { + this._server = server; + this._cacheName = cacheName; + this._cacheNameParam = _pair("cacheName", this._cacheName); +} + +/** + * Get cache value + * + * @this {Cache} + * @param {string} key Key + * @param {Cache~onGet} callback Called on finish + */ +Cache.prototype.get = function(key, callback) { + this._server.runCommand("get", [this._cacheNameParam, _pair("key", key)], callback); +}; + +/** + * Callback for cache get + * @callback Cache~onGet + * @param {string} error Error + * @param {string} result Result value + */ + +/** + * Put cache value + * + * @this {Cache} + * @param {string} key Key + * @param {string} value Value + * @param {Cache~onPut} callback Called on finish + */ +Cache.prototype.put = function(key, value, callback) { + this._server.runCommand("put", [this._cacheNameParam, _pair("key", key), _pair("val", value)], + callback); +} + +/** + * Callback for cache put + * @callback Cache~onPut + * @param {string} error Error + */ + +function _pair(key, value) { + return {key: key, value: value} +} + +exports.Cache = Cache \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/0998c8be/modules/nodejs/src/main/js/ignition.js ---------------------------------------------------------------------- diff --git a/modules/nodejs/src/main/js/ignition.js b/modules/nodejs/src/main/js/ignition.js new file mode 100644 index 0000000..72833a3 --- /dev/null +++ b/modules/nodejs/src/main/js/ignition.js @@ -0,0 +1,50 @@ +/** + * Creates an instance of Ignition + * + * @constructor + */ +function Ignition() { +} + +/** + * Callback for Ignition start + * + * @callback Ignition~onStart + * @param {string} error Error + * @param {Server} server Connected server + */ + +/** + * Open connection with server node + * + * @param {string[]} address List of nodes hosts with ports + * @param {Ignition~onStart} callback Called on finish + */ +Ignition.start = function(address, callback) { + var Server = require("./server").Server; + var numConn = address.length; + for (var addr of address) { + var params = addr.split(":"); + var server = new Server(params[0], params[1]); + server.checkConnection(onConnect.bind(null, server)); + } + + function onConnect(server, error) { + if (!callback) + return; + + numConn--; + if (!error) { + callback.call(null, null, server); + callback = null; + return; + } + + console.log("onConnect:" + error); + + if (!numConn) + callback.call(null, "Cannot connect to servers.", null); + } +} + +exports.Ignition = Ignition; \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/0998c8be/modules/nodejs/src/main/js/server.js ---------------------------------------------------------------------- diff --git a/modules/nodejs/src/main/js/server.js b/modules/nodejs/src/main/js/server.js new file mode 100644 index 0000000..3bb5f60 --- /dev/null +++ b/modules/nodejs/src/main/js/server.js @@ -0,0 +1,97 @@ +/** + * Creates an instance of Server + * + * @constructor + * @this {Server} + * @param {string} host Host address + * @param {number} port Port + */ +function Server(host, port) { + this._host = host; + this._port = port; +} + +/** + * Host value + * + * @this {Server} + * @returns {string} Host value + */ +Server.prototype.host = function() +{ + return this._host; +} + +/** + * Callback for Server runCommand + * + * @callback Server~onRunCommand + * @param {string} error Error + * @param {string} result Result value + */ + +/** + * Run http request + * + * @this {Server} + * @param {string} cmdName command name. + * @param params Parameters for command. + * @param {Server~onRunCommand} Called on finish + */ +Server.prototype.runCommand = function(cmdName, params, callback) { + var paramsString = ""; + + for (var p of params) + //TODO: escape value + paramsString += "&" + p.key + "=" + p.value; + + var requestQry = "cmd=" + cmdName + paramsString; + + var http = require('http'); + + var options = { + host: this._host, + port: this._port, + path: "/ignite?" + requestQry + }; + + function streamCallback(response) { + var fullResponseString = ''; + + response.on('data', function (chunk) { + fullResponseString += chunk; + }); + + response.on('end', function () { + try { + var response = JSON.parse(fullResponseString); + if (response.successStatus) + callback.call(null, response.error, null) + else + callback.call(null, null, response.response); + } catch (e) { + console.log("fail on json parse: " + fullResponseString) + callback.call(null, e, null); + } + }); + } + + var request = http.request(options, streamCallback); + + request.setTimeout(5000, callback.bind(null, "Request timeout: >5 sec")); + + request.on('error', callback); + request.end(); +} + +/** + * Check the connection with server node. + * + * @this {Server} + * @param {Server~onRunCommand} callback Called on finish + */ +Server.prototype.checkConnection = function(callback) { + this.runCommand("version", [], callback); +} + +exports.Server = Server; \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/0998c8be/modules/nodejs/src/main/nodejs/cache.js ---------------------------------------------------------------------- diff --git a/modules/nodejs/src/main/nodejs/cache.js b/modules/nodejs/src/main/nodejs/cache.js deleted file mode 100644 index 59c8ece..0000000 --- a/modules/nodejs/src/main/nodejs/cache.js +++ /dev/null @@ -1,56 +0,0 @@ -/** - * Creates an instance of Cache - * - * @constructor - * @this {Cache} - * @param {Server} server Server class - * @param {string} cacheName Cache name - */ -function Cache(server, cacheName) { - this._server = server; - this._cacheName = cacheName; - this._cacheNameParam = _pair("cacheName", this._cacheName); -} - -/** - * Get cache value - * - * @this {Cache} - * @param {string} key Key - * @param {Cache~onGet} callback Called on finish - */ -Cache.prototype.get = function(key, callback) { - this._server.runCommand("get", [this._cacheNameParam, _pair("key", key)], callback); -}; - -/** - * Callback for cache get - * @callback Cache~onGet - * @param {string} error Error - * @param {string} result Result value - */ - -/** - * Put cache value - * - * @this {Cache} - * @param {string} key Key - * @param {string} value Value - * @param {Cache~onPut} callback Called on finish - */ -Cache.prototype.put = function(key, value, callback) { - this._server.runCommand("put", [this._cacheNameParam, _pair("key", key), _pair("val", value)], - callback); -} - -/** - * Callback for cache put - * @callback Cache~onPut - * @param {string} error Error - */ - -function _pair(key, value) { - return {key: key, value: value} -} - -exports.Cache = Cache \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/0998c8be/modules/nodejs/src/main/nodejs/ignition.js ---------------------------------------------------------------------- diff --git a/modules/nodejs/src/main/nodejs/ignition.js b/modules/nodejs/src/main/nodejs/ignition.js deleted file mode 100644 index 72833a3..0000000 --- a/modules/nodejs/src/main/nodejs/ignition.js +++ /dev/null @@ -1,50 +0,0 @@ -/** - * Creates an instance of Ignition - * - * @constructor - */ -function Ignition() { -} - -/** - * Callback for Ignition start - * - * @callback Ignition~onStart - * @param {string} error Error - * @param {Server} server Connected server - */ - -/** - * Open connection with server node - * - * @param {string[]} address List of nodes hosts with ports - * @param {Ignition~onStart} callback Called on finish - */ -Ignition.start = function(address, callback) { - var Server = require("./server").Server; - var numConn = address.length; - for (var addr of address) { - var params = addr.split(":"); - var server = new Server(params[0], params[1]); - server.checkConnection(onConnect.bind(null, server)); - } - - function onConnect(server, error) { - if (!callback) - return; - - numConn--; - if (!error) { - callback.call(null, null, server); - callback = null; - return; - } - - console.log("onConnect:" + error); - - if (!numConn) - callback.call(null, "Cannot connect to servers.", null); - } -} - -exports.Ignition = Ignition; \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/0998c8be/modules/nodejs/src/main/nodejs/server.js ---------------------------------------------------------------------- diff --git a/modules/nodejs/src/main/nodejs/server.js b/modules/nodejs/src/main/nodejs/server.js deleted file mode 100644 index 3bb5f60..0000000 --- a/modules/nodejs/src/main/nodejs/server.js +++ /dev/null @@ -1,97 +0,0 @@ -/** - * Creates an instance of Server - * - * @constructor - * @this {Server} - * @param {string} host Host address - * @param {number} port Port - */ -function Server(host, port) { - this._host = host; - this._port = port; -} - -/** - * Host value - * - * @this {Server} - * @returns {string} Host value - */ -Server.prototype.host = function() -{ - return this._host; -} - -/** - * Callback for Server runCommand - * - * @callback Server~onRunCommand - * @param {string} error Error - * @param {string} result Result value - */ - -/** - * Run http request - * - * @this {Server} - * @param {string} cmdName command name. - * @param params Parameters for command. - * @param {Server~onRunCommand} Called on finish - */ -Server.prototype.runCommand = function(cmdName, params, callback) { - var paramsString = ""; - - for (var p of params) - //TODO: escape value - paramsString += "&" + p.key + "=" + p.value; - - var requestQry = "cmd=" + cmdName + paramsString; - - var http = require('http'); - - var options = { - host: this._host, - port: this._port, - path: "/ignite?" + requestQry - }; - - function streamCallback(response) { - var fullResponseString = ''; - - response.on('data', function (chunk) { - fullResponseString += chunk; - }); - - response.on('end', function () { - try { - var response = JSON.parse(fullResponseString); - if (response.successStatus) - callback.call(null, response.error, null) - else - callback.call(null, null, response.response); - } catch (e) { - console.log("fail on json parse: " + fullResponseString) - callback.call(null, e, null); - } - }); - } - - var request = http.request(options, streamCallback); - - request.setTimeout(5000, callback.bind(null, "Request timeout: >5 sec")); - - request.on('error', callback); - request.end(); -} - -/** - * Check the connection with server node. - * - * @this {Server} - * @param {Server~onRunCommand} callback Called on finish - */ -Server.prototype.checkConnection = function(callback) { - this.runCommand("version", [], callback); -} - -exports.Server = Server; \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/0998c8be/modules/nodejs/src/test/js/rest-jetty.xml ---------------------------------------------------------------------- diff --git a/modules/nodejs/src/test/js/rest-jetty.xml b/modules/nodejs/src/test/js/rest-jetty.xml new file mode 100644 index 0000000..1ea2a38 --- /dev/null +++ b/modules/nodejs/src/test/js/rest-jetty.xml @@ -0,0 +1,53 @@ + + + + + + + 20 + 200 + + + + https + 8443 + true + true + + + + + + + + + + + + + + + + + + + + + 30000 + true + + + + + + + + + + + + + + + false + \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/0998c8be/modules/nodejs/src/test/js/test-node.xml ---------------------------------------------------------------------- diff --git a/modules/nodejs/src/test/js/test-node.xml b/modules/nodejs/src/test/js/test-node.xml new file mode 100644 index 0000000..a1a17e4 --- /dev/null +++ b/modules/nodejs/src/test/js/test-node.xml @@ -0,0 +1,97 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + true + + + + + + + http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/0998c8be/modules/nodejs/src/test/js/test.js ---------------------------------------------------------------------- diff --git a/modules/nodejs/src/test/js/test.js b/modules/nodejs/src/test/js/test.js new file mode 100644 index 0000000..bdce21d --- /dev/null +++ b/modules/nodejs/src/test/js/test.js @@ -0,0 +1,99 @@ +module.exports = { + 'Test put/get' : function(test) { + test.expect(1); + + var TestUtils = require("./test_utils").TestUtils; + var Cache = require(TestUtils.scriptPath() + "cache").Cache; + var Server = require(TestUtils.scriptPath() + "server").Server; + + var assert = require('assert'); + + //var node = startIgniteNode(); + + setTimeout(initCache, 10000); //If start node from javascrip set timeout 10000); + + function initCache() { + var server = new Server('127.0.0.1', 9090); + var cache = new Cache(server, "mycache"); + cache.put("mykey", "6", onPut.bind(null, cache)); + } + + function onPut(cache, error) { + if (error) { + console.error("Failed to put " + error); + finishTest(test/*, node*/); + return; + } + + console.log("Put finished"); + cache.get("mykey", onGet); + } + + function onGet(error, value) { + if (error) { + console.error("Failed to get " + error); + finishTest(test/*, node*/); + return; + } + + console.log("Get finished"); + test.ok(value === "6", "This shouldn't fail " + value + "<>6"); + finishTest(test/*, node*/); + } + }, + 'Test connection' : function(test) { + test.expect(0); + + //var node = startIgniteNode(); + var TestUtils = require("./test_utils").TestUtils; + var Server = require(TestUtils.scriptPath() + "server").Server; + + setTimeout(initServer, 10000); + + function initServer() { + var server = new Server('127.0.0.1', 9090); + + console.log("Try to check connection"); + + server.checkConnection(onConnect); + } + + function onConnect(error) { + if (error) { + finishWithError(test/*, node*/, error); + return; + } + console.log("Successfully connected"); + finishTest(test/*, node*/); + } + }, + 'Test ignition' : function(test) { + test.expect(1); + + //var node = startIgniteNode('127.0.0.1', 9090); + var TestUtils = require("./test_utils").TestUtils; + var Ignition = require(TestUtils.scriptPath() + "ignition").Ignition; + + setTimeout(Ignition.start.bind(null, 9090, ['127.0.0.0', '127.0.0.1'], onConnect), 5000); + + function onConnect(error, server) { + if (error) { + finishWithError(test/*, node*/, error); + return; + } + test.ok(server.host() === '127.0.0.1') + finishTest(test/*, node*/); + } + } + }; + +function finishWithError(test/*, node*/, error) { + console.log("Error: " + error); + test.ok(false); + finishTest(test/*, node*/); +} + +function finishTest(test/*, node*/) { + //node.kill(); + test.done(); +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/0998c8be/modules/nodejs/src/test/js/test_ignition.js ---------------------------------------------------------------------- diff --git a/modules/nodejs/src/test/js/test_ignition.js b/modules/nodejs/src/test/js/test_ignition.js new file mode 100644 index 0000000..baa9615 --- /dev/null +++ b/modules/nodejs/src/test/js/test_ignition.js @@ -0,0 +1,32 @@ +var TestUtils = require("./test_utils").TestUtils; +var Ignition = require(TestUtils.scriptPath() + "ignition").Ignition; + +exports.test_ignition_fail = function () { + Ignition.start(['127.0.0.3:9091', '127.0.0.1:9092'], onConnect); + + function onConnect(error, server) { + if (error) { + if (error.indexOf("Cannot connect to servers.") == -1) + TestUtils.testFails("Incorrect error message: " + error); + else + TestUtils.testDone(); + + return; + } + + TestUtils.testFails("Test should fail."); + } +} + +exports.ignition_start_success = function() { + Ignition.start(['127.0.0.1:9095'], onConnect); + + function onConnect(error, server) { + if (error) { + TestUtils.testFails(error); + + return; + } + TestUtils.testDone(); + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/0998c8be/modules/nodejs/src/test/js/test_runner.js ---------------------------------------------------------------------- diff --git a/modules/nodejs/src/test/js/test_runner.js b/modules/nodejs/src/test/js/test_runner.js new file mode 100644 index 0000000..6f2cf2b --- /dev/null +++ b/modules/nodejs/src/test/js/test_runner.js @@ -0,0 +1,29 @@ +/** + * Create instance of TestUtils + * + * @constructor + */ +function TestRunner() { +} + +/** + * Test routine. + */ +TestRunner.runTest = function() { + var fileName = process.argv[2].toString().trim(); + + console.log("FileName " + fileName); + + var test = require("./" + fileName); + + var functionName = process.argv[3].toString().trim(); + + if (!test[functionName]) { + console.log("node js test failed: function with name " + functionName + " not found"); + return; + } + test[functionName](); +} + + +TestRunner.runTest(); \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/0998c8be/modules/nodejs/src/test/js/test_utils.js ---------------------------------------------------------------------- diff --git a/modules/nodejs/src/test/js/test_utils.js b/modules/nodejs/src/test/js/test_utils.js new file mode 100644 index 0000000..dca6603 --- /dev/null +++ b/modules/nodejs/src/test/js/test_utils.js @@ -0,0 +1,109 @@ +/** + * Create instance of TestUtils + * + * @constructor + */ +function TestUtils() { +} + +/** + * @returns {string} Path to script dir + */ +TestUtils.scriptPath = function() { + return TestUtils.igniteHome() + + TestUtils.sep() + "modules" + + TestUtils.sep() + "nodejs" + + TestUtils.sep() + "src" + + TestUtils.sep() + "main" + + TestUtils.sep() + "nodejs" + TestUtils.sep(); +} + +/** + * @returns {string} Ignite home path + */ +TestUtils.igniteHome = function() { + return process.env.IGNITE_HOME; +} + +/** + * @returns {string} Path separator + */ +TestUtils.sep = function() { + return require('path').sep; +} + +/** + * @param {string} dir Directory with all ignite libs + * @returns {string} Classpath for ignite node start + */ +TestUtils.classpath = function(dir) { + var fs = require('fs'); + var path = require('path'); + function walk(dir, done) { + var results = []; + var list = fs.readdirSync(dir) + for (var i = 0; i < list.length; ++i) { + file = path.resolve(dir, list[i]); + var stat = fs.statSync(file); + if (stat && stat.isDirectory()) { + if (list[i] != "optional" && file.indexOf("optional") !== -1 && file.indexOf("rest") == -1 ) + continue; + + var sublist = walk(file); + results = results.concat(sublist); + } else { + if (file.indexOf(".jar") !== -1) { + results.push(file); + } + } + } + return results; + }; + + return walk(dir); +}; + +/** + * @returns Process that starts ignite node + */ +TestUtils.startIgniteNode = function() { + var libs = classpath(igniteHome() + TestUtils.sep() + "target" + + TestUtils.sep() + "bin" + + TestUtils.sep() + "apache-ignite-fabric-1.1.1-SNAPSHOT-bin" + + TestUtils.sep() + "libs"); + + var cp = libs.join(require('path').delimiter); + + var spawn = require('child_process').spawn; + + var child = spawn('java',['-classpath', cp, 'org.apache.ignite.startup.cmdline.CommandLineStartup', + "test-node.xml"]); + + child.stdout.on('data', function (data) { + console.log("" + data); + }); + + child.stderr.on('data', function (data) { + console.log("" + data); + }); + + return child; +} + +/** + * Print error to console + * + * @param {string} error Error + */ +TestUtils.testFails = function(error) { + console.log("Node JS test failed: " + error); +} + +/** + * Print ok message to console + */ +TestUtils.testDone = function() { + console.log("Node JS test finished.") +} + +exports.TestUtils = TestUtils; \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/0998c8be/modules/nodejs/src/test/nodejs/rest-jetty.xml ---------------------------------------------------------------------- diff --git a/modules/nodejs/src/test/nodejs/rest-jetty.xml b/modules/nodejs/src/test/nodejs/rest-jetty.xml deleted file mode 100644 index 1ea2a38..0000000 --- a/modules/nodejs/src/test/nodejs/rest-jetty.xml +++ /dev/null @@ -1,53 +0,0 @@ - - - - - - - 20 - 200 - - - - https - 8443 - true - true - - - - - - - - - - - - - - - - - - - - - 30000 - true - - - - - - - - - - - - - - - false - \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/0998c8be/modules/nodejs/src/test/nodejs/test-node.xml ---------------------------------------------------------------------- diff --git a/modules/nodejs/src/test/nodejs/test-node.xml b/modules/nodejs/src/test/nodejs/test-node.xml deleted file mode 100644 index a1a17e4..0000000 --- a/modules/nodejs/src/test/nodejs/test-node.xml +++ /dev/null @@ -1,97 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - true - - - - - - - http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/0998c8be/modules/nodejs/src/test/nodejs/test.js ---------------------------------------------------------------------- diff --git a/modules/nodejs/src/test/nodejs/test.js b/modules/nodejs/src/test/nodejs/test.js deleted file mode 100644 index bdce21d..0000000 --- a/modules/nodejs/src/test/nodejs/test.js +++ /dev/null @@ -1,99 +0,0 @@ -module.exports = { - 'Test put/get' : function(test) { - test.expect(1); - - var TestUtils = require("./test_utils").TestUtils; - var Cache = require(TestUtils.scriptPath() + "cache").Cache; - var Server = require(TestUtils.scriptPath() + "server").Server; - - var assert = require('assert'); - - //var node = startIgniteNode(); - - setTimeout(initCache, 10000); //If start node from javascrip set timeout 10000); - - function initCache() { - var server = new Server('127.0.0.1', 9090); - var cache = new Cache(server, "mycache"); - cache.put("mykey", "6", onPut.bind(null, cache)); - } - - function onPut(cache, error) { - if (error) { - console.error("Failed to put " + error); - finishTest(test/*, node*/); - return; - } - - console.log("Put finished"); - cache.get("mykey", onGet); - } - - function onGet(error, value) { - if (error) { - console.error("Failed to get " + error); - finishTest(test/*, node*/); - return; - } - - console.log("Get finished"); - test.ok(value === "6", "This shouldn't fail " + value + "<>6"); - finishTest(test/*, node*/); - } - }, - 'Test connection' : function(test) { - test.expect(0); - - //var node = startIgniteNode(); - var TestUtils = require("./test_utils").TestUtils; - var Server = require(TestUtils.scriptPath() + "server").Server; - - setTimeout(initServer, 10000); - - function initServer() { - var server = new Server('127.0.0.1', 9090); - - console.log("Try to check connection"); - - server.checkConnection(onConnect); - } - - function onConnect(error) { - if (error) { - finishWithError(test/*, node*/, error); - return; - } - console.log("Successfully connected"); - finishTest(test/*, node*/); - } - }, - 'Test ignition' : function(test) { - test.expect(1); - - //var node = startIgniteNode('127.0.0.1', 9090); - var TestUtils = require("./test_utils").TestUtils; - var Ignition = require(TestUtils.scriptPath() + "ignition").Ignition; - - setTimeout(Ignition.start.bind(null, 9090, ['127.0.0.0', '127.0.0.1'], onConnect), 5000); - - function onConnect(error, server) { - if (error) { - finishWithError(test/*, node*/, error); - return; - } - test.ok(server.host() === '127.0.0.1') - finishTest(test/*, node*/); - } - } - }; - -function finishWithError(test/*, node*/, error) { - console.log("Error: " + error); - test.ok(false); - finishTest(test/*, node*/); -} - -function finishTest(test/*, node*/) { - //node.kill(); - test.done(); -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/0998c8be/modules/nodejs/src/test/nodejs/test_ignition.js ---------------------------------------------------------------------- diff --git a/modules/nodejs/src/test/nodejs/test_ignition.js b/modules/nodejs/src/test/nodejs/test_ignition.js deleted file mode 100644 index baa9615..0000000 --- a/modules/nodejs/src/test/nodejs/test_ignition.js +++ /dev/null @@ -1,32 +0,0 @@ -var TestUtils = require("./test_utils").TestUtils; -var Ignition = require(TestUtils.scriptPath() + "ignition").Ignition; - -exports.test_ignition_fail = function () { - Ignition.start(['127.0.0.3:9091', '127.0.0.1:9092'], onConnect); - - function onConnect(error, server) { - if (error) { - if (error.indexOf("Cannot connect to servers.") == -1) - TestUtils.testFails("Incorrect error message: " + error); - else - TestUtils.testDone(); - - return; - } - - TestUtils.testFails("Test should fail."); - } -} - -exports.ignition_start_success = function() { - Ignition.start(['127.0.0.1:9095'], onConnect); - - function onConnect(error, server) { - if (error) { - TestUtils.testFails(error); - - return; - } - TestUtils.testDone(); - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/0998c8be/modules/nodejs/src/test/nodejs/test_runner.js ---------------------------------------------------------------------- diff --git a/modules/nodejs/src/test/nodejs/test_runner.js b/modules/nodejs/src/test/nodejs/test_runner.js deleted file mode 100644 index 6f2cf2b..0000000 --- a/modules/nodejs/src/test/nodejs/test_runner.js +++ /dev/null @@ -1,29 +0,0 @@ -/** - * Create instance of TestUtils - * - * @constructor - */ -function TestRunner() { -} - -/** - * Test routine. - */ -TestRunner.runTest = function() { - var fileName = process.argv[2].toString().trim(); - - console.log("FileName " + fileName); - - var test = require("./" + fileName); - - var functionName = process.argv[3].toString().trim(); - - if (!test[functionName]) { - console.log("node js test failed: function with name " + functionName + " not found"); - return; - } - test[functionName](); -} - - -TestRunner.runTest(); \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/0998c8be/modules/nodejs/src/test/nodejs/test_utils.js ---------------------------------------------------------------------- diff --git a/modules/nodejs/src/test/nodejs/test_utils.js b/modules/nodejs/src/test/nodejs/test_utils.js deleted file mode 100644 index dca6603..0000000 --- a/modules/nodejs/src/test/nodejs/test_utils.js +++ /dev/null @@ -1,109 +0,0 @@ -/** - * Create instance of TestUtils - * - * @constructor - */ -function TestUtils() { -} - -/** - * @returns {string} Path to script dir - */ -TestUtils.scriptPath = function() { - return TestUtils.igniteHome() + - TestUtils.sep() + "modules" + - TestUtils.sep() + "nodejs" + - TestUtils.sep() + "src" + - TestUtils.sep() + "main" + - TestUtils.sep() + "nodejs" + TestUtils.sep(); -} - -/** - * @returns {string} Ignite home path - */ -TestUtils.igniteHome = function() { - return process.env.IGNITE_HOME; -} - -/** - * @returns {string} Path separator - */ -TestUtils.sep = function() { - return require('path').sep; -} - -/** - * @param {string} dir Directory with all ignite libs - * @returns {string} Classpath for ignite node start - */ -TestUtils.classpath = function(dir) { - var fs = require('fs'); - var path = require('path'); - function walk(dir, done) { - var results = []; - var list = fs.readdirSync(dir) - for (var i = 0; i < list.length; ++i) { - file = path.resolve(dir, list[i]); - var stat = fs.statSync(file); - if (stat && stat.isDirectory()) { - if (list[i] != "optional" && file.indexOf("optional") !== -1 && file.indexOf("rest") == -1 ) - continue; - - var sublist = walk(file); - results = results.concat(sublist); - } else { - if (file.indexOf(".jar") !== -1) { - results.push(file); - } - } - } - return results; - }; - - return walk(dir); -}; - -/** - * @returns Process that starts ignite node - */ -TestUtils.startIgniteNode = function() { - var libs = classpath(igniteHome() + TestUtils.sep() + "target" + - TestUtils.sep() + "bin" + - TestUtils.sep() + "apache-ignite-fabric-1.1.1-SNAPSHOT-bin" + - TestUtils.sep() + "libs"); - - var cp = libs.join(require('path').delimiter); - - var spawn = require('child_process').spawn; - - var child = spawn('java',['-classpath', cp, 'org.apache.ignite.startup.cmdline.CommandLineStartup', - "test-node.xml"]); - - child.stdout.on('data', function (data) { - console.log("" + data); - }); - - child.stderr.on('data', function (data) { - console.log("" + data); - }); - - return child; -} - -/** - * Print error to console - * - * @param {string} error Error - */ -TestUtils.testFails = function(error) { - console.log("Node JS test failed: " + error); -} - -/** - * Print ok message to console - */ -TestUtils.testDone = function() { - console.log("Node JS test finished.") -} - -exports.TestUtils = TestUtils; \ No newline at end of file