ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ivasilin...@apache.org
Subject [2/5] incubator-ignite git commit: #ignite-961: fix comments after review.
Date Mon, 20 Jul 2015 17:26:03 GMT
#ignite-961: fix comments after review.


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

Branch: refs/heads/ignite-961-master
Commit: f93ec6994b62ade48687cb9d4784588d366f8861
Parents: c99433b
Author: ivasilinets <ivasilinets@gridgain.com>
Authored: Mon Jul 20 14:31:13 2015 +0300
Committer: ivasilinets <ivasilinets@gridgain.com>
Committed: Mon Jul 20 14:31:13 2015 +0300

----------------------------------------------------------------------
 .../JettyRestProcessorAbstractSelfTest.java     | 82 +++++++++++++++-----
 .../handlers/query/QueryCommandHandler.java     | 21 ++---
 2 files changed, 75 insertions(+), 28 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/f93ec699/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/JettyRestProcessorAbstractSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/JettyRestProcessorAbstractSelfTest.java
b/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/JettyRestProcessorAbstractSelfTest.java
index c6c8195..c6bf945 100644
--- a/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/JettyRestProcessorAbstractSelfTest.java
+++ b/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/JettyRestProcessorAbstractSelfTest.java
@@ -328,7 +328,7 @@ abstract class JettyRestProcessorAbstractSelfTest extends AbstractRestProcessorS
         jsonEquals(ret,
             // getKey[12] is used since the order is not determined.
             cacheBulkPattern("\\{\\\"getKey[12]\\\":\\\"getVal[12]\\\"\\,\\\"getKey[12]\\\":\\\"getVal[12]\\\"\\}",
-            true));
+                true));
     }
 
     /**
@@ -1024,6 +1024,56 @@ abstract class JettyRestProcessorAbstractSelfTest extends AbstractRestProcessorS
     /**
      * @throws Exception If failed.
      */
+    public void testQuery() throws Exception {
+        grid(0).cache(null).put("1", "1");
+        grid(0).cache(null).put("2", "2");
+        grid(0).cache(null).put("3", "3");
+
+        Map<String, String> params = new HashMap<>();
+        params.put("cmd", "qryexecute");
+        params.put("type", "String");
+        params.put("psz", "1");
+        params.put("qry", URLEncoder.encode("select * from String"));
+
+        String ret = content(params);
+
+        assertNotNull(ret);
+        assertTrue(!ret.isEmpty());
+
+        JSONObject json = JSONObject.fromObject(ret);
+
+        Integer qryId = (Integer)((Map)json.get("response")).get("queryId");
+
+        assertNotNull(qryId);
+
+        ret = content(F.asMap("cmd", "qryfetch", "psz", "1", "qryId", String.valueOf(qryId)));
+
+        json = JSONObject.fromObject(ret);
+
+        Integer qryId0 = (Integer)((Map)json.get("response")).get("queryId");
+
+        Boolean last = (Boolean)((Map)json.get("response")).get("last");
+
+        assertEquals(qryId0, qryId);
+        assertFalse(last);
+
+        ret = content(F.asMap("cmd", "qryfetch", "psz", "1", "qryId", String.valueOf(qryId)));
+
+        json = JSONObject.fromObject(ret);
+
+        qryId0 = (Integer)((Map)json.get("response")).get("queryId");
+
+        last = (Boolean)((Map)json.get("response")).get("last");
+
+        assertEquals(qryId0, qryId);
+        assertTrue(last);
+
+        assertFalse(queryCursorFound());
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
     public void testQueryClose() throws Exception {
         String qry = "salary > ? and salary <= ?";
 
@@ -1047,20 +1097,7 @@ abstract class JettyRestProcessorAbstractSelfTest extends AbstractRestProcessorS
 
         assertEquals(1, items.size());
 
-        boolean found = false;
-
-        for (int i = 0; i < GRID_CNT; ++i) {
-            Map<GridRestCommand, GridRestCommandHandler> handlers =
-                GridTestUtils.getFieldValue(grid(i).context().rest(), "handlers");
-
-            GridRestCommandHandler qryHnd = handlers.get(GridRestCommand.CLOSE_SQL_QUERY);
-
-            ConcurrentHashMap<Long, Iterator> its = GridTestUtils.getFieldValue(qryHnd,
"curs");
-
-            found |= its.size() != 0;
-        }
-
-        assertTrue(found);
+        assertTrue(queryCursorFound());
 
         Integer qryId = (Integer)((Map)json.get("response")).get("queryId");
 
@@ -1071,7 +1108,16 @@ abstract class JettyRestProcessorAbstractSelfTest extends AbstractRestProcessorS
         assertNotNull(ret);
         assertTrue(!ret.isEmpty());
 
-        found = false;
+        assertFalse(queryCursorFound());
+    }
+
+    protected abstract String signature() throws Exception;
+
+    /**
+     * @return True if any query cursor is available.
+     */
+    private boolean queryCursorFound() {
+        boolean found = false;
 
         for (int i = 0; i < GRID_CNT; ++i) {
             Map<GridRestCommand, GridRestCommandHandler> handlers =
@@ -1084,11 +1130,9 @@ abstract class JettyRestProcessorAbstractSelfTest extends AbstractRestProcessorS
             found |= its.size() != 0;
         }
 
-        assertFalse(found);
+        return found;
     }
 
-    protected abstract String signature() throws Exception;
-
     /**
      * Init cache.
      */

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/f93ec699/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/query/QueryCommandHandler.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/query/QueryCommandHandler.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/query/QueryCommandHandler.java
index 097c7aa..1a97995 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/query/QueryCommandHandler.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/query/QueryCommandHandler.java
@@ -113,7 +113,7 @@ public class QueryCommandHandler extends GridRestCommandHandlerAdapter
{
          * @param curs Queries cursors.
          */
         public ExecuteQueryCallable(GridKernalContext ctx, RestSqlQueryRequest req,
-                                    ConcurrentHashMap<Long, Iterator> curs, ConcurrentHashMap<Long,
QueryCursor> qryCurs) {
+            ConcurrentHashMap<Long, Iterator> curs, ConcurrentHashMap<Long, QueryCursor>
qryCurs) {
             this.ctx = ctx;
             this.req = req;
             this.curs = curs;
@@ -122,6 +122,8 @@ public class QueryCommandHandler extends GridRestCommandHandlerAdapter
{
 
         /** {@inheritDoc} */
         @Override public GridRestResponse call() throws Exception {
+            long qryId = qryIdGen.getAndIncrement();
+
             try {
                 Query qry;
 
@@ -140,14 +142,12 @@ public class QueryCommandHandler extends GridRestCommandHandlerAdapter
{
 
                 if (cache == null)
                     return new GridRestResponse(GridRestResponse.STATUS_FAILED,
-                        "No cache with name. [cacheName=" + req.cacheName() + "]");
+                        "No cache with name [cacheName=" + req.cacheName() + "]");
 
                 QueryCursor qryCur = cache.query(qry);
 
                 Iterator cur = qryCur.iterator();
 
-                long qryId = qryIdGen.getAndIncrement();
-
                 qryCurs.put(qryId, qryCur);
                 curs.put(qryId, cur);
 
@@ -156,6 +156,9 @@ public class QueryCommandHandler extends GridRestCommandHandlerAdapter
{
                 return new GridRestResponse(res);
             }
             catch (Exception e) {
+                qryCurs.remove(qryId);
+                curs.remove(qryId);
+
                 return new GridRestResponse(GridRestResponse.STATUS_FAILED, e.getMessage());
             }
         }
@@ -179,8 +182,8 @@ public class QueryCommandHandler extends GridRestCommandHandlerAdapter
{
          * @param curs Queries cursors.
          */
         public CloseQueryCallable(RestSqlQueryRequest req,
-                                  ConcurrentHashMap<Long, Iterator> curs,
-                                  ConcurrentHashMap<Long, QueryCursor> qryCurs) {
+            ConcurrentHashMap<Long, Iterator> curs,
+            ConcurrentHashMap<Long, QueryCursor> qryCurs) {
             this.req = req;
             this.curs = curs;
             this.qryCurs = qryCurs;
@@ -229,7 +232,7 @@ public class QueryCommandHandler extends GridRestCommandHandlerAdapter
{
          * @param curs Queries cursors.
          */
         public FetchQueryCallable(RestSqlQueryRequest req, ConcurrentHashMap<Long, Iterator>
curs,
-                                  ConcurrentHashMap<Long, QueryCursor> qryCurs) {
+            ConcurrentHashMap<Long, QueryCursor> qryCurs) {
             this.req = req;
             this.curs = curs;
             this.qryCurs = qryCurs;
@@ -266,8 +269,8 @@ public class QueryCommandHandler extends GridRestCommandHandlerAdapter
{
      * @return Query result with items.
      */
     private static CacheQueryResult createQueryResult(ConcurrentHashMap<Long, QueryCursor>
qryCurs,
-                                                      ConcurrentHashMap<Long, Iterator>
curs, Iterator cur,
-                                                      RestSqlQueryRequest req, Long qryId)
{
+        ConcurrentHashMap<Long, Iterator> curs, Iterator cur,
+        RestSqlQueryRequest req, Long qryId) {
         CacheQueryResult res = new CacheQueryResult();
 
         List<Object> items = new ArrayList<>();


Mime
View raw message