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 12:13:56 UTC

[20/39] incubator-ignite git commit: #ignite-964: add test put all objects.

#ignite-964: add test put all objects.


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

Branch: refs/heads/ignite-964
Commit: bea777f9d99b2e8a1e5cab8ab2c1215a70d15aff
Parents: eb4f07b
Author: ivasilinets <iv...@gridgain.com>
Authored: Tue Jun 30 17:24:01 2015 +0300
Committer: ivasilinets <iv...@gridgain.com>
Committed: Tue Jun 30 17:24:01 2015 +0300

----------------------------------------------------------------------
 .../processors/scripting/JSONCacheObject.java   | 78 ++++++++++++++++++++
 modules/nodejs/src/main/js/cache.js             |  4 +-
 .../ignite/internal/NodeJsCacheApiSelfTest.java |  7 ++
 modules/nodejs/src/test/js/test-cache-api.js    | 16 ++--
 modules/nodejs/src/test/js/test-utils.js        | 15 ++++
 5 files changed, 113 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/bea777f9/modules/core/src/main/java/org/apache/ignite/internal/processors/scripting/JSONCacheObject.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/scripting/JSONCacheObject.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/scripting/JSONCacheObject.java
new file mode 100644
index 0000000..46067d7
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/scripting/JSONCacheObject.java
@@ -0,0 +1,78 @@
+/*
+ * 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.internal.processors.scripting;
+
+import java.util.*;
+
+/**
+ * Json cache object.
+ */
+public class JSONCacheObject {
+    /** Fields map. */
+    private Map<String, Object> fields = new HashMap<>();
+
+    /**
+     * @param key Field name.
+     * @param val Field value.
+     */
+    public void addField(String key, Object val) {
+        fields.put(key, val);
+    }
+
+    /**
+     * @param key Field name.
+     * @return Field value.
+     */
+    public Object getField(String key) {
+        return fields.get(key);
+    }
+
+    /**
+     * @return Fields key set.
+     */
+    public Set<String> keys() {
+        return fields.keySet();
+    }
+
+    /** {@inheritDoc} */
+    @Override public int hashCode() {
+        //TODO:
+        return fields.hashCode();
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean equals(Object obj) {
+        if (obj == null || !(obj instanceof JSONCacheObject))
+            return false;
+
+        JSONCacheObject obj0 = (JSONCacheObject) obj;
+
+        if (fields.size() != obj0.fields.size())
+            return false;
+
+        for (String key : obj0.keys()) {
+            if (!fields.containsKey(key))
+                return false;
+
+            if (!obj0.getField(key).equals(getField(key)))
+                return false;
+        }
+
+        return true;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/bea777f9/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 8ff6ee3..e0ed505 100644
--- a/modules/nodejs/src/main/js/cache.js
+++ b/modules/nodejs/src/main/js/cache.js
@@ -153,7 +153,6 @@ Cache.prototype._sqlFieldsQuery = function(qry, onQueryExecute) {
 }
 
 Cache.prototype._sqlQuery = function(qry, onQueryExecute) {
-
     if (qry.returnType() == null) {
         qry.error("No type for sql query.");
         qry.end();
@@ -171,12 +170,15 @@ Cache.prototype._sqlQuery = function(qry, onQueryExecute) {
 
 Cache.prototype._createCommand = function(name) {
     var command = new Command(name);
+
     return command.addParam("cacheName", this._cacheName);
 }
 
 Cache.prototype._createQueryCommand = function(name, qry) {
     var command = this._createCommand(name);
+
     command.addParam("qry", qry.query());
+
     return command.addParam("psz", qry.pageSize());
 }
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/bea777f9/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 f17ca60..1a9293c 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
@@ -84,4 +84,11 @@ public class NodeJsCacheApiSelfTest extends NodeJsAbstractTest {
     public void testPutAllGetAll() throws Exception {
         runJsScript("testPutAllGetAll");
     }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testPutAllObjectGetAll() throws Exception {
+        runJsScript("testPutAllObjectGetAll");
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/bea777f9/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 fc29f22..515f543 100644
--- a/modules/nodejs/src/test/js/test-cache-api.js
+++ b/modules/nodejs/src/test/js/test-cache-api.js
@@ -35,6 +35,15 @@ testPutAllGetAll = function() {
     startTest("mycache", {trace: [putAll, getAll], entry: {"key1": "val1", "key2" : "val2"}});
 }
 
+testPutAllObjectGetAll = function() {
+    var key1 = {"name" : "Ann"};
+    var key2 = {"name" : "Paul"};
+    var val1 = {"age" : 12, "books" : ["1", "Book"]};
+    var val2 = {"age" : 13, "books" : ["1", "Book"]};
+
+    startTest("mycache", {trace: [putAll, getAll], entry: {key1 : val1, key2 : val2}});
+}
+
 testRemoveAll = function() {
     startTest("mycache", {trace: [putAll, getAll, removeAll, getNone], entry: {"key1": "val1", "key2" : "val2"}});
 }
@@ -93,10 +102,6 @@ function putAll(cache, entries, next) {
     cache.putAll(entries, next);
 }
 
-function postPutAll(cache, entries, next) {
-    cache.postPutAll(entries, next);
-}
-
 function getAll(cache, entries, next) {
     cache.getAll(Object.keys(entries), onGetAll);
     var expected = entries;
@@ -111,8 +116,7 @@ function getAll(cache, entries, next) {
 
             assert(!!values[key], "Cannot find key. [key=" + key + "].");
 
-            assert(values[key] === expected[key], "Incorrect value. [key=" + key +
-                ", expected=" + expected[key] + ", val= " + values[key] + "].");
+            TestUtils.compareObject(expected[key], values[key]);
         }
         next();
     }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/bea777f9/modules/nodejs/src/test/js/test-utils.js
----------------------------------------------------------------------
diff --git a/modules/nodejs/src/test/js/test-utils.js b/modules/nodejs/src/test/js/test-utils.js
index 0b0aebb..1ec5ab7 100644
--- a/modules/nodejs/src/test/js/test-utils.js
+++ b/modules/nodejs/src/test/js/test-utils.js
@@ -15,6 +15,8 @@
  * limitations under the License.
  */
 
+var assert = require("assert");
+
 /**
  * Create instance of TestUtils
  *
@@ -49,6 +51,19 @@ TestUtils.sep = function() {
     return require('path').sep;
 }
 
+TestUtils.compareObject = function(o1, o2) {
+    if (typeof o1 !== 'object') {
+        assert(o1 === o2, "Incorrect value. [expected=" + o1 + ", val= " + o2 + "].");
+    }
+    else {
+        assert(Object.keys(o1).length === Object.keys(o2).length, "Incorrect key set")
+
+        for (var keyObj of Object.keys(o2)) {
+            TestUtils.compareObject(o1[keyObj], o2[keyObj]);
+        }
+    }
+}
+
 /**
  * @param {string} dir Directory with all ignite libs
  * @returns {string} Classpath for ignite node start