Return-Path: X-Original-To: apmail-sling-commits-archive@www.apache.org Delivered-To: apmail-sling-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id B9498DA61 for ; Wed, 31 Oct 2012 15:40:52 +0000 (UTC) Received: (qmail 11368 invoked by uid 500); 31 Oct 2012 15:40:52 -0000 Delivered-To: apmail-sling-commits-archive@sling.apache.org Received: (qmail 11280 invoked by uid 500); 31 Oct 2012 15:40:50 -0000 Mailing-List: contact commits-help@sling.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@sling.apache.org Delivered-To: mailing list commits@sling.apache.org Received: (qmail 11225 invoked by uid 99); 31 Oct 2012 15:40:49 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 31 Oct 2012 15:40:48 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 31 Oct 2012 15:40:47 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 74B5423889C5; Wed, 31 Oct 2012 15:40:04 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1404209 - in /sling/trunk/bundles/resourceresolver/src: main/java/org/apache/sling/resourceresolver/impl/tree/ResourceProviderEntry.java test/java/org/apache/sling/resourceresolver/impl/tree/ResourceProviderEntryTest.java Date: Wed, 31 Oct 2012 15:40:04 -0000 To: commits@sling.apache.org From: bdelacretaz@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20121031154004.74B5423889C5@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: bdelacretaz Date: Wed Oct 31 15:40:03 2012 New Revision: 1404209 URL: http://svn.apache.org/viewvc?rev=1404209&view=rev Log: SLING-2640 - ResourceProviderEntry did not correctly remove a root provider Modified: sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/tree/ResourceProviderEntry.java sling/trunk/bundles/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/tree/ResourceProviderEntryTest.java Modified: sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/tree/ResourceProviderEntry.java URL: http://svn.apache.org/viewvc/sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/tree/ResourceProviderEntry.java?rev=1404209&r1=1404208&r2=1404209&view=diff ============================================================================== --- sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/tree/ResourceProviderEntry.java (original) +++ sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/tree/ResourceProviderEntry.java Wed Oct 31 15:40:03 2012 @@ -215,15 +215,25 @@ public class ResourceProviderEntry imple * Remove the given resource provider from the tree */ protected synchronized boolean removeResourceProvider(final String prefix, final ProviderHandler resourceProvider) { + boolean result = false; final String[] elements = split(prefix); final List entries = new ArrayList(); this.populateProviderPath(entries, elements); - if (entries.size() > 0 && entries.size() == elements.length) { + if(entries.size() == 0) { + // might be a root provider, try to remove it on this entry + result = this.removeInternalProvider(resourceProvider); + } else if (entries.size() > 0 && entries.size() == elements.length) { // the last element is a perfect match; - return entries.get(entries.size() - 1).removeInternalProvider(resourceProvider); + result = entries.get(entries.size() - 1).removeInternalProvider(resourceProvider); } - return false; + + if(!result) { + // bad news - the provider might be an OSGi service being deactivated, + // so this should be taken care of. + LOGGER.warn("Unable to remove {} for prefix {}, no matching entry found", resourceProvider, prefix); + } + return result; } /** Modified: sling/trunk/bundles/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/tree/ResourceProviderEntryTest.java URL: http://svn.apache.org/viewvc/sling/trunk/bundles/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/tree/ResourceProviderEntryTest.java?rev=1404209&r1=1404208&r2=1404209&view=diff ============================================================================== --- sling/trunk/bundles/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/tree/ResourceProviderEntryTest.java (original) +++ sling/trunk/bundles/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/tree/ResourceProviderEntryTest.java Wed Oct 31 15:40:03 2012 @@ -18,6 +18,7 @@ */ package org.apache.sling.resourceresolver.impl.tree; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNull; import static org.junit.Assert.fail; @@ -34,6 +35,7 @@ import org.apache.sling.api.resource.Res import org.apache.sling.api.resource.ResourceMetadata; import org.apache.sling.api.resource.ResourceProvider; import org.apache.sling.api.resource.ResourceResolver; +import org.apache.sling.api.resource.SyntheticResource; import org.junit.Before; import org.junit.Test; import org.osgi.framework.Constants; @@ -179,6 +181,37 @@ public class ResourceProviderEntryTest { assertEquals(first, root.getResource(null, null, "/rootel/html.js")); assertEquals(second, root.getResource(null, null, "/rootel/child/html.js")); } + + @Test public void testRemoveTheOnlyProvider() { + final ResourceProviderEntry e = new ResourceProviderEntry("/", null); + long counter = 1; + + for(String path : new String[] { "/foo", "/", "/foo/bar" }) { + final ResourceProvider p = new TestResourceProvider(path); + final Map props = new HashMap(); + props.put(Constants.SERVICE_ID, ++counter); + + e.addResourceProvider(path, new ResourceProviderHandler(p, props)); + { + final Resource r = e.getResource(null, null, path); + assertEquals(p, r); + assertFalse(r instanceof SyntheticResource); + } + + e.removeResourceProvider(path, new ResourceProviderHandler(p, props)); + { + final Resource r = e.getResource(null, null, path); + // If our provider is indeed gone, we should get one of the following conditions + if(r == null) { + //fine + } else if(!p.equals(r.getResourceResolver())) { + //fine + } else { + fail("Expecting inactive provider after removing it for " + path); + } + } + } + } protected void assertEquals(ResourceProvider resProvider, Resource res) { org.junit.Assert.assertEquals(resProvider, res.getResourceResolver());