ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sevdoki...@apache.org
Subject [49/50] [abbrv] incubator-ignite git commit: #ignite-961: add metadata test for nodejs.
Date Tue, 28 Jul 2015 11:21:14 GMT
#ignite-961:  add metadata test for nodejs.


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

Branch: refs/heads/ignite-1121
Commit: 70a8b2f9002057b9f70bf328a201f7c33d5350a4
Parents: 9289dab
Author: ivasilinets <ivasilinets@gridgain.com>
Authored: Mon Jul 27 13:23:24 2015 +0300
Committer: ivasilinets <ivasilinets@gridgain.com>
Committed: Mon Jul 27 13:23:24 2015 +0300

----------------------------------------------------------------------
 modules/nodejs/src/main/js/cache.js             | 30 +++++++++--
 .../ignite/internal/NodeJsSqlQuerySelfTest.java |  9 ++++
 modules/nodejs/src/test/js/test-query.js        | 53 +++++++++++++++++++-
 3 files changed, 87 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/70a8b2f9/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 a232558..1600eaa 100644
--- a/modules/nodejs/src/main/js/cache.js
+++ b/modules/nodejs/src/main/js/cache.js
@@ -269,7 +269,7 @@ Cache.prototype.size = function(callback) {
  * @returns {QueryCursor} Cursor for current query.
  */
 Cache.prototype.query = function(qry) {
-    return new QueryCursor(this, qry, true, null);
+    return new QueryCursor(this, qry, true, null, null);
 }
 
 Cache.prototype.__createPromise = function(cmd) {
@@ -302,12 +302,14 @@ Cache.prototype._createCommand = function(name) {
  * @param {SqlQuery|SqlFieldsQuery} qry Sql query
  * @param {boolean} init True if query is not started
  * @param {Object[]} res Current page result
+ * @param fieldsMeta Fields metadata.
  */
-QueryCursor = function(cache, qry, init, res) {
+QueryCursor = function(cache, qry, init, res, fieldsMeta) {
     this._qry = qry;
     this._cache = cache;
     this._init = init;
     this._res = res;
+    this._fieldsMeta = fieldsMeta;
 }
 
 /**
@@ -342,6 +344,10 @@ QueryCursor.prototype.getAll = function() {
             else {
                 cursor._res = res;
 
+                if (cursor._fieldsMeta === null) {
+                    cursor._fieldsMeta = res["fieldsMetadata"];
+                }
+
                 fullRes = fullRes.concat(res["items"]);
 
                 if (res["last"]) {
@@ -372,20 +378,36 @@ QueryCursor.prototype.nextPage = function() {
     var server = this._cache._server;
     var qry = this._qry;
     var cache = this._cache;
+    var fieldsMeta = this._fieldsMeta;
 
     return new Promise(function(resolve, reject) {
        server.runCommand(cmd, function(err, res) {
            if(err !== null) {
-               reject(err);
+                reject(err);
            }
            else {
-               resolve(new QueryCursor(cache, qry, false, res));
+                if (fieldsMeta !== null) {
+                    resolve(new QueryCursor(cache, qry, false, res, fieldsMeta));
+                }
+                else {
+                    resolve(new QueryCursor(cache, qry, false, res, res["fieldsMetadata"]))
+                }
            }
        });
     });
 }
 
 /**
+ * Gets query fields metadata
+ *
+ * @this{QueryCursor}
+ * @returns {Object[]} Query fields metadata.
+ */
+QueryCursor.prototype.fieldsMetadata = function() {
+    return this._fieldsMeta;
+}
+
+/**
  * Gets collections of the query page results.
  *
  * @this{QueryCursor}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/70a8b2f9/modules/nodejs/src/test/java/org/apache/ignite/internal/NodeJsSqlQuerySelfTest.java
----------------------------------------------------------------------
diff --git a/modules/nodejs/src/test/java/org/apache/ignite/internal/NodeJsSqlQuerySelfTest.java
b/modules/nodejs/src/test/java/org/apache/ignite/internal/NodeJsSqlQuerySelfTest.java
index 2e4289e..22d7ad4 100644
--- a/modules/nodejs/src/test/java/org/apache/ignite/internal/NodeJsSqlQuerySelfTest.java
+++ b/modules/nodejs/src/test/java/org/apache/ignite/internal/NodeJsSqlQuerySelfTest.java
@@ -65,6 +65,15 @@ public class NodeJsSqlQuerySelfTest extends NodeJsAbstractTest {
     /**
      * @throws Exception If failed.
      */
+    public void testSqlFieldsMeta() throws Exception {
+        initCache();
+
+        runJsScript("testSqlFieldsMeta");
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
     public void testCloseQuery() throws Exception {
         initCache();
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/70a8b2f9/modules/nodejs/src/test/js/test-query.js
----------------------------------------------------------------------
diff --git a/modules/nodejs/src/test/js/test-query.js b/modules/nodejs/src/test/js/test-query.js
index dcbb310..3d55886 100644
--- a/modules/nodejs/src/test/js/test-query.js
+++ b/modules/nodejs/src/test/js/test-query.js
@@ -124,6 +124,8 @@ testSqlFieldsGetAllQuery = function() {
     TestUtils.startIgniteNode().then(function(ignite) {
         var qry = new SqlFieldsQuery("select concat(firstName, ' ', lastName) from Person");
 
+        var cursor = ignite.cache("person").query(qry);
+
         function onQuery(fullRes) {
             assert(fullRes.length === 4, "Result length is not correct" +
                 "[expected=1, val = " + fullRes.length + "]");
@@ -135,10 +137,14 @@ testSqlFieldsGetAllQuery = function() {
 
             console.log("Result: " + JSON.stringify(fullRes));
 
+            var meta = cursor.fieldsMetadata();
+
+            assert(meta[0]["fieldName"] !== null, "Incorrect fields meta.")
+
             return ignite.cache("person").get("key");
         }
 
-        ignite.cache("person").query(qry).getAll().then(onQuery).then(function(){
+        cursor.getAll().then(onQuery).then(function(){
             TestUtils.testDone();
         })
     }).catch(function(err) {
@@ -146,6 +152,51 @@ testSqlFieldsGetAllQuery = function() {
     });
 }
 
+testSqlFieldsMeta = function() {
+    TestUtils.startIgniteNode().then(function(ignite) {
+        var qry = new SqlFieldsQuery("select firstName, lastName from Person");
+
+        var fullRes = [];
+
+        function onQuery(cursor) {
+            var page = cursor.page();
+
+            fullRes = fullRes.concat(page);
+
+            var meta = cursor.fieldsMetadata();
+
+            console.log("Fields meta: " + JSON.stringify(meta))
+            assert(meta.length === 2, "Incorrect fields meta length [exp=2, val=" + meta.length
+ "]");
+
+            assert(meta[0]["fieldName"] === "FIRSTNAME", "Incorrect fields meta " +
+                "[exp=FIRSTNAME, val=" + meta[0]["fieldName"] + "]");
+            assert(meta[0]["fieldTypeName"] === "java.lang.String", "Incorrect fields meta
" +
+                "[exp=java.lang.String, val=" + meta[0]["fieldTypeName"] + "]");
+            assert(meta[0]["schemaName"] === "person", "Incorrect fields meta " +
+                "[exp=person, val=" + meta[0]["schemaName"] + "]");
+            assert(meta[0]["typeName"] === "PERSON", "Incorrect fields meta " +
+                "[exp=PERSON, val=" + meta[0]["typeName"] + "]");
+
+            if (cursor.isFinished()) {
+                assert(fullRes.length === 4, "Result length is not correct" +
+                    "[expected=1, val = " + fullRes.length + "]");
+
+                console.log("Result: " + JSON.stringify(fullRes));
+
+                TestUtils.testDone();
+
+                return;
+            }
+
+            cursor.nextPage().then(onQuery);
+        }
+
+        ignite.cache("person").query(qry).nextPage().then(onQuery);
+    }).catch(function(err) {
+        assert(err === null, err);
+    });
+}
+
 testSqlQueryWithParams = function() {
     TestUtils.startIgniteNode().then(function(ignite) {
         var qry = new SqlQuery("salary > ? and salary <= ?");


Mime
View raw message