Repository: incubator-ignite Updated Branches: refs/heads/ignite-965 2880a9c58 -> b7f2393e0
#ignite-965: 4 spaces code style. Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/f9f98acb Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/f9f98acb Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/f9f98acb Branch: refs/heads/ignite-965 Commit: f9f98acb4ae357b9f2a66ce3a0e47b6cf43d089c Parents: 2880a9c Author: ivasilinets <ivasilin...@gridgain.com> Authored: Wed Jun 24 12:25:49 2015 +0300 Committer: ivasilinets <ivasilin...@gridgain.com> Committed: Wed Jun 24 12:25:49 2015 +0300 ---------------------------------------------------------------------- modules/nodejs/src/main/js/apache-ignite.js | 10 +- modules/nodejs/src/main/js/cache.js | 54 ++++----- modules/nodejs/src/main/js/compute.js | 24 ++-- modules/nodejs/src/main/js/ignite.js | 8 +- modules/nodejs/src/main/js/ignition.js | 87 +++++++-------- modules/nodejs/src/main/js/package.json | 24 ++-- modules/nodejs/src/main/js/server.js | 128 +++++++++++----------- modules/nodejs/src/test/js/test-cache-api.js | 118 ++++++++++---------- modules/nodejs/src/test/js/test-compute.js | 105 +++++++++--------- modules/nodejs/src/test/js/test-ignition.js | 84 +++++++------- modules/nodejs/src/test/js/test-key.js | 22 ++-- modules/nodejs/src/test/js/test-utils.js | 114 +++++++++---------- 12 files changed, 389 insertions(+), 389 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/f9f98acb/modules/nodejs/src/main/js/apache-ignite.js ---------------------------------------------------------------------- diff --git a/modules/nodejs/src/main/js/apache-ignite.js b/modules/nodejs/src/main/js/apache-ignite.js index 0df6160..e8252fc 100644 --- a/modules/nodejs/src/main/js/apache-ignite.js +++ b/modules/nodejs/src/main/js/apache-ignite.js @@ -16,9 +16,9 @@ */ module.exports = { - Cache : require('./cache.js').Cache, - Ignition : require('./ignition.js').Ignition, - Server : require('./server.js').Server, - Ignite : require('./ignite.js').Ignite, - Compute : require('./compute.js').Compute + Cache : require('./cache.js').Cache, + Ignition : require('./ignition.js').Ignition, + Server : require('./server.js').Server, + Ignite : require('./ignite.js').Ignite, + Compute : require('./compute.js').Compute } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/f9f98acb/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 index 78dd1d8..86eb22a 100644 --- a/modules/nodejs/src/main/js/cache.js +++ b/modules/nodejs/src/main/js/cache.js @@ -26,9 +26,9 @@ var Server = require("./server").Server; * @param {string} cacheName Cache name */ function Cache(server, cacheName) { - this._server = server; - this._cacheName = cacheName; - this._cacheNameParam = Server.pair("cacheName", this._cacheName); + this._server = server; + this._cacheName = cacheName; + this._cacheNameParam = Server.pair("cacheName", this._cacheName); } /** @@ -39,7 +39,7 @@ function Cache(server, cacheName) { * @param {onGet} callback Called on finish */ Cache.prototype.get = function(key, callback) { - this._server.runCommand("get", [this._cacheNameParam, Server.pair("key", key)], callback); + this._server.runCommand("get", [this._cacheNameParam, Server.pair("key", key)], callback); }; /** @@ -51,8 +51,8 @@ Cache.prototype.get = function(key, callback) { * @param {noValue} callback Called on finish */ Cache.prototype.put = function(key, value, callback) { - this._server.runCommand("put", [this._cacheNameParam, Server.pair("key", key), Server.pair("val", value)], - callback); + this._server.runCommand("put", [this._cacheNameParam, Server.pair("key", key), Server.pair("val", value)], + callback); } /** @@ -63,7 +63,7 @@ Cache.prototype.put = function(key, value, callback) { * @param {noValue} callback Called on finish */ Cache.prototype.remove = function(key, callback) { - this._server.runCommand("rmv", [this._cacheNameParam, Server.pair("key", key)], callback); + this._server.runCommand("rmv", [this._cacheNameParam, Server.pair("key", key)], callback); } /** @@ -74,11 +74,11 @@ Cache.prototype.remove = function(key, callback) { * @param {noValue} callback Called on finish */ Cache.prototype.removeAll = function(keys, callback) { - var params = [this._cacheNameParam]; + var params = [this._cacheNameParam]; - params = params.concat(Cache.concatParams("k", keys)); + params = params.concat(Cache.concatParams("k", keys)); - this._server.runCommand("rmvall", params, callback); + this._server.runCommand("rmvall", params, callback); } /** @@ -89,20 +89,20 @@ Cache.prototype.removeAll = function(keys, callback) { * @param {noValue} callback Called on finish */ Cache.prototype.putAll = function(map, callback) { - var keys = Object.keys(map); + var keys = Object.keys(map); - var values = []; + var values = []; - for (var key of keys) { - values.push(map[key]); - } + for (var key of keys) { + values.push(map[key]); + } - var params = Cache.concatParams("k", keys); - params = params.concat(Cache.concatParams("v", values)); + var params = Cache.concatParams("k", keys); + params = params.concat(Cache.concatParams("v", values)); - params.push(this._cacheNameParam); + params.push(this._cacheNameParam); - this._server.runCommand("putall", params, callback); + this._server.runCommand("putall", params, callback); } /** @@ -121,11 +121,11 @@ Cache.prototype.putAll = function(map, callback) { * @param {Cache~onGetAll} callback Called on finish */ Cache.prototype.getAll = function(keys, callback) { - var params = Cache.concatParams("k", keys); + var params = Cache.concatParams("k", keys); - params.push(this._cacheNameParam); + params.push(this._cacheNameParam); - this._server.runCommand("getall", params, callback); + this._server.runCommand("getall", params, callback); } /** @@ -136,13 +136,13 @@ Cache.prototype.getAll = function(keys, callback) { * @returns List of parameters. */ Cache.concatParams = function(pref, keys) { - var temp = [] + var temp = [] - for (var i = 1; i <= keys.length; ++i) { - temp.push(Server.pair(pref + i, keys[i-1])); - } + for (var i = 1; i <= keys.length; ++i) { + temp.push(Server.pair(pref + i, keys[i-1])); + } - return temp; + return temp; } exports.Cache = Cache \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/f9f98acb/modules/nodejs/src/main/js/compute.js ---------------------------------------------------------------------- diff --git a/modules/nodejs/src/main/js/compute.js b/modules/nodejs/src/main/js/compute.js index f00db69..01361d5 100644 --- a/modules/nodejs/src/main/js/compute.js +++ b/modules/nodejs/src/main/js/compute.js @@ -23,7 +23,7 @@ var Server = require("./server").Server; * @param {Server} server Server */ function Compute(server) { - this._server = server; + this._server = server; } /** @@ -34,8 +34,8 @@ function Compute(server) { * @param {noValue} callback Callback */ Compute.prototype.affinityRun = function(cacheName, key, runnable, callback) { - this._server.runCommand("affscriptrun", [Server.pair("cacheName", cacheName), - Server.pair("key", key), Server.pair("func", this._escape(runnable))], callback); + this._server.runCommand("affscriptrun", [Server.pair("cacheName", cacheName), + Server.pair("key", key), Server.pair("func", this._escape(runnable))], callback); } /** @@ -46,8 +46,8 @@ Compute.prototype.affinityRun = function(cacheName, key, runnable, callback) { * @param {onGet} callback Callback */ Compute.prototype.affinityCall = function(cacheName, key, runnable, callback) { - this._server.runCommand("affscriptcall", [Server.pair("cacheName", cacheName), - Server.pair("key", key), Server.pair("func", this._escape(runnable))], callback); + this._server.runCommand("affscriptcall", [Server.pair("cacheName", cacheName), + Server.pair("key", key), Server.pair("func", this._escape(runnable))], callback); } /** @@ -58,13 +58,13 @@ Compute.prototype.affinityCall = function(cacheName, key, runnable, callback) { * @param {onGet} callback Callback */ Compute.prototype.execute = function(map, reduce, arg, callback) { - var params = []; + var params = []; - params.push(Server.pair("map", this._escape(map))); - params.push(Server.pair("reduce", this._escape(reduce))); - params.push(Server.pair("arg", this._escape(arg))); + params.push(Server.pair("map", this._escape(map))); + params.push(Server.pair("reduce", this._escape(reduce))); + params.push(Server.pair("arg", this._escape(arg))); - this._server.runCommand("execscripttask", params, callback); + this._server.runCommand("execscripttask", params, callback); } /** @@ -72,9 +72,9 @@ Compute.prototype.execute = function(map, reduce, arg, callback) { * @returns {string} Encoding function */ Compute.prototype._escape = function(f) { - var qs = require('querystring'); + var qs = require('querystring'); - return qs.escape(f.toString()); + return qs.escape(f.toString()); } /** http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/f9f98acb/modules/nodejs/src/main/js/ignite.js ---------------------------------------------------------------------- diff --git a/modules/nodejs/src/main/js/ignite.js b/modules/nodejs/src/main/js/ignite.js index dca292e..fb24a19 100644 --- a/modules/nodejs/src/main/js/ignite.js +++ b/modules/nodejs/src/main/js/ignite.js @@ -26,7 +26,7 @@ var Compute = require("./compute").Compute * @param {Server} Server */ function Ignite(server) { - this._server = server; + this._server = server; } /** @@ -34,7 +34,7 @@ function Ignite(server) { * @returns {Server} Server */ Ignite.prototype.server = function() { - return this._server; + return this._server; } /** @@ -45,7 +45,7 @@ Ignite.prototype.server = function() { * @returns {Cache} Cache */ Ignite.prototype.cache = function(cacheName) { - return new Cache(this._server, cacheName); + return new Cache(this._server, cacheName); } /** @@ -55,7 +55,7 @@ Ignite.prototype.cache = function(cacheName) { * @returns {Compute} Compute */ Ignite.prototype.compute = function() { - return new Compute(this._server); + return new Compute(this._server); } exports.Ignite = Ignite; http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/f9f98acb/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 index d641d26..e1ecc6c 100644 --- a/modules/nodejs/src/main/js/ignition.js +++ b/modules/nodejs/src/main/js/ignition.js @@ -39,69 +39,70 @@ function Ignition() { * @param {Ignition~onStart} callback Called on finish */ Ignition.start = function(address, secretKey, callback) { - var Server = require("./server").Server; - var Ignite = require("./ignite").Ignite + var Server = require("./server").Server; + var Ignite = require("./ignite").Ignite - var numConn = 0; + var numConn = 0; - for (var addr of address) { - var params = addr.split(":"); + for (var addr of address) { + var params = addr.split(":"); - var portsRange = params[1].split(".."); + var portsRange = params[1].split(".."); - var start; - var end; + var start; + var end; - if (portsRange.length === 1) { - start = parseInt(portsRange[0], 10); - end = start; - } - else if (portsRange.length === 2) { - start = parseInt(portsRange[0], 10); - end = parseInt(portsRange[1], 10); - } - if (isNaN(start) || isNaN(end)) { - incorrectAddress(); + if (portsRange.length === 1) { + start = parseInt(portsRange[0], 10); + end = start; + } + else if (portsRange.length === 2) { + start = parseInt(portsRange[0], 10); + end = parseInt(portsRange[1], 10); + } - return; - } + if (isNaN(start) || isNaN(end)) { + incorrectAddress(); + + return; + } - for (var i = start; i <= end; i++) { - checkServer(params[0], i, secretKey); + for (var i = start; i <= end; i++) { + checkServer(params[0], i, secretKey); + } } - } - function checkServer(host, port, secretKey) { - numConn++; + function checkServer(host, port, secretKey) { + numConn++; - var server = new Server(host, port, secretKey); + var server = new Server(host, port, secretKey); - server.checkConnection(onConnect.bind(null, server)); - } + server.checkConnection(onConnect.bind(null, server)); + } - function incorrectAddress() { - callback.call(null, "Incorrect address format.", null); + function incorrectAddress() { + callback.call(null, "Incorrect address format.", null); - callback = null; - } + callback = null; + } - function onConnect(server, error) { - if (!callback) return; + function onConnect(server, error) { + if (!callback) return; - numConn--; + numConn--; - if (!error) { - callback.call(null, null, new Ignite(server)); + if (!error) { + callback.call(null, null, new Ignite(server)); - callback = null; + callback = null; - return; - } + return; + } - if (!numConn) { - callback.call(null, "Cannot connect to servers. " + error, null); + if (!numConn) { + callback.call(null, "Cannot connect to servers. " + error, null); + } } - } } exports.Ignition = Ignition; \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/f9f98acb/modules/nodejs/src/main/js/package.json ---------------------------------------------------------------------- diff --git a/modules/nodejs/src/main/js/package.json b/modules/nodejs/src/main/js/package.json index 7efc4e2..ae4b911 100644 --- a/modules/nodejs/src/main/js/package.json +++ b/modules/nodejs/src/main/js/package.json @@ -1,14 +1,14 @@ { - "name" : "apache-ignite", - "version" : "1.0.0-SNAPSHOT", - "author" : "Semyon Boikov <sboi...@gridgain.com>", - "contributors": [{ - "name": "Irina Vasilinets", - "email": "ivasilie...@gridgain.com" - }], - "main" : "apache-ignite.js", - "license" : "Apache-2.0", - "keywords" : "grid", - "homepage" : "https://ignite.incubator.apache.org/", - "engines" : { "node" : ">=0.12.4" } + "name" : "apache-ignite", + "version" : "1.0.0-SNAPSHOT", + "author" : "Semyon Boikov <sboi...@gridgain.com>", + "contributors": [{ + "name": "Irina Vasilinets", + "email": "ivasilie...@gridgain.com" + }], + "main" : "apache-ignite.js", + "license" : "Apache-2.0", + "keywords" : "grid", + "homepage" : "https://ignite.incubator.apache.org/", + "engines" : { "node" : ">=0.12.4" } } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/f9f98acb/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 index f1c9d92..2bd0b4e 100644 --- a/modules/nodejs/src/main/js/server.js +++ b/modules/nodejs/src/main/js/server.js @@ -25,9 +25,9 @@ * @param {string} secretKey Secret key for connection */ function Server(host, port, secretKey) { - this._host = host; - this._port = port; - this._secretKey = secretKey; + this._host = host; + this._port = port; + this._secretKey = secretKey; } /** @@ -37,7 +37,7 @@ function Server(host, port, secretKey) { * @returns {string} Host value */ Server.prototype.host = function() { - return this._host; + return this._host; } /** @@ -62,68 +62,68 @@ Server.prototype.host = function() { * @param {onGet} Called on finish */ Server.prototype.runCommand = function(cmdName, params, callback) { - var paramsString = ""; + var paramsString = ""; - for (var p of params) { - paramsString += "&" + p.key + "=" + p.value; - } + for (var p of params) { + paramsString += "&" + p.key + "=" + p.value; + } - var requestQry = "cmd=" + cmdName + paramsString; + var requestQry = "cmd=" + cmdName + paramsString; - var http = require('http'); + var http = require('http'); - var options = { - host: this._host, - port: this._port, - path: "/ignite?" + requestQry, - headers: this._signature() - }; + var options = { + host: this._host, + port: this._port, + path: "/ignite?" + requestQry, + headers: this._signature() + }; - function streamCallback(response) { - var fullResponseString = ''; + function streamCallback(response) { + var fullResponseString = ''; - response.on('data', function (chunk) { - fullResponseString += chunk; - }); + response.on('data', function (chunk) { + fullResponseString += chunk; + }); - response.on('end', function () { - if (response.statusCode !== 200) { - if (response.statusCode === 401) { - callback.call(null, "Authentication failed. Status code 401."); - } - else { - callback.call(null, "Request failed. Status code " + response.statusCode); - } + response.on('end', function () { + if (response.statusCode !== 200) { + if (response.statusCode === 401) { + callback.call(null, "Authentication failed. Status code 401."); + } + else { + callback.call(null, "Request failed. Status code " + response.statusCode); + } - return; - } + return; + } - var igniteResponse; + var igniteResponse; - try { - igniteResponse = JSON.parse(fullResponseString); - } - catch (e) { - callback.call(null, e, null); - return; - } + try { + igniteResponse = JSON.parse(fullResponseString); + } + catch (e) { + callback.call(null, e, null); + return; + } - if (igniteResponse.successStatus) { - callback.call(null, igniteResponse.error, null) - } - else { - callback.call(null, null, igniteResponse.response); - } - }); - } + if (igniteResponse.successStatus) { + callback.call(null, igniteResponse.error, null) + } + else { + callback.call(null, null, igniteResponse.response); + } + }); + } - var request = http.request(options, streamCallback); + var request = http.request(options, streamCallback); - request.setTimeout(5000, callback.bind(null, "Request timeout: >5 sec")); + request.setTimeout(5000, callback.bind(null, "Request timeout: >5 sec")); - request.on('error', callback); + request.on('error', callback); - request.end(); + request.end(); } /** @@ -133,7 +133,7 @@ Server.prototype.runCommand = function(cmdName, params, callback) { * @param {onGet} callback Called on finish */ Server.prototype.checkConnection = function(callback) { - this.runCommand("version", [], callback); + this.runCommand("version", [], callback); } /** @@ -144,7 +144,7 @@ Server.prototype.checkConnection = function(callback) { * @returns Pair of strings */ Server.pair = function(key, value) { - return {key: key, value: value} + return {key: key, value: value} } /** @@ -154,25 +154,25 @@ Server.pair = function(key, value) { * @returns Signature */ Server.prototype._signature = function() { - if (!this._secretKey) { - return ""; - } + if (!this._secretKey) { + return ""; + } - var loadTimeInMS = Date.now(); + var loadTimeInMS = Date.now(); - var baseKey = '' + loadTimeInMS + ":" + this._secretKey; + var baseKey = '' + loadTimeInMS + ":" + this._secretKey; - var crypto = require('crypto') + var crypto = require('crypto') - var shasum = crypto.createHash('sha1'); + var shasum = crypto.createHash('sha1'); - shasum.update(baseKey, 'binary'); + shasum.update(baseKey, 'binary'); - var hash = shasum.digest('base64'); + var hash = shasum.digest('base64'); - var key = loadTimeInMS + ":" + hash; + var key = loadTimeInMS + ":" + hash; - return {"X-Signature" : key}; + return {"X-Signature" : key}; } exports.Server = Server; \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/f9f98acb/modules/nodejs/src/test/js/test-cache-api.js ---------------------------------------------------------------------- diff --git a/modules/nodejs/src/test/js/test-cache-api.js b/modules/nodejs/src/test/js/test-cache-api.js index 1101493..335f888 100644 --- a/modules/nodejs/src/test/js/test-cache-api.js +++ b/modules/nodejs/src/test/js/test-cache-api.js @@ -20,123 +20,123 @@ var TestUtils = require("./test-utils").TestUtils; var assert = require("assert"); testPutGet = function() { - startTest("mycache", {trace: [put, getExist], entry: "6"}); + startTest("mycache", {trace: [put, getExist], entry: "6"}); } testRemove = function() { - startTest("mycache", {trace: [put, getExist, remove, getNonExist], entry: "6"}); + startTest("mycache", {trace: [put, getExist, remove, getNonExist], entry: "6"}); } testRemoveNoKey = function() { - startTest("mycache", {trace: [remove, getNonExist], entry: "6"}); + startTest("mycache", {trace: [remove, getNonExist], entry: "6"}); } testPutAllGetAll = function() { - startTest("mycache", {trace: [putAll, getAll], entry: {"key1": "val1", "key2" : "val2"}}); + startTest("mycache", {trace: [putAll, getAll], entry: {"key1": "val1", "key2" : "val2"}}); } testRemoveAll = function() { - startTest("mycache", {trace: [putAll, getAll, removeAll, getNone], entry: {"key1": "val1", "key2" : "val2"}}); + startTest("mycache", {trace: [putAll, getAll, removeAll, getNone], entry: {"key1": "val1", "key2" : "val2"}}); } testIncorrectCacheName = function() { - startTest("mycache1", {trace: [incorrectPut], entry: "6"}); + startTest("mycache1", {trace: [incorrectPut], entry: "6"}); } function startTest(cacheName, testDescription) { - TestUtils.startIgniteNode(onStart.bind(null, cacheName, testDescription)); + TestUtils.startIgniteNode(onStart.bind(null, cacheName, testDescription)); } function onStart(cacheName, testDescription, error, ignite) { - var cache = ignite.cache(cacheName); - callNext(); - - function callNext(error) { - assert(!error); - var next = testDescription.trace.shift(); - if (next) - next.call(null, cache, testDescription.entry, callNext); - else - TestUtils.testDone(); - } + var cache = ignite.cache(cacheName); + callNext(); + + function callNext(error) { + assert(!error); + var next = testDescription.trace.shift(); + if (next) + next.call(null, cache, testDescription.entry, callNext); + else + TestUtils.testDone(); + } } function put(cache, entry, next) { - cache.put("key", entry, next); + cache.put("key", entry, next); } function getExist(cache, entry, next) { - cache.get("key", onGet); + cache.get("key", onGet); - function onGet(error, value) { - assert(!error); - assert(value === entry); - next(); - } + function onGet(error, value) { + assert(!error); + assert(value === entry); + next(); + } } function remove(cache, entry, next) { - cache.remove("key", next); + cache.remove("key", next); } function getNonExist(cache, entry, next) { - cache.get("key", onGet); + cache.get("key", onGet); - function onGet(error, value) { - assert(!error); - assert(!value); - next(); - } + function onGet(error, value) { + assert(!error); + assert(!value); + next(); + } } function putAll(cache, entries, next) { - cache.putAll(entries, next); + cache.putAll(entries, next); } function getAll(cache, entries, next) { - cache.getAll(Object.keys(entries), onGetAll); - var expected = entries; + cache.getAll(Object.keys(entries), onGetAll); + var expected = entries; - function onGetAll(error, values) { - assert(!error, error); + function onGetAll(error, values) { + assert(!error, error); - var keys = Object.keys(expected); + var keys = Object.keys(expected); - for (var i = 0; i < keys.length; ++i) { - var key = keys[i]; + for (var i = 0; i < keys.length; ++i) { + var key = keys[i]; - assert(!!values[key], "Cannot find key. [key=" + key + "]."); + assert(!!values[key], "Cannot find key. [key=" + key + "]."); - assert(values[key] === expected[key], "Incorrect value. [key=" + key + - ", expected=" + expected[key] + ", val= " + values[key] + "]."); + assert(values[key] === expected[key], "Incorrect value. [key=" + key + + ", expected=" + expected[key] + ", val= " + values[key] + "]."); + } + next(); } - next(); - } } function removeAll(cache, entries, next) { - cache.removeAll(Object.keys(entries), next) + cache.removeAll(Object.keys(entries), next) } function getNone(cache, entries, next) { - cache.getAll(Object.keys(entries), onGetAll); + cache.getAll(Object.keys(entries), onGetAll); - function onGetAll(error, values) { - assert(!error, error); - assert(!values || !Object.keys(values).length); + function onGetAll(error, values) { + assert(!error, error); + assert(!values || !Object.keys(values).length); - next(); - } + next(); + } } function incorrectPut(cache, entry, next) { - cache.put("key", entry, callback); + cache.put("key", entry, callback); - function callback(error) { - assert(!!error, "Do not get error for not exist cache"); - assert(error.indexOf("Failed to find cache for given cache name") !== -1, - "Incorrect message on not exist cache. " + error); + function callback(error) { + assert(!!error, "Do not get error for not exist cache"); + assert(error.indexOf("Failed to find cache for given cache name") !== -1, + "Incorrect message on not exist cache. " + error); - next(); - } + next(); + } } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/f9f98acb/modules/nodejs/src/test/js/test-compute.js ---------------------------------------------------------------------- diff --git a/modules/nodejs/src/test/js/test-compute.js b/modules/nodejs/src/test/js/test-compute.js index 8c1a7fe..a494f3e 100644 --- a/modules/nodejs/src/test/js/test-compute.js +++ b/modules/nodejs/src/test/js/test-compute.js @@ -20,96 +20,95 @@ var TestUtils = require("./test-utils").TestUtils; var assert = require("assert"); testComputeAffinityRun = function() { - TestUtils.startIgniteNode(onStart.bind(null, computeAffinityRun)); + TestUtils.startIgniteNode(onStart.bind(null, computeAffinityRun)); } testComputeAffinityCall = function() { - TestUtils.startIgniteNode(onStart.bind(null, computeAffinityCall)); + TestUtils.startIgniteNode(onStart.bind(null, computeAffinityCall)); } testComputeExecute = function() { - TestUtils.startIgniteNode(computeExecute); + TestUtils.startIgniteNode(computeExecute); } function onStart(onPut, error, ignite) { - var cache = ignite.cache("mycache"); + var cache = ignite.cache("mycache"); - var params = {} + var params = {} - for (var i = 900; i < 1000; ++i) { - params["key" + i] = "val" + i; - } + for (var i = 900; i < 1000; ++i) { + params["key" + i] = "val" + i; + } - cache.putAll(params, onPut.bind(null, ignite)) + cache.putAll(params, onPut.bind(null, ignite)) } function computeAffinityRun(ignite, error) { - var comp = ignite.compute(); + var comp = ignite.compute(); - var f = function () { - println("Hello world!"); + var f = function () { + println("Hello world!"); - ignite.hello(); - } + ignite.hello(); + } - function onEnd(error) { - assert(error == null); + function onEnd(error) { + assert(error == null); - TestUtils.testDone(); - } + TestUtils.testDone(); + } - comp.affinityRun("mycache", "key999", f, onEnd.bind(null)); + comp.affinityRun("mycache", "key999", f, onEnd.bind(null)); } function computeAffinityCall(ignite, error) { - var comp = ignite.compute(); + var comp = ignite.compute(); - var f = function () { - return ignite.hello(); - } - - function onEnd(err, res) { - assert(err == null); + var f = function () { + return ignite.hello(); + } - assert(res.indexOf("HAPPY") !== -1, "Incorrect result message. [mes=" + res + "]."); + function onEnd(err, res) { + assert(err == null); + assert(res.indexOf("HAPPY") !== -1, "Incorrect result message. [mes=" + res + "]."); - TestUtils.testDone(); - } + TestUtils.testDone(); + } - comp.affinityCall("mycache", "key999", f, onEnd.bind(null)); + comp.affinityCall("mycache", "key999", f, onEnd.bind(null)); } function computeExecute(error, ignite) { - var map = function(nodes, arg, emit) { - var words = arg.split(" "); + var map = function(nodes, arg, emit) { + var words = arg.split(" "); - for (var i = 0; i < words.length; i++) { - var f = function (word) { - println(">>> Printing " + word); + for (var i = 0; i < words.length; i++) { + var f = function (word) { + println(">>> Printing " + word); - return word.length; - }; + return word.length; + }; - emit(f, [words[i]], nodes[i % nodes.length]); - } - }; + emit(f, [words[i]], nodes[i % nodes.length]); + } + }; - var reduce = function(results) { - var sum = 0; + var reduce = function(results) { + var sum = 0; - for (var i = 0; i < results.length; ++i) { - sum += parseInt(results[i], 10); - } + for (var i = 0; i < results.length; ++i) { + sum += parseInt(results[i], 10); + } - return sum; - }; + return sum; + }; - var callback = function(err, res) { - assert(err == null, "Get error on compute task. [err=" + err + "]."); - assert(res === 7, "Result is not correct. [expected=7, value=" + res + "]."); + var callback = function(err, res) { + assert(err == null, "Get error on compute task. [err=" + err + "]."); + assert(res === 7, "Result is not correct. [expected=7, value=" + res + "]."); - TestUtils.testDone(); - } + TestUtils.testDone(); + } - ignite.compute().execute(map, reduce, "Hi Alice", callback); + ignite.compute().execute(map, reduce, "Hi Alice", callback); } http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/f9f98acb/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 index 3823109..fd80e61 100644 --- a/modules/nodejs/src/test/js/test-ignition.js +++ b/modules/nodejs/src/test/js/test-ignition.js @@ -23,70 +23,70 @@ var Ignition = Ignite.Ignition; var assert = require("assert"); testIgnitionFail = function () { - Ignition.start(['127.0.0.3:9091', '127.0.0.1:9092'], null, onConnect); - - function onConnect(error, server) { - if (error) { - if (error.indexOf("Cannot connect to servers.") == -1) { - TestUtils.testFails("Incorrect error message: " + error); - } - else { - TestUtils.testDone(); - } + Ignition.start(['127.0.0.3:9091', '127.0.0.1:9092'], null, onConnect); - return; - } + 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."); - } + TestUtils.testFails("Test should fail."); + } } ignitionStartSuccess = function() { - Ignition.start(['127.0.0.0:9095', '127.0.0.1:9095'], null, onConnect); + Ignition.start(['127.0.0.0:9095', '127.0.0.1:9095'], null, onConnect); - function onConnect(error, server) { - if (error) { - TestUtils.testFails(error); + function onConnect(error, server) { + if (error) { + TestUtils.testFails(error); - return; - } + return; + } - TestUtils.testDone(); - } + TestUtils.testDone(); + } } ignitionStartSuccessWithSeveralPorts = function() { - Ignition.start(['127.0.0.1:9090..9100'], null, onConnect); + Ignition.start(['127.0.0.1:9090..9100'], null, onConnect); - function onConnect(error, ignite) { - if (error) { - TestUtils.testFails(error); + function onConnect(error, ignite) { + if (error) { + TestUtils.testFails(error); - return; - } + return; + } - var server = ignite.server(); + var server = ignite.server(); - var host = server.host(); + var host = server.host(); - assert.ok(host.indexOf('127.0.0.1') !== -1, "Incorrect host."); + assert.ok(host.indexOf('127.0.0.1') !== -1, "Incorrect host."); - TestUtils.testDone(); - } + TestUtils.testDone(); + } } ignitionNotStartWithSeveralPorts = function() { - Ignition.start(['127.0.0.1:9090...9100'], null, onConnect); + Ignition.start(['127.0.0.1:9090...9100'], null, onConnect); - function onConnect(error, ignite) { - if (error) { - assert.ok(error.indexOf("Incorrect address format") !== -1, "Incorrect message.") + function onConnect(error, ignite) { + if (error) { + assert.ok(error.indexOf("Incorrect address format") !== -1, "Incorrect message.") - TestUtils.testDone(); + TestUtils.testDone(); - return; - } + return; + } - TestUtils.testFails("Exception should be thrown."); - } + TestUtils.testFails("Exception should be thrown."); + } } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/f9f98acb/modules/nodejs/src/test/js/test-key.js ---------------------------------------------------------------------- diff --git a/modules/nodejs/src/test/js/test-key.js b/modules/nodejs/src/test/js/test-key.js index b02a6b5..be5888e 100644 --- a/modules/nodejs/src/test/js/test-key.js +++ b/modules/nodejs/src/test/js/test-key.js @@ -20,35 +20,35 @@ var TestUtils = require("./test-utils").TestUtils; var assert = require("assert"); testStartWithoutKey = function() { - TestUtils.startIgniteNode(onIncorrectStart); + TestUtils.startIgniteNode(onIncorrectStart); } testStartWithKey = function() { - TestUtils.startIgniteNodeWithKey("secret-key", onStart); + TestUtils.startIgniteNodeWithKey("secret-key", onStart); } testStartWithIncorrectKey = function() { - TestUtils.startIgniteNodeWithKey("secret-key1", onIncorrectStart); + TestUtils.startIgniteNodeWithKey("secret-key1", onIncorrectStart); } function onIncorrectStart(error, ignite) { - assert(error != null, "Do not get authentication error"); + assert(error != null, "Do not get authentication error"); - assert(error.indexOf("Authentication failed. Status code 401.") !== -1, "Incorrect error message: " + error); + assert(error.indexOf("Authentication failed. Status code 401.") !== -1, "Incorrect error message: " + error); - TestUtils.testDone(); + TestUtils.testDone(); } function onStart(error, ignite) { - assert(error === null, "Get error: " + error); + assert(error === null, "Get error: " + error); - assert(ignite !== null, "Cannot connect. Get null ignite."); + assert(ignite !== null, "Cannot connect. Get null ignite."); - var cache = ignite.cache("mycache"); + var cache = ignite.cache("mycache"); - assert(cache !== null, "Cache is null.") + assert(cache !== null, "Cache is null.") - cache.put("key", "6", onPut); + cache.put("key", "6", onPut); } function onPut(error) { http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/f9f98acb/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 index ae2f0f0..0b0aebb 100644 --- a/modules/nodejs/src/test/js/test-utils.js +++ b/modules/nodejs/src/test/js/test-utils.js @@ -27,26 +27,26 @@ 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() + "js" + TestUtils.sep(); + return TestUtils.igniteHome() + + TestUtils.sep() + "modules" + + TestUtils.sep() + "nodejs" + + TestUtils.sep() + "src" + + TestUtils.sep() + "main" + + TestUtils.sep() + "js" + TestUtils.sep(); } /** * @returns {string} Ignite home path */ TestUtils.igniteHome = function() { - return process.env.IGNITE_HOME; + return process.env.IGNITE_HOME; } /** * @returns {string} Path separator */ TestUtils.sep = function() { - return require('path').sep; + return require('path').sep; } /** @@ -54,61 +54,61 @@ TestUtils.sep = function() { * @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); + 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 results; + }; - return walk(dir); + 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 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 cp = libs.join(require('path').delimiter); - var spawn = require('child_process').spawn; + var spawn = require('child_process').spawn; - var child = spawn('java',['-classpath', cp, 'org.apache.ignite.startup.cmdline.CommandLineStartup', - "test-node.xml"]); + 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.stdout.on('data', function (data) { + console.log("" + data); + }); - child.stderr.on('data', function (data) { - console.log("" + data); - }); + child.stderr.on('data', function (data) { + console.log("" + data); + }); - return child; + return child; } /** @@ -117,14 +117,14 @@ TestUtils.startIgniteNode = function() { * @param {string} error Error */ TestUtils.testFails = function(error) { - console.log("Node JS test failed: " + error); + console.log("Node JS test failed: " + error); } /** * Print ok message to console */ TestUtils.testDone = function() { - console.log("Node JS test finished.") + console.log("Node JS test finished.") } /** @@ -133,10 +133,10 @@ TestUtils.testDone = function() { * @param {Ignition~onStart} callback Called on connect */ TestUtils.startIgniteNode = function(callback) { - var Ignite = require(TestUtils.scriptPath()); - var Ignition = Ignite.Ignition; + var Ignite = require(TestUtils.scriptPath()); + var Ignition = Ignite.Ignition; - Ignition.start(['127.0.0.1:9095'], null, callback); + Ignition.start(['127.0.0.1:9095'], null, callback); } /** @@ -146,10 +146,10 @@ TestUtils.startIgniteNode = function(callback) { * @param {Ignition~onStart} callback Called on connect */ TestUtils.startIgniteNodeWithKey = function(secretKey, callback) { - var Ignite = require(TestUtils.scriptPath()); - var Ignition = Ignite.Ignition; + var Ignite = require(TestUtils.scriptPath()); + var Ignition = Ignite.Ignition; - Ignition.start(['127.0.0.1:9095'], secretKey, callback); + Ignition.start(['127.0.0.1:9095'], secretKey, callback); } exports.TestUtils = TestUtils;