ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ivasilin...@apache.org
Subject [4/4] incubator-ignite git commit: #ignite-964: add SIZE for nodejs cache.
Date Wed, 01 Jul 2015 14:08:52 GMT
#ignite-964: add SIZE for nodejs 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/a7bb9ee4
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/a7bb9ee4
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/a7bb9ee4

Branch: refs/heads/ignite-964
Commit: a7bb9ee4a875b5ca6c928a47282e7104498ee8e2
Parents: 13e78da
Author: ivasilinets <ivasilinets@gridgain.com>
Authored: Wed Jul 1 17:08:41 2015 +0300
Committer: ivasilinets <ivasilinets@gridgain.com>
Committed: Wed Jul 1 17:08:41 2015 +0300

----------------------------------------------------------------------
 .../processors/rest/GridRestCommand.java        |  3 ++
 .../processors/rest/GridRestProcessor.java      |  1 +
 .../handlers/cache/GridCacheCommandHandler.java | 20 +++++++++++-
 modules/nodejs/src/main/js/cache.js             |  8 +++++
 .../ignite/internal/NodeJsCacheApiSelfTest.java |  7 ++++
 modules/nodejs/src/test/js/test-cache-api.js    | 34 +++++++++++++++++---
 .../http/jetty/GridJettyRestHandler.java        |  1 +
 7 files changed, 68 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/a7bb9ee4/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/GridRestCommand.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/GridRestCommand.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/GridRestCommand.java
index 90d7dc2..81fb7f5 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/GridRestCommand.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/GridRestCommand.java
@@ -93,6 +93,9 @@ public enum GridRestCommand {
     /** Cache metrics. */
     CACHE_METRICS("cache"),
 
+    /** Cache size. */
+    CACHE_SIZE("cachesize"),
+
     /** Increment. */
     ATOMIC_INCREMENT("incr"),
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/a7bb9ee4/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/GridRestProcessor.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/GridRestProcessor.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/GridRestProcessor.java
index c3c9871..c8cb25a 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/GridRestProcessor.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/GridRestProcessor.java
@@ -575,6 +575,7 @@ public class GridRestProcessor extends GridProcessorAdapter {
                 break;
 
             case CACHE_METRICS:
+            case CACHE_SIZE:
             case TOPOLOGY:
             case NODE:
             case VERSION:

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/a7bb9ee4/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/cache/GridCacheCommandHandler.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/cache/GridCacheCommandHandler.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/cache/GridCacheCommandHandler.java
index 87a87e3..26140f3 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/cache/GridCacheCommandHandler.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/cache/GridCacheCommandHandler.java
@@ -73,7 +73,8 @@ public class GridCacheCommandHandler extends GridRestCommandHandlerAdapter
{
         CACHE_CAS,
         CACHE_APPEND,
         CACHE_PREPEND,
-        CACHE_METRICS
+        CACHE_METRICS,
+        CACHE_SIZE
     );
 
     /** Requests with required parameter {@code key}. */
@@ -329,6 +330,12 @@ public class GridCacheCommandHandler extends GridRestCommandHandlerAdapter
{
                     break;
                 }
 
+                case CACHE_SIZE: {
+                    fut = executeCommand(req.destinationId(), req.clientId(), cacheName,
key, new SizeCommand());
+
+                    break;
+                }
+
                 default:
                     throw new IllegalArgumentException("Invalid command for cache handler:
" + req);
             }
@@ -1304,4 +1311,15 @@ public class GridCacheCommandHandler extends GridRestCommandHandlerAdapter
{
             );
         }
     }
+
+    /** */
+    private static class SizeCommand extends CacheCommand {
+        /** */
+        private static final long serialVersionUID = 0L;
+
+        /** {@inheritDoc} */
+        @Override public IgniteInternalFuture<?> applyx(IgniteInternalCache<Object,
Object> c, GridKernalContext ctx) {
+            return c.sizeAsync(new CachePeekMode[]{CachePeekMode.ALL});
+        }
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/a7bb9ee4/modules/nodejs/src/main/js/cache.js
----------------------------------------------------------------------
diff --git a/modules/nodejs/src/main/js/cache.js b/modules/nodejs/src/main/js/cache.js
index 97175fd..2fea1f6 100644
--- a/modules/nodejs/src/main/js/cache.js
+++ b/modules/nodejs/src/main/js/cache.js
@@ -270,6 +270,14 @@ Cache.prototype.getAndPutIfAbsent = function(key, val, callback) {
 }
 
 /**
+ * @this {Cache}
+ * @param {onGet} callback Called on finish
+ */
+Cache.prototype.size = function(callback) {
+    this._server.runCommand(this._createCommand("cachesize"), callback);
+}
+
+/**
  * Execute sql query
  *
  * @param {SqlQuery|SqlFieldsQuery} qry Query

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/a7bb9ee4/modules/nodejs/src/test/java/org/apache/ignite/internal/NodeJsCacheApiSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/nodejs/src/test/java/org/apache/ignite/internal/NodeJsCacheApiSelfTest.java
b/modules/nodejs/src/test/java/org/apache/ignite/internal/NodeJsCacheApiSelfTest.java
index a79ab6f..3123c13 100644
--- a/modules/nodejs/src/test/java/org/apache/ignite/internal/NodeJsCacheApiSelfTest.java
+++ b/modules/nodejs/src/test/java/org/apache/ignite/internal/NodeJsCacheApiSelfTest.java
@@ -210,4 +210,11 @@ public class NodeJsCacheApiSelfTest extends NodeJsAbstractTest {
     public void testReplaceValueObject() throws Exception {
         runJsScript("testReplaceValueObject");
     }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testSize() throws Exception {
+        runJsScript("testSize");
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/a7bb9ee4/modules/nodejs/src/test/js/test-cache-api.js
----------------------------------------------------------------------
diff --git a/modules/nodejs/src/test/js/test-cache-api.js b/modules/nodejs/src/test/js/test-cache-api.js
index 99c97c9..3d3dad8 100644
--- a/modules/nodejs/src/test/js/test-cache-api.js
+++ b/modules/nodejs/src/test/js/test-cache-api.js
@@ -171,7 +171,7 @@ testReplace = function() {
             cache.get(entry[0], function(err, res) {
                 assert(!err);
                 assert("7" === res, "Get incorrect value on get [exp=7, val=" + res + "]");
-                TestUtils.testDone();
+                next();
             });
         }
     }
@@ -191,7 +191,8 @@ testReplaceObject = function() {
             cache.get(entry[0], function(err, res) {
                 assert(!err);
                 assert(TestUtils.compareObject(newKey, res), "Get incorrect value on get.");
-                TestUtils.testDone();
+
+                next();
             });
         }
     }
@@ -210,7 +211,8 @@ testGetAndReplaceObject = function() {
         function onGetAndReplace(cache, err, res) {
             assert(err === null, "Get error on get and put [err=" + err + "]");
             assert(TestUtils.compareObject(val, res), "Get incorrect value on get.");
-            TestUtils.testDone();
+
+            next();
         }
     }
 
@@ -228,7 +230,7 @@ testReplaceValueObject = function() {
         function onReplaceValue(cache, err, res) {
             assert(err === null, "Get error on get and put [err=" + err + "]");
             assert(res === true, "Incorrect result for replace [expected=true, val" + res
+ "]");
-            TestUtils.testDone();
+            next();
         }
     }
 
@@ -245,7 +247,7 @@ testIncorrectReplaceObject = function() {
         function onReplace(cache, err, res) {
             assert(err !== null, "Do not get error");
             assert(err.indexOf("Failed to update keys") > -1, "Incorrect error message:
" + err);
-            TestUtils.testDone();
+            next();
         }
     }
 
@@ -255,6 +257,28 @@ testIncorrectReplaceObject = function() {
     startTest("mycache", {trace: [put, replace], entry: [key, val]});
 }
 
+testSize = function() {
+    function onSize(exp, next, cache, err, res) {
+            assert(err === null, "Do not get error");
+            assert(res === exp, "Incorrect size: " + res);
+
+            next();
+    }
+
+    function size0(cache, entry, next) {
+        cache.size(onSize.bind(null, 0, next, cache));
+    }
+
+     function size1(cache, entry, next) {
+        cache.size(onSize.bind(null, 1, next, cache));
+    }
+
+    var key = {"name" : "Paul"};
+    var val = {"age" : 12, "books" : ["1", "Book"]};
+
+    startTest("mycache", {trace: [size0, put, size1], entry: [key, val]});
+}
+
 function objectEntries() {
     entries = [];
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/a7bb9ee4/modules/rest-http/src/main/java/org/apache/ignite/internal/processors/rest/protocols/http/jetty/GridJettyRestHandler.java
----------------------------------------------------------------------
diff --git a/modules/rest-http/src/main/java/org/apache/ignite/internal/processors/rest/protocols/http/jetty/GridJettyRestHandler.java
b/modules/rest-http/src/main/java/org/apache/ignite/internal/processors/rest/protocols/http/jetty/GridJettyRestHandler.java
index 8b60fcf..264cf5e 100644
--- a/modules/rest-http/src/main/java/org/apache/ignite/internal/processors/rest/protocols/http/jetty/GridJettyRestHandler.java
+++ b/modules/rest-http/src/main/java/org/apache/ignite/internal/processors/rest/protocols/http/jetty/GridJettyRestHandler.java
@@ -387,6 +387,7 @@ public class GridJettyRestHandler extends AbstractHandler {
             case CACHE_ADD:
             case CACHE_CAS:
             case CACHE_METRICS:
+            case CACHE_SIZE:
             case CACHE_REPLACE:
             case CACHE_APPEND:
             case CACHE_PREPEND: {


Mime
View raw message