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 330d1f3d SLING-13327: add metrics related to observation events 
related to vanity paths and aliases (#235)
330d1f3d is described below

commit 330d1f3d64c3639b878ccd488c5469857df14e3e
Author: Julian Reschke <[email protected]>
AuthorDate: Fri Sep 4 10:32:27 2026 +0200

    SLING-13327: add metrics related to observation events related to vanity 
paths and aliases (#235)
---
 .../impl/ResourceResolverMetrics.java              | 35 ++++++++++++++++++++
 .../impl/mapping/AliasHandler.java                 |  3 ++
 .../resourceresolver/impl/mapping/MapEntries.java  | 38 +++++++++++++++++++---
 .../impl/mapping/VanityPathHandler.java            |  1 +
 .../impl/mapping/AliasMapEntriesTest.java          | 19 +++++++++--
 .../impl/mapping/VanityPathMapEntriesTest.java     | 37 ++++++++++++++-------
 6 files changed, 115 insertions(+), 18 deletions(-)

diff --git 
a/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverMetrics.java
 
b/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverMetrics.java
index 7578ee33..b632f4dc 100644
--- 
a/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverMetrics.java
+++ 
b/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverMetrics.java
@@ -77,6 +77,10 @@ public class ResourceResolverMetrics {
     private ServiceRegistration<Gauge<Long>> 
numberOfVanityPathBloomFalsePositivesGauge;
     private Supplier<Long> numberOfVanityPathBloomFalsePositivesSupplier = 
ZERO_SUPPLIER;
 
+    // number of vanity path related events
+    private ServiceRegistration<Gauge<Long>> numberOfVanityPathEventsGauge;
+    private Supplier<Long> numberOfVanityPathEventsSupplier = ZERO_SUPPLIER;
+
     // number of resources with aliased children
     private ServiceRegistration<Gauge<Long>> 
numberOfResourcesWithAliasedChildrenGauge;
     private Supplier<Long> numberOfResourcesWithAliasedChildrenSupplier = 
ZERO_SUPPLIER;
@@ -93,12 +97,21 @@ public class ResourceResolverMetrics {
     private ServiceRegistration<Gauge<Long>> 
numberOfDetectedConflictingAliasesGauge;
     private Supplier<Long> numberOfDetectedConflictingAliasesSupplier = 
ZERO_SUPPLIER;
 
+    // number of vanity path related events
+    private ServiceRegistration<Gauge<Long>> numberOfAliasEventsGauge;
+    private Supplier<Long> numberOfAliasEventsSupplier = ZERO_SUPPLIER;
+
     private Counter unclosedResourceResolvers;
 
     @Activate
     protected void activate(BundleContext bundleContext) {
+        // vanity paths
         numberOfVanityPathsGauge = registerGauge(
                 bundleContext, METRICS_PREFIX + ".numberOfVanityPaths", () -> 
numberOfVanityPathsSupplier);
+        numberOfVanityPathEventsGauge = registerGauge(
+                bundleContext,
+                METRICS_PREFIX + ".numberOfVanityPathRelatedEvents",
+                () -> numberOfVanityPathEventsSupplier);
         numberOfResourcesWithVanityPathsOnStartupGauge = registerGauge(
                 bundleContext,
                 METRICS_PREFIX + ".numberOfResourcesWithVanityPathsOnStartup",
@@ -113,6 +126,8 @@ public class ResourceResolverMetrics {
                 bundleContext,
                 METRICS_PREFIX + ".numberOfVanityPathBloomFalsePositives",
                 () -> numberOfVanityPathBloomFalsePositivesSupplier);
+
+        // aliases
         numberOfResourcesWithAliasedChildrenGauge = registerGauge(
                 bundleContext,
                 METRICS_PREFIX + ".numberOfResourcesWithAliasedChildren",
@@ -129,6 +144,10 @@ public class ResourceResolverMetrics {
                 bundleContext,
                 METRICS_PREFIX + ".numberOfDetectedConflictingAliases",
                 () -> numberOfDetectedConflictingAliasesSupplier);
+        numberOfAliasEventsGauge = registerGauge(
+                bundleContext, METRICS_PREFIX + ".numberOfAliasRelatedEvents", 
() -> numberOfAliasEventsSupplier);
+
+        // other
         unclosedResourceResolvers = metricsService.counter(METRICS_PREFIX + 
".unclosedResourceResolvers");
     }
 
@@ -185,6 +204,14 @@ public class ResourceResolverMetrics {
         numberOfVanityPathBloomFalsePositivesSupplier = supplier;
     }
 
+    /**
+     * Set the supplier for the number of vanity path related events
+     * @param supplier a supplier returning the number of vanity path related 
events
+     */
+    public void setNumberOfVanityPathEventsSupplier(Supplier<Long> supplier) {
+        numberOfVanityPathEventsSupplier = supplier;
+    }
+
     /**
      * Set the number of aliases in the system
      * @param supplier a supplier returning the number of aliases
@@ -217,6 +244,14 @@ public class ResourceResolverMetrics {
         numberOfDetectedConflictingAliasesSupplier = supplier;
     }
 
+    /**
+     * Set the supplier for the number of alias related events
+     * @param supplier a supplier returning the number of alias related events
+     */
+    public void setNumberOfAliasEventsSupplier(Supplier<Long> supplier) {
+        numberOfAliasEventsSupplier = supplier;
+    }
+
     /**
      * Increment the counter for the number of unresolved resource resolvers
      */
diff --git 
a/src/main/java/org/apache/sling/resourceresolver/impl/mapping/AliasHandler.java
 
b/src/main/java/org/apache/sling/resourceresolver/impl/mapping/AliasHandler.java
index e4faf8fd..922b5de0 100644
--- 
a/src/main/java/org/apache/sling/resourceresolver/impl/mapping/AliasHandler.java
+++ 
b/src/main/java/org/apache/sling/resourceresolver/impl/mapping/AliasHandler.java
@@ -87,6 +87,7 @@ class AliasHandler {
     @NotNull
     Map<String, Map<String, Collection<String>>> aliasMapsMap = 
UNITIALIZED_MAP;
 
+    final AtomicLong aliasEvents;
     final AtomicLong aliasResourcesOnStartup;
     final AtomicLong detectedConflictingAliases;
     final AtomicLong detectedInvalidAliases;
@@ -105,6 +106,7 @@ class AliasHandler {
         this.sendChangeEvent = sendChangeEvent;
         this.drain = drain;
 
+        this.aliasEvents = new AtomicLong(0);
         this.aliasResourcesOnStartup = new AtomicLong(0);
         this.detectedConflictingAliases = new AtomicLong(0);
         this.detectedInvalidAliases = new AtomicLong(0);
@@ -539,6 +541,7 @@ class AliasHandler {
         } else {
             // we read the aliases from the resource given in the method call 
parameters
             String[] aliasArray = 
resource.getValueMap().get(ResourceResolverImpl.PROP_ALIAS, String[].class);
+
             if (aliasArray == null) {
                 return false;
             } else {
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 1784481b..5cc32297 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
@@ -55,6 +55,7 @@ import org.apache.sling.api.resource.ValueMap;
 import 
org.apache.sling.api.resource.observation.ExternalResourceChangeListener;
 import org.apache.sling.api.resource.observation.ResourceChange;
 import org.apache.sling.api.resource.observation.ResourceChangeListener;
+import org.apache.sling.resourceresolver.impl.ResourceResolverImpl;
 import org.apache.sling.resourceresolver.impl.ResourceResolverMetrics;
 import org.jetbrains.annotations.NotNull;
 import org.osgi.framework.BundleContext;
@@ -159,6 +160,7 @@ public class MapEntries implements MapEntriesHandler, 
ResourceChangeListener, Ex
             
metrics.get().setNumberOfDetectedInvalidAliasesSupplier(ah.detectedInvalidAliases::get);
             metrics.get().setNumberOfResourcesWithAliasedChildrenSupplier(() 
-> (long) ah.aliasMapsMap.size());
             
metrics.get().setNumberOfResourcesWithAliasesOnStartupSupplier(ah.aliasResourcesOnStartup::get);
+            metrics.get().setNumberOfAliasEventsSupplier(ah.aliasEvents::get);
 
             // vanity paths
             
metrics.get().setNumberOfResourcesWithVanityPathsOnStartupSupplier(vph.vanityResourcesOnStartup::get);
@@ -166,6 +168,7 @@ public class MapEntries implements MapEntriesHandler, 
ResourceChangeListener, Ex
             
metrics.get().setNumberOfVanityPathBloomNegativesSupplier(vph.vanityPathBloomNegatives::get);
             
metrics.get().setNumberOfVanityPathLookupsSupplier(vph.vanityPathLookups::get);
             
metrics.get().setNumberOfVanityPathsSupplier(vph.vanityCounter::get);
+            
metrics.get().setNumberOfVanityPathEventsSupplier(vph.vanityEvents::get);
         }
     }
 
@@ -195,8 +198,22 @@ public class MapEntries implements MapEntriesHandler, 
ResourceChangeListener, Ex
 
             Resource resource = this.resolver != null ? 
resolver.getResource(ctx.path) : null;
             if (resource != null) {
-                boolean vanityPathAdded = ctx.forVanityPath && 
vph.doAddVanity(resource);
-                boolean aliasAdded = ctx.forAlias && ah.doAddAlias(resource);
+
+                boolean aliasAdded = false;
+                boolean vanityPathAdded = false;
+
+                if (ctx.forAlias) {
+                    if 
(resource.getValueMap().containsKey(ResourceResolverImpl.PROP_ALIAS)) {
+                        ah.aliasEvents.incrementAndGet();
+                    }
+                    aliasAdded = ah.doAddAlias(resource);
+                }
+                if (ctx.forVanityPath) {
+                    if 
(resource.getValueMap().containsKey(VanityPathHandler.PROP_VANITY_PATH)) {
+                        vph.vanityEvents.incrementAndGet();
+                    }
+                    vanityPathAdded = vph.doAddVanity(resource);
+                }
                 return vanityPathAdded || aliasAdded;
             } else {
                 return false;
@@ -215,13 +232,18 @@ public class MapEntries implements MapEntriesHandler, 
ResourceChangeListener, Ex
 
             Resource resource = this.resolver != null ? 
resolver.getResource(ctx.path) : null;
 
-            boolean isValidVanityPath = vph.isValidVanityPath(ctx.path);
-
             if (resource != null) {
 
+                boolean aliasChanged = false;
                 boolean vanityPathChanged = false;
 
+                boolean isValidVanityPath = vph.isValidVanityPath(ctx.path);
+
                 if (ctx.forVanityPath && isValidVanityPath) {
+                    if 
(resource.getValueMap().containsKey(VanityPathHandler.PROP_VANITY_PATH)) {
+                        vph.vanityEvents.incrementAndGet();
+                    }
+
                     // we remove the old vanity path first
                     vanityPathChanged |= vph.doRemoveVanity(ctx.path);
 
@@ -234,7 +256,13 @@ public class MapEntries implements MapEntriesHandler, 
ResourceChangeListener, Ex
                     vanityPathChanged |= vph.doAddVanity(contentRsrc != null ? 
contentRsrc : resource);
                 }
 
-                boolean aliasChanged = ctx.forAlias && 
ah.doUpdateAlias(resource);
+                if (ctx.forAlias) {
+                    if 
(resource.getValueMap().containsKey(ResourceResolverImpl.PROP_ALIAS)) {
+                        ah.aliasEvents.incrementAndGet();
+                    }
+                    aliasChanged = ah.doUpdateAlias(resource);
+                }
+
                 return vanityPathChanged || aliasChanged;
             }
         } finally {
diff --git 
a/src/main/java/org/apache/sling/resourceresolver/impl/mapping/VanityPathHandler.java
 
b/src/main/java/org/apache/sling/resourceresolver/impl/mapping/VanityPathHandler.java
index bd96990d..892cac91 100644
--- 
a/src/main/java/org/apache/sling/resourceresolver/impl/mapping/VanityPathHandler.java
+++ 
b/src/main/java/org/apache/sling/resourceresolver/impl/mapping/VanityPathHandler.java
@@ -68,6 +68,7 @@ public class VanityPathHandler {
     private static final int VANITY_BLOOM_FILTER_MAX_ENTRIES = 10000000;
 
     final AtomicLong vanityCounter = new AtomicLong(0);
+    final AtomicLong vanityEvents = new AtomicLong(0);
     final AtomicLong vanityResourcesOnStartup = new AtomicLong(0);
     final AtomicLong vanityPathLookups = new AtomicLong(0);
     final AtomicLong vanityPathBloomNegatives = new AtomicLong(0);
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 7fbb881f..e884c4b8 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
@@ -708,6 +708,8 @@ public class AliasMapEntriesTest extends 
AbstractMappingMapEntriesTest {
                 "observation events have no effect when no cache is used",
                 resourceResolverFactory.isOptimizeAliasResolutionEnabled());
 
+        int eventCount = 0;
+
         assertEquals(0, aliasMap.size());
 
         Resource parent = createMockedResource("/parent");
@@ -716,6 +718,7 @@ public class AliasMapEntriesTest extends 
AbstractMappingMapEntriesTest {
         
when(result.getValueMap()).thenReturn(buildValueMap(ResourceResolverImpl.PROP_ALIAS,
 "alias"));
 
         updateResource(mapEntries, "/parent/child", new AtomicBoolean());
+        assertEquals(++eventCount, mapEntries.ah.aliasEvents.get());
 
         Map<String, Collection<String>> aliasMapEntry = 
mapEntries.getAliasMap("/parent");
         assertNotNull(aliasMapEntry);
@@ -726,15 +729,16 @@ public class AliasMapEntriesTest extends 
AbstractMappingMapEntriesTest {
 
         
when(result.getValueMap()).thenReturn(buildValueMap(ResourceResolverImpl.PROP_ALIAS,
 "aliasUpdated"));
 
+        // simulate an observation event
         updateResource(mapEntries, "/parent/child", new AtomicBoolean());
+        assertEquals(++eventCount, mapEntries.ah.aliasEvents.get());
+        assertEquals(1, aliasMap.size());
 
         aliasMapEntry = mapEntries.getAliasMap("/parent");
         assertNotNull(aliasMapEntry);
         assertTrue(aliasMapEntry.containsKey("child"));
         assertEquals(List.of("aliasUpdated"), aliasMapEntry.get("child"));
 
-        assertEquals(1, aliasMap.size());
-
         // testing jcr:content node update
         Resource jcrContentResult = createMockedResource(result, 
"jcr:content");
 
@@ -742,6 +746,7 @@ public class AliasMapEntriesTest extends 
AbstractMappingMapEntriesTest {
                 .thenReturn(buildValueMap(ResourceResolverImpl.PROP_ALIAS, 
"aliasJcrContent"));
 
         updateResource(mapEntries, "/parent/child/jcr:content", new 
AtomicBoolean());
+        assertEquals(++eventCount, mapEntries.ah.aliasEvents.get());
 
         aliasMapEntry = mapEntries.getAliasMap("/parent");
         assertNotNull(aliasMapEntry);
@@ -754,6 +759,7 @@ public class AliasMapEntriesTest extends 
AbstractMappingMapEntriesTest {
         when(jcrContentResult.getValueMap())
                 .thenReturn(buildValueMap(ResourceResolverImpl.PROP_ALIAS, 
"aliasJcrContentUpdated"));
         updateResource(mapEntries, "/parent/child/jcr:content", new 
AtomicBoolean());
+        assertEquals(++eventCount, mapEntries.ah.aliasEvents.get());
 
         aliasMapEntry = mapEntries.getAliasMap("/parent");
         assertNotNull(aliasMapEntry);
@@ -765,6 +771,7 @@ public class AliasMapEntriesTest extends 
AbstractMappingMapEntriesTest {
 
         // re-update alias
         updateResource(mapEntries, "/parent/child", new AtomicBoolean());
+        assertEquals(++eventCount, mapEntries.ah.aliasEvents.get());
 
         aliasMapEntry = mapEntries.getAliasMap("/parent");
         assertNotNull(aliasMapEntry);
@@ -778,6 +785,7 @@ public class AliasMapEntriesTest extends 
AbstractMappingMapEntriesTest {
         
when(secondResult.getValueMap()).thenReturn(buildValueMap(ResourceResolverImpl.PROP_ALIAS,
 "alias2"));
 
         updateResource(mapEntries, "/parent/child2", new AtomicBoolean());
+        assertEquals(++eventCount, mapEntries.ah.aliasEvents.get());
         assertEquals(1, aliasMap.size());
 
         aliasMapEntry = mapEntries.getAliasMap("/parent");
@@ -787,6 +795,7 @@ public class AliasMapEntriesTest extends 
AbstractMappingMapEntriesTest {
         when(jcrContentResult.getValueMap())
                 .thenReturn(buildValueMap(ResourceResolverImpl.PROP_ALIAS, 
"aliasJcrContentUpdated"));
         updateResource(mapEntries, "/parent/child/jcr:content", new 
AtomicBoolean());
+        assertEquals(++eventCount, mapEntries.ah.aliasEvents.get());
 
         aliasMapEntry = mapEntries.getAliasMap("/parent");
         assertNotNull(aliasMapEntry);
@@ -800,6 +809,7 @@ public class AliasMapEntriesTest extends 
AbstractMappingMapEntriesTest {
         when(jcrContentResult.getValueMap())
                 .thenReturn(buildValueMap(ResourceResolverImpl.PROP_ALIAS, 
"aliasJcrContentUpdated"));
         updateResource(mapEntries, "/parent/child/jcr:content", new 
AtomicBoolean());
+        assertEquals(++eventCount, mapEntries.ah.aliasEvents.get());
 
         aliasMapEntry = mapEntries.getAliasMap("/parent");
         assertNotNull(aliasMapEntry);
@@ -1290,6 +1300,8 @@ public class AliasMapEntriesTest extends 
AbstractMappingMapEntriesTest {
         ah.initializeAliases();
         assertFalse(ah.isReady());
 
+        assertEquals(0, ah.aliasEvents.get());
+
         // bg init will wait until we give green light - events only from here 
on, no stubbing
         mapEntries.onChange(List.of(new 
ResourceChange(ResourceChange.ChangeType.REMOVED, leaf1.getPath(), false)));
         mapEntries.onChange(List.of(new 
ResourceChange(ResourceChange.ChangeType.ADDED, leaf2.getPath(), false)));
@@ -1299,6 +1311,9 @@ public class AliasMapEntriesTest extends 
AbstractMappingMapEntriesTest {
 
         assertTrue(ah.isReady());
 
+        // REMOVED: no event, ADDED: one event
+        assertEquals(1, ah.aliasEvents.get());
+
         Map<String, Collection<String>> aliasMapEntry = 
mapEntries.getAliasMap(top);
         assertNotNull(aliasMapEntry);
 
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 87298f52..67cdcaf0 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
@@ -229,6 +229,14 @@ public class VanityPathMapEntriesTest extends 
AbstractMappingMapEntriesTest {
         method.invoke(mapEntries, ctx, bool);
     }
 
+    private static boolean updateResource(MapEntries mapEntries, String path, 
AtomicBoolean bool)
+            throws IllegalAccessException, NoSuchMethodException, 
InvocationTargetException {
+        Method method = MapEntries.class.getDeclaredMethod(
+                "updateResource", MapEntries.ChangeContext.class, 
AtomicBoolean.class);
+        method.setAccessible(true);
+        return (Boolean) method.invoke(mapEntries, new 
MapEntries.ChangeContext(path, false, true), bool);
+    }
+
     private static void loadVanityPaths(MapEntries mapEntries, 
ResourceResolver resourceResolver)
             throws IllegalAccessException, NoSuchMethodException, 
InvocationTargetException {
         Method method = 
VanityPathHandler.class.getDeclaredMethod("loadVanityPaths", 
ResourceResolver.class);
@@ -467,6 +475,8 @@ public class VanityPathMapEntriesTest extends 
AbstractMappingMapEntriesTest {
 
     @Test
     public void test_vanity_path_updates() {
+        int eventCount = 0;
+
         Resource parent = createMockedResource("/foo/parent");
         when(parent.getValueMap()).thenReturn(new 
ValueMapDecorator(Collections.emptyMap()));
 
@@ -487,6 +497,7 @@ public class VanityPathMapEntriesTest extends 
AbstractMappingMapEntriesTest {
 
         // add child
         mapEntries.onChange(List.of(new ResourceChange(ChangeType.ADDED, 
child.getPath(), false)));
+        assertEquals(++eventCount, mapEntries.vph.vanityEvents.get());
 
         // two entries for the vanity path
         List<MapEntry> entries = mapEntries.getResolveMaps();
@@ -505,6 +516,7 @@ public class VanityPathMapEntriesTest extends 
AbstractMappingMapEntriesTest {
 
         // update child - no change
         mapEntries.onChange(List.of(new ResourceChange(ChangeType.CHANGED, 
child.getPath(), false)));
+        assertEquals(++eventCount, mapEntries.vph.vanityEvents.get());
         entries = mapEntries.getResolveMaps();
         assertEquals(2, entries.size());
         for (MapEntry entry : entries) {
@@ -547,6 +559,7 @@ public class VanityPathMapEntriesTest extends 
AbstractMappingMapEntriesTest {
                 new ResourceChange(ChangeType.ADDED, parent.getPath(), false),
                 new ResourceChange(ChangeType.ADDED, child.getPath(), false),
                 new ResourceChange(ChangeType.ADDED, child2.getPath(), 
false)));
+        assertEquals(3, mapEntries.vph.vanityEvents.get());
 
         // 6 entries for the vanity path
         List<MapEntry> entries = mapEntries.getResolveMaps();
@@ -637,14 +650,17 @@ public class VanityPathMapEntriesTest extends 
AbstractMappingMapEntriesTest {
 
     @Test
     public void test_doAddVanity() throws Exception {
+        int eventCount = 0;
         List<MapEntry> entries = mapEntries.getResolveMaps();
         assertEquals(0, entries.size());
         assertEquals(0, getVanityTargets(mapEntries).size());
+        assertEquals(0, mapEntries.vph.vanityEvents.get());
 
         Resource justVanityPath = createMockedResource("/justVanityPath");
         
when(justVanityPath.getValueMap()).thenReturn(buildValueMap("sling:vanityPath", 
"/target/justVanityPath"));
 
         addResource(mapEntries, "/justVanityPath", new AtomicBoolean());
+        assertEquals(++eventCount, mapEntries.vph.vanityEvents.get());
 
         entries = mapEntries.getResolveMaps();
         assertEquals(2, entries.size());
@@ -656,6 +672,7 @@ public class VanityPathMapEntriesTest extends 
AbstractMappingMapEntriesTest {
         
when(badVanityPath.getValueMap()).thenReturn(buildValueMap("sling:vanityPath", 
"/content/mypage/en-us-{132"));
 
         addResource(mapEntries, "/badVanityPath", new AtomicBoolean());
+        assertEquals(++eventCount, mapEntries.vph.vanityEvents.get());
 
         assertEquals(2, entries.size());
         assertEquals(1, getVanityTargets(mapEntries).size());
@@ -668,7 +685,7 @@ public class VanityPathMapEntriesTest extends 
AbstractMappingMapEntriesTest {
                 .thenReturn(buildValueMap("sling:vanityPath", 
"/target/vanityPathOnJcrContent"));
 
         addResource(mapEntries, "/vanityPathOnJcrContent/jcr:content", new 
AtomicBoolean());
-
+        assertEquals(++eventCount, mapEntries.vph.vanityEvents.get());
         entries = mapEntries.getResolveMaps();
         assertEquals(4, entries.size());
 
@@ -732,20 +749,19 @@ public class VanityPathMapEntriesTest extends 
AbstractMappingMapEntriesTest {
 
     @Test
     public void test_doUpdateVanity() throws Exception {
+        int eventCount = 0;
+
         Map<String, List<MapEntry>> resolveMapsMap = 
getResolveMapsMap(mapEntries);
         assertEquals(1, resolveMapsMap.size());
 
         Map<String, List<String>> vanityTargets = getVanityTargets(mapEntries);
         assertEquals(0, vanityTargets.size());
 
-        final Method updateResource = MapEntries.class.getDeclaredMethod(
-                "updateResource", MapEntries.ChangeContext.class, 
AtomicBoolean.class);
-        updateResource.setAccessible(true);
-
         Resource justVanityPath = createMockedResource("/justVanityPath");
         
when(justVanityPath.getValueMap()).thenReturn(buildValueMap("sling:vanityPath", 
"/target/justVanityPath"));
 
         addResource(mapEntries, "/justVanityPath", new AtomicBoolean());
+        assertEquals(++eventCount, mapEntries.vph.vanityEvents.get());
 
         assertEquals(2, resolveMapsMap.size());
         assertEquals(1, vanityTargets.size());
@@ -758,8 +774,8 @@ public class VanityPathMapEntriesTest extends 
AbstractMappingMapEntriesTest {
         // update vanity path
         when(justVanityPath.getValueMap())
                 .thenReturn(buildValueMap("sling:vanityPath", 
"/target/justVanityPathUpdated"));
-        updateResource.invoke(
-                mapEntries, new MapEntries.ChangeContext("/justVanityPath", 
false, true), new AtomicBoolean());
+        updateResource(mapEntries, "/justVanityPath", new AtomicBoolean());
+        assertEquals(++eventCount, mapEntries.vph.vanityEvents.get());
 
         assertEquals(2, resolveMapsMap.size());
         assertEquals(1, vanityTargets.size());
@@ -779,6 +795,7 @@ public class VanityPathMapEntriesTest extends 
AbstractMappingMapEntriesTest {
                 .thenReturn(buildValueMap("sling:vanityPath", 
"/target/vanityPathOnJcrContent"));
 
         addResource(mapEntries, "/vanityPathOnJcrContent/jcr:content", new 
AtomicBoolean());
+        assertEquals(++eventCount, mapEntries.vph.vanityEvents.get());
 
         assertEquals(3, resolveMapsMap.size());
         assertEquals(2, vanityTargets.size());
@@ -792,10 +809,8 @@ public class VanityPathMapEntriesTest extends 
AbstractMappingMapEntriesTest {
         // update vanity path
         when(vanityPathOnJcrContent.getValueMap())
                 .thenReturn(buildValueMap("sling:vanityPath", 
"/target/vanityPathOnJcrContentUpdated"));
-        updateResource.invoke(
-                mapEntries,
-                new 
MapEntries.ChangeContext("/vanityPathOnJcrContent/jcr:content", false, true),
-                new AtomicBoolean());
+        updateResource(mapEntries, "/vanityPathOnJcrContent/jcr:content", new 
AtomicBoolean());
+        assertEquals(++eventCount, mapEntries.vph.vanityEvents.get());
 
         assertEquals(3, resolveMapsMap.size());
         assertEquals(2, vanityTargets.size());

Reply via email to