sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From asa...@apache.org
Subject svn commit: r1615925 - in /sling/trunk/bundles/resourceresolver/src: main/java/org/apache/sling/resourceresolver/impl/mapping/MapEntries.java test/java/org/apache/sling/resourceresolver/impl/mapping/MapEntriesTest.java
Date Tue, 05 Aug 2014 13:13:43 GMT
Author: asanso
Date: Tue Aug  5 13:13:42 2014
New Revision: 1615925

URL: http://svn.apache.org/r1615925
Log:
SLING-3290 - Long startup time with many vanityPath

* split a method in two in order to improve extensibility  (no functional changes)

Modified:
    sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/mapping/MapEntries.java
    sling/trunk/bundles/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/mapping/MapEntriesTest.java

Modified: sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/mapping/MapEntries.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/mapping/MapEntries.java?rev=1615925&r1=1615924&r2=1615925&view=diff
==============================================================================
--- sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/mapping/MapEntries.java
(original)
+++ sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/mapping/MapEntries.java
Tue Aug  5 13:13:42 2014
@@ -660,6 +660,36 @@ public class MapEntries implements Event
     }
 
     // ---------- internal
+    
+    private boolean isValidVanityPath(Resource resource){
+        // ignore system tree
+        if (resource.getPath().startsWith(JCR_SYSTEM_PREFIX)) {
+            log.debug("isValidVanityPath: not valid {}", resource);
+            return false;
+        }
+
+        // check white list
+        if ( this.vanityPathConfig != null ) {
+            boolean allowed = false;
+            for(final VanityPathConfig config : this.vanityPathConfig) {
+                if ( resource.getPath().startsWith(config.prefix) ) {
+                    allowed = !config.isExclude;
+                    break;
+                }
+            }
+            if ( !allowed ) {
+                log.debug("isValidVanityPath: not valid as not in white list {}", resource);
+                return false;
+            }
+        }
+        // require properties
+        final ValueMap props = resource.adaptTo(ValueMap.class);
+        if (props == null) {
+            log.debug("isValidVanityPath: not valid {} without properties", resource);
+            return false;
+        }
+        return true;
+    }
 
     private String getActualContentPath(String path){
         final String checkPath;
@@ -878,33 +908,12 @@ public class MapEntries implements Event
      * Load vanity path given a resource
      */
     private void loadVanityPath(final Resource resource, final Map<String, List<MapEntry>>
entryMap, final Map <String, List<String>> targetPaths) {
-        // ignore system tree
-        if (resource.getPath().startsWith(JCR_SYSTEM_PREFIX)) {
-            log.debug("loadVanityPaths: Ignoring {}", resource);
+        
+        if (!isValidVanityPath(resource)) {            
             return;
         }
-
-        // check white list
-        if ( this.vanityPathConfig != null ) {
-            boolean allowed = false;
-            for(final VanityPathConfig config : this.vanityPathConfig) {
-                if ( resource.getPath().startsWith(config.prefix) ) {
-                    allowed = !config.isExclude;
-                    break;
-                }
-            }
-            if ( !allowed ) {
-                log.debug("loadVanityPaths: Ignoring as not in white list {}", resource);
-                return;
-            }
-        }
-        // require properties
+        
         final ValueMap props = resource.adaptTo(ValueMap.class);
-        if (props == null) {
-            log.debug("loadVanityPaths: Ignoring {} without properties", resource);
-            return;
-        }
-
         long vanityOrder = 0;
         if (props.containsKey(PROP_VANITY_ORDER)) {
             vanityOrder = props.get(PROP_VANITY_ORDER, Long.class);

Modified: sling/trunk/bundles/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/mapping/MapEntriesTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/mapping/MapEntriesTest.java?rev=1615925&r1=1615924&r2=1615925&view=diff
==============================================================================
--- sling/trunk/bundles/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/mapping/MapEntriesTest.java
(original)
+++ sling/trunk/bundles/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/mapping/MapEntriesTest.java
Tue Aug  5 13:13:42 2014
@@ -27,6 +27,7 @@ import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
 import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -1128,4 +1129,21 @@ public class MapEntriesTest {
         aliasMapEntry = mapEntries.getAliasMap("/parent");
         assertNull(aliasMapEntry);
     }
+    
+    @Test
+    public void test_isValidVanityPath() throws Exception {
+        Method method = MapEntries.class.getDeclaredMethod("isValidVanityPath", Resource.class);
+        method.setAccessible(true);
+        
+        final Resource resource = mock(Resource.class);
+        when(resource.getPath()).thenReturn("/jcr:system/node");
+        
+        assertFalse((Boolean)method.invoke(mapEntries, resource));
+        
+        when(resource.getPath()).thenReturn("/justVanityPath");
+        assertFalse((Boolean)method.invoke(mapEntries, resource));
+        
+        when(resource.adaptTo(ValueMap.class)).thenReturn(mock(ValueMap.class));
+        assertTrue((Boolean)method.invoke(mapEntries, resource));
+    }
 }



Mime
View raw message