incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bdelacre...@apache.org
Subject svn commit: r824840 - 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 Tue, 13 Oct 2009 16:49:34 GMT
Author: bdelacretaz
Date: Tue Oct 13 16:49:33 2009
New Revision: 824840

URL: http://svn.apache.org/viewvc?rev=824840&view=rev
Log:
SLING-1148 - RegisteredResource persisted in the bundle storage area

Added:
    sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/PersistentResourceList.java
  (with props)
    sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/PersistentResourceListTest.java
  (with props)
    sling/trunk/installer/osgi/it/src/test/java/org/apache/sling/osgi/installer/it/RemovedResourceDetectionTest.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/ConfigurationPid.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/RegisteredResourceComparator.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/BundleUpdateTask.java
    sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/MockBundleResource.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=824840&r1=824839&r2=824840&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
Tue Oct 13 16:49:33 2009
@@ -87,7 +87,7 @@
 			
 		} else {
 			final BundleInfo info = getBundleInfo(ctx, toActivate);
-			final Version newVersion = (Version)toActivate.getAttributes().get(Constants.BUNDLE_VERSION);
+			final Version newVersion = new Version((String)toActivate.getAttributes().get(Constants.BUNDLE_VERSION));
 			if(info == null) {
 			    // bundle is not installed yet: install and save digest to avoid
 			    // unnecessary updates

Modified: sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/ConfigurationPid.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/ConfigurationPid.java?rev=824840&r1=824839&r2=824840&view=diff
==============================================================================
--- sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/ConfigurationPid.java
(original)
+++ sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/ConfigurationPid.java
Tue Oct 13 16:49:33 2009
@@ -18,13 +18,16 @@
  */
 package org.apache.sling.osgi.installer.impl;
 
+import java.io.Serializable;
+
 import org.apache.sling.osgi.installer.impl.tasks.ConfigInstallTask;
 
 /** Builds configration PIDs out of filenames, examples:
  *      o.a.s.foo.bar.cfg -> pid = o.a.s.foo.bar
  *      o.a.s.foo.bar-a.cfg -> pid = o.a.s.foo.bar, factory pid = a 
  */
-public class ConfigurationPid {
+public class ConfigurationPid implements Serializable {
+    private static final long serialVersionUID = 1L;
     private final String configPid;
     private final String factoryPid;
 

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=824840&r1=824839&r2=824840&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
Tue Oct 13 16:49:33 2009
@@ -18,6 +18,7 @@
  */
 package org.apache.sling.osgi.installer.impl;
 
+import java.io.File;
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Collection;
@@ -25,7 +26,6 @@
 import java.util.HashSet;
 import java.util.LinkedList;
 import java.util.List;
-import java.util.Map;
 import java.util.Set;
 import java.util.SortedSet;
 import java.util.TreeSet;
@@ -58,8 +58,8 @@
     private boolean retriesScheduled;
     
     /** Group our RegisteredResource by OSGi entity */ 
-    private Map<String, SortedSet<RegisteredResource>>registeredResources = 
-        new HashMap<String, SortedSet<RegisteredResource>>();
+    private final HashMap<String, SortedSet<RegisteredResource>> registeredResources;
+    private final PersistentResourceList persistentList;
     
     private final BundleTaskCreator bundleTaskCreator = new BundleTaskCreator();
     private final ConfigTaskCreator configTaskCreator = new ConfigTaskCreator();
@@ -67,6 +67,9 @@
     OsgiInstallerThread(OsgiInstallerContext ctx) {
         setName(getClass().getSimpleName());
         this.ctx = ctx;
+        final File f = ctx.getBundleContext().getDataFile("RegisteredResourceList.ser");
+        persistentList = new PersistentResourceList(ctx,f);
+        registeredResources = persistentList.getData();
     }
 
     void deactivate() {
@@ -106,7 +109,12 @@
             	}
             	
             	retriesScheduled = false;
-                executeTasks();
+                if(executeTasks() > 0) {
+                    if(ctx.getLogService() != null) {
+                        ctx.getLogService().log(LogService.LOG_DEBUG, "Tasks have been executed,
saving persistentList");
+                    }
+                    persistentList.save();
+                }
                 
                 // Some integration tests depend on this delay, make sure to
                 // rerun/adapt them if changing this value
@@ -329,17 +337,20 @@
         }
     }
     
-    private void executeTasks() throws Exception {
+    private int executeTasks() throws Exception {
+        int counter = 0;
         while(!tasks.isEmpty()) {
             OsgiInstallerTask t = null;
             synchronized (tasks) {
                 t = tasks.first();
             }
             t.execute(ctx);
+            counter++;
             synchronized (tasks) {
                 tasks.remove(t);
             }
         }
+        return counter;
     }
     
     private void cleanupInstallableResources() {

Added: 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=824840&view=auto
==============================================================================
--- sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/PersistentResourceList.java
(added)
+++ sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/PersistentResourceList.java
Tue Oct 13 16:49:33 2009
@@ -0,0 +1,78 @@
+/*
+ * 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.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.util.HashMap;
+import java.util.SortedSet;
+
+import org.osgi.service.log.LogService;
+
+/** Persistent list of RegisteredResource, used by installer to
+ *  keep track of all registered resources
+ */
+class PersistentResourceList {
+    private final HashMap<String, SortedSet<RegisteredResource>> data;
+    private final File dataFile;
+    
+    @SuppressWarnings("unchecked")
+    PersistentResourceList(OsgiInstallerContext ctx, File dataFile) {
+        this.dataFile = dataFile;
+        
+        ObjectInputStream ois = null;
+        HashMap<String, SortedSet<RegisteredResource>> restoredData = null;
+        try {
+            ois = new ObjectInputStream(new FileInputStream(dataFile));
+            restoredData = (HashMap<String, SortedSet<RegisteredResource>>)ois.readObject();
+        } catch(Exception e) {
+            if(ctx.getLogService() != null) {
+                ctx.getLogService().log(LogService.LOG_INFO, 
+                        "Unable to restore data, starting with empty list (" + e.toString());
+            }
+        } finally {
+            if(ois != null) {
+                try {
+                    ois.close();
+                } catch(IOException ignore) {
+                    // ignore
+                }
+            }
+        }
+        
+        data = restoredData != null ? restoredData : new HashMap<String, SortedSet<RegisteredResource>>();
+    }
+    
+    HashMap<String, SortedSet<RegisteredResource>>  getData() {
+        return data;
+    }
+
+    void save() throws IOException {
+        ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(dataFile));
+        try {
+            oos.writeObject(data);
+        } finally {
+            oos.close();
+        }
+    }
+}

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

Propchange: sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/PersistentResourceList.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Modified: sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/RegisteredResourceComparator.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/RegisteredResourceComparator.java?rev=824840&r1=824839&r2=824840&view=diff
==============================================================================
--- sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/RegisteredResourceComparator.java
(original)
+++ sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/RegisteredResourceComparator.java
Tue Oct 13 16:49:33 2009
@@ -18,6 +18,7 @@
  */
 package org.apache.sling.osgi.installer.impl;
 
+import java.io.Serializable;
 import java.util.Comparator;
 
 import org.osgi.framework.Constants;
@@ -28,7 +29,9 @@
  * 	name, config PID, etc.) in sorted sets, and this comparator is used
  *  to sort the resources in the sets.
  */
-class RegisteredResourceComparator implements Comparator<RegisteredResource >{
+class RegisteredResourceComparator implements Comparator<RegisteredResource>, Serializable
{
+
+    private static final long serialVersionUID = 1L;
 
     public int compare(RegisteredResource a, RegisteredResource b) {
     	final boolean aBundle = a.getResourceType() == RegisteredResource.ResourceType.BUNDLE;
@@ -59,8 +62,8 @@
         
         // Then by version
         if(result == 0) {
-            final Version va = (Version)a.getAttributes().get(Constants.BUNDLE_VERSION);
-            final Version vb = (Version)b.getAttributes().get(Constants.BUNDLE_VERSION);
+            final Version va = new Version((String)a.getAttributes().get(Constants.BUNDLE_VERSION));
+            final Version vb = new Version((String)b.getAttributes().get(Constants.BUNDLE_VERSION));
             isSnapshot = va!= null && va.toString().contains(OsgiInstallerImpl.MAVEN_SNAPSHOT_MARKER);
             if(va != null && vb != null) {
                 // higher version has more priority, must come first so invert comparison

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=824840&r1=824839&r2=824840&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
Tue Oct 13 16:49:33 2009
@@ -26,6 +26,7 @@
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
+import java.io.Serializable;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Dictionary;
@@ -43,14 +44,14 @@
 import org.apache.sling.osgi.installer.impl.propertyconverter.PropertyValue;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.Constants;
-import org.osgi.framework.Version;
 
 /** A resource that's been registered in the OSGi controller.
  * 	Data can be either an InputStream or a Dictionary, and we store
  *  it locally to avoid holding up to classes or data from our 
  *  clients, in case those disappear while we're installing stuff. 
  */
-public class RegisteredResourceImpl implements RegisteredResource { 
+public class RegisteredResourceImpl implements RegisteredResource, Serializable { 
+    private static final long serialVersionUID = 1L;
 	private final String url;
 	private final String urlScheme;
 	private final String digest;
@@ -303,7 +304,7 @@
     	
         if(m != null) {
             attributes.put(Constants.BUNDLE_SYMBOLICNAME, sn);
-            attributes.put(Constants.BUNDLE_VERSION, new Version(v));
+            attributes.put(Constants.BUNDLE_VERSION, v.toString());
         }
     }
     

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=824840&r1=824839&r2=824840&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
Tue Oct 13 16:49:33 2009
@@ -60,7 +60,7 @@
         boolean snapshot = false;
         if(b != null) {
         	final Version currentVersion = new Version((String)b.getHeaders().get(Constants.BUNDLE_VERSION));
-        	final Version newVersion = (Version)resource.getAttributes().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) {

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=824840&r1=824839&r2=824840&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
Tue Oct 13 16:49:33 2009
@@ -20,18 +20,19 @@
 
 import java.io.IOException;
 import java.io.InputStream;
+import java.io.Serializable;
 import java.util.Dictionary;
 import java.util.HashMap;
 import java.util.Map;
 
 import org.apache.sling.osgi.installer.InstallableResource;
 import org.osgi.framework.Constants;
-import org.osgi.framework.Version;
 
 /** Mock RegisteredResource that simulates a bundle */
-public class MockBundleResource implements RegisteredResource {
+public class MockBundleResource implements RegisteredResource, Serializable {
 
-	private final Map<String, Object> attributes = new HashMap<String, Object>();
+    private static final long serialVersionUID = 1L;
+    private final Map<String, Object> attributes = new HashMap<String, Object>();
 	private boolean installable = true;
 	private final String digest;
 	private final int priority;
@@ -44,7 +45,7 @@
     
 	MockBundleResource(String symbolicName, String version, int priority) {
 		attributes.put(Constants.BUNDLE_SYMBOLICNAME, symbolicName);
-		attributes.put(Constants.BUNDLE_VERSION, new Version(version));
+		attributes.put(Constants.BUNDLE_VERSION, version);
 		digest = symbolicName + "." + version;
 		this.priority = priority;
 		serialNumber = getNextSerialNumber();
@@ -52,7 +53,7 @@
 	
     MockBundleResource(String symbolicName, String version, int priority, String digest)
{
         attributes.put(Constants.BUNDLE_SYMBOLICNAME, symbolicName);
-        attributes.put(Constants.BUNDLE_VERSION, new Version(version));
+        attributes.put(Constants.BUNDLE_VERSION, version);
         this.digest = digest;
         this.priority = priority;
         serialNumber = getNextSerialNumber();

Added: 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=824840&view=auto
==============================================================================
--- sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/PersistentResourceListTest.java
(added)
+++ sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/PersistentResourceListTest.java
Tue Oct 13 16:49:33 2009
@@ -0,0 +1,121 @@
+/*
+ * 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 static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import java.io.File;
+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;
+import org.osgi.framework.Version;
+
+/** Test the PersistentResourceList */
+public class PersistentResourceListTest {
+    private final static int TEST_SCALE = 5;
+    private final static String FAKE = "fakebundle.";
+    
+    @Test
+    public void testFileNotFound() {
+        File f = new File("NONEXISTENT");
+        PersistentResourceList p = new PersistentResourceList(new MockOsgiInstallerContext(),
f);
+        assertNotNull(p.getData());
+    }
+    
+    @Test
+    public void testBadDataFile() throws IOException {
+        File f  = File.createTempFile(getClass().getSimpleName(), ".ser");
+        f.deleteOnExit();
+        ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(f));
+        try {
+            oos.writeObject("Some data that's not what we expect");
+        } finally {
+            oos.close();
+        }
+        PersistentResourceList p = new PersistentResourceList(new MockOsgiInstallerContext(),
f);
+        assertNotNull(p.getData());
+        assertEquals("Constructor must fail gracefully with invalid data file", 0, p.getData().size());
+    }
+    
+    @Test
+    public void testTestData() {
+        File f = new File("NONEXISTENT");
+        PersistentResourceList p = new PersistentResourceList(new MockOsgiInstallerContext(),
f);
+        assertNotNull(p.getData());
+        addTestData(p);
+        assertTestData(p);
+    }
+    
+    @Test
+    public void testSaveAndRetrieve() throws IOException {
+        File f  = File.createTempFile(getClass().getSimpleName(), ".ser");
+        f.deleteOnExit();
+        {
+            PersistentResourceList p = new PersistentResourceList(new MockOsgiInstallerContext(),
f);
+            addTestData(p);
+            p.save();
+        }
+        {
+            PersistentResourceList p = new PersistentResourceList(new MockOsgiInstallerContext(),
f);
+            assertTestData(p);
+        }
+    }
+    
+    private void addTestData(PersistentResourceList p) {
+        for(int i = 0; i < TEST_SCALE; i++) {
+            final String symbolicName = FAKE + i;
+            TreeSet<RegisteredResource> s = new TreeSet<RegisteredResource>(new
RegisteredResourceComparator());
+            for(int j= TEST_SCALE - 2; j >= 1; j--) {
+                s.add(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);
+            assertNotNull(symbolicName + " must be found", s);
+            Iterator<RegisteredResource> it = s.iterator();
+            for(int j= TEST_SCALE - 2; j >= 1; j--) {
+                RegisteredResource r = it.next();
+                assertNotNull("RegisteredResource " + j + " must be found");
+                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);
+        }
+    }
+    
+    private String getFakeVersion(int i, int j) {
+        return j + "." + i + ".0";
+    }
+}

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

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

Added: 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=824840&view=auto
==============================================================================
--- sling/trunk/installer/osgi/it/src/test/java/org/apache/sling/osgi/installer/it/RemovedResourceDetectionTest.java
(added)
+++ sling/trunk/installer/osgi/it/src/test/java/org/apache/sling/osgi/installer/it/RemovedResourceDetectionTest.java
Tue Oct 13 16:49:33 2009
@@ -0,0 +1,86 @@
+/*
+ * 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.util.ArrayList;
+import java.util.List;
+
+import org.apache.sling.osgi.installer.InstallableResource;
+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;
+
+/** Verify that the removal of resources is detected even if
+ *  the OsgiController was stopped when resource was removed.
+ */
+@RunWith(JUnit4TestRunner.class)
+public class RemovedResourceDetectionTest 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 testRemoveResourceAndRestart() throws Exception {
+        
+        final String symbolicNameA = "osgi-installer-testbundle";
+        final String symbolicNameB = "osgi-installer-testB";
+        
+        // Install two bundles and verify
+        assertNull(symbolicNameA + " must be absent before installing", findBundle(symbolicNameA));
+        resetCounters();
+        installer.addResource(getInstallableResource(
+                getTestBundle(BUNDLE_BASE_NAME + "-testbundle-1.1.jar")));
+        waitForInstallerAction(OsgiInstaller.WORKER_THREAD_BECOMES_IDLE_COUNTER, 1);
+        assertBundle("After initial install", symbolicNameA, "1.1", Bundle.ACTIVE);
+        
+        assertNull(symbolicNameB + " must be absent before installing", findBundle(symbolicNameB));
+        resetCounters();
+        installer.addResource(getInstallableResource(
+                getTestBundle(BUNDLE_BASE_NAME + "-testB-1.0.jar")));
+        waitForInstallerAction(OsgiInstaller.WORKER_THREAD_BECOMES_IDLE_COUNTER, 1);
+        assertBundle("After initial install", symbolicNameB, "1.0", Bundle.ACTIVE);
+        
+        // Restart installer, register only second bundle and verify that first one is gone
+        restartInstaller();
+        resetCounters();
+        final List<InstallableResource> data = new ArrayList<InstallableResource>();
+        data.add(getInstallableResource(getTestBundle(BUNDLE_BASE_NAME + "-testB-1.0.jar")));
+        installer.registerResources(data, URL_SCHEME);
+        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));
+    }
+}
\ No newline at end of file

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

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



Mime
View raw message