joerghoh commented on code in PR #197:
URL: 
https://github.com/apache/sling-org-apache-sling-resourceresolver/pull/197#discussion_r2297890504


##########
src/test/java/org/apache/sling/resourceresolver/impl/mapping/AliasMapEntriesTest.java:
##########
@@ -1252,6 +1259,118 @@ public void test_initAliasesAfterDispose() {
         assertFalse("alias handler should not have set up cache", 
ah.usesCache());
     }
 
+    @Test
+    public void test_event_alias_during_bg_init1() {
+        Assume.assumeTrue(
+                "simulation of resource removal during bg init only meaningful 
in 'bg init' case",
+                resourceResolverFactory.isAliasCacheInitInBackground());
+
+        Resource root = createMockedResource("/");
+        Resource top = createMockedResource(root, "top");
+        Resource leaf1 = createMockedResource(top, "leaf1");
+        
when(leaf1.getValueMap()).thenReturn(buildValueMap(ResourceResolverImpl.PROP_ALIAS,
 "alias1"));
+
+        CountDownLatch greenLight = new CountDownLatch(1);
+
+        when(resourceResolver.findResources(anyString(), eq("JCR-SQL2")))
+                .thenAnswer((Answer<Iterator<Resource>>) invocation -> {
+                    greenLight.await();
+                    return Set.of(leaf1).iterator();
+                });
+
+        AliasHandler ah = mapEntries.ah;
+        ah.initializeAliases();
+        assertFalse(ah.isReady());
+
+        // bg init will wait until we give green light
+
+        Resource leaf2 = createMockedResource(top, "leaf2");
+        
when(leaf2.getValueMap()).thenReturn(buildValueMap(ResourceResolverImpl.PROP_ALIAS,
 "alias2"));
+
+        removeResource(leaf1);
+        mapEntries.onChange(List.of(new 
ResourceChange(ResourceChange.ChangeType.REMOVED, leaf1.getPath(), false)));
+        mapEntries.onChange(List.of(new 
ResourceChange(ResourceChange.ChangeType.ADDED, leaf2.getPath(), false)));
+
+        greenLight.countDown();
+        waitForBgInit();
+
+        assertTrue(ah.isReady());
+
+        Map<String, Collection<String>> aliasMapEntry = 
mapEntries.getAliasMap(top);
+        assertNotNull(aliasMapEntry);
+
+        Collection<String> leaf1Entry = aliasMapEntry.get(leaf1.getName());
+        assertNull(
+                "Alias Map Entry for " + top.getPath() + " should not contain 
an entry for " + leaf1.getName()
+                        + " due to removal event during background init, but 
got: "
+                        + leaf1Entry,
+                leaf1Entry);
+
+        Collection<String> leaf2Entry = aliasMapEntry.get(leaf2.getName());
+        assertNotNull(
+                "Alias Map Entry for " + top.getPath() + " should contain an 
entry for " + leaf2.getName()
+                        + " due to addition event during background init, but 
got: " + leaf2Entry,
+                leaf2Entry);
+
+        assertIterableEquals(Set.of("alias2"), leaf2Entry, "Alias Array for " 
+ leaf2.getName() + " incorrect");
+    }
+
+    @Test
+    public void test_event_alias_during_bg_init2() {

Review Comment:
   maybe a comment to outline the difference between the 2 new testcases 
```_init1``` and ```_init2``` 



##########
src/main/java/org/apache/sling/resourceresolver/impl/mapping/MapEntries.java:
##########
@@ -485,6 +516,8 @@ public void onChange(final List<ResourceChange> changes) {
     private boolean handleResourceChange(
             ResourceChange.ChangeType type,
             String path,
+            boolean forAlias,
+            boolean forVanityPath,

Review Comment:
   I am not happy with the signature of this method anymore, it has now 6 
parameters, and we need to pass on all parameters to the respective 
``(remove|add|update)Resource`` methods.
   I think we should create a very simple record-style class as a container as 
a subclass (maybe ``ResourceChangeContext```). 
   That could simplify the code quite a bit.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to