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/09 00:25:13 UTC

incubator-ignite git commit: #ignite-961: Rearrange test-cache-api.js

Repository: incubator-ignite
Updated Branches:
  refs/heads/ignite-961 bc4a4e3a8 -> d7db2005f


#ignite-961: Rearrange test-cache-api.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/d7db2005
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/d7db2005
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/d7db2005

Branch: refs/heads/ignite-961
Commit: d7db2005f49dabf2a9f292bdcfdb64e1c3b74eb1
Parents: bc4a4e3
Author: ivasilinets <iv...@gridgain.com>
Authored: Tue Jun 9 01:25:03 2015 +0300
Committer: ivasilinets <iv...@gridgain.com>
Committed: Tue Jun 9 01:25:03 2015 +0300

----------------------------------------------------------------------
 modules/nodejs/src/test/js/test-cache-api.js | 158 ++++++++++------------
 1 file changed, 74 insertions(+), 84 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/d7db2005/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 9b513c4..e3f11ab 100644
--- a/modules/nodejs/src/test/js/test-cache-api.js
+++ b/modules/nodejs/src/test/js/test-cache-api.js
@@ -24,132 +24,122 @@ var Server = Apache.Server;
 var assert = require("assert");
 
 testPutGet = function() {
-  TestUtils.startIgniteNode(onStart.bind(null, onPut, "mycache"));
-}
-
-testIncorrectCacheName = function() {
-  TestUtils.startIgniteNode(onStart.bind(null, onIncorrectPut, "mycache1"));
+  startTest("mycache", {trace: [putSV, getExistSV], entry: "6"});
 }
 
 testRemove = function() {
-  TestUtils.startIgniteNode(onStart.bind(null, onPutRemove, "mycache"));
+  startTest("mycache", {trace: [putSV, getExistSV, removeSV, getNonExistSV], entry: "6"});
 }
 
 testRemoveNoKey = function() {
-  TestUtils.startIgniteNode(onStartRemove.bind(null, onRemove, "mycache"));
+  startTest("mycache", {trace: [removeSV, getNonExistSV], entry: "6"});
 }
 
-testRemoveAll = function() {
-  TestUtils.startIgniteNode(onStart.bind(null, onPutRemoveAll, "mycache"));
-}
 
 testPutAllGetAll = function() {
-  TestUtils.startIgniteNode(onStartGetAll.bind(null, "mycache"));
-}
-
-function onStartGetAll(cacheName, error, ignite) {
-  var cache = ignite.cache(cacheName);
-
-  var map = {"key1": "val1", "key2" : "val2"};
-
-  cache.putAll(map, onPutAll.bind(null, cache, map));
+  startTest("mycache", {trace: [putAll, getAll], entry: {"key1": "val1", "key2" : "val2"}});
 }
 
-function onPutAll(cache, map, error) {
-  assert(error == null);
-
-  cache.getAll(Object.keys(map), onGetAll.bind(null, cache, map));
+testRemoveAll = function() {
+  startTest("mycache", {trace: [putAll, getAll, removeAll, getNone], entry: {"key1": "val1", "key2" : "val2"}});
 }
 
-function onGetAll(cache, expected, error, values) {
-  assert(error == null, error);
-
-  var keys = Object.keys(expected);
-
-  for (var i = 0; i < keys.length; ++i) {
-    var key = keys[i];
-
-    assert(!!values[key], "Cannot find key. [key=" + key + "].");
-
-    assert(values[key] === expected[key], "Incorrect value. [key=" + key +
-      ", expected=" + expected[key] + ", val= " + values[key] + "].");
-  }
-
-  TestUtils.testDone();
+testIncorrectCacheName = function() {
+  startTest("mycache1", {trace: [incorrectPut], entry: "6"});
 }
 
-function onStart(onPut1, cacheName, error, ignite) {
-  var cache = ignite.cache(cacheName);
-
-  cache.put("key", "6", onPut1.bind(null, cache));
+function startTest(cacheName, testDescription) {
+  TestUtils.startIgniteNode(onStartSV.bind(null, cacheName, testDescription));
 }
 
-function onStartRemove(onPut1, cacheName, error, ignite) {
+function onStartSV(cacheName, testDescription, error, ignite) {
   var cache = ignite.cache(cacheName);
-
-  cache.remove("key", onRemove.bind(null, cache));
+  callNext();
+
+  function callNext(error) {
+    assert(!error);
+    var next = testDescription.trace.shift();
+    if (next)
+        next.call(null, cache, testDescription.entry, callNext);
+    else
+        TestUtils.testDone();
+  }
 }
 
-function onPutRemove(cache, error) {
-  assert(error == null);
-
-  cache.get("key", onGetRemove.bind(null, cache));
+function putSV(cache, entry, next) {
+    cache.put("key", entry, next);
 }
 
-function onPutRemoveAll(cache, error) {
-  assert(error == null);
+function getExistSV(cache, entry, next) {
+    cache.get("key", onGet);
 
-  cache.get("key", onGetRemoveAll.bind(null, cache));
+    function onGet(error, value) {
+        assert(!error);
+        assert(value === entry);
+        next();
+    }
 }
 
-function onGetRemoveAll(cache, error, value) {
-  assert(error == null);
-
-  assert(value == 6);
-
-  cache.removeAll(["key"], onRemove.bind(null, cache));
+function removeSV(cache, entry, next) {
+    cache.remove("key", next);
 }
 
-function onGetRemove(cache, error, value) {
-  assert(error == null);
+function getNonExistSV(cache, entry, next) {
+    cache.get("key", onGet);
 
-  assert(value == 6);
-
-  cache.remove("key", onRemove.bind(null, cache));
+    function onGet(error, value) {
+        assert(!error);
+        assert(!value);
+        next();
+    }
 }
 
-function onRemove(cache, error) {
-  assert(error == null);
-
-  cache.get("key", onGet.bind(null, null));
+function putAll(cache, entries, next) {
+    cache.putAll(entries, next);
 }
 
-function onPut(cache, error) {
-  assert(error == null);
+function getAll(cache, entries, next) {
+    cache.getAll(Object.keys(entries), onGetAll);
+    var expected = entries;
 
-  cache.get("key", onGet.bind(null, 6));
-}
+    function onGetAll(error, values) {
+        assert(!error, error);
 
-function onGet(expected, error, value) {
-  console.log("onGet [error=" + error + ", val=" + value + "].");
+        var keys = Object.keys(expected);
 
-  assert(error == null);
+        for (var i = 0; i < keys.length; ++i) {
+            var key = keys[i];
 
-  assert.equal(value, expected, "Get return incorrect value. [expected=" + expected + ", val=" + value + "].");
+            assert(!!values[key], "Cannot find key. [key=" + key + "].");
 
-  TestUtils.testDone();
+            assert(values[key] === expected[key], "Incorrect value. [key=" + key +
+              ", expected=" + expected[key] + ", val= " + values[key] + "].");
+        }
+        next();
+    }
 }
 
-function onIncorrectPut(cache, error) {
-  if (error) {
-    console.error("Failed to put " + error);
+function removeAll(cache, entries, next) {
+    cache.removeAll(Object.keys(entries), next)
+}
 
-    assert(error.indexOf("Failed to find cache for given cache name") !== -1);
+function getNone(cache, entries, next) {
+    cache.getAll(Object.keys(entries), onGetAll);
 
-    TestUtils.testDone();
+    function onGetAll(error, values) {
+        assert(!error, error);
+        assert(!values || !Object.keys(values).length);
+        next();
+    }
+}
 
-    return;
-  }
+function incorrectPut(cache, entry, next) {
+    cache.put("key", entry, callback);
 
-  TestUtils.testFails("Exception should be thrown.");
+    function callback(error) {
+        assert(!!error);
+        console.error("Failed to put " + error);
+        assert(error.indexOf("Failed to find cache for given cache name") !== -1);
+        next();
+    }
 }
\ No newline at end of file