incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bdelacre...@apache.org
Subject svn commit: r806097 - 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, 20 Aug 2009 09:31:56 GMT
Author: bdelacretaz
Date: Thu Aug 20 09:31:54 2009
New Revision: 806097

URL: http://svn.apache.org/viewvc?rev=806097&view=rev
Log:
SLING-1078 - keep track of bundle digests to avoid unnecessary updates, and test snapshot
updates

Added:
    sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/MockOsgiInstallerContext.java
      - copied, changed from r805815, sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/MockOsgiControllerContext.java
Removed:
    sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/MockOsgiControllerContext.java
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/OsgiInstallerThread.java
    sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/RegisteredResourceImpl.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/BundleRemoveTask.java
    sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/BundleStartTask.java
    sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/BundleUpdateTask.java
    sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/SynchronousRefreshPackagesTask.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/MockBundleResource.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/StorageTest.java
    sling/trunk/installer/osgi/it/src/test/java/org/apache/sling/osgi/installer/it/BundleSnapshotUpdateTest.java
    sling/trunk/installer/osgi/it/src/test/java/org/apache/sling/osgi/installer/it/OsgiInstallerTestBase.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=806097&r1=806096&r2=806097&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 Aug 20 09:31:54 2009
@@ -18,6 +18,8 @@
  */
 package org.apache.sling.osgi.installer.impl;
 
+import java.util.HashMap;
+import java.util.Map;
 import java.util.SortedSet;
 
 import org.apache.sling.osgi.installer.impl.tasks.BundleInstallTask;
@@ -25,15 +27,21 @@
 import org.apache.sling.osgi.installer.impl.tasks.BundleUpdateTask;
 import org.apache.sling.osgi.installer.impl.tasks.TaskUtilities;
 import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleContext;
 import org.osgi.framework.Constants;
 import org.osgi.framework.Version;
+import org.osgi.service.log.LogService;
 
 /** TaskCreator that processes a list of bundle RegisteredResources */
 class BundleTaskCreator implements OsgiInstallerThread.TaskCreator {
 
     public static final String MAVEN_SNAPSHOT_MARKER = "SNAPSHOT";
     
+    /** Store the digests of the bundles for which we create update tasks,
+     *  keyed by symbolic name, to avoid generating repated updates
+     *  for snapshot bundles
+     */
+    private final Map<String, String> digests = new HashMap<String, String>();
+    
     /** Holds the bundle info that we need, makes it easier to test
      *  without an OSGi framework */ 
     static class BundleInfo {
@@ -56,7 +64,7 @@
 	 *  has desired state == active, and generates the appropriate OSGi tasks to
 	 *  reach this state. 
 	 */
-	public void createTasks(BundleContext ctx, SortedSet<RegisteredResource> resources,
SortedSet<OsgiInstallerTask> tasks) {
+	public void createTasks(OsgiInstallerContext ctx, SortedSet<RegisteredResource> resources,
SortedSet<OsgiInstallerTask> tasks) {
 		
 		// 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
@@ -68,10 +76,15 @@
 			}
 		}
 
+		RegisteredResource toUpdate = null;
+		String digestToSave = null;
+		final RegisteredResource firstResource = resources.first(); 
+		final String symbolicName = firstResource == null ? null : 
+		    (String)firstResource.getAttributes().get(Constants.BUNDLE_SYMBOLICNAME);
+		
 		if(toActivate == null) {
-		    // None of our resources are installable, remove corresponding bundle
-		    final BundleInfo info = getBundleInfo(ctx, resources.first());
-		    if(info != null) {
+		    // None of our resources are installable, remove corresponding bundle if present
+		    if(getBundleInfo(ctx, resources.first()) != null) {
 	            tasks.add(new BundleRemoveTask(resources.first()));
 	        }
 			
@@ -79,26 +92,55 @@
 			final BundleInfo info = getBundleInfo(ctx, toActivate);
 			final Version newVersion = (Version)toActivate.getAttributes().get(Constants.BUNDLE_VERSION);
 			if(info == null) {
-			    // bundle is not installed yet
+			    // bundle is not installed yet: install and save digest to avoid
+			    // unnecessary updates
 				tasks.add(new BundleInstallTask(toActivate));
+				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
-	                tasks.add(new BundleUpdateTask(toActivate));
+			        toUpdate = toActivate;
 			    } else if(compare == 0 && newVersion.toString().indexOf(MAVEN_SNAPSHOT_MARKER)
>= 0){
 			        // installed, same version but SNAPSHOT
-			        // TODO: update only if not updated with same digest yet
-			        tasks.add(new BundleUpdateTask(toActivate));
+                    toUpdate = toActivate;
+			    }
+			}
+
+			// Save the digest of installed and updated resources, keyed by
+			// bundle symbolic name, to avoid unnecessary updates
+			if(toUpdate != null) {
+			    final String previousDigest = digests.get(symbolicName);
+			    if(toUpdate.getDigest().equals(previousDigest)) {
+			        if(ctx.getLogService() != null) {
+			            ctx.getLogService().log(LogService.LOG_DEBUG, 
+			                    "Ignoring update of " + toUpdate + ", digest didn't change");
+			        }
+                    digestToSave = previousDigest;
+			    } else {
+                    if(ctx.getLogService() != null) {
+                        ctx.getLogService().log(LogService.LOG_DEBUG, 
+                                "Scheduling update of " + toUpdate + ", digest has changed");
+                    }
+			        tasks.add(new BundleUpdateTask(toUpdate));
+			        digestToSave = toUpdate.getDigest();
 			    }
 			}
+			
+			if(digestToSave == null) {
+			    if(symbolicName != null) {
+			        digests.remove(symbolicName);
+			    }
+			} else {
+			    digests.put(symbolicName, digestToSave);
+			}
 		}
 	}
 
-	protected BundleInfo getBundleInfo(BundleContext ctx, RegisteredResource bundle) {
+	protected BundleInfo getBundleInfo(OsgiInstallerContext ctx, RegisteredResource bundle)
{
 		final String symbolicName = (String)bundle.getAttributes().get(Constants.BUNDLE_SYMBOLICNAME);
-		final Bundle b = TaskUtilities.getMatchingBundle(ctx, symbolicName);
+		final Bundle b = TaskUtilities.getMatchingBundle(ctx.getBundleContext(), symbolicName);
 		if(b == null) {
 		    return null;
         }

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=806097&r1=806096&r2=806097&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
Thu Aug 20 09:31:54 2009
@@ -26,7 +26,6 @@
 import java.util.SortedSet;
 import java.util.TreeSet;
 
-import org.osgi.framework.BundleContext;
 import org.osgi.service.log.LogService;
 
 /** Worker thread where all OSGi tasks are executed.
@@ -57,7 +56,7 @@
     	 * 	@param resources ordered set of RegisteredResource which all have the same entityId
     	 * 	@param tasks lists of tasks, to which we'll add the ones computed by this method
     	 */
-    	void createTasks(BundleContext ctx, SortedSet<RegisteredResource> resources, SortedSet<OsgiInstallerTask>
tasks);
+    	void createTasks(OsgiInstallerContext ctx, SortedSet<RegisteredResource> resources,
SortedSet<OsgiInstallerTask> tasks);
     }
     
     OsgiInstallerThread(OsgiInstallerContext ctx) {
@@ -152,9 +151,11 @@
         }
         
         // Walk the list of entities, and create appropriate OSGi tasks for each group
+        // TODO do nothing for a group that's "stable" - i.e. one where no tasks were
+        // created in the last cycle??
         for(SortedSet<RegisteredResource> group : registeredResources.values()) {
             if(group.first().getResourceType().equals(RegisteredResource.ResourceType.BUNDLE))
{
-                bundleTaskCreator.createTasks(ctx.getBundleContext(), group, tasks);
+                bundleTaskCreator.createTasks(ctx, group, tasks);
             } else {
                 throw new IllegalArgumentException("No TaskCreator for resource type "+ group.first().getResourceType());
             } 

Modified: sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/RegisteredResourceImpl.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/RegisteredResourceImpl.java?rev=806097&r1=806096&r2=806097&view=diff
==============================================================================
--- sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/RegisteredResourceImpl.java
(original)
+++ sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/RegisteredResourceImpl.java
Thu Aug 20 09:31:54 2009
@@ -129,6 +129,11 @@
     	}
 	}
 	
+	@Override
+	public String toString() {
+	    return getClass().getSimpleName() + " " + url + " (" + digest + ")";
+	}
+	
 	protected File getDataFile(BundleContext ctx) throws IOException {
 		String filename = null;
 		synchronized (getClass()) {

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=806097&r1=806096&r2=806097&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 Aug 20 09:31:54 2009
@@ -41,6 +41,7 @@
     
     @Override
     public void execute(OsgiInstallerContext ctx) throws Exception {
+        super.execute(ctx);
         final Bundle b = ctx.getBundleContext().installBundle(resource.getUrl(), resource.getInputStream());
         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/BundleRemoveTask.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/BundleRemoveTask.java?rev=806097&r1=806096&r2=806097&view=diff
==============================================================================
--- sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/BundleRemoveTask.java
(original)
+++ sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/BundleRemoveTask.java
Thu Aug 20 09:31:54 2009
@@ -44,6 +44,7 @@
     
     @Override
     public void execute(OsgiInstallerContext ctx) throws Exception {
+        super.execute(ctx);
         final String symbolicName = (String)resource.getAttributes().get(Constants.BUNDLE_SYMBOLICNAME);
         final Bundle b = TaskUtilities.getMatchingBundle(ctx.getBundleContext(), symbolicName);
         if(b == null) {

Modified: sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/BundleStartTask.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/BundleStartTask.java?rev=806097&r1=806096&r2=806097&view=diff
==============================================================================
--- sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/BundleStartTask.java
(original)
+++ sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/BundleStartTask.java
Thu Aug 20 09:31:54 2009
@@ -55,9 +55,10 @@
 		return getClass().getSimpleName() + ": bundle " + bundleId;
 	}
 
-	public void execute(OsgiInstallerContext tctx) throws Exception {
-		final Bundle b = tctx.getBundleContext().getBundle(bundleId);
-		final LogService log = tctx.getLogService();
+	public void execute(OsgiInstallerContext ctx) throws Exception {
+        super.execute(ctx);
+		final Bundle b = ctx.getBundleContext().getBundle(bundleId);
+		final LogService log = ctx.getLogService();
 		boolean needToRetry = false;
 		
 		if(b == null) {
@@ -102,11 +103,11 @@
                     eventsCountForRetrying = Activator.getTotalEventsCount() + 1;
 	            }
 	            
-	            tctx.addTaskToNextCycle(this);
+	            ctx.addTaskToNextCycle(this);
 	        }
 		}
 		retryCount++;
-		tctx.incrementCounter(OsgiInstaller.OSGI_TASKS_COUNTER);
+		ctx.incrementCounter(OsgiInstaller.OSGI_TASKS_COUNTER);
 	}
 	
 	/** Do not execute this task if waiting for events */

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=806097&r1=806096&r2=806097&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 Aug 20 09:31:54 2009
@@ -41,8 +41,14 @@
         return resource;
     }
     
+    @Override 
+    public String toString() {
+        return getClass().getSimpleName() + ": " + resource;
+    }
+    
     @Override
     public void execute(OsgiInstallerContext ctx) throws Exception {
+        super.execute(ctx);
         final String symbolicName = (String)resource.getAttributes().get(Constants.BUNDLE_SYMBOLICNAME);
         final Bundle b = TaskUtilities.getMatchingBundle(ctx.getBundleContext(), symbolicName);
         if(b == null) {

Modified: sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/SynchronousRefreshPackagesTask.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/SynchronousRefreshPackagesTask.java?rev=806097&r1=806096&r2=806097&view=diff
==============================================================================
--- sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/SynchronousRefreshPackagesTask.java
(original)
+++ sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/SynchronousRefreshPackagesTask.java
Thu Aug 20 09:31:54 2009
@@ -62,6 +62,7 @@
 	}
 
 	public void execute(OsgiInstallerContext ctx) throws Exception {
+        super.execute(ctx);
 		this.ctx = ctx;
         final int targetEventCount = packageRefreshEventsCount + 1;
         final long start = System.currentTimeMillis();

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=806097&r1=806096&r2=806097&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 Aug 20 09:31:54 2009
@@ -32,6 +32,7 @@
 
 public class BundleTaskCreatorTest {
 	public static final String SN = "TestSymbolicName";
+	private final OsgiInstallerContext ctx = new MockOsgiInstallerContext();
 	
 	private SortedSet<OsgiInstallerTask> getTasks(RegisteredResource [] resources, BundleTaskCreator
btc) {
 		final SortedSet<RegisteredResource> s = OsgiInstallerThread.createRegisteredResourcesEntry();
@@ -40,7 +41,7 @@
 		}
 		
 		final SortedSet<OsgiInstallerTask> tasks = new TreeSet<OsgiInstallerTask>();
-		btc.createTasks(null, s, tasks);
+		btc.createTasks(ctx, s, tasks);
 		return tasks;
 	}
 	

Modified: sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/MockBundleResource.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/MockBundleResource.java?rev=806097&r1=806096&r2=806097&view=diff
==============================================================================
--- sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/MockBundleResource.java
(original)
+++ sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/MockBundleResource.java
Thu Aug 20 09:31:54 2009
@@ -32,10 +32,12 @@
 
 	private final Map<String, Object> attributes = new HashMap<String, Object>();
 	private boolean installable = true;
+	private final String digest;
 	
 	MockBundleResource(String symbolicName, String version) {
 		attributes.put(Constants.BUNDLE_SYMBOLICNAME, symbolicName);
 		attributes.put(Constants.BUNDLE_VERSION, new Version(version));
+		digest = symbolicName + "." + version;
 	}
 	
 	public void cleanup() {
@@ -50,7 +52,7 @@
 	}
 
 	public String getDigest() {
-		return null;
+		return digest;
 	}
 
 	public String getEntityId() {

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=806097&r1=806096&r2=806097&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 Aug 20 09:31:54 2009
@@ -21,7 +21,6 @@
 import java.util.HashMap;
 import java.util.Map;
 
-import org.osgi.framework.BundleContext;
 import org.osgi.framework.Constants;
 import org.osgi.framework.Version;
 
@@ -35,8 +34,7 @@
     }
     
     @Override
-    protected BundleInfo getBundleInfo(BundleContext ctx, RegisteredResource bundle) {
+    protected BundleInfo getBundleInfo(OsgiInstallerContext ctx, RegisteredResource bundle)
{
         return fakeBundleInfo.get(bundle.getAttributes().get(Constants.BUNDLE_SYMBOLICNAME));
     }
-    
 }

Copied: sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/MockOsgiInstallerContext.java
(from r805815, sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/MockOsgiControllerContext.java)
URL: http://svn.apache.org/viewvc/sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/MockOsgiInstallerContext.java?p2=sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/MockOsgiInstallerContext.java&p1=sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/MockOsgiControllerContext.java&r1=805815&r2=806097&rev=806097&view=diff
==============================================================================
--- sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/MockOsgiControllerContext.java
(original)
+++ sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/MockOsgiInstallerContext.java
Thu Aug 20 09:31:54 2009
@@ -23,7 +23,7 @@
 import org.osgi.service.log.LogService;
 import org.osgi.service.packageadmin.PackageAdmin;
 
-public class MockOsgiControllerContext implements OsgiInstallerContext {
+public class MockOsgiInstallerContext implements OsgiInstallerContext {
 
 	public void addTaskToCurrentCycle(OsgiInstallerTask t) {
 	}

Modified: sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/StorageTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/StorageTest.java?rev=806097&r1=806096&r2=806097&view=diff
==============================================================================
--- sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/StorageTest.java
(original)
+++ sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/StorageTest.java
Thu Aug 20 09:31:54 2009
@@ -29,7 +29,7 @@
 /** Test the Storage class */
 public class StorageTest {
 
-	private final OsgiInstallerContext ocs = new MockOsgiControllerContext();
+	private final OsgiInstallerContext ocs = new MockOsgiInstallerContext();
 	
     @org.junit.Test public void testEmptyDataFile() throws Exception {
         final Storage s = new Storage(Utilities.getTestFile(), ocs);

Modified: sling/trunk/installer/osgi/it/src/test/java/org/apache/sling/osgi/installer/it/BundleSnapshotUpdateTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/osgi/it/src/test/java/org/apache/sling/osgi/installer/it/BundleSnapshotUpdateTest.java?rev=806097&r1=806096&r2=806097&view=diff
==============================================================================
--- sling/trunk/installer/osgi/it/src/test/java/org/apache/sling/osgi/installer/it/BundleSnapshotUpdateTest.java
(original)
+++ sling/trunk/installer/osgi/it/src/test/java/org/apache/sling/osgi/installer/it/BundleSnapshotUpdateTest.java
Thu Aug 20 09:31:54 2009
@@ -60,37 +60,61 @@
         assertNull("Test bundle must be absent before installing", findBundle(symbolicName));
         resetCounters();
         installer.addResource(getInstallableResource(
-                getTestBundle(BUNDLE_BASE_NAME + "-testbundle-1.1.jar")));
+                getTestBundle(BUNDLE_BASE_NAME + "-testbundle-1.1.jar"), "digest1"));
         // wait for two tasks: install and start
         waitForInstallerAction(OsgiInstaller.OSGI_TASKS_COUNTER, 2);
         final Bundle b = findBundle(symbolicName);
         assertNotNull("Test bundle 1.1 must be found after waitForInstallerAction", b);
+        assertNoOsgiTasks("At end of test");
         
-        final long nOps = installer.getCounters()[OsgiInstaller.OSGI_TASKS_COUNTER];
+        // Update with same digest must be ignored
+        long nOps = installer.getCounters()[OsgiInstaller.OSGI_TASKS_COUNTER];
         installer.addResource(getInstallableResource(
-                getTestBundle(BUNDLE_BASE_NAME + "-testbundle-1.1.jar")));
+                getTestBundle(BUNDLE_BASE_NAME + "-testbundle-1.1.jar"), "digest1"));
         waitForInstallerAction(OsgiInstaller.INSTALLER_CYCLES_COUNTER, 1);
-        assertEquals("Updating non-snapshot bundle must not generate any OSGi tasks",
+        assertEquals("Updating testbundle with same digest must not generate any OSGi tasks",
                 nOps, installer.getCounters()[OsgiInstaller.OSGI_TASKS_COUNTER]);
+        
+        // Update with different digest must be ignored
+        nOps = installer.getCounters()[OsgiInstaller.OSGI_TASKS_COUNTER];
+        installer.addResource(getInstallableResource(
+                getTestBundle(BUNDLE_BASE_NAME + "-testbundle-1.1.jar"), "digest2"));
+        waitForInstallerAction(OsgiInstaller.INSTALLER_CYCLES_COUNTER, 1);
+        assertEquals("Updating testbundle with different digest must not generate any OSGi
tasks",
+                nOps, installer.getCounters()[OsgiInstaller.OSGI_TASKS_COUNTER]);
+        
+        assertNoOsgiTasks("At end of test");
     }
     
     @Test
     public void testSnapshot() throws IOException {
+        
+        // Install test bundle
         final String symbolicName = "osgi-installer-snapshot-test";
         assertNull("Snapshot test bundle must be absent before installing", findBundle(symbolicName));
         resetCounters();
         installer.addResource(getInstallableResource(
-                getTestBundle(BUNDLE_BASE_NAME + "-snap.jar")));
+                getTestBundle(BUNDLE_BASE_NAME + "-snap.jar"), "digest1"));
         // wait for two tasks: install and start
         waitForInstallerAction(OsgiInstaller.OSGI_TASKS_COUNTER, 2);
         final Bundle b = findBundle(symbolicName);
         assertNotNull("Snapshot bundle must be found after waitForInstallerAction", b);
 
-        resetCounters();
+        // Update with same digest must be ignored
+        final long nOps = installer.getCounters()[OsgiInstaller.OSGI_TASKS_COUNTER];
         installer.addResource(getInstallableResource(
-                getTestBundle(BUNDLE_BASE_NAME + "-snap.jar")));
+                getTestBundle(BUNDLE_BASE_NAME + "-snap.jar"), "digest1"));
         waitForInstallerAction(OsgiInstaller.INSTALLER_CYCLES_COUNTER, 1);
-        // If this fails it means bundle has not been updated
+        assertEquals("Updating snapshot bundle with same digest must not generate any OSGi
tasks",
+                nOps, installer.getCounters()[OsgiInstaller.OSGI_TASKS_COUNTER]);
+        
+        // Update with different digest must generate an OSGi update
+        resetCounters();
+        installer.addResource(getInstallableResource(
+                getTestBundle(BUNDLE_BASE_NAME + "-snap.jar"), "digest2"));
         waitForInstallerAction(OsgiInstaller.OSGI_TASKS_COUNTER, 1);
+        
+        // And no more OSGi tasks after that
+        assertNoOsgiTasks("At end of test");
     }
 }

Modified: sling/trunk/installer/osgi/it/src/test/java/org/apache/sling/osgi/installer/it/OsgiInstallerTestBase.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/osgi/it/src/test/java/org/apache/sling/osgi/installer/it/OsgiInstallerTestBase.java?rev=806097&r1=806096&r2=806097&view=diff
==============================================================================
--- sling/trunk/installer/osgi/it/src/test/java/org/apache/sling/osgi/installer/it/OsgiInstallerTestBase.java
(original)
+++ sling/trunk/installer/osgi/it/src/test/java/org/apache/sling/osgi/installer/it/OsgiInstallerTestBase.java
Thu Aug 20 09:31:54 2009
@@ -168,8 +168,14 @@
     }
     
     protected InstallableResource getInstallableResource(File testBundle) throws IOException
{
+        return getInstallableResource(testBundle, null);
+    }
+    
+    protected InstallableResource getInstallableResource(File testBundle, String digest)
throws IOException {
         final String url = URL_SCHEME + testBundle.getAbsolutePath();
-        final String digest = testBundle.getAbsolutePath() + testBundle.lastModified();
+        if(digest == null) {
+            digest = testBundle.getAbsolutePath() + testBundle.lastModified();
+        }
         return new InstallableResource(url, new FileInputStream(testBundle), digest);
     }
     
@@ -207,12 +213,13 @@
     }
     
     protected void waitForInstallerAction(int counterType, long howMany) {
-        // if waiting for installer cycles, reset counters first - we know
-        // we want to wait from now on, not from an earlier resetCounters() call
+        // if waiting for installer cycles, get initial value from
+        // that counter - we know we want to wait from now on, not from an 
+        // earlier resetCounters() call
+        long targetValue = counters[counterType] + howMany;
         if(counterType == OsgiInstaller.INSTALLER_CYCLES_COUNTER) {
-            resetCounters();
+            targetValue = installer.getCounters()[counterType] + howMany;
         }
-        final long targetValue = counters[counterType] + howMany;
         final long endTime = System.currentTimeMillis() + WAIT_FOR_ACTION_TIMEOUT_MSEC;
         long lastValue = 0;
         while(System.currentTimeMillis() < endTime) {



Mime
View raw message