ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vkuliche...@apache.org
Subject [35/50] [abbrv] ignite git commit: IGNITE-3337 REST HTTP: metadata command returns all caches even if a cache name is passed to request - Fixes #816.
Date Mon, 04 Jul 2016 19:03:11 GMT
IGNITE-3337 REST HTTP: metadata command returns all caches even if a cache name is passed to
request - Fixes #816.

Signed-off-by: Andrey Novikov <anovikov@apache.org>


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

Branch: refs/heads/ignite-2949
Commit: c60fcafc2c73d6ca52a9e60677980ae97a1f8505
Parents: d03258b
Author: samaitra <saikat.maitra@gmail.com>
Authored: Wed Jun 29 17:30:31 2016 +0700
Committer: Andrey Novikov <anovikov@apache.org>
Committed: Wed Jun 29 17:30:31 2016 +0700

----------------------------------------------------------------------
 .../integration/ClientAbstractSelfTest.java     |  4 +-
 .../JettyRestProcessorAbstractSelfTest.java     | 97 ++++++++++++++++++--
 .../handlers/cache/GridCacheCommandHandler.java | 16 +---
 .../cache/GridCacheCommandHandlerSelfTest.java  | 31 +++++++
 4 files changed, 126 insertions(+), 22 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/c60fcafc/modules/clients/src/test/java/org/apache/ignite/internal/client/integration/ClientAbstractSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/clients/src/test/java/org/apache/ignite/internal/client/integration/ClientAbstractSelfTest.java
b/modules/clients/src/test/java/org/apache/ignite/internal/client/integration/ClientAbstractSelfTest.java
index 3fbd570..36b0c0f 100644
--- a/modules/clients/src/test/java/org/apache/ignite/internal/client/integration/ClientAbstractSelfTest.java
+++ b/modules/clients/src/test/java/org/apache/ignite/internal/client/integration/ClientAbstractSelfTest.java
@@ -502,8 +502,8 @@ public abstract class ClientAbstractSelfTest extends GridCommonAbstractTest
{
 
         GridClientCompute compute = client.compute();
 
-        Assert.assertEquals(17, compute.execute(taskName, taskArg));
-        Assert.assertEquals(17, compute.executeAsync(taskName, taskArg).get());
+        Assert.assertEquals(new Integer(17), compute.execute(taskName, taskArg));
+        Assert.assertEquals(new Integer(17), compute.executeAsync(taskName, taskArg).get());
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/ignite/blob/c60fcafc/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 81bffcf..18b6a51 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
@@ -28,13 +28,7 @@ import java.net.URLConnection;
 import java.net.URLEncoder;
 import java.nio.charset.StandardCharsets;
 import java.text.DateFormat;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Locale;
-import java.util.Map;
-import java.util.Set;
-import java.util.UUID;
+import java.util.*;
 import java.util.concurrent.ConcurrentHashMap;
 import com.fasterxml.jackson.databind.JsonNode;
 import com.fasterxml.jackson.databind.ObjectMapper;
@@ -1103,6 +1097,7 @@ public abstract class JettyRestProcessorAbstractSelfTest extends AbstractRestPro
         Collection<GridCacheSqlMetadata> meta = cache.context().queries().sqlMetadata();
 
         testMetadata(meta);
+        testMetadataForVoidCacheName(meta);
     }
 
     /**
@@ -1119,6 +1114,94 @@ public abstract class JettyRestProcessorAbstractSelfTest extends AbstractRestPro
         Collection<GridCacheSqlMetadata> metas = c.context().queries().sqlMetadata();
 
         testMetadata(metas);
+        testMetadataForVoidCacheName(metas);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testMetadataForVoidCacheName(Collection<GridCacheSqlMetadata> metas)
throws Exception {
+
+        Map<String, String> params = F.asMap("cmd", GridRestCommand.CACHE_METADATA.key());
+
+        String ret = content(params);
+
+        info("Cache metadata result: " + ret);
+
+        JsonNode arr = jsonResponse(ret);
+
+        assertTrue(arr.isArray());
+        assertEquals(metas.size(), arr.size());
+
+        for (JsonNode item : arr) {
+            JsonNode cacheNameNode = item.get("cacheName");
+            final String cacheName = cacheNameNode != null ? cacheNameNode.asText() : null;
+
+            GridCacheSqlMetadata meta = F.find(metas, null, new P1<GridCacheSqlMetadata>()
{
+                @Override public boolean apply(GridCacheSqlMetadata meta) {
+                    return F.eq(meta.cacheName(), cacheName);
+                }
+            });
+
+            assertNotNull("REST return metadata for unexpected cache: " + cacheName, meta);
+
+            JsonNode types = item.get("types");
+
+            assertNotNull(types);
+            assertFalse(types.isNull());
+
+            assertEqualsCollections(meta.types(), JSON_MAPPER.treeToValue(types, Collection.class));
+
+            JsonNode keyClasses = item.get("keyClasses");
+
+            assertNotNull(keyClasses);
+            assertFalse(keyClasses.isNull());
+
+            assertTrue(meta.keyClasses().equals(JSON_MAPPER.treeToValue(keyClasses, Map.class)));
+
+            JsonNode valClasses = item.get("valClasses");
+
+            assertNotNull(valClasses);
+            assertFalse(valClasses.isNull());
+
+            assertTrue(meta.valClasses().equals(JSON_MAPPER.treeToValue(valClasses, Map.class)));
+
+            JsonNode fields = item.get("fields");
+
+            assertNotNull(fields);
+            assertFalse(fields.isNull());
+            assertTrue(meta.fields().equals(JSON_MAPPER.treeToValue(fields, Map.class)));
+
+            JsonNode indexesByType = item.get("indexes");
+
+            assertNotNull(indexesByType);
+            assertFalse(indexesByType.isNull());
+            assertEquals(meta.indexes().size(), indexesByType.size());
+
+            for (Map.Entry<String, Collection<GridCacheSqlIndexMetadata>> metaIndexes
: meta.indexes().entrySet()) {
+                JsonNode indexes = indexesByType.get(metaIndexes.getKey());
+
+                assertNotNull(indexes);
+                assertFalse(indexes.isNull());
+                assertEquals(metaIndexes.getValue().size(), indexes.size());
+
+                for (final GridCacheSqlIndexMetadata metaIdx : metaIndexes.getValue()) {
+                    JsonNode idx = F.find(indexes, null, new P1<JsonNode>() {
+                        @Override public boolean apply(JsonNode idx) {
+                            return metaIdx.name().equals(idx.get("name").asText());
+                        }
+                    });
+
+                    assertNotNull(idx);
+
+                    assertEqualsCollections(metaIdx.fields(),
+                            JSON_MAPPER.treeToValue(idx.get("fields"), Collection.class));
+                    assertEqualsCollections(metaIdx.descendings(),
+                            JSON_MAPPER.treeToValue(idx.get("descendings"), Collection.class));
+                    assertEquals(metaIdx.unique(), idx.get("unique").asBoolean());
+                }
+            }
+        }
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/ignite/blob/c60fcafc/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 85611de..e8179d9 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
@@ -383,7 +383,7 @@ public class GridCacheCommandHandler extends GridRestCommandHandlerAdapter
{
                 }
 
                 case CACHE_METADATA: {
-                    fut = ctx.task().execute(MetadataTask.class, cacheName);
+                    fut = ctx.task().execute(MetadataTask.class, null);
 
                     break;
                 }
@@ -904,7 +904,7 @@ public class GridCacheCommandHandler extends GridRestCommandHandlerAdapter
{
 
     /** */
     @GridInternal
-    private static class MetadataTask extends ComputeTaskAdapter<String, GridRestResponse>
{
+    private static class MetadataTask extends ComputeTaskAdapter<Void, GridRestResponse>
{
         /** */
         private static final long serialVersionUID = 0L;
 
@@ -912,13 +912,9 @@ public class GridCacheCommandHandler extends GridRestCommandHandlerAdapter
{
         @IgniteInstanceResource
         private IgniteEx ignite;
 
-        /** */
-        private String cacheName;
-
         /** {@inheritDoc} */
         @Nullable @Override public Map<? extends ComputeJob, ClusterNode> map(List<ClusterNode>
subgrid,
-            @Nullable String cacheName) throws IgniteException {
-            this.cacheName = cacheName;
+            @Nullable Void arg) throws IgniteException {
 
             GridDiscoveryManager discovery = ignite.context().discovery();
 
@@ -962,12 +958,6 @@ public class GridCacheCommandHandler extends GridRestCommandHandlerAdapter
{
 
             Collection<GridCacheSqlMetadata> metas = new ArrayList<>(map.size());
 
-            // Metadata for current cache must be first in list.
-            GridCacheSqlMetadata cacheMeta = map.remove(cacheName);
-
-            if (cacheMeta != null)
-                metas.add(cacheMeta);
-
             metas.addAll(map.values());
 
             return new GridRestResponse(metas);

http://git-wip-us.apache.org/repos/asf/ignite/blob/c60fcafc/modules/core/src/test/java/org/apache/ignite/internal/processors/rest/handlers/cache/GridCacheCommandHandlerSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/rest/handlers/cache/GridCacheCommandHandlerSelfTest.java
b/modules/core/src/test/java/org/apache/ignite/internal/processors/rest/handlers/cache/GridCacheCommandHandlerSelfTest.java
index 740b166..3c99dca 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/rest/handlers/cache/GridCacheCommandHandlerSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/rest/handlers/cache/GridCacheCommandHandlerSelfTest.java
@@ -37,6 +37,7 @@ import org.apache.ignite.internal.IgniteInternalFuture;
 import org.apache.ignite.internal.IgniteKernal;
 import org.apache.ignite.internal.processors.cache.IgniteInternalCache;
 import org.apache.ignite.internal.processors.rest.GridRestCommand;
+import org.apache.ignite.internal.processors.rest.GridRestResponse;
 import org.apache.ignite.internal.processors.rest.handlers.GridRestCommandHandler;
 import org.apache.ignite.internal.processors.rest.request.GridRestCacheRequest;
 import org.apache.ignite.internal.util.future.GridFinishedFuture;
@@ -194,6 +195,36 @@ public class GridCacheCommandHandlerSelfTest extends GridCommonAbstractTest
{
     }
 
     /**
+     * @throws Exception If failed.
+     */
+    public void testHandleMetadataForAllCache() throws Exception {
+        GridCacheCommandHandler cmdHandler = new GridCacheCommandHandler(((IgniteKernal)grid()).context());
+        GridRestCacheRequest req = new GridRestCacheRequest();
+
+        req.command(GridRestCommand.GET_OR_CREATE_CACHE);
+        req.cacheName("partitioned_cache");
+
+        IgniteInternalFuture<GridRestResponse> resp = cmdHandler.handleAsync(req);
+
+        req = new GridRestCacheRequest();
+        req.command(GridRestCommand.GET_OR_CREATE_CACHE);
+        req.cacheName("replicated_cache");
+
+        resp = cmdHandler.handleAsync(req);
+
+        req = new GridRestCacheRequest();
+        req.command(GridRestCommand.CACHE_METADATA);
+        req.cacheName(null);
+
+        resp = cmdHandler.handleAsync(req);
+
+        assertNull(resp.result().getError());
+        assertEquals(GridRestResponse.STATUS_SUCCESS, resp.result().getSuccessStatus());
+        assertEquals("[CacheSqlMetadata [cacheName=null], CacheSqlMetadata [cacheName=replicated_cache],
CacheSqlMetadata [cacheName=partitioned_cache]]",
+                resp.result().getResponse().toString());
+    }
+
+    /**
      * Test command handler.
      */
     private static class TestableCacheCommandHandler extends GridCacheCommandHandler {


Mime
View raw message