incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r996317 - in /sling/trunk/installer/osgi/installer/src: main/java/org/apache/sling/osgi/installer/impl/ main/java/org/apache/sling/osgi/installer/impl/tasks/ test/java/org/apache/sling/osgi/installer/impl/ test/java/org/apache/sling/osgi/in...
Date Sun, 12 Sep 2010 14:10:48 GMT
Author: cziegeler
Date: Sun Sep 12 14:10:47 2010
New Revision: 996317

URL: http://svn.apache.org/viewvc?rev=996317&view=rev
Log:
SLING-1737 : Add state management for resources

Added:
    sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/EntityResourceList.java
  (with props)
Modified:
    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/PersistentResourceList.java
    sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/BundleTaskCreator.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/PersistentResourceListTest.java
    sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/tasks/BundleTaskCreatorTest.java

Added: sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/EntityResourceList.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/EntityResourceList.java?rev=996317&view=auto
==============================================================================
--- sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/EntityResourceList.java
(added)
+++ sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/EntityResourceList.java
Sun Sep 12 14:10:47 2010
@@ -0,0 +1,119 @@
+/*
+ * 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.impl;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+import java.util.SortedSet;
+import java.util.TreeSet;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Persistent list of RegisteredResource, used by installer to
+ * keep track of all registered resources
+ */
+public class EntityResourceList implements Serializable {
+
+    private static final long serialVersionUID = 6326554136639675505L;
+
+    private static final Logger LOGGER = LoggerFactory.getLogger(EntityResourceList.class);
+
+    private final SortedSet<RegisteredResource> resources = new TreeSet<RegisteredResource>();
+
+    public boolean isEmpty() {
+        return resources.isEmpty();
+    }
+
+    public RegisteredResource getFirst() {
+        return resources.first();
+    }
+
+    public Collection<RegisteredResource> getResources() {
+        return resources;
+    }
+
+    public void addOrUpdate(final RegisteredResource r) {
+        LOGGER.debug("Adding new resource: {}", r);
+        // If an object with same sort key is already present, replace with the
+        // new one which might have different attributes
+        boolean first = true;
+        for(final RegisteredResource rr : resources) {
+            if ( rr.getURL().equals(r.getURL()) ) {
+                LOGGER.debug("Cleanup obsolete resource: {}", rr);
+                rr.cleanup();
+                resources.remove(rr);
+                if ( first && rr.equals(r) ) {
+                    r.setState(rr.getState());
+                }
+                break;
+            }
+            first = false;
+        }
+        resources.add(r);
+    }
+
+    public void remove(final String url) {
+        final Iterator<RegisteredResource> i = resources.iterator();
+        boolean first = true;
+        while ( i.hasNext() ) {
+            final RegisteredResource r = i.next();
+            if ( r.getURL().equals(url) ) {
+                if ( first && (r.getState() == RegisteredResource.State.INSTALLED
+                        || r.getState() == RegisteredResource.State.INSTALL)) {
+                    LOGGER.debug("Marking for uninstalling: {}", r);
+                    r.setState(RegisteredResource.State.UNINSTALL);
+                } else {
+                    LOGGER.debug("Removing unused: {}", r);
+                    i.remove();
+                    r.cleanup();
+                }
+            }
+            first = false;
+        }
+    }
+
+    public void remove(final RegisteredResource r) {
+        if ( resources.remove(r) ) {
+            LOGGER.debug("Removing unused: {}", r);
+            r.cleanup();
+        }
+    }
+
+    public boolean compact() {
+        boolean changed = false;
+        final List<RegisteredResource> toDelete = new ArrayList<RegisteredResource>();
+        for(final RegisteredResource r : resources) {
+            if ( r.getState() == RegisteredResource.State.UNINSTALLED ) {
+                toDelete.add(r);
+            }
+        }
+        for(final RegisteredResource r : toDelete) {
+            changed = true;
+            resources.remove(r);
+            r.cleanup();
+            LOGGER.debug("Removing uninstalled from list: {}", r);
+        }
+        return changed;
+    }
+}

Propchange: sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/EntityResourceList.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/EntityResourceList.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision rev url

Propchange: sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/EntityResourceList.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

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=996317&r1=996316&r2=996317&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
Sun Sep 12 14:10:47 2010
@@ -22,7 +22,6 @@ import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
 import java.util.ArrayList;
-import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashSet;
@@ -298,11 +297,11 @@ public class OsgiInstallerImpl
                 // set all previously found resources that are not available anymore to uninstall
                 // if they have been installed - remove resources with a different state
                 for(final String entityId : this.persistentList.getEntityIds()) {
-                    final Collection<RegisteredResource> group = this.persistentList.getResources(entityId);
+                    final EntityResourceList group = this.persistentList.getEntityResourceList(entityId);
 
                     final List<RegisteredResource> toRemove = new ArrayList<RegisteredResource>();
                     boolean first = true;
-                    for(final RegisteredResource r : group) {
+                    for(final RegisteredResource r : group.getResources()) {
                         if ( r.getScheme().equals(entry.getKey()) ) {
                             logger.debug("Checking {}", r);
                             // search if we have a new entry with the same url
@@ -352,7 +351,7 @@ public class OsgiInstallerImpl
             if ( changed ) {
                 printResources("Merged");
                 for(final String entityId : this.persistentList.getEntityIds()) {
-                    final Collection<RegisteredResource> group = this.persistentList.getResources(entityId);
+                    final EntityResourceList group = this.persistentList.getEntityResourceList(entityId);
                     if ( !group.isEmpty() ) {
 
                         // The first resource in each group defines what should be done within
this group.
@@ -364,7 +363,7 @@ public class OsgiInstallerImpl
                         // IGNORED   : Nothing to do
                         // UNINSTALLED : This can't happen - but we do nothing in this case
anyway
 
-                        final Iterator<RegisteredResource> i = group.iterator();
+                        final Iterator<RegisteredResource> i = group.getResources().iterator();
                         final RegisteredResource first = i.next();
 
                         RegisteredResource toActivate = null;
@@ -405,7 +404,7 @@ public class OsgiInstallerImpl
             sb.append(id);
             sb.append(" : [");
             boolean first = true;
-            for(final RegisteredResource rr : this.persistentList.getResources(id)) {
+            for(final RegisteredResource rr : this.persistentList.getEntityResourceList(id).getResources())
{
                 if ( !first) {
                     sb.append(", ");
                 }
@@ -432,11 +431,11 @@ public class OsgiInstallerImpl
 
         // Walk the list of entities, and create appropriate OSGi tasks for each group
         for(final String entityId : this.persistentList.getEntityIds()) {
-            final Collection<RegisteredResource> group = this.persistentList.getResources(entityId);
+            final EntityResourceList group = this.persistentList.getEntityResourceList(entityId);
             if ( !group.isEmpty() ) {
 
                 // Check the first resource in each group
-                final Iterator<RegisteredResource> i = group.iterator();
+                final Iterator<RegisteredResource> i = group.getResources().iterator();
                 final RegisteredResource first = i.next();
 
                 RegisteredResource toActivate = null;

Modified: sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/PersistentResourceList.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/PersistentResourceList.java?rev=996317&r1=996316&r2=996317&view=diff
==============================================================================
--- sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/PersistentResourceList.java
(original)
+++ sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/PersistentResourceList.java
Sun Sep 12 14:10:47 2010
@@ -24,14 +24,10 @@ import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.ObjectInputStream;
 import java.io.ObjectOutputStream;
-import java.util.ArrayList;
 import java.util.Collection;
 import java.util.HashMap;
 import java.util.Iterator;
-import java.util.List;
 import java.util.Map;
-import java.util.SortedSet;
-import java.util.TreeSet;
 
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -51,19 +47,19 @@ public class PersistentResourceList {
      * The value is a set containing all registered resources for the
      * same entity. Usually this is just one resource per entity.
      */
-    private final Map<String, SortedSet<RegisteredResource>> data;
+    private final Map<String, EntityResourceList> data;
     private final File dataFile;
 
     @SuppressWarnings("unchecked")
     public PersistentResourceList(final File dataFile) {
         this.dataFile = dataFile;
 
-        Map<String, SortedSet<RegisteredResource>> restoredData = null;
+        Map<String, EntityResourceList> restoredData = null;
         if ( dataFile.exists() ) {
             ObjectInputStream ois = null;
             try {
                 ois = new ObjectInputStream(new FileInputStream(dataFile));
-                restoredData = (Map<String, SortedSet<RegisteredResource>>)ois.readObject();
+                restoredData = (Map<String, EntityResourceList>)ois.readObject();
                 logger.debug("Restored rsource list: {}", restoredData);
             } catch (final Exception e) {
                 logger.warn("Unable to restore data, starting with empty list (" + e.getMessage()
+ ")", e);
@@ -77,12 +73,7 @@ public class PersistentResourceList {
                 }
             }
         }
-        data = restoredData != null ? restoredData : new HashMap<String, SortedSet<RegisteredResource>>();
-    }
-
-    /** This method is just for testing. */
-    Map<String, SortedSet<RegisteredResource>>  getData() {
-        return data;
+        data = restoredData != null ? restoredData : new HashMap<String, EntityResourceList>();
     }
 
     public void save() {
@@ -104,85 +95,39 @@ public class PersistentResourceList {
     }
 
     public void addOrUpdate(final RegisteredResource r) {
-        logger.debug("Adding: {}", r);
-        SortedSet<RegisteredResource> t = this.data.get(r.getEntityId());
+        EntityResourceList t = this.data.get(r.getEntityId());
         if (t == null) {
-            t = new TreeSet<RegisteredResource>();
+            t = new EntityResourceList();
             this.data.put(r.getEntityId(), t);
         }
 
-        // If an object with same sort key is already present, replace with the
-        // new one which might have different attributes
-        boolean first = true;
-        for(final RegisteredResource rr : t) {
-            if ( rr.getURL().equals(r.getURL()) ) {
-                logger.debug("Cleanup obsolete resource: {}", rr);
-                rr.cleanup();
-                t.remove(rr);
-                if ( first && rr.equals(r) ) {
-                    r.setState(rr.getState());
-                }
-                break;
-            }
-            first = false;
-        }
-        t.add(r);
+        t.addOrUpdate(r);
     }
 
     public void remove(final String url) {
-        for(final SortedSet<RegisteredResource> group : this.data.values()) {
-            final Iterator<RegisteredResource> i = group.iterator();
-            boolean first = true;
-            while ( i.hasNext() ) {
-                final RegisteredResource r = i.next();
-                if ( r.getURL().equals(url) ) {
-                    if ( first && (r.getState() == RegisteredResource.State.INSTALLED
-                            || r.getState() == RegisteredResource.State.INSTALL)) {
-                        logger.debug("Marking for uninstalling: {}", r);
-                        r.setState(RegisteredResource.State.UNINSTALL);
-                    } else {
-                        logger.debug("Removing unused: {}", r);
-                        i.remove();
-                        r.cleanup();
-                    }
-                }
-                first = false;
-            }
+        for(final EntityResourceList group : this.data.values()) {
+            group.remove(url);
         }
     }
 
     public void remove(final RegisteredResource r) {
-        final SortedSet<RegisteredResource> group = this.data.get(r.getEntityId());
+        final EntityResourceList group = this.data.get(r.getEntityId());
         if ( group != null ) {
-            logger.debug("Removing unused: {}", r);
             group.remove(r);
-            r.cleanup();
         }
     }
 
-    public Collection<RegisteredResource> getResources(final String entityId) {
+    public EntityResourceList getEntityResourceList(final String entityId) {
         return this.data.get(entityId);
     }
 
     public boolean compact() {
         boolean changed = false;
-        final Iterator<Map.Entry<String, SortedSet<RegisteredResource>>>
i = this.data.entrySet().iterator();
+        final Iterator<Map.Entry<String, EntityResourceList>> i = this.data.entrySet().iterator();
         while ( i.hasNext() ) {
-            final Map.Entry<String, SortedSet<RegisteredResource>> entry = i.next();
-
-            final List<RegisteredResource> toDelete = new ArrayList<RegisteredResource>();
-            for(final RegisteredResource r : entry.getValue()) {
-                if ( r.getState() == RegisteredResource.State.UNINSTALLED ) {
-                    toDelete.add(r);
-                }
-            }
-            for(final RegisteredResource r : toDelete) {
-                changed = true;
-                entry.getValue().remove(r);
-                r.cleanup();
-                logger.debug("Removing from list, uninstalled: {}", r);
-            }
+            final Map.Entry<String, EntityResourceList> entry = i.next();
 
+            changed |= entry.getValue().compact();
             if ( entry.getValue().isEmpty() ) {
                 changed = true;
                 i.remove();

Modified: sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/BundleTaskCreator.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/BundleTaskCreator.java?rev=996317&r1=996316&r2=996317&view=diff
==============================================================================
--- sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/BundleTaskCreator.java
(original)
+++ sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/BundleTaskCreator.java
Sun Sep 12 14:10:47 2010
@@ -147,7 +147,9 @@ public class BundleTaskCreator {
 		// Uninstall
 		if (toActivate.getState() == RegisteredResource.State.UNINSTALL) {
 		    // Remove corresponding bundle if present and if we installed it
-		    if (info != null && this.bundleDigestsStorage.getInstalledVersion(symbolicName)
!= null) {
+		    if (info != null
+		        && this.bundleDigestsStorage.getInstalledVersion(symbolicName) != null
+		        && this.bundleDigestsStorage.getDigest(symbolicName).equals(toActivate.getDigest()))
{
 		        result = new BundleRemoveTask(toActivate, this);
 		    } else {
 	            logger.info("Bundle {} was not installed by this module, not removed", symbolicName);

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=996317&r1=996316&r2=996317&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
Sun Sep 12 14:10:47 2010
@@ -127,21 +127,21 @@ public class MockBundleResource implemen
 	 * @see org.apache.sling.osgi.installer.impl.RegisteredResource#getId()
 	 */
 	public String getId() {
-		return null;
+		return this.attributes.get(Constants.BUNDLE_SYMBOLICNAME) + "-" + this.attributes.get(Constants.BUNDLE_VERSION);
 	}
 
 	/**
 	 * @see org.apache.sling.osgi.installer.impl.RegisteredResource#getURL()
 	 */
 	public String getURL() {
-		return null;
+		return this.getScheme() + ":" + this.getId();
 	}
 
     /**
      * @see org.apache.sling.osgi.installer.impl.RegisteredResource#getScheme()
      */
     public String getScheme() {
-        return null;
+        return "test";
     }
 
     /**

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=996317&r1=996316&r2=996317&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
Sun Sep 12 14:10:47 2010
@@ -26,8 +26,6 @@ import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.ObjectOutputStream;
 import java.util.Iterator;
-import java.util.SortedSet;
-import java.util.TreeSet;
 
 import org.junit.Test;
 import org.osgi.framework.Constants;
@@ -42,7 +40,8 @@ public class PersistentResourceListTest 
     public void testFileNotFound() throws IOException {
         File f = new File("NONEXISTENT");
         PersistentResourceList p = new PersistentResourceList(f);
-        assertNotNull(p.getData());
+        // check if data is available - we call a method which would result in an NPE otherwise!
+        p.getEntityIds();
     }
 
     @Test
@@ -56,15 +55,17 @@ public class PersistentResourceListTest 
             oos.close();
         }
         PersistentResourceList p = new PersistentResourceList(f);
-        assertNotNull(p.getData());
-        assertEquals("Constructor must fail gracefully with invalid data file", 0, p.getData().size());
+        // check if data is available - we call a method which would result in an NPE otherwise!
+        p.getEntityIds();
+        assertEquals("Constructor must fail gracefully with invalid data file", 0, p.getEntityIds().size());
     }
 
     @Test
     public void testTestData() throws IOException {
         File f = new File("NONEXISTENT");
         PersistentResourceList p = new PersistentResourceList(f);
-        assertNotNull(p.getData());
+        // check if data is available - we call a method which would result in an NPE otherwise!
+        p.getEntityIds();
         addTestData(p);
         assertTestData(p);
     }
@@ -87,31 +88,30 @@ public class PersistentResourceListTest 
     private void addTestData(PersistentResourceList p) {
         for(int i = 0; i < TEST_SCALE; i++) {
             final String symbolicName = FAKE + i;
-            TreeSet<RegisteredResource> s = new TreeSet<RegisteredResource>();
             for(int j= TEST_SCALE - 2; j >= 1; j--) {
-                s.add(new MockBundleResource(symbolicName, getFakeVersion(i, j)));
+                p.addOrUpdate(new MockBundleResource(symbolicName, getFakeVersion(i, j)));
             }
-            p.getData().put(symbolicName, s);
         }
     }
 
     private void assertTestData(PersistentResourceList p) {
         for(int i = 0; i < TEST_SCALE; i++) {
             final String symbolicName = FAKE + i;
-            SortedSet<RegisteredResource> s = p.getData().get(symbolicName);
+
+            final EntityResourceList s = p.getEntityResourceList("bundle:" + symbolicName);
             assertNotNull(symbolicName + " must be found", s);
-            Iterator<RegisteredResource> it = s.iterator();
+
+            final Iterator<RegisteredResource> it = s.getResources().iterator();
             for(int j= TEST_SCALE - 2; j >= 1; j--) {
                 RegisteredResource r = it.next();
-                assertNotNull("RegisteredResource " + j + " must be found");
+                assertNotNull("RegisteredResource " + j + " must be found", r);
                 String sn = (String)r.getAttributes().get(Constants.BUNDLE_SYMBOLICNAME);
                 assertEquals("RegisteredResource " + j + " symbolic name must match", symbolicName,
sn);
                 Version v = new Version((String)r.getAttributes().get(Constants.BUNDLE_VERSION));
                 assertEquals("RegisteredResource " + j + " version must match", getFakeVersion(i,
j), v.toString());
             }
-            s.add(new MockBundleResource(symbolicName, "2." + i));
-            s.add(new MockBundleResource(symbolicName, "3." + i));
-            p.getData().put(symbolicName, s);
+            p.addOrUpdate(new MockBundleResource(symbolicName, "2." + i));
+            p.addOrUpdate(new MockBundleResource(symbolicName, "3." + i));
         }
     }
 

Modified: sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/tasks/BundleTaskCreatorTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/tasks/BundleTaskCreatorTest.java?rev=996317&r1=996316&r2=996317&view=diff
==============================================================================
--- sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/tasks/BundleTaskCreatorTest.java
(original)
+++ sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/tasks/BundleTaskCreatorTest.java
Sun Sep 12 14:10:47 2010
@@ -198,8 +198,12 @@ public class BundleTaskCreatorTest {
             c.addBundleInfo(SN, "1.1", Bundle.ACTIVE);
             c.getBundleDigestStorage().putInfo(SN, r[1].getDigest(), "1.1");
             final SortedSet<OsgiInstallerTask> s = getTasks(r, c);
-            assertEquals("Expected one task, as we installed that bundle", 1, s.size());
-            assertTrue("Expected a BundleRemoveTask", s.first() instanceof BundleRemoveTask);
+            assertEquals("Expected two tasks, as we installed that bundle", 2, s.size());
+            final Iterator<OsgiInstallerTask> i = s.iterator();
+            final OsgiInstallerTask first = i.next();
+            assertTrue("Expected a ChangeStateTask:" + first , first instanceof ChangeStateTask);
+            final OsgiInstallerTask second = i.next();
+            assertTrue("Expected a BundleRemoveTask: " + second, second instanceof BundleRemoveTask);
         }
     }
 
@@ -216,7 +220,8 @@ public class BundleTaskCreatorTest {
        {
             final MockBundleTaskCreator c = new MockBundleTaskCreator();
             c.addBundleInfo(SN, "1.1.0", Bundle.ACTIVE);
-            c.getBundleDigestStorage().putInfo(SN, "fakedigest", "1.1.0");
+            c.getBundleDigestStorage().putInfo(SN, r[1].getDigest(), "1.1.0");
+
             final SortedSet<OsgiInstallerTask> s = getTasks(r, c);
             assertEquals("Expected two tasks", 2, s.size());
             final Iterator<OsgiInstallerTask> i = s.iterator();



Mime
View raw message