You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by re...@apache.org on 2025/02/03 12:37:59 UTC
(sling-org-apache-sling-resourceresolver) branch master updated: Revert "SLING-12636: Resource Resolver: add test coverage for background init (#136)"
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 7ca429a Revert "SLING-12636: Resource Resolver: add test coverage for background init (#136)"
7ca429a is described below
commit 7ca429a88531e927b38b709190149a98f4523915
Author: Julian Reschke <re...@apache.org>
AuthorDate: Mon Feb 3 13:37:46 2025 +0100
Revert "SLING-12636: Resource Resolver: add test coverage for background init (#136)"
This reverts commit ba7588bc5cf5bda1aae55c3e5022659fcc440380.
---
.../resourceresolver/impl/mapping/MapEntries.java | 2 -
.../impl/mapping/VanityPathMapEntriesTest.java | 70 ++++++----------------
2 files changed, 19 insertions(+), 53 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 80556f0..95a4164 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
@@ -1166,10 +1166,8 @@ public class MapEntries implements
this.initializing.lock();
try {
if (this.factory.isVanityPathEnabled()) {
- vanityPathsProcessed.set(false);
this.vanityBloomFilter = createVanityBloomFilter();
VanityPathInitializer vpi = new VanityPathInitializer(this.factory);
-
if (this.factory.isVanityPathCacheInitInBackground()) {
this.log.debug("bg init starting");
Thread vpinit = new Thread(vpi, "VanityPathInitializer");
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 d0da9df..218db15 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
@@ -90,26 +90,23 @@ public class VanityPathMapEntriesTest extends AbstractMappingMapEntriesTest {
@Mock
private EventAdmin eventAdmin;
- private final int pageSize;
- private final boolean isMaxCachedVanityPathEntriesStartup;
- private final boolean isVanityPathCacheInitInBackground;
+ private int pageSize;
+ private boolean isMaxCachedVanityPathEntriesStartup;
private int prevPageSize = 1000;
- @Parameters(name="{0} {1} {2}")
+ @Parameters(name="{0} {1}")
public static Collection<Object[]> data() {
return List.of(new Object[][] {
- {1000, false, true},
- {1, true, false},
- {1000, true, false}}
+ {1000, false},
+ {1, true},
+ {1000, true}}
);
}
- public VanityPathMapEntriesTest(int pageSize, boolean isMaxCachedVanityPathEntriesStartup,
- boolean isVanityPathCacheInitInBackground) {
+ public VanityPathMapEntriesTest(int pageSize, boolean isMaxCachedVanityPathEntriesStartup) {
this.pageSize = pageSize;
this.isMaxCachedVanityPathEntriesStartup = isMaxCachedVanityPathEntriesStartup;
- this.isVanityPathCacheInitInBackground = isVanityPathCacheInitInBackground;
}
@Override
@@ -136,7 +133,6 @@ public class VanityPathMapEntriesTest extends AbstractMappingMapEntriesTest {
Collections.sort(configs);
when(bundle.getSymbolicName()).thenReturn("TESTBUNDLE");
when(bundleContext.getBundle()).thenReturn(bundle);
- when(resourceResolverFactory.getServiceUserAuthenticationInfo(anyString())).thenReturn(Map.of());
when(resourceResolverFactory.getServiceResourceResolver(any(Map.class))).thenReturn(resourceResolver);
when(resourceResolverFactory.isVanityPathEnabled()).thenReturn(true);
when(resourceResolverFactory.getVanityPathConfig()).thenReturn(configs);
@@ -144,7 +140,6 @@ public class VanityPathMapEntriesTest extends AbstractMappingMapEntriesTest {
when(resourceResolverFactory.getMapRoot()).thenReturn(MapEntries.DEFAULT_MAP_ROOT);
when(resourceResolverFactory.getMaxCachedVanityPathEntries()).thenReturn(-1L);
when(resourceResolverFactory.isMaxCachedVanityPathEntriesStartup()).thenReturn(isMaxCachedVanityPathEntriesStartup);
- when(resourceResolverFactory.isVanityPathCacheInitInBackground()).thenReturn(isVanityPathCacheInitInBackground);
when(resourceResolver.findResources(anyString(), eq("sql"))).thenReturn(
Collections.emptyIterator());
when(resourceResolver.findResources(anyString(), eq("JCR-SQL2"))).thenReturn(
@@ -154,35 +149,6 @@ public class VanityPathMapEntriesTest extends AbstractMappingMapEntriesTest {
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 {
- mapEntries.initializeVanityPaths();
- waitForBgInit();
}
@Override
@@ -200,9 +166,8 @@ public class VanityPathMapEntriesTest extends AbstractMappingMapEntriesTest {
String oneMore = "one-more";
prepareMapEntriesForVanityPath(false, false, containerName,
childName, oneMore, vanityPath);
-
- initializeVanityPaths();
-
+ mapEntries.doInit();
+ mapEntries.initializeVanityPaths();
Map<String, List<String>> vanityMap = mapEntries.getVanityPathMappings();
assertNotNull(vanityMap);
assertEquals(vanityPath, vanityMap.get("/" + containerName + "/" + childName).get(0));
@@ -219,9 +184,8 @@ public class VanityPathMapEntriesTest extends AbstractMappingMapEntriesTest {
String oneMore = "one-more";
prepareMapEntriesForVanityPath(true, true, containerName,
childName, oneMore, vanityPath);
-
- initializeVanityPaths();
-
+ mapEntries.doInit();
+ mapEntries.initializeVanityPaths();
Map<String, List<String>> vanityMap = mapEntries.getVanityPathMappings();
assertNotNull(vanityMap);
// not present
@@ -335,7 +299,8 @@ public class VanityPathMapEntriesTest extends AbstractMappingMapEntriesTest {
}
});
- initializeVanityPaths();
+ mapEntries.doInit();
+ mapEntries.initializeVanityPaths();
List<MapEntry> entries = mapEntries.getResolveMaps();
@@ -381,7 +346,8 @@ public class VanityPathMapEntriesTest extends AbstractMappingMapEntriesTest {
when(resourceResolver.findResources(anyString(), eq("JCR-SQL2"))).thenAnswer((Answer<Iterator<Resource>>) invocation -> Collections.emptyIterator());
- initializeVanityPaths();
+ mapEntries.doInit();
+ mapEntries.initializeVanityPaths();
// map entries should have no alias atm
assertTrue( mapEntries.getResolveMaps().isEmpty());
@@ -494,6 +460,7 @@ public class VanityPathMapEntriesTest extends AbstractMappingMapEntriesTest {
resources.add(getVanityPathResource(val));
}
+
when(resourceResolver.findResources(anyString(), eq("JCR-SQL2"))).thenAnswer((Answer<Iterator<Resource>>) invocation -> {
String query = invocation.getArguments()[0].toString();
if (matchesPagedQuery(query)) {
@@ -508,7 +475,8 @@ public class VanityPathMapEntriesTest extends AbstractMappingMapEntriesTest {
}
});
- initializeVanityPaths();
+ mapEntries.doInit();
+ mapEntries.initializeVanityPaths();
List<MapEntry> entries = mapEntries.getResolveMaps();
// each valid resource results in 2 entries
@@ -1286,7 +1254,7 @@ public class VanityPathMapEntriesTest extends AbstractMappingMapEntriesTest {
return vp.length == 0 ? "": vp[0];
}
- private final Comparator<Resource> vanityResourceComparator = (o1, o2) -> {
+ private Comparator<Resource> vanityResourceComparator = (o1, o2) -> {
String s1 = getFirstVanityPath(o1);
String s2 = getFirstVanityPath(o2);
return s1.compareTo(s2);