You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by iv...@apache.org on 2015/07/30 16:59:44 UTC

incubator-ignite git commit: #ignite-1051: add tests for nodejs examples.

Repository: incubator-ignite
Updated Branches:
  refs/heads/ignite-1051 [created] 20fbf3dae


#ignite-1051: add tests for nodejs examples.


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

Branch: refs/heads/ignite-1051
Commit: 20fbf3dae99636e58685aed40c6bbd58926b3c95
Parents: 6961060
Author: ivasilinets <iv...@gridgain.com>
Authored: Thu Jul 30 17:59:34 2015 +0300
Committer: ivasilinets <iv...@gridgain.com>
Committed: Thu Jul 30 17:59:34 2015 +0300

----------------------------------------------------------------------
 examples/pom.xml                                |  8 ++
 .../ignite/examples/NodeJsExamplesSelfTest.java | 92 ++++++++++++++++++++
 modules/nodejs/src/main/js/server.js            |  2 -
 .../ignite/internal/NodeJsAbstractTest.java     | 34 +++++++-
 modules/nodejs/src/test/js/test-runner.js       |  2 +-
 .../nodejs/src/test/js/test-script-runner.js    | 37 ++++++++
 6 files changed, 168 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/20fbf3da/examples/pom.xml
----------------------------------------------------------------------
diff --git a/examples/pom.xml b/examples/pom.xml
index 8204a36..54dc2ea 100644
--- a/examples/pom.xml
+++ b/examples/pom.xml
@@ -63,6 +63,14 @@
 
         <dependency>
             <groupId>org.apache.ignite</groupId>
+            <artifactId>ignite-nodejs</artifactId>
+            <version>${project.version}</version>
+            <type>test-jar</type>
+            <scope>test</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.ignite</groupId>
             <artifactId>ignite-spring</artifactId>
             <version>${project.version}</version>
         </dependency>

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/20fbf3da/examples/src/test/java/org/apache/ignite/examples/NodeJsExamplesSelfTest.java
----------------------------------------------------------------------
diff --git a/examples/src/test/java/org/apache/ignite/examples/NodeJsExamplesSelfTest.java b/examples/src/test/java/org/apache/ignite/examples/NodeJsExamplesSelfTest.java
new file mode 100644
index 0000000..ee6e401
--- /dev/null
+++ b/examples/src/test/java/org/apache/ignite/examples/NodeJsExamplesSelfTest.java
@@ -0,0 +1,92 @@
+/*
+ * 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.
+ */
+
+package org.apache.ignite.examples;
+
+import org.apache.ignite.configuration.*;
+import org.apache.ignite.internal.*;
+import org.apache.ignite.internal.util.typedef.internal.*;
+
+/**
+ * Test for nodejs examples.
+ */
+public class NodeJsExamplesSelfTest extends NodeJsAbstractTest {
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
+        return loadConfiguration("examples/config/js/example-query.xml");
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTestsStarted() throws Exception {
+        startGrid(0);
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTestsStopped() throws Exception {
+        stopAllGrids();
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testCacheApiExample() throws Exception {
+        run("cache-api-example.js");
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testCachePutGetExample() throws Exception {
+        run("cache-put-get-example.js");
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testQueryExample() throws Exception {
+        run("cache-query-example.js");
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testFieldsQueryExample() throws Exception {
+        run("cache-sql-fields-query-example.js");
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testComputeRunExample() throws Exception {
+        run("compute-run-example.js");
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testComputeMapReduceExample() throws Exception {
+        run("map-reduce-example.js");
+    }
+
+    /**
+     * @param fileName Example file name.
+     * @throws Exception If failed.
+     */
+    private void run(String fileName) throws Exception {
+        runJsScript(null, U.getIgniteHome() + "/examples/src/main/js/" + fileName, ">>> end");
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/20fbf3da/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 7fa22b1..fe2e12b 100644
--- a/modules/nodejs/src/main/js/server.js
+++ b/modules/nodejs/src/main/js/server.js
@@ -86,8 +86,6 @@ Server.prototype.runCommand = function(cmd, callback) {
         });
 
         response.on('end', function () {
-            //console.log("Full response:" + fullResponseString);
-
             if (response.statusCode !== 200) {
                 if (response.statusCode === 401) {
                     callback.call(null, "Authentication failed. Status code 401.");

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/20fbf3da/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 47152e9..011d727 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
@@ -58,6 +58,13 @@ public class NodeJsAbstractTest extends GridCommonAbstractTest {
         this.fileName = fileName;
     }
 
+    /**
+     * Empty constructor.
+     */
+    protected NodeJsAbstractTest() {
+        // No-op.
+    }
+
     /** {@inheritDoc} */
     @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
         IgniteConfiguration cfg = super.getConfiguration(gridName);
@@ -111,6 +118,16 @@ public class NodeJsAbstractTest extends GridCommonAbstractTest {
      * @throws Exception If script failed.
      */
     protected void runJsScript(String functionName) throws Exception {
+        runJsScript(functionName, getNodeJsTestDir() + fileName, null);
+    }
+
+    /**
+     * @param functionName Function name.
+     * @param fileName File name.
+     * @param scriptFinished Script finished string.
+     * @throws Exception If script failed.
+     */
+    protected void runJsScript(String functionName, String fileName, String scriptFinished) throws Exception {
         final CountDownLatch readyLatch = new CountDownLatch(1);
 
         GridJavaProcess proc = null;
@@ -120,9 +137,18 @@ public class NodeJsAbstractTest extends GridCommonAbstractTest {
         List<String> cmd = new ArrayList<>();
 
         cmd.add("node");
-        cmd.add(getNodeJsTestDir() + "test-runner.js");
-        cmd.add(fileName);
-        cmd.add(functionName);
+
+        if (functionName != null) {
+            cmd.add(getNodeJsTestDir() + "test-runner.js");
+            cmd.add(fileName);
+            cmd.add(functionName);
+        }
+        else {
+            cmd.add(getNodeJsTestDir() + "test-script-runner.js");
+            cmd.add(fileName);
+        }
+
+        final String finishedFlag = scriptFinished != null ? scriptFinished : SCRIPT_FINISHED;
 
         Map<String, String> env = new HashMap<>();
 
@@ -136,7 +162,7 @@ public class NodeJsAbstractTest extends GridCommonAbstractTest {
 
                         s = s.toLowerCase();
 
-                        if (s.contains(SCRIPT_FINISHED))
+                        if (s.contains(finishedFlag))
                             readyLatch.countDown();
 
                         if (s.contains("assert") || s.contains(SCRIPT_FAILED)) {

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/20fbf3da/modules/nodejs/src/test/js/test-runner.js
----------------------------------------------------------------------
diff --git a/modules/nodejs/src/test/js/test-runner.js b/modules/nodejs/src/test/js/test-runner.js
index 9ee1092..86ac082 100644
--- a/modules/nodejs/src/test/js/test-runner.js
+++ b/modules/nodejs/src/test/js/test-runner.js
@@ -31,7 +31,7 @@ TestRunner.runTest = function() {
 
     console.log("FileName " + fileName);
 
-    require("./" + fileName);
+    require(fileName);
 
     var functionName = process.argv[3].toString().trim();
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/20fbf3da/modules/nodejs/src/test/js/test-script-runner.js
----------------------------------------------------------------------
diff --git a/modules/nodejs/src/test/js/test-script-runner.js b/modules/nodejs/src/test/js/test-script-runner.js
new file mode 100644
index 0000000..9ebfbce
--- /dev/null
+++ b/modules/nodejs/src/test/js/test-script-runner.js
@@ -0,0 +1,37 @@
+/*
+ * 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 ScriptTestRunner
+ *
+ * @constructor
+ */
+function ScriptTestRunner() {
+}
+
+/**
+ * Test routine
+ */
+ScriptTestRunner.runTest = function() {
+    var fileName = process.argv[2].toString().trim();
+
+    console.log("FileName " + fileName);
+
+    require(fileName);
+}
+
+ScriptTestRunner.runTest();
\ No newline at end of file