reschke commented on code in PR #136:
URL: 
https://github.com/apache/sling-org-apache-sling-resourceresolver/pull/136#discussion_r1930369745


##########
src/test/java/org/apache/sling/resourceresolver/impl/mapping/VanityPathMapEntriesTest.java:
##########
@@ -149,6 +154,36 @@ public void setup() throws Exception {
         Optional<ResourceResolverMetrics> metrics = Optional.empty();
 
         mapEntries = new MapEntries(resourceResolverFactory, bundleContext, 
eventAdmin, stringInterpolationProvider, metrics);
+        waitForBgInit();
+    }
+
+    // get internal flag that signals completion of background task
+    private AtomicBoolean getVanityPathsProcessed() {
+        try {
+            Field field = 
MapEntries.class.getDeclaredField("vanityPathsProcessed");
+            field.setAccessible(true);
+            return (AtomicBoolean) field.get(mapEntries);
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+    // wait for background thread to complete
+    private void waitForBgInit() {
+        while (!getVanityPathsProcessed().get()) {
+            try {
+                Thread.sleep(10);
+            } catch (InterruptedException e) {
+                // ignored
+            }
+        }
+    }
+
+    // get vanity paths (after waiting for bg init to complete)
+    private void initializeVanityPaths() throws IOException {
+        getVanityPathsProcessed().set(false);

Review Comment:
   Ok. The reason is that the internal state of `MapEntries` did not account 
for `loadVanityPaths` called twice.
   
   I added that, and was able to remove `getVanityPathsProcessed().set(false);` 
from the test.
   
   Your point about extending `MapEntries` is understood; however the point of 
*this* change was to improve test coverage before doing any changes of what's 
being tested.



-- 
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