You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by sb...@apache.org on 2015/06/05 17:18:30 UTC

incubator-ignite git commit: #nodejs: add test_ignition.js

Repository: incubator-ignite
Updated Branches:
  refs/heads/nodejs 82da81d22 -> 8aeb5f05c


#nodejs: add test_ignition.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/8aeb5f05
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/8aeb5f05
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/8aeb5f05

Branch: refs/heads/nodejs
Commit: 8aeb5f05cdcea7a4a4e513242d785eba6cc8ad3b
Parents: 82da81d
Author: ivasilinets <iv...@gridgain.com>
Authored: Fri Jun 5 18:18:23 2015 +0300
Committer: ivasilinets <iv...@gridgain.com>
Committed: Fri Jun 5 18:18:23 2015 +0300

----------------------------------------------------------------------
 .../ignite/internal/NodeJsAbstractTest.java     |  14 ++-
 .../apache/ignite/internal/NodeJsSelfTest.java  |   4 +-
 modules/nodejs/src/test/nodejs/test.js          |  83 ++------------
 modules/nodejs/src/test/nodejs/test_ignition.js |  14 +++
 modules/nodejs/src/test/nodejs/test_utils.js    | 109 +++++++++++++++++++
 5 files changed, 144 insertions(+), 80 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/8aeb5f05/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 597dd03..ba04f53 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
@@ -36,6 +36,12 @@ public class NodeJsAbstractTest extends GridCommonAbstractTest {
     /** Cache name. */
     public static final String CACHE_NAME = "mycache";
 
+    /** Failed message. */
+    public static final String SCRIPT_FAILED = "node js test failed:";
+
+    /** Ok message. */
+    public static final String SCRIPT_FINISHED = "node js test finished.";
+
     /** {@inheritDoc} */
     @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
         IgniteConfiguration cfg = super.getConfiguration(gridName);
@@ -89,7 +95,7 @@ public class NodeJsAbstractTest extends GridCommonAbstractTest {
 
         List<String> cmd = new ArrayList<>();
 
-        cmd.add("C:\\Program Files\\nodejs\\node_modules\\.bin\\nodeunit.cmd");
+        cmd.add("node");
 
         cmd.add(path);
 
@@ -106,10 +112,12 @@ public class NodeJsAbstractTest extends GridCommonAbstractTest {
                     @Override public void apply(String s) {
                         info("Node js: " + s);
 
-                        if (s.contains("OK: "))
+                        s = s.toLowerCase();
+
+                        if (s.contains(SCRIPT_FINISHED))
                             readyLatch.countDown();
 
-                        if (s.contains("Error") || s.contains("FAILURES")) {
+                        if (s.contains("error") || s.contains("fail") || s.contains(SCRIPT_FAILED)) {
                             errors.add("Script failed: " + s);
 
                             readyLatch.countDown();

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/8aeb5f05/modules/nodejs/src/test/java/org/apache/ignite/internal/NodeJsSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/nodejs/src/test/java/org/apache/ignite/internal/NodeJsSelfTest.java b/modules/nodejs/src/test/java/org/apache/ignite/internal/NodeJsSelfTest.java
index 82c29eb..2821e3e 100644
--- a/modules/nodejs/src/test/java/org/apache/ignite/internal/NodeJsSelfTest.java
+++ b/modules/nodejs/src/test/java/org/apache/ignite/internal/NodeJsSelfTest.java
@@ -34,7 +34,7 @@ public class NodeJsSelfTest extends NodeJsAbstractTest {
     /**
      * @throws Exception If failed.
      */
-    public void testPutGetJs() throws Exception {
-        runJsScript(getNodeJsTestDir() + "test.js");
+    public void testIgnitionStart() throws Exception {
+        runJsScript(getNodeJsTestDir() + "test_ignition.js");
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/8aeb5f05/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
index 39fcafd..bdce21d 100644
--- a/modules/nodejs/src/test/nodejs/test.js
+++ b/modules/nodejs/src/test/nodejs/test.js
@@ -2,8 +2,9 @@ module.exports = {
     'Test put/get' : function(test) {
         test.expect(1);
 
-        var Cache = require(scriptPath() + "cache").Cache;
-        var Server = require(scriptPath() + "server").Server;
+        var TestUtils = require("./test_utils").TestUtils;
+        var Cache = require(TestUtils.scriptPath() + "cache").Cache;
+        var Server = require(TestUtils.scriptPath() + "server").Server;
 
         var assert = require('assert');
 
@@ -44,8 +45,8 @@ module.exports = {
         test.expect(0);
 
         //var node = startIgniteNode();
-
-        var Server = require(scriptPath() + "server").Server;
+        var TestUtils = require("./test_utils").TestUtils;
+        var Server = require(TestUtils.scriptPath() + "server").Server;
 
         setTimeout(initServer, 10000);
 
@@ -70,8 +71,8 @@ module.exports = {
         test.expect(1);
 
         //var node = startIgniteNode('127.0.0.1', 9090);
-
-        var Ignition = require(scriptPath() + "ignition").Ignition;
+        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);
 
@@ -86,39 +87,6 @@ module.exports = {
     }
  };
 
-function scriptPath() {
-    return igniteHome() +
-       sep() + "modules" +
-       sep() + "nodejs" +
-       sep() + "src" +
-       sep() + "main" +
-       sep() + "nodejs" + sep();
-}
-
-function startIgniteNode() {
-    var libs = classpath(igniteHome() +  sep() + "target" +
-        sep() + "bin" +
-        sep() + "apache-ignite-fabric-1.1.1-SNAPSHOT-bin" +
-        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;
-}
-
 function finishWithError(test/*, node*/, error) {
     console.log("Error: " + error);
     test.ok(false);
@@ -128,39 +96,4 @@ function finishWithError(test/*, node*/, error) {
 function finishTest(test/*, node*/) {
     //node.kill();
     test.done();
-}
-
-function igniteHome() {
-    return process.env.IGNITE_HOME;
-}
-
-function sep() {
-    return require('path').sep;
-}
-
-function classpath(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);
-};
\ No newline at end of file
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/8aeb5f05/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
new file mode 100644
index 0000000..df7e240
--- /dev/null
+++ b/modules/nodejs/src/test/nodejs/test_ignition.js
@@ -0,0 +1,14 @@
+var TestUtils = require("./test_utils").TestUtils;
+var Ignition = require(TestUtils.scriptPath() + "ignition").Ignition;
+
+Ignition.start(9090, ['127.0.0.0', '127.0.0.1'], 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/8aeb5f05/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
new file mode 100644
index 0000000..dca6603
--- /dev/null
+++ b/modules/nodejs/src/test/nodejs/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