You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by bd...@apache.org on 2009/08/24 16:40:07 UTC

svn commit: r807247 - in /sling/trunk/installer/osgi: installer/src/main/java/org/apache/sling/osgi/installer/impl/OsgiInstallerThread.java it/src/test/java/org/apache/sling/osgi/installer/it/RegisterResourcesTest.java

Author: bdelacretaz
Date: Mon Aug 24 14:40:07 2009
New Revision: 807247

URL: http://svn.apache.org/viewvc?rev=807247&view=rev
Log:
SLING-1078 - fix handling of registerResources with empty collection of resources

Modified:
    sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/OsgiInstallerThread.java
    sling/trunk/installer/osgi/it/src/test/java/org/apache/sling/osgi/installer/it/RegisterResourcesTest.java

Modified: sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/OsgiInstallerThread.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/OsgiInstallerThread.java?rev=807247&r1=807246&r2=807247&view=diff
==============================================================================
--- sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/OsgiInstallerThread.java (original)
+++ sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/OsgiInstallerThread.java Mon Aug 24 14:40:07 2009
@@ -22,9 +22,11 @@
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 import java.util.SortedSet;
 import java.util.TreeSet;
 
@@ -52,6 +54,7 @@
     private final SortedSet<OsgiInstallerTask> tasks = new TreeSet<OsgiInstallerTask>();
     private final SortedSet<OsgiInstallerTask> tasksForNextCycle = new TreeSet<OsgiInstallerTask>();
     private final List<SortedSet<RegisteredResource>> newResourcesSets = new ArrayList<SortedSet<RegisteredResource>>();
+    private final Set<String> newResourcesSchemes = new HashSet<String>(); 
     private boolean active = true;
     
     /** Group our RegisteredResource by OSGi entity */ 
@@ -158,11 +161,14 @@
             toAdd.add(rr);
         }
         
-        if(!toAdd.isEmpty()) {
-            synchronized (newResources) {
-                newResourcesSets.add(toAdd);
-                newResources.notify();
+        synchronized (newResources) {
+            if(!toAdd.isEmpty()) {
+            	newResourcesSets.add(toAdd);
             }
+            // Need to manage schemes separately: in case toAdd is empty we
+            // want to mark all such resources as non-installable
+            newResourcesSchemes.add(urlScheme);
+            newResources.notify();
         }
     }
     
@@ -172,8 +178,7 @@
             // of available resources for a given scheme. So, before adding them mark
             // all resources with the same scheme in newResources, and existing
             // registeredResources, as not installable
-            for(SortedSet<RegisteredResource> s : newResourcesSets) {
-                final String scheme = s.first().getUrlScheme();
+        	for(String scheme : newResourcesSchemes) {
                 debug("Processing set of new resources with scheme " + scheme);
                 for(RegisteredResource r : newResources) {
                     if(r.getUrlScheme().equals(scheme)) {
@@ -189,10 +194,13 @@
                         }
                     }
                 }
+        	}
+            for(SortedSet<RegisteredResource> s : newResourcesSets) {
                 newResources.addAll(s);
-                debug("Added set of " + s.size() + " new resources with scheme " + scheme);
+                debug("Added set of " + s.size() + " new resources with scheme " + s.first().getUrlScheme());
             }
             newResourcesSets.clear();
+            newResourcesSchemes.clear();
             
             for(RegisteredResource r : newResources) {
                 SortedSet<RegisteredResource> t = registeredResources.get(r.getEntityId());

Modified: sling/trunk/installer/osgi/it/src/test/java/org/apache/sling/osgi/installer/it/RegisterResourcesTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/osgi/it/src/test/java/org/apache/sling/osgi/installer/it/RegisterResourcesTest.java?rev=807247&r1=807246&r2=807247&view=diff
==============================================================================
--- sling/trunk/installer/osgi/it/src/test/java/org/apache/sling/osgi/installer/it/RegisterResourcesTest.java (original)
+++ sling/trunk/installer/osgi/it/src/test/java/org/apache/sling/osgi/installer/it/RegisterResourcesTest.java Mon Aug 24 14:40:07 2009
@@ -16,9 +16,13 @@
  */
 package org.apache.sling.osgi.installer.it;
 
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
+
 import java.io.FileInputStream;
 import java.io.IOException;
 import java.util.ArrayList;
+import java.util.LinkedList;
 import java.util.List;
 
 import org.apache.sling.osgi.installer.InstallableResource;
@@ -32,9 +36,6 @@
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleException;
 
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertFalse;
-
 @RunWith(JUnit4TestRunner.class)
 /** Test the {@link OsgiInstaller.registerResources} method, which lets a client
  *  supply a new list of resources.
@@ -156,4 +157,33 @@
             assertBundle("testA bundle should still be present", "osgi-installer-testA", "1.0", Bundle.ACTIVE);
         }
     }
+    
+    @Test
+    public void reAddZeroResourcesTest() throws IOException {
+        {
+            resetCounters();
+            final List<InstallableResource> r = new ArrayList<InstallableResource>();
+            r.add(getInstallableResource(getTestBundle(BUNDLE_BASE_NAME + "-testB-1.0.jar")));
+            r.add(getInstallableResource(getTestBundle(BUNDLE_BASE_NAME + "-needsB.jar")));
+            r.add(getInstallableResource(getTestBundle(BUNDLE_BASE_NAME + "-testbundle-1.0.jar")));
+            r.add(getInstallableResource(getTestBundle(BUNDLE_BASE_NAME + "-testbundle-1.1.jar")));
+            
+            installer.registerResources(r, URL_SCHEME);
+            waitForInstallerAction(OsgiInstaller.WORKER_THREAD_BECOMES_IDLE_COUNTER, 1);
+            
+            final String info = "After initial registration";
+            assertBundle(info, "osgi-installer-testB", "1.0", Bundle.ACTIVE);
+            assertBundle(info, "osgi-installer-needsB", "1.0", Bundle.ACTIVE);
+            assertBundle(info, "osgi-installer-testbundle", "1.1", Bundle.ACTIVE);
+        }
+        
+        {
+        	resetCounters();
+        	installer.registerResources(new LinkedList<InstallableResource>(), URL_SCHEME);
+            waitForInstallerAction(OsgiInstaller.WORKER_THREAD_BECOMES_IDLE_COUNTER, 1);
+            assertNull("After registration with no resources, testB bundle must be gone", findBundle("osgi-installer-testB"));
+            assertNull("After registration with no resources, testB bundle must be gone", findBundle("osgi-installer-needsB"));
+            assertNull("After registration with no resources, testB bundle must be gone", findBundle("osgi-installer-testbundle"));
+        }
+    }
 }