Author: bdelacretaz
Date: Wed Aug 19 10:17:55 2009
New Revision: 805730

URL: http://svn.apache.org/viewvc?rev=805730&view=rev
Log:
SLING-1078 - 'Reinstall lower version' integration test passes

Modified:
    
sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/OsgiInstallerTask.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/it/pom.xml
    
sling/trunk/installer/osgi/it/src/test/java/org/apache/sling/osgi/installer/it/BundleInstallTest.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/OsgiInstallerTask.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/OsgiInstallerTask.java?rev=805730&r1=805729&r2=805730&view=diff
==============================================================================
--- 
sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/OsgiInstallerTask.java
 (original)
+++ 
sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/OsgiInstallerTask.java
 Wed Aug 19 10:17:55 2009
@@ -18,10 +18,16 @@
  */
 package org.apache.sling.osgi.installer.impl;
 
+import org.osgi.service.log.LogService;
+
 /** Base class for tasks that can be executed by the {...@link 
OsgiInstallerImpl} */ 
 public abstract class OsgiInstallerTask implements 
Comparable<OsgiInstallerTask> {
        /** Execute this task */
-       public abstract void execute(OsgiInstallerContext ctx) throws Exception;
+       public void execute(OsgiInstallerContext ctx) throws Exception {
+               if(ctx.getLogService() != null) {
+                       ctx.getLogService().log(LogService.LOG_DEBUG, 
"Executing task " + this);
+               }
+       }
        
        /** Tasks are sorted according to this key */
        public abstract String getSortKey();

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=805730&r1=805729&r2=805730&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
 Wed Aug 19 10:17:55 2009
@@ -32,6 +32,11 @@
         this.resource = r;
     }
     
+    @Override 
+    public String toString() {
+       return getClass().getSimpleName() + ": " + resource;
+    }
+    
     @Override
     public void execute(OsgiInstallerContext ctx) throws Exception {
         final Bundle b = 
ctx.getBundleContext().installBundle(resource.getUrl(), 
resource.getInputStream());

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=805730&r1=805729&r2=805730&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
 Wed Aug 19 10:17:55 2009
@@ -36,6 +36,11 @@
         this.resource = r;
     }
     
+    @Override 
+    public String toString() {
+       return getClass().getSimpleName() + ": " + resource;
+    }
+    
     @Override
     public void execute(OsgiInstallerContext ctx) throws Exception {
         final String symbolicName = 
(String)resource.getAttributes().get(Constants.BUNDLE_SYMBOLICNAME);

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=805730&r1=805729&r2=805730&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
 Wed Aug 19 10:17:55 2009
@@ -48,7 +48,7 @@
 
        @Override
        public String toString() {
-               return getClass().getSimpleName() + " (bundle " + bundleId + 
")";
+               return getClass().getSimpleName() + ": bundle " + bundleId;
        }
 
        public void execute(OsgiInstallerContext tctx) throws Exception {

Modified: sling/trunk/installer/osgi/it/pom.xml
URL: 
http://svn.apache.org/viewvc/sling/trunk/installer/osgi/it/pom.xml?rev=805730&r1=805729&r2=805730&view=diff
==============================================================================
--- sling/trunk/installer/osgi/it/pom.xml (original)
+++ sling/trunk/installer/osgi/it/pom.xml Wed Aug 19 10:17:55 2009
@@ -34,6 +34,7 @@
     <description>Integration tests of the Sling OSGi installer 
bundle</description>
   
   <properties>
+    <pax.exam.log.level>INFO</pax.exam.log.level>
     <!-- This can be set to activate remote debugging of the Pax Exam tests -->
     <pax.exam.debug.port></pax.exam.debug.port>
   </properties>
@@ -73,6 +74,10 @@
                             <value>${pom.version}</value>
                         </property>
                         <property>
+                            <name>pax.exam.log.level</name>
+                            <value>${pax.exam.log.level}</value>
+                        </property>
+                        <property>
                             <name>pax.exam.debug.port</name>
                             <value>${pax.exam.debug.port}</value>
                         </property>

Modified: 
sling/trunk/installer/osgi/it/src/test/java/org/apache/sling/osgi/installer/it/BundleInstallTest.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/installer/osgi/it/src/test/java/org/apache/sling/osgi/installer/it/BundleInstallTest.java?rev=805730&r1=805729&r2=805730&view=diff
==============================================================================
--- 
sling/trunk/installer/osgi/it/src/test/java/org/apache/sling/osgi/installer/it/BundleInstallTest.java
 (original)
+++ 
sling/trunk/installer/osgi/it/src/test/java/org/apache/sling/osgi/installer/it/BundleInstallTest.java
 Wed Aug 19 10:17:55 2009
@@ -19,7 +19,6 @@
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertFalse;
 
 import org.apache.sling.osgi.installer.OsgiInstaller;
 import org.junit.After;
@@ -47,12 +46,13 @@
     public void tearDown() {
         super.tearDown();
     }
-
+    
        @Test
     public void testInstallUpgradeDowngradeBundle() throws Exception {
        final String symbolicName = "osgi-installer-testbundle";
        final String uri = symbolicName + JAR_EXT;
        final String BUNDLE_VERSION = "Bundle-Version";
+       int testIndex = 0;
        
        assertNull("Test bundle must not be present before test", 
findBundle(symbolicName));
        
@@ -71,6 +71,8 @@
                assertEquals("Installed bundle must be started", Bundle.ACTIVE, 
b.getState());
                assertEquals("Version must be 1.1", "1.1", 
b.getHeaders().get(BUNDLE_VERSION));
        }
+       
+       assertNoOsgiTasks("After test " + testIndex++);
 
        // Upgrade to later version, verify
        {
@@ -86,6 +88,8 @@
                assertEquals("Bundle ID must not change after update", 
bundleId, b.getBundleId());
        }
 
+       assertNoOsgiTasks("After test " + testIndex++);
+       
        // Downgrade to lower version, installed bundle must not change
         {
             resetCounters();
@@ -101,6 +105,8 @@
             assertEquals("Bundle ID must not change after ignored downgrade", 
bundleId, b.getBundleId());
         }
        
+       assertNoOsgiTasks("After test " + testIndex++);
+       
        // Uninstall
        {
             resetCounters();
@@ -115,9 +121,13 @@
             waitForInstallerAction(OsgiInstaller.OSGI_TASKS_COUNTER, 1);
             final Bundle b = findBundle(symbolicName);
             assertNull("Bundle must be gone", b);
+            
+            // uninstall task generates package refresh and a number of bundle 
start tasks, consume these
+            waitForInstallerAction(OsgiInstaller.INSTALLER_CYCLES_COUNTER, 2);
        }
        
-       /** TODO
+       assertNoOsgiTasks("After test " + testIndex++);
+       
        // Reinstall lower version, must work
         {
             resetCounters();
@@ -130,14 +140,12 @@
             bundleId = b.getBundleId();
             assertEquals("Reinstalled bundle must be started", Bundle.ACTIVE, 
b.getState());
             assertEquals("Reinstalled bundle version must be 1.1", "1.1", 
b.getHeaders().get(BUNDLE_VERSION));
-            assertFalse("Bundle ID must have changed after uninstall and 
reinstall", bundleId == b.getBundleId());
         }
-        */
         
+       assertNoOsgiTasks("After test " + testIndex++);
     }
        
-       /** TODO
-    
+    /** TODO
     @Test
     public void testBundleStatePreserved() throws Exception {
        final OsgiInstaller c = getService(OsgiInstaller.class);

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=805730&r1=805729&r2=805730&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
 Wed Aug 19 10:17:55 2009
@@ -17,13 +17,16 @@
 package org.apache.sling.osgi.installer.it;
 
 import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.fail;
 import static org.ops4j.pax.exam.CoreOptions.felix;
 import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
 import static org.ops4j.pax.exam.CoreOptions.options;
 import static org.ops4j.pax.exam.CoreOptions.provision;
 import static org.ops4j.pax.exam.CoreOptions.waitForFrameworkStartup;
+import static org.ops4j.pax.exam.CoreOptions.systemProperty;
 import static org.ops4j.pax.exam.container.def.PaxRunnerOptions.vmOption;
+import static org.ops4j.pax.exam.container.def.PaxRunnerOptions.logProfile;
 
 import java.io.File;
 import java.io.FileInputStream;
@@ -218,6 +221,14 @@
                 + ", expected value " + targetValue + ", actual " + lastValue);
     }
     
+    /** Verify that no OSGi actions are executed in next two installer cycles 
*/
+    protected void assertNoOsgiTasks(String info) {
+       final long actionsCounter = 
installer.getCounters()[OsgiInstaller.OSGI_TASKS_COUNTER];
+       waitForInstallerAction(OsgiInstaller.INSTALLER_CYCLES_COUNTER, 2);
+       assertEquals(info + ": OSGi tasks counter should not have changed", 
+                       actionsCounter, 
installer.getCounters()[OsgiInstaller.OSGI_TASKS_COUNTER]);
+    }
+    
     public static Option[] defaultConfiguration() {
        String vmOpt = "-Dosgi.installer.testing";
        
@@ -231,6 +242,7 @@
        }
 
        // optional debugging
+       final String paxDebugLevel = System.getProperty("pax.exam.log.level");
        final String paxDebugPort = System.getProperty("pax.exam.debug.port");
        if(paxDebugPort != null && paxDebugPort.length() > 0) {
                vmOpt += " 
-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=" + paxDebugPort; 
@@ -240,7 +252,11 @@
                 felix(),
                 vmOption(vmOpt),
                 waitForFrameworkStartup(),
-                       provision(
+                
+                logProfile(),
+                systemProperty( 
"org.ops4j.pax.logging.DefaultServiceLog.level" ).value(paxDebugLevel),
+                
+                provision(
                            mavenBundle("org.apache.felix", 
"org.apache.felix.scr"),
                            mavenBundle("org.apache.felix", 
"org.apache.felix.configadmin"),
                            mavenBundle("org.apache.sling", 
"org.apache.sling.commons.log"),


Reply via email to