Author: bdelacretaz
Date: Fri Aug 28 08:14:36 2009
New Revision: 808807

URL: http://svn.apache.org/viewvc?rev=808807&view=rev
Log:
SLING-1078 - config with same digest as previously uninstalled one was not 
reinstalled

Modified:
    
sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/ConfigTaskCreator.java
    
sling/trunk/installer/osgi/it/src/test/java/org/apache/sling/osgi/installer/it/BundleInstallUpgradeDowngradeTest.java
    
sling/trunk/installer/osgi/it/src/test/java/org/apache/sling/osgi/installer/it/ConfigInstallTest.java

Modified: 
sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/ConfigTaskCreator.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/ConfigTaskCreator.java?rev=808807&r1=808806&r2=808807&view=diff
==============================================================================
--- 
sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/ConfigTaskCreator.java
 (original)
+++ 
sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/ConfigTaskCreator.java
 Fri Aug 28 08:14:36 2009
@@ -49,22 +49,19 @@
                if(toActivate == null) {
                    // None of our resources are installable, remove 
corresponding config
                    // (task simply does nothing if config does not exist)
-                   tasks.add(new ConfigRemoveTask(resources.first()));
+                   final RegisteredResource first = resources.first();
+                   tasks.add(new ConfigRemoveTask(first));
+                   digests.remove(getDigestKey(first));
                } else {
-                   final ConfigurationPid cp = 
(ConfigurationPid)toActivate.getAttributes().get(RegisteredResource.CONFIG_PID_ATTRIBUTE);
-                   if(cp == null) {
-                       throw new IllegalArgumentException("Resource does not 
provide a CONFIG_PID_ATTRIBUTE: " + toActivate);
-                   }
-                   final String pid = cp.getCompositePid();
-                   
-                   final String previousDigest = digests.get(pid);
+                   final String key = getDigestKey(toActivate);
+                   final String previousDigest = digests.get(key);
                    if(toActivate.getDigest().equals(previousDigest)) {
                        if(ctx.getLogService() != null) {
-                           ctx.getLogService().log(LogService.LOG_DEBUG, 
"Configuration (" + pid + ") already installed, ignored: " + toActivate); 
+                           ctx.getLogService().log(LogService.LOG_DEBUG, 
"Configuration (" + key+ ") already installed, ignored: " + toActivate); 
                        }
                    } else {
                        tasks.add(new ConfigInstallTask(toActivate));
-                       digests.put(pid, toActivate.getDigest());
+                       digests.put(key, toActivate.getDigest());
                 if(ctx.getLogService() != null) {
                     ctx.getLogService().log(LogService.LOG_DEBUG, 
                             "Scheduling update/install of config " + 
toActivate + ", digest has changed or was absent");
@@ -72,4 +69,12 @@
                    }
                }
        }
+       
+       private String getDigestKey(RegisteredResource r) {
+        final ConfigurationPid cp = 
(ConfigurationPid)r.getAttributes().get(RegisteredResource.CONFIG_PID_ATTRIBUTE);
+        if(cp == null) {
+            throw new IllegalArgumentException("Resource does not provide a 
CONFIG_PID_ATTRIBUTE: " + r);
+        }
+        return cp.getCompositePid();
+       }
 }

Modified: 
sling/trunk/installer/osgi/it/src/test/java/org/apache/sling/osgi/installer/it/BundleInstallUpgradeDowngradeTest.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/installer/osgi/it/src/test/java/org/apache/sling/osgi/installer/it/BundleInstallUpgradeDowngradeTest.java?rev=808807&r1=808806&r2=808807&view=diff
==============================================================================
--- 
sling/trunk/installer/osgi/it/src/test/java/org/apache/sling/osgi/installer/it/BundleInstallUpgradeDowngradeTest.java
 (original)
+++ 
sling/trunk/installer/osgi/it/src/test/java/org/apache/sling/osgi/installer/it/BundleInstallUpgradeDowngradeTest.java
 Fri Aug 28 08:14:36 2009
@@ -135,4 +135,41 @@
 
         assertNoOsgiTasks("After test " + testIndex++);
        }
+       
+          @Test
+           public void testRemoveAndReadd() throws Exception {
+               final String symbolicName = "osgi-installer-testbundle";
+               int testIndex = 0;
+               
+               {
+                   assertNull("Test bundle must be absent before installing", 
findBundle(symbolicName));
+                   resetCounters();
+                   installer.addResource(getInstallableResource(
+                           getTestBundle(BUNDLE_BASE_NAME + 
"-testbundle-1.1.jar")));
+                   
waitForInstallerAction(OsgiInstaller.WORKER_THREAD_BECOMES_IDLE_COUNTER, 1);
+                   assertBundle("After installing", symbolicName, "1.1", 
Bundle.ACTIVE);
+               }
+               
+               assertNoOsgiTasks("After test " + testIndex++);
+               
+            {
+                resetCounters();
+                installer.removeResource(getNonInstallableResource(
+                        getTestBundle(BUNDLE_BASE_NAME + 
"-testbundle-1.1.jar")));
+                
waitForInstallerAction(OsgiInstaller.WORKER_THREAD_BECOMES_IDLE_COUNTER, 1);
+                assertNull("Test bundle must be gone", 
findBundle(symbolicName));
+            }
+            
+            assertNoOsgiTasks("After test " + testIndex++);
+            
+            {
+                resetCounters();
+                installer.addResource(getInstallableResource(
+                        getTestBundle(BUNDLE_BASE_NAME + 
"-testbundle-1.1.jar")));
+                
waitForInstallerAction(OsgiInstaller.WORKER_THREAD_BECOMES_IDLE_COUNTER, 1);
+                assertBundle("After reinstalling", symbolicName, "1.1", 
Bundle.ACTIVE);
+            }
+            
+            assertNoOsgiTasks("After test " + testIndex++);
+          }
 }
\ No newline at end of file

Modified: 
sling/trunk/installer/osgi/it/src/test/java/org/apache/sling/osgi/installer/it/ConfigInstallTest.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/installer/osgi/it/src/test/java/org/apache/sling/osgi/installer/it/ConfigInstallTest.java?rev=808807&r1=808806&r2=808807&view=diff
==============================================================================
--- 
sling/trunk/installer/osgi/it/src/test/java/org/apache/sling/osgi/installer/it/ConfigInstallTest.java
 (original)
+++ 
sling/trunk/installer/osgi/it/src/test/java/org/apache/sling/osgi/installer/it/ConfigInstallTest.java
 Fri Aug 28 08:14:36 2009
@@ -68,16 +68,26 @@
         installer.addResource(r);
         
waitForInstallerAction(OsgiInstaller.WORKER_THREAD_BECOMES_IDLE_COUNTER, 1);
         
-        final Configuration cfg = waitForConfiguration("After installing", 
cfgPid, TIMEOUT, true);
-        assertNotNull("Config " + cfgPid + " must be found after installing", 
cfg);
-        final String value = (String)cfg.getProperties().get("foo");
-        assertEquals("Config value must match", "bar", value);
+        Configuration cfg = waitForConfiguration("After installing", cfgPid, 
TIMEOUT, true);
+        assertEquals("Config value must match", "bar", 
(String)cfg.getProperties().get("foo"));
         
         resetCounters();
         installer.removeResource(new InstallableResource(r.getUrl()));
         
waitForInstallerAction(OsgiInstaller.WORKER_THREAD_BECOMES_IDLE_COUNTER, 1);
-        
         waitForConfiguration("After removing", cfgPid, TIMEOUT, false);
+        
+        // Reinstalling with same digest must work
+        resetCounters();
+        installer.addResource(r);
+        
waitForInstallerAction(OsgiInstaller.WORKER_THREAD_BECOMES_IDLE_COUNTER, 1);
+        cfg = waitForConfiguration("After reinstalling", cfgPid, TIMEOUT, 
true);
+        assertEquals("Config value must match", "bar", 
(String)cfg.getProperties().get("foo"));
+        
+        resetCounters();
+        installer.removeResource(new InstallableResource(r.getUrl()));
+        
waitForInstallerAction(OsgiInstaller.WORKER_THREAD_BECOMES_IDLE_COUNTER, 1);
+        waitForConfiguration("After removing for the second time", cfgPid, 
TIMEOUT, false);
+        
     }
     
     @Test


Reply via email to