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/08/07 07:46:10 UTC
(sling-org-apache-sling-resourceresolver) 01/01: SLING-12879: add wiring to handler and test class (wip)
This is an automated email from the ASF dual-hosted git repository.
reschke pushed a commit to branch SLING-12879
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-resourceresolver.git
commit 096cb0e8fde8d4cbd2f37cf7dfbbd149c62c3501
Author: Julian Reschke <re...@apache.org>
AuthorDate: Thu Aug 7 08:45:52 2025 +0100
SLING-12879: add wiring to handler and test class (wip)
---
.../impl/CommonResourceResolverFactoryImpl.java | 6 ++++++
.../resourceresolver/impl/mapping/AliasHandler.java | 8 +++++++-
.../impl/mapping/MapConfigurationProvider.java | 4 +++-
.../impl/mapping/AliasMapEntriesTest.java | 19 ++++++++++++++++---
4 files changed, 32 insertions(+), 5 deletions(-)
diff --git a/src/main/java/org/apache/sling/resourceresolver/impl/CommonResourceResolverFactoryImpl.java b/src/main/java/org/apache/sling/resourceresolver/impl/CommonResourceResolverFactoryImpl.java
index 935fe244..3428e8c6 100644
--- a/src/main/java/org/apache/sling/resourceresolver/impl/CommonResourceResolverFactoryImpl.java
+++ b/src/main/java/org/apache/sling/resourceresolver/impl/CommonResourceResolverFactoryImpl.java
@@ -397,6 +397,12 @@ public class CommonResourceResolverFactoryImpl implements MapConfigurationProvid
return this.activator.getVanityPathConfigurer().isVanityPathCacheInitInBackground();
}
+ @Override
+ public boolean isAliasCacheInitInBackground() {
+ // wiring to config will be added later
+ return false;
+ }
+
/**
* get's the ServiceTracker of the ResourceAccessSecurity service
*/
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 6b0e8d53..f8f5e0f0 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
@@ -129,7 +129,13 @@ class AliasHandler {
// optimization made in SLING-2521
if (this.factory.isOptimizeAliasResolutionEnabled()) {
AliasInitializer ai = new AliasInitializer();
- ai.run();
+ if (this.factory.isAliasCacheInitInBackground()) {
+ this.log.debug("bg init starting");
+ Thread aiinit = new Thread(ai, "AliasInitializer");
+ aiinit.start();
+ } else {
+ ai.run();
+ }
}
doUpdateConfiguration.run();
diff --git a/src/main/java/org/apache/sling/resourceresolver/impl/mapping/MapConfigurationProvider.java b/src/main/java/org/apache/sling/resourceresolver/impl/mapping/MapConfigurationProvider.java
index b731aed6..aab6e86b 100644
--- a/src/main/java/org/apache/sling/resourceresolver/impl/mapping/MapConfigurationProvider.java
+++ b/src/main/java/org/apache/sling/resourceresolver/impl/mapping/MapConfigurationProvider.java
@@ -57,9 +57,11 @@ public interface MapConfigurationProvider extends ResourceResolverFactory {
int getVanityBloomFilterMaxBytes();
+ boolean hasVanityPathPrecedence();
+
boolean isOptimizeAliasResolutionEnabled();
- boolean hasVanityPathPrecedence();
+ boolean isAliasCacheInitInBackground();
Map<String, Object> getServiceUserAuthenticationInfo(final String subServiceName) throws LoginException;
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 6923a1c0..3b63302c 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
@@ -47,6 +47,8 @@ import org.apache.sling.resourceresolver.impl.ResourceResolverMetrics;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.mockito.stubbing.Answer;
@@ -67,6 +69,7 @@ import static org.mockito.Mockito.when;
/**
* Tests related to {@link MapEntries} that are specific to aliases.
*/
+@RunWith(Parameterized.class)
public class AliasMapEntriesTest extends AbstractMappingMapEntriesTest {
private MapEntries mapEntries;
@@ -92,10 +95,19 @@ public class AliasMapEntriesTest extends AbstractMappingMapEntriesTest {
private static final Runnable NOOP = () -> {};
- public AliasMapEntriesTest() {}
-
private AutoCloseable mockCloser;
+ private final boolean isAliasCacheInitInBackground;
+
+ @Parameterized.Parameters(name = "isAliasCacheInitInBackground={0}")
+ public static Collection<Object[]> data() {
+ return List.of(new Object[][] {{false}, {true}});
+ }
+
+ public AliasMapEntriesTest(boolean isAliasCacheInitInBackground) {
+ this.isAliasCacheInitInBackground = isAliasCacheInitInBackground;
+ }
+
@Override
@SuppressWarnings({"unchecked"})
@Before
@@ -107,7 +119,8 @@ public class AliasMapEntriesTest extends AbstractMappingMapEntriesTest {
when(resourceResolverFactory.getServiceResourceResolver(any(Map.class))).thenReturn(resourceResolver);
when(resourceResolverFactory.isVanityPathEnabled()).thenReturn(true);
when(resourceResolverFactory.getVanityPathConfig()).thenReturn(List.of());
- when(resourceResolverFactory.isOptimizeAliasResolutionEnabled()).thenReturn(true);
+ when(resourceResolverFactory.isOptimizeAliasResolutionEnabled()).thenReturn(isAliasCacheInitInBackground);
+ when(resourceResolverFactory.isAliasCacheInitInBackground()).thenReturn(true);
when(resourceResolverFactory.getObservationPaths()).thenReturn(new Path[] {new Path("/")});
when(resourceResolverFactory.getMapRoot()).thenReturn(MapEntries.DEFAULT_MAP_ROOT);
when(resourceResolverFactory.getMaxCachedVanityPathEntries()).thenReturn(-1L);