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

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


The following commit(s) were added to refs/heads/SLING-12894 by this push:
     new 1006c2d8 SLING-12900: improve test coverage for VP bg init vs events, 
minor refactoring (#193)
1006c2d8 is described below

commit 1006c2d86e52bae5f550ecf05e7a9230842213b0
Author: Julian Reschke <[email protected]>
AuthorDate: Thu Aug 21 16:33:14 2025 +0200

    SLING-12900: improve test coverage for VP bg init vs events, minor 
refactoring (#193)
---
 .../resourceresolver/impl/mapping/MapEntries.java  | 28 +++++++--------
 .../impl/mapping/VanityPathMapEntriesTest.java     | 40 ++++++++++++++++++++++
 2 files changed, 53 insertions(+), 15 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 6d6d35b9..5b7d147f 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
@@ -481,22 +481,20 @@ public class MapEntries implements MapEntriesHandler, 
ResourceChangeListener, Ex
             boolean queuedForAlias = false;
             boolean queuedForVanityPath = false;
 
-            if (RELEVANT_CHANGE_TYPES.contains(type)) {
-                // during startup: just enqueue the events
-
-                if (ahInStartup) {
-                    Map.Entry<String, ResourceChange.ChangeType> entry = new 
SimpleEntry<>(path, type);
-                    log.trace("enqueued for aliases {}", entry);
-                    resourceChangeQueueForAliases.add(entry);
-                    queuedForAlias = true;
-                }
+            // during startup: just enqueue the events
 
-                if (vphInStartup) {
-                    Map.Entry<String, ResourceChange.ChangeType> entry = new 
SimpleEntry<>(path, type);
-                    log.trace("enqueued for vanity paths {}", entry);
-                    resourceChangeQueueForVanityPaths.add(entry);
-                    queuedForVanityPath = true;
-                }
+            if (ahInStartup && RELEVANT_CHANGE_TYPES.contains(type)) {
+                Map.Entry<String, ResourceChange.ChangeType> entry = new 
SimpleEntry<>(path, type);
+                log.trace("enqueued for aliases {}", entry);
+                resourceChangeQueueForAliases.add(entry);
+                queuedForAlias = true;
+            }
+
+            if (vphInStartup && RELEVANT_CHANGE_TYPES.contains(type)) {
+                Map.Entry<String, ResourceChange.ChangeType> entry = new 
SimpleEntry<>(path, type);
+                log.trace("enqueued for vanity paths {}", entry);
+                resourceChangeQueueForVanityPaths.add(entry);
+                queuedForVanityPath = true;
             }
 
             if (!queuedForAlias || !queuedForVanityPath) {
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 08b52eec..b2c3c6b0 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
@@ -32,6 +32,7 @@ import java.util.List;
 import java.util.Map;
 import java.util.Optional;
 import java.util.Set;
+import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
 import java.util.concurrent.atomic.AtomicBoolean;
@@ -52,6 +53,7 @@ import org.apache.sling.api.wrappers.ValueMapDecorator;
 import org.apache.sling.resourceresolver.impl.ResourceResolverMetrics;
 import 
org.apache.sling.resourceresolver.impl.mapping.MapConfigurationProvider.VanityPathConfig;
 import org.junit.After;
+import org.junit.Assume;
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -1274,6 +1276,44 @@ public class VanityPathMapEntriesTest extends 
AbstractMappingMapEntriesTest {
         assertTrue(finalVanityMap.get("/eventTest").contains("/baa"));
     }
 
+    @Test
+    public void test_remove_vanity_path_during_bg_init() {
+        Assume.assumeTrue(
+                "simulation of resource removal during bg init only meaningful 
in 'bg init' case",
+                resourceResolverFactory.isVanityPathCacheInitInBackground());
+
+        Resource root = createMockedResource("/");
+        Resource foo = createMockedResource(root, "foo");
+        Resource leaf = createMockedResource(foo, "leaf");
+
+        when(leaf.getValueMap()).thenReturn(buildValueMap("sling:vanityPath", 
"/bar"));
+
+        CountDownLatch greenLight = new CountDownLatch(1);
+
+        when(resourceResolver.findResources(anyString(), eq("JCR-SQL2")))
+                .thenAnswer((Answer<Iterator<Resource>>) invocation -> {
+                    greenLight.await();
+                    return Set.of(leaf).iterator();
+                });
+
+        VanityPathHandler vph = mapEntries.vph;
+        vph.initializeVanityPaths();
+        assertFalse(vph.isReady());
+
+        // bg init will wait until we give green light
+        mapEntries.onChange(List.of(new 
ResourceChange(ResourceChange.ChangeType.REMOVED, leaf.getPath(), false)));
+
+        greenLight.countDown();
+        waitForBgInit();
+
+        assertTrue(vph.isReady());
+
+        Map<String, List<String>> vanityPathMappings = 
mapEntries.getVanityPathMappings();
+        List<String> mappings = vanityPathMappings.get("/foo/leaf");
+
+        assertNull("expected no (null) mapping for /foo/leaf", mappings);
+    }
+
     // checks for the expected list of queries and the cache statistics
     private void checkCounters(
             String testName,

Reply via email to