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/01 18:38:22 UTC

incubator-ignite git commit: #ignite-964: compute should be able to work with cache.

Repository: incubator-ignite
Updated Branches:
  refs/heads/ignite-964-1 [created] fb65fa1ef


#ignite-964: compute should be able to work with cache.


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

Branch: refs/heads/ignite-964-1
Commit: fb65fa1efbc219239ce58deb39cb65551f2a2b8c
Parents: 43d8cd3
Author: ivasilinets <iv...@gridgain.com>
Authored: Wed Jul 1 19:38:03 2015 +0300
Committer: ivasilinets <iv...@gridgain.com>
Committed: Wed Jul 1 19:38:03 2015 +0300

----------------------------------------------------------------------
 .../ignite/internal/NodeJsComputeSelfTest.java  | 14 +++
 modules/nodejs/src/test/js/test-compute.js      | 97 +++++++++++++++++++-
 2 files changed, 110 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/fb65fa1e/modules/nodejs/src/test/java/org/apache/ignite/internal/NodeJsComputeSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/nodejs/src/test/java/org/apache/ignite/internal/NodeJsComputeSelfTest.java b/modules/nodejs/src/test/java/org/apache/ignite/internal/NodeJsComputeSelfTest.java
index 3a00231..a9ff998 100644
--- a/modules/nodejs/src/test/java/org/apache/ignite/internal/NodeJsComputeSelfTest.java
+++ b/modules/nodejs/src/test/java/org/apache/ignite/internal/NodeJsComputeSelfTest.java
@@ -83,6 +83,20 @@ public class NodeJsComputeSelfTest extends NodeJsAbstractTest {
     /**
      * @throws Exception If failed.
      */
+    public void testComputeCacheSizeExecute() throws Exception {
+        runJsScript("testComputeCacheSizeExecute");
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testComputeCacheExecute() throws Exception {
+        runJsScript("testComputeCacheExecute");
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
     public void testRestartGrid() throws Exception {
         final AtomicInteger id = new AtomicInteger(2);
         IgniteInternalFuture<Long> fut = GridTestUtils.runMultiThreadedAsync(new Callable<Object>() {

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/fb65fa1e/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 943ab02..b7ac463 100644
--- a/modules/nodejs/src/test/js/test-compute.js
+++ b/modules/nodejs/src/test/js/test-compute.js
@@ -17,6 +17,9 @@
 
 var TestUtils = require("./test-utils").TestUtils;
 
+var Ignite = require(TestUtils.scriptPath());
+var Entry = Ignite.Entry;
+
 var assert = require("assert");
 
 testComputeRunScript = function() {
@@ -31,6 +34,14 @@ testComputeAllNodeExecute = function() {
     TestUtils.startIgniteNode(computeAllNodeExecute);
 }
 
+testComputeCacheSizeExecute = function() {
+    TestUtils.startIgniteNode(computeCacheSizeExecute);
+}
+
+testComputeCacheExecute = function() {
+    TestUtils.startIgniteNode(computeCacheExecute);
+}
+
 function onStart(onPut, error, ignite) {
     var cache = ignite.cache("mycache");
 
@@ -80,7 +91,7 @@ function computeExecute(error, ignite) {
         var sum = 0;
 
         for (var i = 0; i < results.length; ++i) {
-            sum += parseInt(results[i], 10);
+            sum += JSON.parse(results[i]);
         }
 
         return sum;
@@ -119,6 +130,90 @@ function computeAllNodeExecute(error, ignite) {
     ignite.compute().execute(map, reduce, "", callback);
 }
 
+function computeCacheExecute(error, ignite) {
+    var map = function(nodes, args) {
+        for (var i = 0; i < nodes.length; i++) {
+            var f = function (args1) {
+                println("!!!!!!!arg" + args1 + " JSON" + JSON.stringify(args1));
+                var o =  ignite.cache("mycache").get(args1[0]);
+                println("!!!!!!!o" + o + " JSON" + JSON.stringify(o));
+                return o;
+            };
+
+            emit(f, args, nodes[i]);
+        }
+    };
+
+    var reduce = function(results) {
+        println("!!!!!!!!!!results=" + results);
+        var exp = {"age" : 12, "books" : ["1", "Book"]};
+
+        for (var i = 0; i < results.length; i++) {
+            var val = JSON.parse(results[i]);
+
+            println("Incorrect value [exp=" + JSON.stringify(exp) + ", val=" + JSON.stringify(val) + "]");
+        }
+
+        return sum;
+    };
+
+    var callback = function(err, res) {
+        assert(err == null, "Get error on compute task [err=" + err + "]");
+
+        ignite.cache("mycache").size(function(err, size){
+            assert(size === res, "Incorrect size [size=" + size + ", res=" + res + "]");
+            TestUtils.testDone();
+        })
+    }
+
+    entries = [];
+
+    var key1 = {"name" : "Ann"};
+    var key2 = {"name" : "Paul"};
+    var val1 = {"age" : 12, "books" : ["1", "Book"]};
+    var val2 = {"age" : 13, "books" : ["1", "Book"]};
+
+    entries.push(new Entry(key1, val1));
+    entries.push(new Entry(key2, val2));
+
+    ignite.cache("mycache").putAll(entries, function(err) {ignite.compute().execute(map, reduce, [key1, val1], callback);});
+}
+
+function computeCacheSizeExecute(error, ignite) {
+    var map = function(nodes, arg) {
+        for (var i = 0; i < nodes.length; i++) {
+            var f = function (args) {
+                println("!!!!!Node id " + ignite.localNode().id());
+
+                return ignite.cache("mycache").localSize();
+            };
+
+            emit(f, [], nodes[i]);
+        }
+    };
+
+    var reduce = function(results) {
+        var sum = 0;
+
+        for (var i = 0; i < results.length; i++) {
+            sum += JSON.parse(results[i]);
+        }
+
+        return sum;
+    };
+
+    var callback = function(err, res) {
+        assert(err == null, "Get error on compute task [err=" + err + "]");
+
+        ignite.cache("mycache").size(function(err, size){
+            assert(size === res, "Incorrect size [size=" + size + ", res=" + res + "]");
+            TestUtils.testDone();
+        })
+    }
+
+    ignite.cache("mycache").putAll("key", "val", function(err) {ignite.compute().execute(map, reduce, "", callback);});
+}
+
 testComputeFuncWithErrorExecute = function() {
     var map = function(nodes, arg) {
         var f = function(args){throw "Bad function";};