ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sboi...@apache.org
Subject incubator-ignite git commit: #nodejs: Change tests for nodejs.
Date Sun, 07 Jun 2015 19:26:18 GMT
Repository: incubator-ignite
Updated Branches:
  refs/heads/nodejs f8d2261df -> bfa16e5ce


#nodejs: Change tests for nodejs.


Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/bfa16e5c
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/bfa16e5c
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/bfa16e5c

Branch: refs/heads/nodejs
Commit: bfa16e5ceeec243ea979b9a90dd0aad6f9962e37
Parents: f8d2261
Author: ivasilinets <ivasilinets@gridgain.com>
Authored: Sun Jun 7 22:25:21 2015 +0300
Committer: ivasilinets <ivasilinets@gridgain.com>
Committed: Sun Jun 7 22:25:21 2015 +0300

----------------------------------------------------------------------
 modules/nodejs/src/main/nodejs/ignition.js      |  1 +
 modules/nodejs/src/main/nodejs/server.js        |  2 ++
 .../ignite/internal/NodeJsAbstractTest.java     | 22 ++++++++++----
 .../apache/ignite/internal/NodeJsSelfTest.java  |  9 ++++--
 modules/nodejs/src/test/nodejs/test_ignition.js | 30 ++++++++++++++++----
 .../src/test/nodejs/test_ignition_fail.js       | 17 -----------
 modules/nodejs/src/test/nodejs/test_utils.js    | 18 +++++++++++-
 7 files changed, 68 insertions(+), 31 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/bfa16e5c/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
index b771f75..5d5652d 100644
--- a/modules/nodejs/src/main/nodejs/ignition.js
+++ b/modules/nodejs/src/main/nodejs/ignition.js
@@ -41,6 +41,7 @@ Ignition.start = function(address, callback) {
         }
 
         console.log(error);
+
         if (!numConn)
             callback.call(null, "Cannot connect to servers.", null);
     }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/bfa16e5c/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
index fa6d477..ec770da 100644
--- a/modules/nodejs/src/main/nodejs/server.js
+++ b/modules/nodejs/src/main/nodejs/server.js
@@ -77,6 +77,8 @@ Server.prototype.runCommand = function(cmdName, params, callback) {
 
     var request = http.request(options, streamCallback);
 
+    request.setTimeout(5000, callback.bind(null, "Request timeout: >5 sec"));
+
     request.on('error', callback);
     request.end();
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/bfa16e5c/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 23b3b80..05cd6ef 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
@@ -42,6 +42,16 @@ public class NodeJsAbstractTest extends GridCommonAbstractTest {
     /** Ok message. */
     public static final String SCRIPT_FINISHED = "node js test finished.";
 
+    /** Node JS file with tests. */
+    private String fileName;
+
+    /**
+     * @param fileName Node JS file name.
+     */
+    protected NodeJsAbstractTest(String fileName) {
+        this.fileName = fileName;
+    }
+
     /** {@inheritDoc} */
     @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception
{
         IgniteConfiguration cfg = super.getConfiguration(gridName);
@@ -83,10 +93,10 @@ public class NodeJsAbstractTest extends GridCommonAbstractTest {
     }
 
     /**
-     * @param path Path to script.
+     * @param functionName Function name.
      * @throws Exception If script failed.
      */
-    protected void runJsScript(String path) throws Exception {
+    protected void runJsScript(String functionName) throws Exception {
         final CountDownLatch readyLatch = new CountDownLatch(1);
 
         GridJavaProcess proc = null;
@@ -97,7 +107,11 @@ public class NodeJsAbstractTest extends GridCommonAbstractTest {
 
         cmd.add("node");
 
-        cmd.add(path);
+        cmd.add(getNodeJsTestDir() + "test_utils.js");
+
+        cmd.add(fileName);
+
+        cmd.add(functionName);
 
         Map<String, String> env = new HashMap<>();
 
@@ -130,8 +144,6 @@ public class NodeJsAbstractTest extends GridCommonAbstractTest {
             assertTrue(readyLatch.await(60, SECONDS));
 
             assertEquals(errors.toString(), 0, errors.size());
-
-            proc.getProcess().waitFor();
         }
         finally {
             if (proc != null)

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/bfa16e5c/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 66e973d..93b6fc6 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
@@ -21,6 +21,11 @@ package org.apache.ignite.internal;
  * Test node js client.
  */
 public class NodeJsSelfTest extends NodeJsAbstractTest {
+    /** Constructor. */
+    public NodeJsSelfTest() {
+        super("test_ignition.js");
+    }
+
     /** {@inheritDoc} */
     @Override protected void beforeTestsStarted() throws Exception {
         startGrid(0);
@@ -35,13 +40,13 @@ public class NodeJsSelfTest extends NodeJsAbstractTest {
      * @throws Exception If failed.
      */
     public void testIgnitionStart() throws Exception {
-        runJsScript(getNodeJsTestDir() + "test_ignition.js");
+        runJsScript("ignition_start_success");
     }
 
     /**
      * @throws Exception If failed.
      */
     public void testIgnitionFailedStart() throws Exception {
-        runJsScript(getNodeJsTestDir() + "test_ignition_fail.js");
+        runJsScript("test_ignition_fail");
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/bfa16e5c/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
index c441b01..db9f9f5 100644
--- a/modules/nodejs/src/test/nodejs/test_ignition.js
+++ b/modules/nodejs/src/test/nodejs/test_ignition.js
@@ -1,14 +1,32 @@
 var TestUtils = require("./test_utils").TestUtils;
 var Ignition = require(TestUtils.scriptPath() + "ignition").Ignition;
 
-Ignition.start(['127.0.0.0:9090', '127.0.0.1:9090'], onConnect);
+test_ignition_fail = function ()  {
+    Ignition.start(['127.0.0.3:9091', '127.0.0.1:9092'], onConnect);
 
-function onConnect(error, server) {
-    if (error) {
-        TestUtils.testFails(error);
+    function onConnect(error, server) {
+        if (error) {
+            if (error.indexOf("Cannot connect to servers.") == -1)
+                TestUtils.testFails("Incorrect error message: " + error);
+            else
+                TestUtils.testDone();
 
-        return;
+            return;
+        }
+
+        TestUtils.testFails("Test should fail.");
     }
+}
+
+ignition_start_success = function() {
+    Ignition.start(['127.0.0.0:9090', '127.0.0.1:9090'], onConnect);
 
-    TestUtils.testDone();
+    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/bfa16e5c/modules/nodejs/src/test/nodejs/test_ignition_fail.js
----------------------------------------------------------------------
diff --git a/modules/nodejs/src/test/nodejs/test_ignition_fail.js b/modules/nodejs/src/test/nodejs/test_ignition_fail.js
deleted file mode 100644
index 2259592..0000000
--- a/modules/nodejs/src/test/nodejs/test_ignition_fail.js
+++ /dev/null
@@ -1,17 +0,0 @@
-var TestUtils = require("./test_utils").TestUtils;
-var Ignition = require(TestUtils.scriptPath() + "ignition").Ignition;
-
-Ignition.start(['127.0.0.0: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.");
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/bfa16e5c/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
index dca6603..20dc504 100644
--- a/modules/nodejs/src/test/nodejs/test_utils.js
+++ b/modules/nodejs/src/test/nodejs/test_utils.js
@@ -106,4 +106,20 @@ TestUtils.testDone = function() {
     console.log("Node JS test finished.")
 }
 
-exports.TestUtils = TestUtils;
\ No newline at end of file
+/**
+ * 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


Mime
View raw message