You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by re...@apache.org on 2025/01/23 14:11:58 UTC

(sling-org-apache-sling-resourceresolver) branch master updated: SLING-12634: Resource Resolver: isMaxCachedVanityPathEntriesStartup check does not handle unlimited cache size (#135)

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

reschke pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-resourceresolver.git


The following commit(s) were added to refs/heads/master by this push:
     new b4be9ce  SLING-12634: Resource Resolver: isMaxCachedVanityPathEntriesStartup check does not handle unlimited cache size (#135)
b4be9ce is described below

commit b4be9cee504dd03afbceda82e8913d84766ea649
Author: Julian Reschke <ju...@gmx.de>
AuthorDate: Thu Jan 23 15:11:52 2025 +0100

    SLING-12634: Resource Resolver: isMaxCachedVanityPathEntriesStartup check does not handle unlimited cache size (#135)
    
    * SLING-12634: Resource Resolver: isMaxCachedVanityPathEntriesStartup check does not handle unlimited cache size
    
    * Update src/test/java/org/apache/sling/resourceresolver/impl/mapping/VanityPathMapEntriesTest.java
    
    Co-authored-by: Jörg Hoh <jo...@users.noreply.github.com>
    
    ---------
    
    Co-authored-by: Jörg Hoh <jo...@users.noreply.github.com>
---
 .../resourceresolver/impl/mapping/MapEntries.java  |  5 +++-
 .../impl/mapping/VanityPathMapEntriesTest.java     | 33 +++++++++++++---------
 2 files changed, 24 insertions(+), 14 deletions(-)

diff --git a/src/main/java/org/apache/sling/resourceresolver/impl/mapping/MapEntries.java b/src/main/java/org/apache/sling/resourceresolver/impl/mapping/MapEntries.java
index 836f639..95a4164 100644
--- a/src/main/java/org/apache/sling/resourceresolver/impl/mapping/MapEntries.java
+++ b/src/main/java/org/apache/sling/resourceresolver/impl/mapping/MapEntries.java
@@ -1460,7 +1460,10 @@ public class MapEntries implements
                 }
                 if ( isValid ) {
                     totalValid += 1;
-                    if (this.vanityPathsProcessed.get() && (this.factory.isMaxCachedVanityPathEntriesStartup() || vanityCounter.longValue() < this.factory.getMaxCachedVanityPathEntries())) {
+                    if (this.vanityPathsProcessed.get()
+                            && (this.factory.isMaxCachedVanityPathEntriesStartup()
+                                || this.isAllVanityPathEntriesCached()
+                                || vanityCounter.longValue() < this.factory.getMaxCachedVanityPathEntries())) {
                         loadVanityPath(resource, resolveMapsMap, vanityTargets, true, true);
                         entryMap = resolveMapsMap;
                     } else {
diff --git a/src/test/java/org/apache/sling/resourceresolver/impl/mapping/VanityPathMapEntriesTest.java b/src/test/java/org/apache/sling/resourceresolver/impl/mapping/VanityPathMapEntriesTest.java
index 01e6b04..218db15 100644
--- a/src/test/java/org/apache/sling/resourceresolver/impl/mapping/VanityPathMapEntriesTest.java
+++ b/src/test/java/org/apache/sling/resourceresolver/impl/mapping/VanityPathMapEntriesTest.java
@@ -91,15 +91,22 @@ public class VanityPathMapEntriesTest extends AbstractMappingMapEntriesTest {
     private EventAdmin eventAdmin;
 
     private int pageSize;
+    private boolean isMaxCachedVanityPathEntriesStartup;
+
     private int prevPageSize = 1000;
 
-    @Parameters(name = "page size -> {0}")
+    @Parameters(name="{0} {1}")
     public static Collection<Object[]> data() {
-        return Arrays.asList(new Object[][] { { 1 }, { 1000 } });
+        return List.of(new Object[][] {
+                {1000, false},
+                {1, true},
+                {1000, true}}
+        );
     }
 
-    public VanityPathMapEntriesTest(int pageSize) {
+    public VanityPathMapEntriesTest(int pageSize, boolean isMaxCachedVanityPathEntriesStartup) {
         this.pageSize = pageSize;
+        this.isMaxCachedVanityPathEntriesStartup = isMaxCachedVanityPathEntriesStartup;
     }
 
     @Override
@@ -132,7 +139,7 @@ public class VanityPathMapEntriesTest extends AbstractMappingMapEntriesTest {
         when(resourceResolverFactory.getObservationPaths()).thenReturn(new Path[] {new Path("/")});
         when(resourceResolverFactory.getMapRoot()).thenReturn(MapEntries.DEFAULT_MAP_ROOT);
         when(resourceResolverFactory.getMaxCachedVanityPathEntries()).thenReturn(-1L);
-        when(resourceResolverFactory.isMaxCachedVanityPathEntriesStartup()).thenReturn(true);
+        when(resourceResolverFactory.isMaxCachedVanityPathEntriesStartup()).thenReturn(isMaxCachedVanityPathEntriesStartup);
         when(resourceResolver.findResources(anyString(), eq("sql"))).thenReturn(
                 Collections.emptyIterator());
         when(resourceResolver.findResources(anyString(), eq("JCR-SQL2"))).thenReturn(
@@ -921,7 +928,6 @@ public class VanityPathMapEntriesTest extends AbstractMappingMapEntriesTest {
         when(justVanityPath.getName()).thenReturn("justVanityPath");
         when(justVanityPath.getValueMap()).thenReturn(buildValueMap("sling:vanityPath", "/target/justVanityPath"));
 
-
         when(resourceResolver.findResources(anyString(), eq("JCR-SQL2"))).thenAnswer((Answer<Iterator<Resource>>) invocation -> {
             if (invocation.getArguments()[0].toString().contains("sling:vanityPath")) {
                 return Collections.singleton(justVanityPath).iterator();
@@ -939,7 +945,7 @@ public class VanityPathMapEntriesTest extends AbstractMappingMapEntriesTest {
         Field vanityCounter = MapEntries.class.getDeclaredField("vanityCounter");
         vanityCounter.setAccessible(true);
         AtomicLong counter = (AtomicLong) vanityCounter.get(mapEntries);
-        assertEquals(2, counter.longValue());
+        assertEquals(this.isMaxCachedVanityPathEntriesStartup ? 2 : 0, counter.longValue());
 
         final Resource justVanityPath2 = mock(Resource.class, "justVanityPath2");
         when(resourceResolver.getResource("/justVanityPath2")).thenReturn(justVanityPath2);
@@ -958,7 +964,7 @@ public class VanityPathMapEntriesTest extends AbstractMappingMapEntriesTest {
         method.invoke(mapEntries, "/target/justVanityPath");
 
         counter = (AtomicLong) vanityCounter.get(mapEntries);
-        assertEquals(4, counter.longValue());
+        assertEquals(this.isMaxCachedVanityPathEntriesStartup ? 4 : 0, counter.longValue());
     }
 
     @Test
@@ -1138,7 +1144,6 @@ public class VanityPathMapEntriesTest extends AbstractMappingMapEntriesTest {
         List<MapEntry> entries = mapEntries.getResolveMaps();
         assertEquals(0, entries.size());
 
-
         final Resource justVanityPath = mock(Resource.class,
                 "justVanityPath");
 
@@ -1162,26 +1167,28 @@ public class VanityPathMapEntriesTest extends AbstractMappingMapEntriesTest {
                 });
 
         Method method =
-                MapEntries.class.getDeclaredMethod("getMapEntryList",String.class);
+                MapEntries.class.getDeclaredMethod("getMapEntryList", String.class);
         method.setAccessible(true);
         method.invoke(mapEntries, "/target/justVanityPath");
 
+        final int expected = 2;
+
         entries = mapEntries.getResolveMaps();
-        assertEquals(2, entries.size());
+        assertEquals(expected, entries.size());
 
         Field vanityCounter =
                 MapEntries.class.getDeclaredField("vanityCounter");
         vanityCounter.setAccessible(true);
         AtomicLong counter = (AtomicLong) vanityCounter.get(mapEntries);
-        assertEquals(2, counter.longValue());
+        assertEquals(expected, counter.longValue());
 
         method.invoke(mapEntries, "/target/justVanityPath");
 
         entries = mapEntries.getResolveMaps();
-        assertEquals(2, entries.size());
+        assertEquals(expected, entries.size());
 
         counter = (AtomicLong) vanityCounter.get(mapEntries);
-        assertEquals(2, counter.longValue());
+        assertEquals(expected, counter.longValue());
     }
 
     @Test