You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by bd...@apache.org on 2020/09/24 12:52:52 UTC

[sling-org-apache-sling-graphql-core] branch bug/SLING-9766 created (now 40d280b)

This is an automated email from the ASF dual-hosted git repository.

bdelacretaz pushed a change to branch bug/SLING-9766
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-graphql-core.git.


      at 40d280b  SLING-9766 - take selectors into account in cache key

This branch includes the following new commits:

     new 40d280b  SLING-9766 - take selectors into account in cache key

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[sling-org-apache-sling-graphql-core] 01/01: SLING-9766 - take selectors into account in cache key

Posted by bd...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

bdelacretaz pushed a commit to branch bug/SLING-9766
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-graphql-core.git

commit 40d280b1eb670ceb462ecf7f99de196428b45cb2
Author: Bertrand Delacretaz <bd...@apache.org>
AuthorDate: Thu Sep 24 14:52:32 2020 +0200

    SLING-9766 - take selectors into account in cache key
---
 .../core/cache/SimpleGraphQLCacheProvider.java       |  2 +-
 .../core/cache/SimpleGraphQLCacheProviderTest.java   | 20 ++++++++++++++++++++
 2 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/src/main/java/org/apache/sling/graphql/core/cache/SimpleGraphQLCacheProvider.java b/src/main/java/org/apache/sling/graphql/core/cache/SimpleGraphQLCacheProvider.java
index 97a6092..e725564 100644
--- a/src/main/java/org/apache/sling/graphql/core/cache/SimpleGraphQLCacheProvider.java
+++ b/src/main/java/org/apache/sling/graphql/core/cache/SimpleGraphQLCacheProvider.java
@@ -161,7 +161,7 @@ public class SimpleGraphQLCacheProvider implements GraphQLCacheProvider {
             String key = getCacheKey(hash, resourceType, selectorString);
             persistedQueriesCache.put(key, query);
             if (persistedQueriesCache.containsKey(key)) {
-                return hash;
+                return key;
             }
             return null;
         } finally {
diff --git a/src/test/java/org/apache/sling/graphql/core/cache/SimpleGraphQLCacheProviderTest.java b/src/test/java/org/apache/sling/graphql/core/cache/SimpleGraphQLCacheProviderTest.java
index 16fe357..154524c 100644
--- a/src/test/java/org/apache/sling/graphql/core/cache/SimpleGraphQLCacheProviderTest.java
+++ b/src/test/java/org/apache/sling/graphql/core/cache/SimpleGraphQLCacheProviderTest.java
@@ -30,12 +30,15 @@ import org.junit.Test;
 import com.codahale.metrics.MetricRegistry;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
 import static org.mockito.Matchers.anyString;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
+import java.util.UUID;
+
 public class SimpleGraphQLCacheProviderTest {
 
     @Rule
@@ -137,4 +140,21 @@ public class SimpleGraphQLCacheProviderTest {
         assertEquals("c", provider.getQuery(cHash, "a/b/c", null));
     }
 
+    @Test
+    public void testSelectors() {
+        context.registerInjectActivateService(new SimpleGraphQLCacheProvider(), "cacheSize", 2, "maxMemory", 40);
+        SimpleGraphQLCacheProvider provider = (SimpleGraphQLCacheProvider) context.getService(GraphQLCacheProvider.class);
+        assertNotNull(provider);
+
+        final String queryText = UUID.randomUUID().toString();
+        final String path = "testing/selectors";
+        final String selectors = UUID.randomUUID().toString();
+
+        String aHash = provider.cacheQuery(queryText, path, null);
+        String bHash = provider.cacheQuery(queryText, path, null);
+        String cHash = provider.cacheQuery(queryText, path, selectors);
+
+        assertEquals("Expecting the same hash for same query", aHash, bHash);
+        assertNotEquals("Expecting a different hash with added selectors", aHash, cHash);
+    }
 }