incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bdelacre...@apache.org
Subject svn commit: r805838 - in /sling/trunk/installer/osgi: installer/src/main/java/org/apache/sling/osgi/installer/impl/ it/src/test/java/org/apache/sling/osgi/installer/it/
Date Wed, 19 Aug 2009 15:30:05 GMT
Author: bdelacretaz
Date: Wed Aug 19 15:30:04 2009
New Revision: 805838

URL: http://svn.apache.org/viewvc?rev=805838&view=rev
Log:
SLING-1078 - all integration tests from take three re-activated and all pass

Added:
    sling/trunk/installer/osgi/it/src/test/java/org/apache/sling/osgi/installer/it/BundleDependenciesTest.java
  (with props)
    sling/trunk/installer/osgi/it/src/test/java/org/apache/sling/osgi/installer/it/BundleInstallUpgradeDowngradeTest.java
      - copied, changed from r805815, 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/BundleStartRetriesTest.java
  (with props)
    sling/trunk/installer/osgi/it/src/test/java/org/apache/sling/osgi/installer/it/BundleStatePreservedTest.java
  (with props)
Removed:
    sling/trunk/installer/osgi/it/src/test/java/org/apache/sling/osgi/installer/it/BundleInstallTest.java
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/OsgiInstallerThread.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/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=805838&r1=805837&r2=805838&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
Wed Aug 19 15:30:04 2009
@@ -89,8 +89,7 @@
 		if(getLogService() != null) {
 			getLogService().log(LogService.LOG_DEBUG, "adding task to next cycle:" + t);
 		}
-		// TODO
-		//tasksForNextCycle.add(t);
+		installerThread.addTaskToNextCycle(t);
 	}
 
 	public BundleContext getBundleContext() {

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=805838&r1=805837&r2=805838&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
Wed Aug 19 15:30:04 2009
@@ -18,11 +18,11 @@
  */
 package org.apache.sling.osgi.installer.impl;
 
+import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
-import java.util.Set;
 import java.util.SortedSet;
 import java.util.TreeSet;
 
@@ -42,6 +42,7 @@
     private final OsgiInstallerContext ctx;
     private final List<RegisteredResource> newResources = new LinkedList<RegisteredResource>();
     private final SortedSet<OsgiInstallerTask> tasks = new TreeSet<OsgiInstallerTask>();
+    private final SortedSet<OsgiInstallerTask> tasksForNextCycle = new TreeSet<OsgiInstallerTask>();
     
     /** Group our RegisteredResource by OSGi entity */ 
     private Map<String, SortedSet<RegisteredResource>>registeredResources = 
@@ -121,6 +122,12 @@
             newResources.clear();
         }
     }
+    
+    void addTaskToNextCycle(OsgiInstallerTask t) {
+        synchronized (tasksForNextCycle) {
+            tasksForNextCycle.add(t);
+        }
+    }
 
     /** Factored out to use the exact same structure in tests */
     static SortedSet<RegisteredResource> createRegisteredResourcesEntry() {
@@ -128,8 +135,22 @@
     }
     
     
-    /** Compute OSGi tasks based on our resources, and add to supplied list of tasks */
-    void computeTasks() {
+    /** Compute OSGi tasks based on our resources, and add to supplied list of tasks */ 
+    void computeTasks() throws Exception {
+        // Add tasks that were scheduled for next cycle and are executable now
+        final List<OsgiInstallerTask> toKeep = new ArrayList<OsgiInstallerTask>();
+        synchronized (tasksForNextCycle) {
+            for(OsgiInstallerTask t : tasksForNextCycle) {
+                if(t.isExecutable(ctx)) {
+                    tasks.add(t);
+                } else {
+                    toKeep.add(t);
+                }
+            }
+            tasksForNextCycle.clear();
+            tasksForNextCycle.addAll(toKeep);
+        }
+        
         // Walk the list of entities, and create appropriate OSGi tasks for each group
         for(SortedSet<RegisteredResource> group : registeredResources.values()) {
             if(group.first().getResourceType().equals(RegisteredResource.ResourceType.BUNDLE))
{

Added: sling/trunk/installer/osgi/it/src/test/java/org/apache/sling/osgi/installer/it/BundleDependenciesTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/osgi/it/src/test/java/org/apache/sling/osgi/installer/it/BundleDependenciesTest.java?rev=805838&view=auto
==============================================================================
--- sling/trunk/installer/osgi/it/src/test/java/org/apache/sling/osgi/installer/it/BundleDependenciesTest.java
(added)
+++ sling/trunk/installer/osgi/it/src/test/java/org/apache/sling/osgi/installer/it/BundleDependenciesTest.java
Wed Aug 19 15:30:04 2009
@@ -0,0 +1,81 @@
+/*
+ * 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.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+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;
+
+@RunWith(JUnit4TestRunner.class)
+public class BundleDependenciesTest 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();
+    }
+    
+    // needsB bundle requires testB, try loading needsB first,
+    // then testB, and verify that in the end needsB is started     
+    @Test
+    public void testBundleDependencies() throws Exception {
+        final String testB = "osgi-installer-testB";
+        final String needsB = "osgi-installer-needsB";
+        
+        assertNull("TestB bundle must not be present at beginning of test", findBundle(testB));
+        
+        // without testB, needsB must not start
+        {
+            resetCounters();
+            installer.addResource(getInstallableResource(getTestBundle(BUNDLE_BASE_NAME +
"-needsB.jar")));
+            waitForInstallerAction(OsgiInstaller.OSGI_TASKS_COUNTER, 2);
+            final Bundle b = findBundle(needsB);
+            assertNotNull(needsB + " must be installed", b);
+            assertFalse(needsB + " must not be started, testB not present", b.getState()
== Bundle.ACTIVE);
+        }
+        
+       // now install testB -> needsB must start
+        {
+            resetCounters();
+            installer.addResource(getInstallableResource(getTestBundle(BUNDLE_BASE_NAME +
"-testB-1.0.jar")));
+            waitForInstallerAction(OsgiInstaller.OSGI_TASKS_COUNTER, 2);
+            assertNotNull(testB + " must be installed", findBundle(testB));
+            final Bundle b = findBundle(needsB);
+            assertNotNull(needsB + " must still be installed", b);
+            assertTrue(needsB + " must be started now that testB is installed", b.getState()
== Bundle.ACTIVE);
+        }
+    }
+}
\ No newline at end of file

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

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

Copied: sling/trunk/installer/osgi/it/src/test/java/org/apache/sling/osgi/installer/it/BundleInstallUpgradeDowngradeTest.java
(from r805815, 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/BundleInstallUpgradeDowngradeTest.java?p2=sling/trunk/installer/osgi/it/src/test/java/org/apache/sling/osgi/installer/it/BundleInstallUpgradeDowngradeTest.java&p1=sling/trunk/installer/osgi/it/src/test/java/org/apache/sling/osgi/installer/it/BundleInstallTest.java&r1=805815&r2=805838&rev=805838&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/BundleInstallUpgradeDowngradeTest.java
Wed Aug 19 15:30:04 2009
@@ -28,9 +28,10 @@
 import org.ops4j.pax.exam.Option;
 import org.ops4j.pax.exam.junit.JUnit4TestRunner;
 import org.osgi.framework.Bundle;
+import org.osgi.framework.Constants;
 
 @RunWith(JUnit4TestRunner.class)
-public class BundleInstallTest extends OsgiInstallerTestBase {
+public class BundleInstallUpgradeDowngradeTest extends OsgiInstallerTestBase {
 
     @org.ops4j.pax.exam.junit.Configuration
     public static Option[] configuration() {
@@ -50,7 +51,6 @@
 	@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;
     	
@@ -62,7 +62,7 @@
             assertNull("Test bundle must be absent before installing", findBundle(symbolicName));
     	    resetCounters();
     	    installer.addResource(getInstallableResource(
-    	            getTestBundle("org.apache.sling.osgi.installer.it-" + POM_VERSION + "-testbundle-1.1.jar")));
+    	            getTestBundle(BUNDLE_BASE_NAME + "-testbundle-1.1.jar")));
     	    // wait for two tasks: install and start
     	    waitForInstallerAction(OsgiInstaller.OSGI_TASKS_COUNTER, 2);
     	    final Bundle b = findBundle(symbolicName);
@@ -78,7 +78,7 @@
     	{
     	    resetCounters();
             installer.addResource(getInstallableResource(
-                    getTestBundle("org.apache.sling.osgi.installer.it-" + POM_VERSION + "-testbundle-1.2.jar")));
+                    getTestBundle(BUNDLE_BASE_NAME + "-testbundle-1.2.jar")));
             // wait for two tasks: update (includes stop) and start
             waitForInstallerAction(OsgiInstaller.OSGI_TASKS_COUNTER, 2);
         	final Bundle b = findBundle(symbolicName);
@@ -94,7 +94,7 @@
         {
             resetCounters();
             installer.addResource(getInstallableResource(
-                    getTestBundle("org.apache.sling.osgi.installer.it-" + POM_VERSION + "-testbundle-1.0.jar")));
+                    getTestBundle(BUNDLE_BASE_NAME + "-testbundle-1.0.jar")));
             
             // wait for two cycles to make sure no updates happen
             waitForInstallerAction(OsgiInstaller.INSTALLER_CYCLES_COUNTER, 2);
@@ -111,11 +111,11 @@
     	{
             resetCounters();
             installer.removeResource(getInstallableResource(
-                    getTestBundle("org.apache.sling.osgi.installer.it-" + POM_VERSION + "-testbundle-1.0.jar")));
+                    getTestBundle(BUNDLE_BASE_NAME + "-testbundle-1.0.jar")));
             installer.removeResource(getInstallableResource(
-                    getTestBundle("org.apache.sling.osgi.installer.it-" + POM_VERSION + "-testbundle-1.1.jar")));
+                    getTestBundle(BUNDLE_BASE_NAME + "-testbundle-1.1.jar")));
             installer.removeResource(getInstallableResource(
-                    getTestBundle("org.apache.sling.osgi.installer.it-" + POM_VERSION + "-testbundle-1.2.jar")));
+                    getTestBundle(BUNDLE_BASE_NAME + "-testbundle-1.2.jar")));
             
             // wait for one task: uninstall
             waitForInstallerAction(OsgiInstaller.OSGI_TASKS_COUNTER, 1);
@@ -132,146 +132,16 @@
         {
             resetCounters();
             installer.addResource(getInstallableResource(
-                    getTestBundle("org.apache.sling.osgi.installer.it-" + POM_VERSION + "-testbundle-1.1.jar")));
+                    getTestBundle(BUNDLE_BASE_NAME + "-testbundle-1.1.jar")));
             // wait for two tasks: install and start
             waitForInstallerAction(OsgiInstaller.OSGI_TASKS_COUNTER, 2);
             final Bundle b = findBundle(symbolicName);
             assertNotNull("Reinstalled test bundle 1.1 must be found after waitForInstallerAction",
b);
             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));
+            assertEquals("Reinstalled bundle version must be 1.1", "1.1", b.getHeaders().get(Constants.BUNDLE_VERSION));
         }
-        
-    	assertNoOsgiTasks("After test " + testIndex++);
-    }
-	
-    /** TODO
-    @Test
-    public void testBundleStatePreserved() throws Exception {
-    	final OsgiInstaller c = getService(OsgiInstaller.class);
-    	
-    	// Install two bundles, one started, one stopped
-    	{
-        	c.scheduleInstallOrUpdate("otherBundleA.jar", 
-        			new FileInstallableResource(getTestBundle("org.apache.sling.osgi.installer.it-"
+ POM_VERSION + "-testA-1.0.jar")));
-        	c.waitForInstallerAction();
-    	}
-    	{
-        	c.scheduleInstallOrUpdate("testB.jar", 
-        			new FileInstallableResource(getTestBundle("org.apache.sling.osgi.installer.it-"
+ POM_VERSION + "-testB-1.0.jar")));
-        	c.waitForInstallerAction();
-        	final Bundle b = findBundle("osgi-installer-testB");
-        	assertNotNull("Test bundle must be found", b);
-        	b.stop();
-    	}
-    	
-    	assertEquals("Bundle A must be started", Bundle.ACTIVE, findBundle("osgi-installer-testA").getState());
-    	assertEquals("Bundle B must be stopped", Bundle.RESOLVED, findBundle("osgi-installer-testB").getState());
-    	
-    	// Execute some OsgiController operations
-    	final String symbolicName = "osgi-installer-testbundle";
-    	final String uri = symbolicName + JAR_EXT;
-    	final String BUNDLE_VERSION = "Bundle-Version";
-    	c.scheduleInstallOrUpdate(uri, 
-    			new FileInstallableResource(getTestBundle("org.apache.sling.osgi.installer.it-" +
POM_VERSION + "-testbundle-1.1.jar")));
-    	c.waitForInstallerAction();
-    	c.scheduleInstallOrUpdate(uri, 
-    			new FileInstallableResource(getTestBundle("org.apache.sling.osgi.installer.it-" +
POM_VERSION + "-testbundle-1.2.jar")));
-    	c.waitForInstallerAction();
-    	c.scheduleInstallOrUpdate(uri, 
-    			new FileInstallableResource(getTestBundle("org.apache.sling.osgi.installer.it-" +
POM_VERSION + "-testbundle-1.0.jar")));
-    	c.waitForInstallerAction();
-    	final Bundle b = findBundle(symbolicName);
-    	assertNotNull("Installed bundle must be found", b);
-    	assertEquals("Installed bundle must be started", Bundle.ACTIVE, b.getState());
-    	assertEquals("Version must be 1.2", "1.2", b.getHeaders().get(BUNDLE_VERSION));
-    	
-    	// And check that bundles A and B have kept their states
-    	assertEquals("Bundle A must be started", Bundle.ACTIVE, findBundle("osgi-installer-testA").getState());
-    	assertEquals("Bundle B must be stopped", Bundle.RESOLVED, findBundle("osgi-installer-testB").getState());
-    }
-    
-    // needsB bundle requires testB, try loading needsB first,
-	// then testB, and verify that in the end needsB is started 	
-    @Test
-    public void testBundleDependencies() throws Exception {
-    	final OsgiInstaller c = getService(OsgiInstaller.class);
-    	
-    	final String testB = "osgi-installer-testB";
-    	final String needsB = "osgi-installer-needsB";
-    	
-    	{
-        	final Bundle b = findBundle(testB);
-        	if(b != null) {
-        		c.scheduleUninstall(testB + JAR_EXT);
-        		c.waitForInstallerAction();
-        	}
-        	assertNull(testB + " bundle must not be installed before test", findBundle(testB));
-    	}
-    	
-    	// without testB, needsB must not start
-    	{
-        	c.scheduleInstallOrUpdate(needsB + JAR_EXT,
-        			new FileInstallableResource(getTestBundle("org.apache.sling.osgi.installer.it-"
+ POM_VERSION + "-needsB.jar")));
-        	c.waitForInstallerAction();
-        	final Bundle b = findBundle(needsB);
-        	assertNotNull(needsB + " must be installed", b);
-        	assertFalse(needsB + " must not be started, testB not present", b.getState() ==
Bundle.ACTIVE);
-    	}
-    	
-    	// Check SLING-1042 retry rules
-    	assertTrue("OsgiController must implement OsgiControllerStatistics", c instanceof OsgiControllerStatistics);
-    	final OsgiControllerStatistics stats = (OsgiControllerStatistics)c;
-    	
-    	{
-    	    long n = stats.getExecutedTasksCount();
-    	    c.waitForInstallerAction();
-            assertTrue("First retry must not wait for an event", stats.getExecutedTasksCount()
> n);
-            n = stats.getExecutedTasksCount();
-            c.waitForInstallerAction();
-    	    assertEquals("Retrying before a bundle event happens must not execute any OsgiControllerTask",
n, stats.getExecutedTasksCount());
-    	    
-            n = stats.getExecutedTasksCount();
-    	    generateBundleEvent();
-            c.waitForInstallerAction();
-            assertTrue("Retrying after a bundle event must execute at least one OsgiControllerTask",
stats.getExecutedTasksCount() > n);
-    	}
-    	
-    	{
-    	    // wait until no more events are received
-            final long timeout = System.currentTimeMillis() + 2000L;
-            while(System.currentTimeMillis() < timeout) {
-                final long n = stats.getExecutedTasksCount();
-                c.waitForInstallerAction();
-                if(n == stats.getExecutedTasksCount()) {
-                    break;
-                }
-                Thread.sleep(10L);
-            }
-            
-            if(System.currentTimeMillis() >= timeout) {
-                fail("Retries did not stop within specified time");
-            }
-    	}
-    	
-        {
-            long n = stats.getExecutedTasksCount();
-            c.waitForInstallerAction();
-            assertEquals("Retrying before a framework event happens must not execute any
OsgiControllerTask", n, stats.getExecutedTasksCount());
-            refreshPackages();
-            c.waitForInstallerAction();
-            assertTrue("Retrying after framework event must execute at least one OsgiControllerTask",
stats.getExecutedTasksCount() > n);
-        }
-        
-    	// now install testB -> needsB must start
-    	{
-        	c.scheduleInstallOrUpdate(testB + JAR_EXT,
-        			new FileInstallableResource(getTestBundle("org.apache.sling.osgi.installer.it-"
+ POM_VERSION + "-testB-1.0.jar")));
-        	c.waitForInstallerAction();
-        	final Bundle b = findBundle(needsB);
-        	assertNotNull(needsB + " must be installed", b);
-        	assertTrue(needsB + " must be started now that testB is installed", b.getState()
== Bundle.ACTIVE);
-    	}
-    }
-    */
-}
+
+        assertNoOsgiTasks("After test " + testIndex++);
+	}
+}
\ No newline at end of file

Added: sling/trunk/installer/osgi/it/src/test/java/org/apache/sling/osgi/installer/it/BundleStartRetriesTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/osgi/it/src/test/java/org/apache/sling/osgi/installer/it/BundleStartRetriesTest.java?rev=805838&view=auto
==============================================================================
--- sling/trunk/installer/osgi/it/src/test/java/org/apache/sling/osgi/installer/it/BundleStartRetriesTest.java
(added)
+++ sling/trunk/installer/osgi/it/src/test/java/org/apache/sling/osgi/installer/it/BundleStartRetriesTest.java
Wed Aug 19 15:30:04 2009
@@ -0,0 +1,67 @@
+package org.apache.sling.osgi.installer.it;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+
+import org.apache.sling.osgi.installer.OsgiInstaller;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.Option;
+import org.ops4j.pax.exam.junit.JUnit4TestRunner;
+import org.osgi.framework.Bundle;
+
+/** Test the bundle start retries logic of SLING-1042 */
+@RunWith(JUnit4TestRunner.class)
+public class BundleStartRetriesTest 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 testBundleStartRetries() throws Exception {
+        final String testB = "osgi-installer-testB";
+        final String needsB = "osgi-installer-needsB";
+        
+        assertNull("TestB bundle must not be present at beginning of test", findBundle(testB));
+        
+        // without testB, needsB must not start
+        resetCounters();
+        final long nOps = installer.getCounters()[OsgiInstaller.OSGI_TASKS_COUNTER];
+        installer.addResource(getInstallableResource(getTestBundle(BUNDLE_BASE_NAME + "-needsB.jar")));
+        waitForInstallerAction(OsgiInstaller.OSGI_TASKS_COUNTER, 2);
+        Bundle b = findBundle(needsB);
+        assertNotNull(needsB + " must be installed", b);
+        assertFalse(needsB + " must not be started, testB not present", b.getState() == Bundle.ACTIVE);
+        
+        // the bundle start task must be retried immediately
+        // (== 3 tasks since last counters reset)
+        waitForInstallerAction(OsgiInstaller.OSGI_TASKS_COUNTER, 3);
+        
+        // and no more retries must happen before receiving a bundle event 
+        waitForInstallerAction(OsgiInstaller.INSTALLER_CYCLES_COUNTER, 2);
+        assertEquals("Exactly 3 OSGi tasks must have been executed after a few installer
cycles",
+                nOps + 3, installer.getCounters()[OsgiInstaller.OSGI_TASKS_COUNTER]);
+
+        // generate a bundle event -> must trigger just one retry
+        generateBundleEvent();
+        waitForInstallerAction(OsgiInstaller.INSTALLER_CYCLES_COUNTER, 3);
+        assertEquals("Exactly 4 OSGi tasks total must have been executed after bundle event
received",
+                nOps + 4, installer.getCounters()[OsgiInstaller.OSGI_TASKS_COUNTER]);
+    }
+
+}

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

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

Added: sling/trunk/installer/osgi/it/src/test/java/org/apache/sling/osgi/installer/it/BundleStatePreservedTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/osgi/it/src/test/java/org/apache/sling/osgi/installer/it/BundleStatePreservedTest.java?rev=805838&view=auto
==============================================================================
--- sling/trunk/installer/osgi/it/src/test/java/org/apache/sling/osgi/installer/it/BundleStatePreservedTest.java
(added)
+++ sling/trunk/installer/osgi/it/src/test/java/org/apache/sling/osgi/installer/it/BundleStatePreservedTest.java
Wed Aug 19 15:30:04 2009
@@ -0,0 +1,97 @@
+/*
+ * 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.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+
+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;
+import org.osgi.framework.Constants;
+
+@RunWith(JUnit4TestRunner.class)
+public class BundleStatePreservedTest 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 testBundleStatePreserved() throws Exception {
+    	// Install two bundles, one started, one stopped
+    	{
+            resetCounters();
+            installer.addResource(getInstallableResource(
+                    getTestBundle(BUNDLE_BASE_NAME + "-testA-1.0.jar")));
+            waitForInstallerAction(OsgiInstaller.OSGI_TASKS_COUNTER, 2);
+    	}
+        {
+            resetCounters();
+            installer.addResource(getInstallableResource(
+                    getTestBundle(BUNDLE_BASE_NAME + "-testB-1.0.jar")));
+            waitForInstallerAction(OsgiInstaller.OSGI_TASKS_COUNTER, 2);
+            final Bundle b = findBundle("osgi-installer-testB");
+            assertNotNull("Test bundle B must be found", b);
+            b.stop();
+        }
+    	
+    	assertEquals("Bundle A must be started", Bundle.ACTIVE, findBundle("osgi-installer-testA").getState());
+    	assertEquals("Bundle B must be stopped", Bundle.RESOLVED, findBundle("osgi-installer-testB").getState());
+    	
+    	// Execute some OsgiController operations
+        installer.addResource(getInstallableResource(getTestBundle(BUNDLE_BASE_NAME + "-testbundle-1.0.jar")));
+        waitForInstallerAction(OsgiInstaller.INSTALLER_CYCLES_COUNTER, 1);
+        installer.addResource(getInstallableResource(getTestBundle(BUNDLE_BASE_NAME + "-testbundle-1.2.jar")));
+        waitForInstallerAction(OsgiInstaller.INSTALLER_CYCLES_COUNTER, 1);
+        installer.addResource(getInstallableResource(getTestBundle(BUNDLE_BASE_NAME + "-testbundle-1.1.jar")));
+        waitForInstallerAction(OsgiInstaller.INSTALLER_CYCLES_COUNTER, 1);
+        
+        final String symbolicName = "osgi-installer-testbundle";
+    	final Bundle b = findBundle(symbolicName);
+    	assertNotNull("Installed bundle must be found", b);
+    	assertEquals("Installed bundle must be started", Bundle.ACTIVE, b.getState());
+    	assertEquals("Version must be 1.2", "1.2", b.getHeaders().get(Constants.BUNDLE_VERSION));
+    	
+        installer.removeResource(getInstallableResource(getTestBundle(BUNDLE_BASE_NAME +
"-testbundle-1.0.jar")));
+        installer.removeResource(getInstallableResource(getTestBundle(BUNDLE_BASE_NAME +
"-testbundle-1.1.jar")));
+        installer.removeResource(getInstallableResource(getTestBundle(BUNDLE_BASE_NAME +
"-testbundle-1.2.jar")));
+        waitForInstallerAction(OsgiInstaller.INSTALLER_CYCLES_COUNTER, 2);
+        assertNull("testbundle must be gone at end of test", findBundle(symbolicName));
+        
+    	// Now check that bundles A and B have kept their states
+    	assertEquals("Bundle A must be started", Bundle.ACTIVE, findBundle("osgi-installer-testA").getState());
+    	assertEquals("Bundle B must be stopped", Bundle.RESOLVED, findBundle("osgi-installer-testB").getState());
+    }
+}
\ No newline at end of file

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

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

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=805838&r1=805837&r2=805838&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 15:30:04 2009
@@ -56,7 +56,8 @@
 	protected OsgiInstaller installer;
 	private long [] counters;
 	public static final long WAIT_FOR_ACTION_TIMEOUT_MSEC = 5000;
-	
+    public static final String BUNDLE_BASE_NAME = "org.apache.sling.osgi.installer.it-" +
POM_VERSION;
+    
     @Inject
     protected BundleContext bundleContext;
     
@@ -206,6 +207,11 @@
     }
     
     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(counterType == OsgiInstaller.INSTALLER_CYCLES_COUNTER) {
+            resetCounters();
+        }
         final long targetValue = counters[counterType] + howMany;
         final long endTime = System.currentTimeMillis() + WAIT_FOR_ACTION_TIMEOUT_MSEC;
         long lastValue = 0;



Mime
View raw message