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 12:42:37 UTC
(sling-org-apache-sling-resourceresolver) branch SLING-12634 created (now d634358)
This is an automated email from the ASF dual-hosted git repository.
reschke pushed a change to branch SLING-12634
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-resourceresolver.git
at d634358 SLING-12634: Resource Resolver: isMaxCachedVanityPathEntriesStartup check does not handle unlimited cache size
This branch includes the following new commits:
new d634358 SLING-12634: Resource Resolver: isMaxCachedVanityPathEntriesStartup check does not handle unlimited cache size
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-resourceresolver) 01/01: SLING-12634: Resource Resolver: isMaxCachedVanityPathEntriesStartup check does not handle unlimited cache size
Posted by re...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
reschke pushed a commit to branch SLING-12634
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-resourceresolver.git
commit d6343583a6cd6adadff5a368911d0df80120dbfc
Author: Julian Reschke <re...@apache.org>
AuthorDate: Thu Jan 23 13:42:13 2025 +0100
SLING-12634: Resource Resolver: isMaxCachedVanityPathEntriesStartup check does not handle unlimited cache size
---
.../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..d7e1b71 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");
+ 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