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
commit 69d57b9b37fee303a52d69d3a7e2979494fd3584 Author: Julian Reschke <[email protected]> AuthorDate: Tue Aug 19 16:21:06 2025 +0100 SLING-12894: alias refactoring - support observation events while bg init not finished --- .../impl/mapping/AliasMapEntriesTest.java | 38 ++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/src/test/java/org/apache/sling/resourceresolver/impl/mapping/AliasMapEntriesTest.java b/src/test/java/org/apache/sling/resourceresolver/impl/mapping/AliasMapEntriesTest.java index 8ac52f15..b9ed9319 100644 --- a/src/test/java/org/apache/sling/resourceresolver/impl/mapping/AliasMapEntriesTest.java +++ b/src/test/java/org/apache/sling/resourceresolver/impl/mapping/AliasMapEntriesTest.java @@ -1238,6 +1238,44 @@ public class AliasMapEntriesTest extends AbstractMappingMapEntriesTest { assertFalse("alias handler should not have set up cache", ah.usesCache()); } + @Test + public void test_remove_alias_during_bg_init() + throws InvocationTargetException, IllegalAccessException, NoSuchMethodException { + Assume.assumeTrue( + "simulation of resource removal during bg init only meaningful in 'bg init' case", + resourceResolverFactory.isAliasCacheInitInBackground()); + AliasHandler ah = mapEntries.ah; + + Resource root = createMockedResource("/"); + Resource top = createMockedResource(root, "top"); + Resource leaf = createMockedResource(top, "leaf"); + when(leaf.getValueMap()).thenReturn(buildValueMap(ResourceResolverImpl.PROP_ALIAS, "alias")); + + AtomicBoolean greenLight = new AtomicBoolean(false); + + when(resourceResolver.findResources(anyString(), eq("JCR-SQL2"))) + .thenAnswer((Answer<Iterator<Resource>>) invocation -> { + while (!greenLight.get()) { + // yes, busy wait; eat this, code quality checkers + } + return Set.of(leaf).iterator(); + }); + + ah.initializeAliases(); + + // bg init will wait until we give green light + removeResource(mapEntries, leaf.getPath(), null); + + greenLight.set(true); + waitForBgInit(); + + Map<String, Collection<String>> aliasMapEntry = mapEntries.getAliasMap(top); + assertTrue( + "Alias Map for " + top.getPath() + + " should be empty due to removal event during background init, bug got: " + aliasMapEntry, + aliasMapEntry.isEmpty()); + } + // utilities for testing alias queries // used for paged query of all
