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/23 19:47:46 UTC

[20/20] incubator-ignite git commit: #ignite-965: code style test-compute.js

#ignite-965: code style test-compute.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/47276a81
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/47276a81
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/47276a81

Branch: refs/heads/ignite-965
Commit: 47276a81e715a5525a66a875d37e13892bf13216
Parents: d7e5465
Author: ivasilinets <iv...@gridgain.com>
Authored: Tue Jun 23 20:47:03 2015 +0300
Committer: ivasilinets <iv...@gridgain.com>
Committed: Tue Jun 23 20:47:03 2015 +0300

----------------------------------------------------------------------
 .../internal/processors/scripting/IgniteJS.java |  8 ++-
 modules/nodejs/src/test/js/test-compute.js      | 66 +++++++++-----------
 2 files changed, 34 insertions(+), 40 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/47276a81/modules/core/src/main/java/org/apache/ignite/internal/processors/scripting/IgniteJS.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/scripting/IgniteJS.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/scripting/IgniteJS.java
index 6ffe1b1..dd7624c 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/scripting/IgniteJS.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/scripting/IgniteJS.java
@@ -21,7 +21,11 @@ package org.apache.ignite.internal.processors.scripting;
  * Ignite JS binding.
  */
 public class IgniteJS {
-    public void hello() {
-        System.out.println("HELLO HAPPY WORLD!!!");
+    public String hello() {
+        String str = "HELLO HAPPY WORLD!!!";
+
+        System.out.println(str);
+
+        return str;
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/47276a81/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 c444380..2267662 100644
--- a/modules/nodejs/src/test/js/test-compute.js
+++ b/modules/nodejs/src/test/js/test-compute.js
@@ -20,29 +20,30 @@ var TestUtils = require("./test-utils").TestUtils;
 var assert = require("assert");
 
 testComputeAffinityRun = function() {
-  TestUtils.startIgniteNode(onStart.bind(null, onPut));
+  TestUtils.startIgniteNode(onStart.bind(null, computeAffinityRun));
 }
 
 testComputeAffinityCall = function() {
-  TestUtils.startIgniteNode(onStart.bind(null, onPut1));
+  TestUtils.startIgniteNode(onStart.bind(null, computeAffinityCall));
 }
 
 testComputeExecute = function() {
-  TestUtils.startIgniteNode(onStart1);
+  TestUtils.startIgniteNode(computeExecute);
 }
 
-function onStart(locOnPut, error, ignite) {
+function onStart(onPut, error, ignite) {
   var cache = ignite.cache("mycache");
 
   var params = {}
 
-  for (var i = 900; i < 1000; ++i)
+  for (var i = 900; i < 1000; ++i) {
     params["key" + i] = "val" + i;
+  }
 
-  cache.putAll(params, locOnPut.bind(null, ignite))
+  cache.putAll(params, onPut.bind(null, ignite))
 }
 
-function onPut(ignite, error) {
+function computeAffinityRun(ignite, error) {
   var comp = ignite.compute();
 
   var f = function () {
@@ -51,40 +52,34 @@ function onPut(ignite, error) {
     ignite.hello();
   }
 
-  comp.affinityRun("mycache", "key999", f, onError.bind(null));
-}
-
-function onError(error) {
-  console.log("Error "  + error);
+  function onEnd(error) {
+    assert(error == null);
 
-  assert(error == null);
+    TestUtils.testDone();
+  }
 
-  TestUtils.testDone();
+  comp.affinityRun("mycache", "key999", f, onEnd.bind(null));
 }
 
-function onPut1(ignite, error) {
+function computeAffinityCall(ignite, error) {
   var comp = ignite.compute();
 
   var f = function () {
-    println("Hello world!");
-
-    ignite.hello();
+    return ignite.hello();
   }
 
-  comp.affinityCall("mycache", "key999", f, onError1.bind(null));
-}
+  function onEnd(err, res) {
+    assert(err == null);
 
-function onError1(error, res) {
-  console.log("Error "  + error);
+    assert(res.indexOf("HAPPY") !== -1, "Incorrect result message. [mes=" + res + "].");
 
-  assert(error == null);
-
-  console.log("!!!!!!!!RES = " + res);
+    TestUtils.testDone();
+  }
 
-  TestUtils.testDone();
+  comp.affinityCall("mycache", "key999", f, onEnd.bind(null));
 }
 
-function onStart1(error, ignite) {
+function computeExecute(error, ignite) {
   var map = function(nodes, arg, emit) {
     var words = arg.split(" ");
 
@@ -108,17 +103,12 @@ function onStart1(error, ignite) {
     return sum;
   };
 
-  ignite.compute().execute(map, reduce, "Hi Alice", onComputeResult);
-}
-
-function onComputeResult(error, res) {
-  console.log("Error "  + error);
+  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 + "].");
 
-  assert(error == null);
-
-  console.log("!!!!!!!!EXECUTE TASK RESULT = " + res);
-
-  assert(res === 7, "Result is not correct. [expected=7, value=" + res + "].")
+    TestUtils.testDone();
+  }
 
-  TestUtils.testDone();
+  ignite.compute().execute(map, reduce, "Hi Alice", callback);
 }