incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bdelacre...@apache.org
Subject svn commit: r825404 - in /sling/trunk/installer/osgi: installer/src/main/java/org/apache/sling/osgi/installer/impl/ installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/ installer/src/test/java/org/apache/sling/osgi/installer/impl/ it/src...
Date Thu, 15 Oct 2009 06:01:12 GMT
Author: bdelacretaz
Date: Thu Oct 15 06:01:12 2009
New Revision: 825404

URL: http://svn.apache.org/viewvc?rev=825404&view=rev
Log:
SLING-1106 - do not downgrade a bundle that we didn't install

Added:
    sling/trunk/installer/osgi/it/src/test/java/org/apache/sling/osgi/installer/it/ContextBundleUpdateTest.java
  (with props)
Modified:
    sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/BundleTaskCreator.java
    sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/OsgiInstallerContext.java
    sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/OsgiInstallerImpl.java
    sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/BundleInstallTask.java
    sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/BundleUpdateTask.java
    sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/BundleTaskCreatorTest.java
    sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/MockBundleTaskCreator.java
    sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/MockOsgiInstallerContext.java
    sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/PersistentResourceListTest.java
    sling/trunk/installer/osgi/it/src/test/java/org/apache/sling/osgi/installer/it/BundlePrioritiesTest.java
    sling/trunk/installer/osgi/it/src/test/java/org/apache/sling/osgi/installer/it/RemovedResourceDetectionTest.java

Modified: sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/BundleTaskCreator.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/BundleTaskCreator.java?rev=825404&r1=825403&r2=825404&view=diff
==============================================================================
--- sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/BundleTaskCreator.java
(original)
+++ sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/BundleTaskCreator.java
Thu Oct 15 06:01:12 2009
@@ -18,6 +18,7 @@
  */
 package org.apache.sling.osgi.installer.impl;
 
+import java.io.IOException;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.SortedSet;
@@ -42,15 +43,18 @@
     /** Holds the bundle info that we need, makes it easier to test
      *  without an OSGi framework */ 
     static class BundleInfo {
+        final String symbolicName;
         final Version version;
         final int state;
         
-        BundleInfo(Version version, int state) {
+        BundleInfo(String symbolicName, Version version, int state) {
+            this.symbolicName = symbolicName;
             this.version = version;
             this.state = state;
         }
         
         BundleInfo(Bundle b) {
+            this.symbolicName = b.getSymbolicName();
             this.version = new Version((String)b.getHeaders().get(Constants.BUNDLE_VERSION));
             this.state = b.getState();
         }
@@ -61,7 +65,7 @@
 	 *  has desired state == active, and generates the appropriate OSGi tasks to
 	 *  reach this state. 
 	 */
-	public void createTasks(OsgiInstallerContext ctx, SortedSet<RegisteredResource> resources,
SortedSet<OsgiInstallerTask> tasks) {
+	public void createTasks(OsgiInstallerContext ctx, SortedSet<RegisteredResource> resources,
SortedSet<OsgiInstallerTask> tasks) throws IOException {
 		
 		// Find the bundle that must be active: the resources collection is ordered according
 		// to priorities, so we just need to find the first one that is installable
@@ -95,10 +99,27 @@
 				digestToSave = toActivate.getDigest();
 			} else {
 			    final int compare = info.version.compareTo(newVersion); 
-			    if(compare != 0) {
-	                // installed but different version. Can be a later version if 
-			        // the newer version resource was removed, in case we downgrade
-			        toUpdate = toActivate;
+                if(compare < 0) {
+                    // installed version is lower -> update
+                    toUpdate = toActivate;
+                } else if(compare > 0) {
+	                // installed version is higher -> downgrade only if
+                    // we installed that version
+                    final String installedVersion = ctx.getInstalledBundleVersion(info.symbolicName);
+                    if(info.version.toString().equals(installedVersion)) {
+                        toUpdate = toActivate;
+                        if(ctx.getLogService() != null) {
+                            ctx.getLogService().log(LogService.LOG_INFO, 
+                                    "Bundle " + info.symbolicName + " " + installedVersion

+                                    + " was installed by this module, downgrading to " +
newVersion);
+                        }
+                    } else {
+                        if(ctx.getLogService() != null) {
+                            ctx.getLogService().log(LogService.LOG_INFO, 
+                                    "Bundle " + info.symbolicName + " " + installedVersion

+                                    + " was not installed by this module, leaving as is");
+                        }
+                    }
 			    } else if(compare == 0 && ctx.isSnapshot(newVersion)){
 			        // installed, same version but SNAPSHOT
                     toUpdate = toActivate;

Modified: sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/OsgiInstallerContext.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/OsgiInstallerContext.java?rev=825404&r1=825403&r2=825404&view=diff
==============================================================================
--- sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/OsgiInstallerContext.java
(original)
+++ sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/OsgiInstallerContext.java
Thu Oct 15 06:01:12 2009
@@ -46,11 +46,16 @@
 	 */
 	void addTaskToNextCycle(OsgiInstallerTask t);
 	
-	/** Store a bundle's digest, keyed by symbolic ID + version */
-	void saveBundleDigest(Bundle b, String digest) throws IOException;
+	/** Store a bundle's digest and installed version, keyed by symbolic ID */
+	void saveInstalledBundleInfo(Bundle b, String digest, String version) throws IOException;
 	
-	/** Retrieve a bundle's digest that was stored by storeBundleDigest 
+	/** Retrieve a bundle's digest that was stored by saveInstalledBundleInfo  
 	 *  @return null if no digest was stored   
 	 * */
-	String getBundleDigest(Bundle b) throws IOException;
+	String getInstalledBundleDigest(Bundle b) throws IOException;
+	
+    /** Retrieve a bundle's version that was stored by saveInstalledBundleInfo  
+     *  @return null if no version was stored   
+     * */
+    String getInstalledBundleVersion(String symbolicName) throws IOException;
 }

Modified: sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/OsgiInstallerImpl.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/OsgiInstallerImpl.java?rev=825404&r1=825403&r2=825404&view=diff
==============================================================================
--- sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/OsgiInstallerImpl.java
(original)
+++ sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/OsgiInstallerImpl.java
Thu Oct 15 06:01:12 2009
@@ -172,14 +172,21 @@
 		return v.toString().indexOf(MAVEN_SNAPSHOT_MARKER) >= 0;
 	}
 
-    public String getBundleDigest(Bundle b) throws IOException {
+    public String getInstalledBundleDigest(Bundle b) throws IOException {
         if(bundleDigestsStorage == null) {
             return null;
         }
         return bundleDigestsStorage.getDigest(b.getSymbolicName());
     }
 
-    public void saveBundleDigest(Bundle b, String digest) throws IOException {
-        bundleDigestsStorage.putInfo(b.getSymbolicName(), digest, "");
+    public String getInstalledBundleVersion(String symbolicName) throws IOException {
+        if(bundleDigestsStorage == null) {
+            return null;
+        }
+        return bundleDigestsStorage.getInstalledVersion(symbolicName);
+    }
+
+    public void saveInstalledBundleInfo(Bundle b, String digest, String version) throws IOException
{
+        bundleDigestsStorage.putInfo(b.getSymbolicName(), digest, version);
     }
  }
\ No newline at end of file

Modified: sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/BundleInstallTask.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/BundleInstallTask.java?rev=825404&r1=825403&r2=825404&view=diff
==============================================================================
--- sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/BundleInstallTask.java
(original)
+++ sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/BundleInstallTask.java
Thu Oct 15 06:01:12 2009
@@ -23,6 +23,8 @@
 import org.apache.sling.osgi.installer.impl.OsgiInstallerTask;
 import org.apache.sling.osgi.installer.impl.RegisteredResource;
 import org.osgi.framework.Bundle;
+import org.osgi.framework.Constants;
+import org.osgi.framework.Version;
 
 /** Install a bundle supplied as a RegisteredResource.
  *  Creates a BundleStartTask to start the bundle */
@@ -41,7 +43,8 @@
     
     public void execute(OsgiInstallerContext ctx) throws Exception {
         final Bundle b = ctx.getBundleContext().installBundle(resource.getUrl(), resource.getInputStream());
-        ctx.saveBundleDigest(b, resource.getDigest());
+        final Version newVersion = new Version((String)resource.getAttributes().get(Constants.BUNDLE_VERSION));
+        ctx.saveInstalledBundleInfo(b, resource.getDigest(), newVersion.toString());
         logExecution(ctx);
         ctx.addTaskToCurrentCycle(new BundleStartTask(b.getBundleId()));
         ctx.incrementCounter(OsgiInstaller.OSGI_TASKS_COUNTER);

Modified: sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/BundleUpdateTask.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/BundleUpdateTask.java?rev=825404&r1=825403&r2=825404&view=diff
==============================================================================
--- sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/BundleUpdateTask.java
(original)
+++ sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/BundleUpdateTask.java
Thu Oct 15 06:01:12 2009
@@ -58,25 +58,23 @@
         
         // Do not update if same version, unless snapshot
         boolean snapshot = false;
-        if(b != null) {
-        	final Version currentVersion = new Version((String)b.getHeaders().get(Constants.BUNDLE_VERSION));
-        	final Version newVersion = new Version((String)resource.getAttributes().get(Constants.BUNDLE_VERSION));
-        	snapshot = ctx.isSnapshot(newVersion);
-        	if(currentVersion.equals(newVersion) && !snapshot) {
-        		if(ctx.getLogService() != null) {
-            		ctx.getLogService().log(
-            				LogService.LOG_DEBUG, 
-            				"Same version is already installed, and not a snapshot, ignoring update:"
+ resource);
-        		}
-        		return;
-        	}
-        }
+    	final Version currentVersion = new Version((String)b.getHeaders().get(Constants.BUNDLE_VERSION));
+    	final Version newVersion = new Version((String)resource.getAttributes().get(Constants.BUNDLE_VERSION));
+    	snapshot = ctx.isSnapshot(newVersion);
+    	if(currentVersion.equals(newVersion) && !snapshot) {
+    		if(ctx.getLogService() != null) {
+        		ctx.getLogService().log(
+        				LogService.LOG_DEBUG, 
+        				"Same version is already installed, and not a snapshot, ignoring update:" + resource);
+    		}
+    		return;
+    	}
         
         // If snapshot and ready to update, cancel if digest didn't change - as the list
         // of RegisteredResources is not saved, this might not have been detected earlier,
         // if the snapshot was installed and the installer was later restarted
-        if( (b != null) && snapshot) {
-            final String oldDigest = ctx.getBundleDigest(b);
+        if(snapshot) {
+            final String oldDigest = ctx.getInstalledBundleDigest(b);
             if(resource.getDigest().equals(oldDigest)) {
                 if(ctx.getLogService() != null) {
                     ctx.getLogService().log(
@@ -95,7 +93,7 @@
         }
         b.stop();
         b.update(resource.getInputStream());
-        ctx.saveBundleDigest(b, resource.getDigest());
+        ctx.saveInstalledBundleInfo(b, resource.getDigest(), newVersion.toString());
         ctx.addTaskToCurrentCycle(new SynchronousRefreshPackagesTask());
         if(ctx.getLogService() != null) {
             ctx.getLogService().log(LogService.LOG_DEBUG, "Bundle updated: " + b.getBundleId()
+ "/" + b.getSymbolicName());

Modified: sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/BundleTaskCreatorTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/BundleTaskCreatorTest.java?rev=825404&r1=825403&r2=825404&view=diff
==============================================================================
--- sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/BundleTaskCreatorTest.java
(original)
+++ sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/BundleTaskCreatorTest.java
Thu Oct 15 06:01:12 2009
@@ -21,20 +21,27 @@
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
 
+import java.io.IOException;
 import java.util.SortedSet;
 import java.util.TreeSet;
 
 import org.apache.sling.osgi.installer.impl.tasks.BundleInstallTask;
 import org.apache.sling.osgi.installer.impl.tasks.BundleRemoveTask;
 import org.apache.sling.osgi.installer.impl.tasks.BundleUpdateTask;
+import org.junit.Before;
 import org.junit.Test;
 import org.osgi.framework.Bundle;
 
 public class BundleTaskCreatorTest {
 	public static final String SN = "TestSymbolicName";
-	private final OsgiInstallerContext ctx = new MockOsgiInstallerContext();
+	private MockOsgiInstallerContext ctx;
 	
-	private SortedSet<OsgiInstallerTask> getTasks(RegisteredResource [] resources, BundleTaskCreator
btc) {
+	@Before
+	public void setUp() throws IOException {
+	    ctx = new MockOsgiInstallerContext();
+	}
+	
+	private SortedSet<OsgiInstallerTask> getTasks(RegisteredResource [] resources, BundleTaskCreator
btc) throws IOException {
 		final SortedSet<RegisteredResource> s = OsgiInstallerThread.createRegisteredResourcesEntry();
 		for(RegisteredResource r : resources) {
 			s.add(r);
@@ -46,7 +53,7 @@
 	}
 	
 	@Test 
-	public void testSingleBundleNew() {
+	public void testSingleBundleNew() throws IOException {
 		final RegisteredResource [] r = {
 				new MockBundleResource(SN, "1.0")
 		};
@@ -57,7 +64,7 @@
 	}
 
 	@Test
-    public void testSingleBundleAlreadyInstalled() {
+    public void testSingleBundleAlreadyInstalled() throws IOException {
         final RegisteredResource [] r = {
                 new MockBundleResource(SN, "1.0")
         };
@@ -78,7 +85,7 @@
     }
 	
     @Test 
-    public void testBundleUpgrade() {
+    public void testBundleUpgrade() throws IOException {
         final RegisteredResource [] r = {
                 new MockBundleResource(SN, "1.1")
         };
@@ -93,7 +100,7 @@
     }
     
     @Test 
-    public void testBundleUpgradeBothRegistered() {
+    public void testBundleUpgradeBothRegistered() throws IOException {
         final RegisteredResource [] r = {
                 new MockBundleResource(SN, "1.1"),
                 new MockBundleResource(SN, "1.0")
@@ -109,7 +116,7 @@
     }
     
     @Test 
-    public void testBundleUpgradeBothRegisteredReversed() {
+    public void testBundleUpgradeBothRegisteredReversed() throws IOException {
         final RegisteredResource [] r = {
                 new MockBundleResource(SN, "1.0"),
                 new MockBundleResource(SN, "1.1")
@@ -125,7 +132,7 @@
     }
     
     @Test 
-    public void testBundleUpgradeSnapshot() {
+    public void testBundleUpgradeSnapshot() throws IOException {
         // Need to use OSGi-compliant version number, in bundles
         // bnd and other tools generate correct numbers.
         final String v = "2.0.7.SNAPSHOT";
@@ -143,7 +150,7 @@
     }
     
     @Test 
-    public void testBundleRemoveSingle() {
+    public void testBundleRemoveSingle() throws IOException {
         final RegisteredResource [] r = {
                 new MockBundleResource(SN, "1.0")
         };
@@ -159,7 +166,7 @@
     }
     
     @Test 
-    public void testBundleRemoveMultiple() {
+    public void testBundleRemoveMultiple() throws IOException {
         final RegisteredResource [] r = {
                 new MockBundleResource(SN, "1.0"),
                 new MockBundleResource(SN, "1.1"),
@@ -179,10 +186,10 @@
     }
     
     @Test 
-    public void testDowngradeOfRemovedResource() {
+    public void testDowngradeOfRemovedResource() throws IOException {
         final RegisteredResource [] r = {
-                new MockBundleResource(SN, "1.0"),
-                new MockBundleResource(SN, "1.1"),
+                new MockBundleResource(SN, "1.0.0"),
+                new MockBundleResource(SN, "1.1.0"),
         };
         
         // Simulate V1.1 installed but resource is gone -> downgrade to 1.0
@@ -190,7 +197,8 @@
         
        {
             final MockBundleTaskCreator c = new MockBundleTaskCreator();
-            c.addBundleInfo(SN, "1.1", Bundle.ACTIVE);
+            c.addBundleInfo(SN, "1.1.0", Bundle.ACTIVE);
+            ctx.saveInstalledBundleInfo(SN, "fakedigest", "1.1.0");
             final SortedSet<OsgiInstallerTask> s = getTasks(r, c);
             assertEquals("Expected one task", 1, s.size());
             assertTrue("Expected a BundleUpdateTask", s.first() instanceof BundleUpdateTask);
@@ -198,5 +206,4 @@
             assertEquals("Update should be to V1.0", r[0], t.getResource());
         }
     }
-    
 }
\ No newline at end of file

Modified: sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/MockBundleTaskCreator.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/MockBundleTaskCreator.java?rev=825404&r1=825403&r2=825404&view=diff
==============================================================================
--- sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/MockBundleTaskCreator.java
(original)
+++ sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/MockBundleTaskCreator.java
Thu Oct 15 06:01:12 2009
@@ -30,7 +30,7 @@
     private final Map<String, BundleInfo> fakeBundleInfo = new HashMap<String, BundleInfo>();
     
     void addBundleInfo(String symbolicName, String version, int state) {
-        fakeBundleInfo.put(symbolicName, new BundleInfo(new Version(version), state));
+        fakeBundleInfo.put(symbolicName, new BundleInfo(symbolicName, new Version(version),
state));
     }
     
     @Override

Modified: sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/MockOsgiInstallerContext.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/MockOsgiInstallerContext.java?rev=825404&r1=825403&r2=825404&view=diff
==============================================================================
--- sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/MockOsgiInstallerContext.java
(original)
+++ sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/MockOsgiInstallerContext.java
Thu Oct 15 06:01:12 2009
@@ -18,6 +18,7 @@
  */
 package org.apache.sling.osgi.installer.impl;
 
+import java.io.File;
 import java.io.IOException;
 
 import org.osgi.framework.Bundle;
@@ -29,6 +30,14 @@
 
 public class MockOsgiInstallerContext implements OsgiInstallerContext {
 
+    private final PersistentBundleInfo persistentBundleInfo;
+    
+    public MockOsgiInstallerContext() throws IOException {
+        final File f = File.createTempFile(MockOsgiInstallerContext.class.getSimpleName(),
".data");
+        f.deleteOnExit();
+        persistentBundleInfo = new PersistentBundleInfo(this, f);
+    }
+    
 	public void addTaskToCurrentCycle(OsgiInstallerTask t) {
 	}
 
@@ -65,10 +74,19 @@
 		return v.toString().indexOf(OsgiInstallerImpl.MAVEN_SNAPSHOT_MARKER) >= 0;
 	}
 
-    public String getBundleDigest(Bundle b) throws IOException {
-        return null;
+    public String getInstalledBundleDigest(Bundle b) throws IOException {
+        return persistentBundleInfo.getDigest(b.getSymbolicName());
     }
 
-    public void saveBundleDigest(Bundle b, String digest) throws IOException {
+    public String getInstalledBundleVersion(String symbolicName) throws IOException {
+        return persistentBundleInfo.getInstalledVersion(symbolicName);
+    }
+
+    public void saveInstalledBundleInfo(Bundle b, String digest, String version) throws IOException
{
+        saveInstalledBundleInfo(b.getSymbolicName(), digest, version);
+    }
+    
+    public void saveInstalledBundleInfo(String symbolicName, String digest, String version)
throws IOException {
+        persistentBundleInfo.putInfo(symbolicName, digest, version);
     }
 }

Modified: sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/PersistentResourceListTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/PersistentResourceListTest.java?rev=825404&r1=825403&r2=825404&view=diff
==============================================================================
--- sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/PersistentResourceListTest.java
(original)
+++ sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/PersistentResourceListTest.java
Thu Oct 15 06:01:12 2009
@@ -39,7 +39,7 @@
     private final static String FAKE = "fakebundle.";
     
     @Test
-    public void testFileNotFound() {
+    public void testFileNotFound() throws IOException {
         File f = new File("NONEXISTENT");
         PersistentResourceList p = new PersistentResourceList(new MockOsgiInstallerContext(),
f);
         assertNotNull(p.getData());
@@ -61,7 +61,7 @@
     }
     
     @Test
-    public void testTestData() {
+    public void testTestData() throws IOException {
         File f = new File("NONEXISTENT");
         PersistentResourceList p = new PersistentResourceList(new MockOsgiInstallerContext(),
f);
         assertNotNull(p.getData());

Modified: sling/trunk/installer/osgi/it/src/test/java/org/apache/sling/osgi/installer/it/BundlePrioritiesTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/osgi/it/src/test/java/org/apache/sling/osgi/installer/it/BundlePrioritiesTest.java?rev=825404&r1=825403&r2=825404&view=diff
==============================================================================
--- sling/trunk/installer/osgi/it/src/test/java/org/apache/sling/osgi/installer/it/BundlePrioritiesTest.java
(original)
+++ sling/trunk/installer/osgi/it/src/test/java/org/apache/sling/osgi/installer/it/BundlePrioritiesTest.java
Thu Oct 15 06:01:12 2009
@@ -61,8 +61,7 @@
             resetCounters();
             installer.addResource(getInstallableResource(
                     getTestBundle(BUNDLE_BASE_NAME + "-snap.jar"), "digest1"));
-            // wait for two tasks: install and start
-            waitForInstallerAction(OsgiInstaller.OSGI_TASKS_COUNTER, 2);
+            waitForInstallerAction(OsgiInstaller.WORKER_THREAD_BECOMES_IDLE_COUNTER, 1);
             assertBundle("Initial install", symbolicName, null, Bundle.ACTIVE);
         }
 
@@ -76,8 +75,7 @@
             resetCounters();
             installer.addResource(getInstallableResource(
                     getTestBundle(BUNDLE_BASE_NAME + "-snap.jar"), "digest3", highPriority));
-            // wait for two tasks: update and restart
-            waitForInstallerAction(OsgiInstaller.OSGI_TASKS_COUNTER, 2);
+            waitForInstallerAction(OsgiInstaller.WORKER_THREAD_BECOMES_IDLE_COUNTER, 1);
         }
         
         assertNoOsgiTasks("At end of test");

Added: sling/trunk/installer/osgi/it/src/test/java/org/apache/sling/osgi/installer/it/ContextBundleUpdateTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/osgi/it/src/test/java/org/apache/sling/osgi/installer/it/ContextBundleUpdateTest.java?rev=825404&view=auto
==============================================================================
--- sling/trunk/installer/osgi/it/src/test/java/org/apache/sling/osgi/installer/it/ContextBundleUpdateTest.java
(added)
+++ sling/trunk/installer/osgi/it/src/test/java/org/apache/sling/osgi/installer/it/ContextBundleUpdateTest.java
Thu Oct 15 06:01:12 2009
@@ -0,0 +1,84 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sling.osgi.installer.it;
+
+import static org.junit.Assert.assertNull;
+
+import java.io.FileInputStream;
+import java.io.InputStream;
+
+import org.apache.sling.osgi.installer.OsgiInstaller;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.Option;
+import org.ops4j.pax.exam.junit.JUnit4TestRunner;
+import org.osgi.framework.Bundle;
+
+/** Test the second SLING-1106 scenario: if a bundle is updated
+ * 	via the BundleContext, the installer should not downgrade it
+ * 	back to its own version.
+ */
+@RunWith(JUnit4TestRunner.class)
+public class ContextBundleUpdateTest extends OsgiInstallerTestBase {
+    @org.ops4j.pax.exam.junit.Configuration
+    public static Option[] configuration() {
+        return defaultConfiguration();
+    }
+    
+    @Before
+    public void setUp() {
+        setupInstaller();
+    }
+    
+    @After
+    public void tearDown() {
+        super.tearDown();
+    }
+ 
+	@Test
+	public void testContextUpdate() throws Exception {
+		
+		// Install V1.0 via installer
+        final String symbolicName = "osgi-installer-testbundle";
+        assertNull("Test bundle must be absent before installing", findBundle(symbolicName));
+        resetCounters();
+        installer.addResource(getInstallableResource(
+                getTestBundle(BUNDLE_BASE_NAME + "-testbundle-1.0.jar"), "digest0"));
+        waitForInstallerAction(OsgiInstaller.WORKER_THREAD_BECOMES_IDLE_COUNTER, 1);
+        final Bundle b = assertBundle("After initial install", symbolicName, "1.0", Bundle.ACTIVE);
+        
+        // Update to 1.1, directly via bundle context
+        final InputStream is = new FileInputStream(getTestBundle(BUNDLE_BASE_NAME + "-testbundle-1.1.jar"));
+        try {
+        	b.update(is);
+        } finally {
+        	is.close();
+        }
+        assertBundle("After direct update", symbolicName, "1.1", Bundle.ACTIVE);
+        
+        // Install another bundle (to trigger installer queue activity), wait
+        // for installer to be idle and check version
+        resetCounters();
+        installer.addResource(getInstallableResource(
+                getTestBundle(BUNDLE_BASE_NAME + "-snap.jar"), "digest1"));
+        waitForInstallerAction(OsgiInstaller.WORKER_THREAD_BECOMES_IDLE_COUNTER, 1);
+        assertBundle("-snap bundle install", "osgi-installer-snapshot-test", null, Bundle.ACTIVE);
+        assertBundle("After installing another bundle", symbolicName, "1.1", Bundle.ACTIVE);
+	}
+}

Propchange: sling/trunk/installer/osgi/it/src/test/java/org/apache/sling/osgi/installer/it/ContextBundleUpdateTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sling/trunk/installer/osgi/it/src/test/java/org/apache/sling/osgi/installer/it/ContextBundleUpdateTest.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Modified: sling/trunk/installer/osgi/it/src/test/java/org/apache/sling/osgi/installer/it/RemovedResourceDetectionTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/osgi/it/src/test/java/org/apache/sling/osgi/installer/it/RemovedResourceDetectionTest.java?rev=825404&r1=825403&r2=825404&view=diff
==============================================================================
--- sling/trunk/installer/osgi/it/src/test/java/org/apache/sling/osgi/installer/it/RemovedResourceDetectionTest.java
(original)
+++ sling/trunk/installer/osgi/it/src/test/java/org/apache/sling/osgi/installer/it/RemovedResourceDetectionTest.java
Thu Oct 15 06:01:12 2009
@@ -79,6 +79,7 @@
         final List<InstallableResource> data = new ArrayList<InstallableResource>();
         data.add(getInstallableResource(getTestBundle(BUNDLE_BASE_NAME + "-testB-1.0.jar")));
         installer.registerResources(data, URL_SCHEME);
+        sleep(500);
         waitForInstallerAction(OsgiInstaller.WORKER_THREAD_BECOMES_IDLE_COUNTER, 1);
         assertBundle("After installer restart", symbolicNameB, "1.0", Bundle.ACTIVE);
         assertNull("Bundle not in second list should be removed", findBundle(symbolicNameA));



Mime
View raw message