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 9251E17FB2 for ; Mon, 8 Jun 2015 10:12:53 +0000 (UTC) Received: (qmail 11298 invoked by uid 500); 8 Jun 2015 10:12:53 -0000 Delivered-To: apmail-ignite-commits-archive@ignite.apache.org Received: (qmail 11266 invoked by uid 500); 8 Jun 2015 10:12:53 -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 11257 invoked by uid 99); 8 Jun 2015 10:12:53 -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:53 +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 10343 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 8662CDFF82; 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:23 -0000 Message-Id: <53df7f5a87254013b12fbb98c02602bd@git.apache.org> In-Reply-To: <45db4b432fcb4b64bc4416fbc57e611c@git.apache.org> References: <45db4b432fcb4b64bc4416fbc57e611c@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [5/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/0e197f2b Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/0e197f2b Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/0e197f2b Branch: refs/heads/ignite-nodejs Commit: 0e197f2b3ebb5b1c9ea85bdad0f2e37853722408 Parents: 628f0a9 Author: ivasilinets Authored: Mon Jun 8 12:38:14 2015 +0300 Committer: ivasilinets Committed: Mon Jun 8 12:38:14 2015 +0300 ---------------------------------------------------------------------- modules/nodejs/src/main/js/cache.js | 73 ++++++++++ modules/nodejs/src/main/js/ignition.js | 67 +++++++++ modules/nodejs/src/main/js/server.js | 113 +++++++++++++++ modules/nodejs/src/main/nodejs/cache.js | 73 ---------- modules/nodejs/src/main/nodejs/ignition.js | 67 --------- modules/nodejs/src/main/nodejs/server.js | 113 --------------- .../ignite/internal/NodeJsAbstractTest.java | 2 +- modules/nodejs/src/test/js/rest-jetty.xml | 71 ++++++++++ modules/nodejs/src/test/js/test-node.xml | 97 +++++++++++++ modules/nodejs/src/test/js/test.js | 116 +++++++++++++++ modules/nodejs/src/test/js/test_ignition.js | 49 +++++++ modules/nodejs/src/test/js/test_put_get.js | 50 +++++++ modules/nodejs/src/test/js/test_utils.js | 142 +++++++++++++++++++ modules/nodejs/src/test/nodejs/rest-jetty.xml | 71 ---------- modules/nodejs/src/test/nodejs/test-node.xml | 97 ------------- modules/nodejs/src/test/nodejs/test.js | 116 --------------- modules/nodejs/src/test/nodejs/test_ignition.js | 49 ------- modules/nodejs/src/test/nodejs/test_put_get.js | 50 ------- modules/nodejs/src/test/nodejs/test_utils.js | 142 ------------------- 19 files changed, 779 insertions(+), 779 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/0e197f2b/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..9ee6f9c --- /dev/null +++ b/modules/nodejs/src/main/js/cache.js @@ -0,0 +1,73 @@ +/* + * 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. + */ + +/** + * 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/0e197f2b/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..6cb6e72 --- /dev/null +++ b/modules/nodejs/src/main/js/ignition.js @@ -0,0 +1,67 @@ +/* + * 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. + */ + +/** + * 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(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/0e197f2b/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..7bdb360 --- /dev/null +++ b/modules/nodejs/src/main/js/server.js @@ -0,0 +1,113 @@ +/* + * 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. + */ + +/** + * 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) { + 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/0e197f2b/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 9ee6f9c..0000000 --- a/modules/nodejs/src/main/nodejs/cache.js +++ /dev/null @@ -1,73 +0,0 @@ -/* - * 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. - */ - -/** - * 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/0e197f2b/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 6cb6e72..0000000 --- a/modules/nodejs/src/main/nodejs/ignition.js +++ /dev/null @@ -1,67 +0,0 @@ -/* - * 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. - */ - -/** - * 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(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/0e197f2b/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 7bdb360..0000000 --- a/modules/nodejs/src/main/nodejs/server.js +++ /dev/null @@ -1,113 +0,0 @@ -/* - * 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. - */ - -/** - * 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) { - 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/0e197f2b/modules/nodejs/src/test/java/org/apache/ignite/internal/NodeJsAbstractTest.java ---------------------------------------------------------------------- diff --git a/modules/nodejs/src/test/java/org/apache/ignite/internal/NodeJsAbstractTest.java b/modules/nodejs/src/test/java/org/apache/ignite/internal/NodeJsAbstractTest.java index 01abc22..b5e96f3 100644 --- a/modules/nodejs/src/test/java/org/apache/ignite/internal/NodeJsAbstractTest.java +++ b/modules/nodejs/src/test/java/org/apache/ignite/internal/NodeJsAbstractTest.java @@ -89,7 +89,7 @@ public class NodeJsAbstractTest extends GridCommonAbstractTest { sep + "nodejs" + sep + "src" + sep + "test" + - sep + "nodejs" + sep; + sep + "js" + sep; } /** http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/0e197f2b/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..d292d06 --- /dev/null +++ b/modules/nodejs/src/test/js/rest-jetty.xml @@ -0,0 +1,71 @@ + + + + + + + + + + 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/0e197f2b/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/0e197f2b/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..7485072 --- /dev/null +++ b/modules/nodejs/src/test/js/test.js @@ -0,0 +1,116 @@ +/* + * 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. + */ + +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); + + 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/0e197f2b/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..e1e18cc --- /dev/null +++ b/modules/nodejs/src/test/js/test_ignition.js @@ -0,0 +1,49 @@ +/* + * 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. + */ + +var TestUtils = require("./test_utils").TestUtils; +var Ignition = require(TestUtils.scriptPath() + "ignition").Ignition; + +testIgnitionFail = 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."); + } +} + +ignitionStartSuccess = function() { + Ignition.start(['127.0.0.0:9090', '127.0.0.1:9090'], 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/0e197f2b/modules/nodejs/src/test/js/test_put_get.js ---------------------------------------------------------------------- diff --git a/modules/nodejs/src/test/js/test_put_get.js b/modules/nodejs/src/test/js/test_put_get.js new file mode 100644 index 0000000..af3695b --- /dev/null +++ b/modules/nodejs/src/test/js/test_put_get.js @@ -0,0 +1,50 @@ +/* + * 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. + */ + +var TestUtils = require("./test_utils").TestUtils; +var Cache = require(TestUtils.scriptPath() + "cache").Cache; +var Server = require(TestUtils.scriptPath() + "server").Server; + +testPutGet = function() { + var server = new Server('127.0.0.1', 9090); + var cache = new Cache(server, "mycache"); + cache.put("key", "6", onPut.bind(null, cache)); +} + +function onPut(cache, error) { + if (error) { + TestUtils.testFails("Incorrect error message: " + error); + return; + } + + console.log("Put finished"); + cache.get("key", onGet); +} + +function onGet(error, value) { + if (error) { + console.error("Failed to get " + error); + TestUtils.testFails("Incorrect error message: " + error); + return; + } + + var assert = require("assert"); + + assert.equal(value, 6, "Get return incorrect value. + [expected=" + 6 + ", val=" + value + "]."); + + TestUtils.testDone(); +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/0e197f2b/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..a37c0ed --- /dev/null +++ b/modules/nodejs/src/test/js/test_utils.js @@ -0,0 +1,142 @@ +/* + * 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. + */ + +/** + * 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() + "js" + 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.") +} + +/** + * Test routine. + */ +TestUtils.runTest = function() { + var fileName = process.argv[2].toString().trim(); + require("./" + fileName); + var functionName = process.argv[3].toString().trim(); + if (!global[functionName]) { + console.log("node js test failed: function with name " + functionName + " not found"); + return; + } + global[functionName](); +} + +exports.TestUtils = TestUtils; + +TestUtils.runTest(); \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/0e197f2b/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 d292d06..0000000 --- a/modules/nodejs/src/test/nodejs/rest-jetty.xml +++ /dev/null @@ -1,71 +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/0e197f2b/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/0e197f2b/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 7485072..0000000 --- a/modules/nodejs/src/test/nodejs/test.js +++ /dev/null @@ -1,116 +0,0 @@ -/* - * 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. - */ - -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); - - 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/0e197f2b/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 e1e18cc..0000000 --- a/modules/nodejs/src/test/nodejs/test_ignition.js +++ /dev/null @@ -1,49 +0,0 @@ -/* - * 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. - */ - -var TestUtils = require("./test_utils").TestUtils; -var Ignition = require(TestUtils.scriptPath() + "ignition").Ignition; - -testIgnitionFail = 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."); - } -} - -ignitionStartSuccess = function() { - Ignition.start(['127.0.0.0:9090', '127.0.0.1:9090'], 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/0e197f2b/modules/nodejs/src/test/nodejs/test_put_get.js ---------------------------------------------------------------------- diff --git a/modules/nodejs/src/test/nodejs/test_put_get.js b/modules/nodejs/src/test/nodejs/test_put_get.js deleted file mode 100644 index af3695b..0000000 --- a/modules/nodejs/src/test/nodejs/test_put_get.js +++ /dev/null @@ -1,50 +0,0 @@ -/* - * 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. - */ - -var TestUtils = require("./test_utils").TestUtils; -var Cache = require(TestUtils.scriptPath() + "cache").Cache; -var Server = require(TestUtils.scriptPath() + "server").Server; - -testPutGet = function() { - var server = new Server('127.0.0.1', 9090); - var cache = new Cache(server, "mycache"); - cache.put("key", "6", onPut.bind(null, cache)); -} - -function onPut(cache, error) { - if (error) { - TestUtils.testFails("Incorrect error message: " + error); - return; - } - - console.log("Put finished"); - cache.get("key", onGet); -} - -function onGet(error, value) { - if (error) { - console.error("Failed to get " + error); - TestUtils.testFails("Incorrect error message: " + error); - return; - } - - var assert = require("assert"); - - assert.equal(value, 6, "Get return incorrect value. + [expected=" + 6 + ", val=" + value + "]."); - - TestUtils.testDone(); -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/0e197f2b/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 1383a84..0000000 --- a/modules/nodejs/src/test/nodejs/test_utils.js +++ /dev/null @@ -1,142 +0,0 @@ -/* - * 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. - */ - -/** - * 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.") -} - -/** - * Test routine. - */ -TestUtils.runTest = function() { - var fileName = process.argv[2].toString().trim(); - require("./" + fileName); - var functionName = process.argv[3].toString().trim(); - if (!global[functionName]) { - console.log("node js test failed: function with name " + functionName + " not found"); - return; - } - global[functionName](); -} - -exports.TestUtils = TestUtils; - -TestUtils.runTest(); \ No newline at end of file