Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Watson2010-04-02 12:07:09 -0400
committerThomas Watson2010-04-02 12:07:09 -0400
commit0600072aabc6267c58631637ac8efb9585cb1971 (patch)
tree7bc15972c934fb67b6eaa530f440e34fc7f54851
parent45fad02a992a4e0f6e6eae32a7a177b82da74878 (diff)
downloadrt.equinox.framework-0600072aabc6267c58631637ac8efb9585cb1971.tar.gz
rt.equinox.framework-0600072aabc6267c58631637ac8efb9585cb1971.tar.xz
rt.equinox.framework-0600072aabc6267c58631637ac8efb9585cb1971.zip
Bug 300820 - Failure in testBug289719 on I20100125-0800 build
-rw-r--r--bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/PackageAdminBundleTests.java71
-rw-r--r--bundles/org.eclipse.osgi/core/framework/org/eclipse/osgi/framework/internal/core/StartLevelManager.java9
2 files changed, 64 insertions, 16 deletions
diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/PackageAdminBundleTests.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/PackageAdminBundleTests.java
index 3280d32d1..de074ba2f 100644
--- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/PackageAdminBundleTests.java
+++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/PackageAdminBundleTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2009 IBM Corporation and others.
+ * Copyright (c) 2007, 2010 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -10,8 +10,11 @@
*******************************************************************************/
package org.eclipse.osgi.tests.bundles;
+import java.io.PrintWriter;
+import java.io.StringWriter;
import java.net.URL;
import java.util.ArrayList;
+import java.util.Arrays;
import junit.framework.Test;
import junit.framework.TestSuite;
import org.eclipse.osgi.tests.OSGiTestsActivator;
@@ -35,6 +38,37 @@ public class PackageAdminBundleTests extends AbstractBundleTests {
}
}
+ public class Bug289719Listener implements SynchronousBundleListener {
+
+ ArrayList expectedEvents = new ArrayList();
+ ArrayList failures = new ArrayList();
+ int i = 0;
+
+ public synchronized void setExpectedEvents(BundleEvent[] events) {
+ i = 0;
+ failures.clear();
+ expectedEvents.clear();
+ expectedEvents.addAll(Arrays.asList(events));
+ }
+
+ public synchronized void bundleChanged(BundleEvent event) {
+ BundleEvent expected = expectedEvents.size() == 0 ? null : (BundleEvent) expectedEvents.remove(0);
+ try {
+ assertEquals("Compare results: " + i, expected, event);
+ } catch (Throwable t) {
+ failures.add(t);
+ } finally {
+ i++;
+ }
+ }
+
+ public synchronized Throwable[] getFailures() {
+ Throwable[] results = (Throwable[]) failures.toArray(new Throwable[failures.size()]);
+ setExpectedEvents(new BundleEvent[0]);
+ return results;
+ }
+ }
+
public static Test suite() {
return new TestSuite(PackageAdminBundleTests.class);
}
@@ -174,8 +208,8 @@ public class PackageAdminBundleTests extends AbstractBundleTests {
Bundle bug259903a = installer.installBundle("test.bug259903.a"); //$NON-NLS-1$
Bundle bug259903b = installer.installBundle("test.bug259903.b"); //$NON-NLS-1$
Bundle bug259903c = installer.installBundle("test.bug259903.c"); //$NON-NLS-1$
- TestListener testListener = new TestListener();
- OSGiTestsActivator.getContext().addBundleListener(testListener);
+ Bug289719Listener testListener = new Bug289719Listener();
+
try {
installer.resolveBundles(new Bundle[] {bug259903a, bug259903b, bug259903c});
bug259903a.start();
@@ -184,22 +218,25 @@ public class PackageAdminBundleTests extends AbstractBundleTests {
installer.getStartLevel().setBundleStartLevel(bug259903c, 2);
installer.getStartLevel().setBundleStartLevel(bug259903b, 3);
installer.getStartLevel().setBundleStartLevel(bug259903a, 4);
-
- testListener.getEvents(); // clear events
+ OSGiTestsActivator.getContext().addBundleListener(testListener);
+ BundleEvent[] expectedEvents = new BundleEvent[] {new BundleEvent(BundleEvent.STOPPING, bug259903a), new BundleEvent(BundleEvent.STOPPED, bug259903a), new BundleEvent(BundleEvent.STOPPING, bug259903b), new BundleEvent(BundleEvent.STOPPED, bug259903b), new BundleEvent(BundleEvent.STOPPING, bug259903c), new BundleEvent(BundleEvent.STOPPED, bug259903c), new BundleEvent(BundleEvent.UNRESOLVED, bug259903a), new BundleEvent(BundleEvent.UNRESOLVED, bug259903b), new BundleEvent(BundleEvent.UNRESOLVED, bug259903c), new BundleEvent(BundleEvent.RESOLVED, bug259903c), new BundleEvent(BundleEvent.RESOLVED, bug259903b), new BundleEvent(BundleEvent.RESOLVED, bug259903a), new BundleEvent(BundleEvent.STARTING, bug259903c), new BundleEvent(BundleEvent.STARTED, bug259903c),
+ new BundleEvent(BundleEvent.STARTING, bug259903b), new BundleEvent(BundleEvent.STARTED, bug259903b), new BundleEvent(BundleEvent.STARTING, bug259903a), new BundleEvent(BundleEvent.STARTED, bug259903a)};
+ testListener.setExpectedEvents(expectedEvents);
installer.refreshPackages(new Bundle[] {bug259903a});
- Object[] expectedEvents = new Object[] {new BundleEvent(BundleEvent.STOPPING, bug259903a), new BundleEvent(BundleEvent.STOPPED, bug259903a), new BundleEvent(BundleEvent.STOPPING, bug259903b), new BundleEvent(BundleEvent.STOPPED, bug259903b), new BundleEvent(BundleEvent.STOPPING, bug259903c), new BundleEvent(BundleEvent.STOPPED, bug259903c), new BundleEvent(BundleEvent.UNRESOLVED, bug259903a), new BundleEvent(BundleEvent.UNRESOLVED, bug259903b), new BundleEvent(BundleEvent.UNRESOLVED, bug259903c), new BundleEvent(BundleEvent.RESOLVED, bug259903c), new BundleEvent(BundleEvent.RESOLVED, bug259903b), new BundleEvent(BundleEvent.RESOLVED, bug259903a), new BundleEvent(BundleEvent.STARTING, bug259903c), new BundleEvent(BundleEvent.STARTED, bug259903c),
- new BundleEvent(BundleEvent.STARTING, bug259903b), new BundleEvent(BundleEvent.STARTED, bug259903b), new BundleEvent(BundleEvent.STARTING, bug259903a), new BundleEvent(BundleEvent.STARTED, bug259903a),};
- Object[] actualEvents = testListener.getEvents();
- compareResults(expectedEvents, actualEvents);
+ Throwable[] results = testListener.getFailures();
+ if (results.length > 0)
+ fail(getMessage(results));
+ expectedEvents = new BundleEvent[] {new BundleEvent(BundleEvent.STOPPING, bug259903c), new BundleEvent(BundleEvent.STOPPED, bug259903c), new BundleEvent(BundleEvent.STOPPING, bug259903b), new BundleEvent(BundleEvent.STOPPED, bug259903b), new BundleEvent(BundleEvent.STOPPING, bug259903a), new BundleEvent(BundleEvent.STOPPED, bug259903a), new BundleEvent(BundleEvent.UNRESOLVED, bug259903c), new BundleEvent(BundleEvent.UNRESOLVED, bug259903b), new BundleEvent(BundleEvent.UNRESOLVED, bug259903a), new BundleEvent(BundleEvent.RESOLVED, bug259903a), new BundleEvent(BundleEvent.RESOLVED, bug259903b), new BundleEvent(BundleEvent.RESOLVED, bug259903c), new BundleEvent(BundleEvent.STARTING, bug259903a), new BundleEvent(BundleEvent.STARTED, bug259903a),
+ new BundleEvent(BundleEvent.STARTING, bug259903b), new BundleEvent(BundleEvent.STARTED, bug259903b), new BundleEvent(BundleEvent.STARTING, bug259903c), new BundleEvent(BundleEvent.STARTED, bug259903c)};
+ testListener.setExpectedEvents(expectedEvents);
installer.getStartLevel().setBundleStartLevel(bug259903c, 4);
installer.getStartLevel().setBundleStartLevel(bug259903b, 4);
installer.getStartLevel().setBundleStartLevel(bug259903a, 4);
installer.refreshPackages(new Bundle[] {bug259903a});
- expectedEvents = new Object[] {new BundleEvent(BundleEvent.STOPPING, bug259903c), new BundleEvent(BundleEvent.STOPPED, bug259903c), new BundleEvent(BundleEvent.STOPPING, bug259903b), new BundleEvent(BundleEvent.STOPPED, bug259903b), new BundleEvent(BundleEvent.STOPPING, bug259903a), new BundleEvent(BundleEvent.STOPPED, bug259903a), new BundleEvent(BundleEvent.UNRESOLVED, bug259903c), new BundleEvent(BundleEvent.UNRESOLVED, bug259903b), new BundleEvent(BundleEvent.UNRESOLVED, bug259903a), new BundleEvent(BundleEvent.RESOLVED, bug259903a), new BundleEvent(BundleEvent.RESOLVED, bug259903b), new BundleEvent(BundleEvent.RESOLVED, bug259903c), new BundleEvent(BundleEvent.STARTING, bug259903a), new BundleEvent(BundleEvent.STARTED, bug259903a),
- new BundleEvent(BundleEvent.STARTING, bug259903b), new BundleEvent(BundleEvent.STARTED, bug259903b), new BundleEvent(BundleEvent.STARTING, bug259903c), new BundleEvent(BundleEvent.STARTED, bug259903c),};
- actualEvents = testListener.getEvents();
- compareResults(expectedEvents, actualEvents);
+ results = testListener.getFailures();
+ if (results.length > 0)
+ fail(getMessage(results));
} catch (Exception e) {
fail("Unexpected exception", e); //$NON-NLS-1$
@@ -207,4 +244,12 @@ public class PackageAdminBundleTests extends AbstractBundleTests {
OSGiTestsActivator.getContext().removeBundleListener(testListener);
}
}
+
+ private String getMessage(Throwable[] results) {
+ StringWriter sw = new StringWriter();
+ PrintWriter pw = new PrintWriter(sw);
+ for (int i = 0; i < results.length; i++)
+ results[i].printStackTrace(pw);
+ return sw.toString();
+ }
}
diff --git a/bundles/org.eclipse.osgi/core/framework/org/eclipse/osgi/framework/internal/core/StartLevelManager.java b/bundles/org.eclipse.osgi/core/framework/org/eclipse/osgi/framework/internal/core/StartLevelManager.java
index 5ecc3e39a..64425f045 100644
--- a/bundles/org.eclipse.osgi/core/framework/org/eclipse/osgi/framework/internal/core/StartLevelManager.java
+++ b/bundles/org.eclipse.osgi/core/framework/org/eclipse/osgi/framework/internal/core/StartLevelManager.java
@@ -356,7 +356,7 @@ public class StartLevelManager implements EventDispatcher, EventListener, StartL
* <tt>AdminPermission</tt> and the Java runtime environment supports
* permissions.
*/
- public void setBundleStartLevel(org.osgi.framework.Bundle bundle, int newSL) {
+ public void setBundleStartLevel(Bundle bundle, int newSL) {
String exceptionText = null;
if (bundle.getBundleId() == 0) { // system bundle has id=0
@@ -372,7 +372,8 @@ public class StartLevelManager implements EventDispatcher, EventListener, StartL
framework.checkAdminPermission(bundle, AdminPermission.EXECUTE);
try {
// if the bundle's startlevel is not already at the requested startlevel
- if (newSL != ((org.eclipse.osgi.framework.internal.core.AbstractBundle) bundle).getStartLevel()) {
+ int oldSL = ((AbstractBundle) bundle).getStartLevel();
+ if (newSL != oldSL) {
final AbstractBundle b = (AbstractBundle) bundle;
b.getBundleData().setStartLevel(newSL);
try {
@@ -389,7 +390,9 @@ public class StartLevelManager implements EventDispatcher, EventListener, StartL
throw (RuntimeException) e.getException();
}
// handle starting or stopping the bundle asynchronously
- issueEvent(new StartLevelEvent(StartLevelEvent.CHANGE_BUNDLE_SL, newSL, (AbstractBundle) bundle));
+ if (newSL > oldSL || !((AbstractBundle) bundle).isActive())
+ // only need to do this if the newSL > oldSL (stopping) or the bundle is not active (could activate)
+ issueEvent(new StartLevelEvent(StartLevelEvent.CHANGE_BUNDLE_SL, newSL, (AbstractBundle) bundle));
}
} catch (IOException e) {
framework.publishFrameworkEvent(FrameworkEvent.ERROR, bundle, e);

Back to the top