diff options
author | Thomas Watson | 2020-05-19 22:17:16 +0000 |
---|---|---|
committer | Thomas Watson | 2020-05-20 19:59:41 +0000 |
commit | b744056353e7d54dba04b35b7855f253685df288 (patch) | |
tree | 2796bf923d78edf7e03c42ddcb3bca12801d7d1c | |
parent | 3bc986c22e78806d076a6830a590c2b6f9d23d26 (diff) | |
download | rt.equinox.framework-b744056353e7d54dba04b35b7855f253685df288.tar.gz rt.equinox.framework-b744056353e7d54dba04b35b7855f253685df288.tar.xz rt.equinox.framework-b744056353e7d54dba04b35b7855f253685df288.zip |
Bug 563372 - Improve tests to capture why a framework does not stop.S4_16_0_M3I20200521-1000I20200520-1800
Add a new method that captures a thread dump when the stop operation
has a timeout.
Change-Id: I938902904c1f972ac65a8d85db19b6e57a7ba580
17 files changed, 284 insertions, 934 deletions
diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/AbstractBundleTests.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/AbstractBundleTests.java index 74ad42fc7..2d278ee44 100644 --- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/AbstractBundleTests.java +++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/AbstractBundleTests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006, 20010 IBM Corporation and others. + * Copyright (c) 2006, 2020 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -24,13 +24,16 @@ import java.util.jar.Attributes; import java.util.jar.JarOutputStream; import java.util.jar.Manifest; import org.eclipse.core.tests.harness.CoreTest; +import org.eclipse.osgi.framework.util.ThreadInfoReport; import org.eclipse.osgi.launch.Equinox; import org.eclipse.osgi.tests.OSGiTestsActivator; +import org.osgi.framework.Bundle; import org.osgi.framework.BundleContext; import org.osgi.framework.BundleEvent; import org.osgi.framework.BundleException; import org.osgi.framework.Constants; import org.osgi.framework.FrameworkEvent; +import org.osgi.framework.launch.Framework; public class AbstractBundleTests extends CoreTest { public static int BUNDLE_LISTENER = 0x01; @@ -267,15 +270,95 @@ public class AbstractBundleTests extends CoreTest { equinox.start(); } - protected void stopQuietly(Equinox equinox) { + static public void stop(Framework equinox, int expected) { + FrameworkEvent actual = stop(equinox); + if (expected > 0) { + assertNotNull("No FrameworkEvent returned.", actual); + assertEquals("Wrong FrameworkEvent.", getFrameworkEventType(expected), + getFrameworkEventType(actual.getType())); + } + } + + static private String getFrameworkEventType(int type) { + switch (type) { + case FrameworkEvent.ERROR: + return "ERROR"; + case FrameworkEvent.INFO: + return "INFO"; + case FrameworkEvent.STARTED: + return "STARTED"; + case FrameworkEvent.STOPPED: + return "STOPPED"; + case FrameworkEvent.STOPPED_BOOTCLASSPATH_MODIFIED: + return "STOPPED_BOOTCLASSPATH_MODIFIED"; + case FrameworkEvent.STOPPED_SYSTEM_REFRESHED: + return "STOPPED_SYSTEM_REFRESHED"; + case FrameworkEvent.STOPPED_UPDATE: + return "STOPPED_UPDATE"; + default: + return "UNKNOWN:" + type; + } + } + + static public FrameworkEvent stop(Framework equinox) { + return stop(equinox, false, 10000); + } + + static public FrameworkEvent stopQuietly(Framework equinox) { + return stop(equinox, true, 10000); + } + + static public FrameworkEvent stop(Framework equinox, boolean quietly, long timeout) { if (equinox == null) - return; + return null; + BundleContext bc = equinox.getBundleContext(); + final String uuid = bc == null ? null : bc.getProperty(Constants.FRAMEWORK_UUID); try { equinox.stop(); - equinox.waitForStop(5000); - } catch (Exception e) { - // Ignore + } catch (BundleException e) { + if (!quietly) { + fail("Unexpected erorr stopping framework", e); //$NON-NLS-1$ + } } + try { + FrameworkEvent stopEvent = equinox.waitForStop(timeout); + if (stopEvent.getType() == FrameworkEvent.WAIT_TIMEDOUT) { + StringBuilder sb = new StringBuilder("Framework state is: "); + sb.append(getState(equinox)).append(" - ").append(uuid).append('\n'); + sb.append(ThreadInfoReport.getThreadDump(null)).append('\n'); + if (!quietly) { + fail(sb.toString()); + } else { + System.out.println(sb.toString()); + } + } + return stopEvent; + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + if (!quietly) { + fail("Unexpected interrupted exception", e); //$NON-NLS-1$ + } + } + return null; } + static private String getState(Framework framework) { + int state = framework.getState(); + switch (state) { + case Bundle.UNINSTALLED: + return "UNINSTALLED"; + case Bundle.INSTALLED: + return "INSTALLED"; + case Bundle.RESOLVED: + return "RESOLVED"; + case Bundle.STARTING: + return "STARTING"; + case Bundle.ACTIVE: + return "ACTIVE"; + case Bundle.STOPPING: + return "STOPPING"; + default: + return "UNKNOWN:" + state; + } + } }
\ No newline at end of file diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/CascadeConfigTests.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/CascadeConfigTests.java index dc0e78a4d..dc7d06074 100644 --- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/CascadeConfigTests.java +++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/CascadeConfigTests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008, 2016 IBM Corporation and others. + * Copyright (c) 2008, 2020 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -15,12 +15,17 @@ package org.eclipse.osgi.tests.bundles; import java.io.File; import java.io.FileOutputStream; -import java.util.*; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; +import java.util.Properties; import junit.framework.Test; import junit.framework.TestSuite; import org.eclipse.osgi.launch.Equinox; import org.eclipse.osgi.tests.OSGiTestsActivator; -import org.osgi.framework.*; +import org.osgi.framework.Bundle; +import org.osgi.framework.BundleContext; +import org.osgi.framework.Constants; import org.osgi.framework.launch.Framework; import org.osgi.framework.wiring.FrameworkWiring; @@ -40,8 +45,7 @@ public class CascadeConfigTests extends AbstractBundleTests { BundleContext systemContext = equinox.getBundleContext(); systemContext.installBundle(installer.getBundleLocation("test")); - equinox.stop(); - equinox.waitForStop(10000); + stopQuietly(equinox); // Now create a child framework and make sure test1 bundle is there File configChild = OSGiTestsActivator.getContext().getDataFile(getName() + "_child"); @@ -58,8 +62,7 @@ public class CascadeConfigTests extends AbstractBundleTests { systemContext.installBundle(installer.getBundleLocation("test2")); - equinox.stop(); - equinox.waitForStop(10000); + stop(equinox); // reuse the same configuration and make sure both bundles are there equinox = new Equinox(childMap); @@ -71,8 +74,7 @@ public class CascadeConfigTests extends AbstractBundleTests { Bundle test2 = systemContext.getBundle(installer.getBundleLocation("test2")); assertNotNull("Missing bundle.", test2); - equinox.stop(); - equinox.waitForStop(10000); + stop(equinox); // restart using the parent and make sure only the test1 bundle is there equinox = new Equinox(parentMap); @@ -84,8 +86,7 @@ public class CascadeConfigTests extends AbstractBundleTests { test2 = systemContext.getBundle(installer.getBundleLocation("test2")); assertNull("Unexpected bundle.", test2); - equinox.stop(); - equinox.waitForStop(10000); + stop(equinox); } public void testCascadeConfigDataArea() throws Exception { @@ -100,8 +101,7 @@ public class CascadeConfigTests extends AbstractBundleTests { Bundle b = systemContext.installBundle(installer.getBundleLocation("substitutes.a")); equinox.adapt(FrameworkWiring.class).resolveBundles(Collections.singletonList(b)); - equinox.stop(); - equinox.waitForStop(10000); + stop(equinox); // Now create a child framework and make sure bundle is there File configChild = OSGiTestsActivator.getContext().getDataFile(getName() + "_child"); @@ -123,8 +123,7 @@ public class CascadeConfigTests extends AbstractBundleTests { File dataFile = test1Context.getDataFile("test1"); assertTrue(dataFile.getAbsolutePath().startsWith(configChild.getAbsolutePath())); - equinox.stop(); - equinox.waitForStop(10000); + stop(equinox); // get parent again equinox = new Equinox(parentMap); @@ -143,8 +142,7 @@ public class CascadeConfigTests extends AbstractBundleTests { dataFile = test1Context.getDataFile("test1"); assertTrue(dataFile.getAbsolutePath().startsWith(configParent.getAbsolutePath())); - equinox.stop(); - equinox.waitForStop(10000); + stop(equinox); } public void testCascadeConfigIni() throws Exception { @@ -181,7 +179,6 @@ public class CascadeConfigTests extends AbstractBundleTests { assertEquals("Wrong value for parent.child.key", "child", systemContext.getProperty("parent.child.key")); assertEquals("Wrong value for child.key", "child", systemContext.getProperty("child.key")); - equinox.stop(); - equinox.waitForStop(10000); + stop(equinox); } } diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/DiscardBundleTests.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/DiscardBundleTests.java index 6821483fc..8fecc9980 100644 --- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/DiscardBundleTests.java +++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/DiscardBundleTests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2013 IBM Corporation and others. + * Copyright (c) 2013, 2020 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -26,7 +26,6 @@ import org.eclipse.osgi.launch.Equinox; import org.eclipse.osgi.tests.OSGiTestsActivator; import org.osgi.framework.BundleException; import org.osgi.framework.Constants; -import org.osgi.framework.FrameworkEvent; /* * The framework must discard a persisted bundle when the @@ -204,19 +203,13 @@ public class DiscardBundleTests extends AbstractBundleTests { return new File(root, BUNDLE_JAR); } - private Equinox restart(Equinox equinox, Map<String, ?> configuration) throws BundleException, InterruptedException { + private Equinox restart(Equinox equinox, Map<String, ?> configuration) throws BundleException { stop(equinox); equinox = new Equinox(configuration); initAndStart(equinox); return equinox; } - private void stop(Equinox equinox) throws BundleException, InterruptedException { - equinox.stop(); - FrameworkEvent event = equinox.waitForStop(5000); - assertEquals("The framework was not stopped", FrameworkEvent.STOPPED, event.getType()); - } - private void touchFile(File file) { if (file.isDirectory()) file = new File(file, BUNDLE_MANIFEST); diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/ImportJavaSEPackagesTests.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/ImportJavaSEPackagesTests.java index 36d9c8891..2e4bb9398 100644 --- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/ImportJavaSEPackagesTests.java +++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/ImportJavaSEPackagesTests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2018 IBM Corporation and others. + * Copyright (c) 2018, 2020 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -76,13 +76,7 @@ public class ImportJavaSEPackagesTests extends AbstractBundleTests { assertEquals("It should throw a bundle exception of type manifest error", BundleException.MANIFEST_ERROR, e.getType()); assertTrue("It should throw a Bundle Exception stating Invalid manifest header Export-Package", e.getMessage().contains("Cannot specify java.* packages in Export headers")); } finally { - - try { - equinox.stop(); - equinox.waitForStop(10000); - } catch (Exception e) { - //do nothing - } + stopQuietly(equinox); } } @@ -109,13 +103,7 @@ public class ImportJavaSEPackagesTests extends AbstractBundleTests { } catch (BundleException e) { fail("Failed to test Import-Package header"); } finally { - - try { - equinox.stop(); - equinox.waitForStop(10000); - } catch (Exception e) { - //do nothing - } + stopQuietly(equinox); } } @@ -217,13 +205,7 @@ public class ImportJavaSEPackagesTests extends AbstractBundleTests { } catch (BundleException e) { fail("Failed to test System packages"); } finally { - - try { - equinox.stop(); - equinox.waitForStop(10000); - } catch (Exception e) { - //do nothing - } + stopQuietly(equinox); } } diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/MultiReleaseJarTests.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/MultiReleaseJarTests.java index 81700d000..39712fffc 100644 --- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/MultiReleaseJarTests.java +++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/MultiReleaseJarTests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2017 IBM Corporation and others. + * Copyright (c) 2017, 2020 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -397,12 +397,7 @@ public class MultiReleaseJarTests extends AbstractBundleTests { assertEquals("Wrong class.", (rv >= 11) ? "BASE11" : "BASEXX", loadClass("multi.release.test.sub2.TestClass11", mrBundle, false)); assertEquals("Wrong class.", (rv >= 11) ? "ADD11" : CNFE, loadClass("multi.release.test.sub2.TestClassAdd11", mrBundle, true)); } finally { - try { - equinox.stop(); - equinox.waitForStop(10000); - } catch (Exception e) { - // ignore; - } + stopQuietly(equinox); } } @@ -480,12 +475,7 @@ public class MultiReleaseJarTests extends AbstractBundleTests { assertEquals("Wrong resource.", (rv >= 11) ? "ADD 11" : RNF, readResource("multi/release/test/sub2/testResourceAdd11.txt", mrBundle)); } finally { - try { - equinox.stop(); - equinox.waitForStop(10000); - } catch (Exception e) { - // ignore; - } + stopQuietly(equinox); } } @@ -591,12 +581,7 @@ public class MultiReleaseJarTests extends AbstractBundleTests { assertEquals("Wrong resource.", (rv >= 11) ? "ADD 11" : RNF, readResources("multi/release/test/sub2/testResourceAdd11.txt", mrBundle)); } finally { - try { - equinox.stop(); - equinox.waitForStop(10000); - } catch (Exception e) { - // ignore; - } + stopQuietly(equinox); } } @@ -689,12 +674,7 @@ public class MultiReleaseJarTests extends AbstractBundleTests { listResources("multi/release/test", expected, mrBundle, 0); listResources("multi/release/test", expectedRecurse, mrBundle, BundleWiring.LISTRESOURCES_RECURSE); } finally { - try { - equinox.stop(); - equinox.waitForStop(10000); - } catch (Exception e) { - // ignore; - } + stopQuietly(equinox); } } @@ -755,12 +735,7 @@ public class MultiReleaseJarTests extends AbstractBundleTests { assertTrue("Wrong package filter: " + filter, filter.contains(expectedPkg)); } finally { - try { - equinox.stop(); - equinox.waitForStop(10000); - } catch (Exception e) { - // ignore; - } + stopQuietly(equinox); } } @@ -776,8 +751,7 @@ public class MultiReleaseJarTests extends AbstractBundleTests { location = mrBundle.getLocation(); mrBundle.start(); } finally { - equinox.stop(); - equinox.waitForStop(10000); + stop(equinox); } System.out.println("Equinox state: " + equinox.getState()); for (int rv = 8; rv <= 11; rv++) { @@ -793,8 +767,7 @@ public class MultiReleaseJarTests extends AbstractBundleTests { location = mrBundle.getLocation(); mrBundle.start(); } finally { - equinox.stop(); - equinox.waitForStop(10000); + stop(equinox); } for (int rv = 8; rv <= 11; rv++) { @@ -838,12 +811,7 @@ public class MultiReleaseJarTests extends AbstractBundleTests { assertTrue("Wrong package filter: " + rv + " " + filter, filter.contains(expectedPkg)); } finally { - try { - equinox.stop(); - equinox.waitForStop(10000); - } catch (Exception e) { - // ignore; - } + stopQuietly(equinox); } } @@ -863,8 +831,7 @@ public class MultiReleaseJarTests extends AbstractBundleTests { Bundle mrBundle = systemContext.installBundle("reference:" + copyMrJarBundle.toURI().toString()); mrBundle.start(); } finally { - equinox.stop(); - equinox.waitForStop(1000); + stop(equinox); } copyMrJarBundle.delete(); @@ -875,8 +842,7 @@ public class MultiReleaseJarTests extends AbstractBundleTests { try { equinox.start(); } finally { - equinox.stop(); - equinox.waitForStop(1000); + stop(equinox); } } @@ -898,8 +864,7 @@ public class MultiReleaseJarTests extends AbstractBundleTests { Object testService = loader.iterator().next(); assertEquals("Wrong service found.", "SERVICE_BASE", testService.toString()); } finally { - equinox.stop(); - equinox.waitForStop(1000); + stop(equinox); } } @@ -927,8 +892,7 @@ public class MultiReleaseJarTests extends AbstractBundleTests { } } finally { - equinox.stop(); - equinox.waitForStop(1000); + stop(equinox); } } @@ -948,8 +912,7 @@ public class MultiReleaseJarTests extends AbstractBundleTests { Collection<String> list = mrBundle.adapt(BundleWiring.class).listResources("/META-INF/", "*.txt", 0); assertTrue("Found versioned META-INF resources: " + list, list.isEmpty()); } finally { - equinox.stop(); - equinox.waitForStop(1000); + stop(equinox); } } } diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/SystemBundleTests.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/SystemBundleTests.java index 890324f4f..61aa581ff 100755 --- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/SystemBundleTests.java +++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/SystemBundleTests.java @@ -163,16 +163,7 @@ public class SystemBundleTests extends AbstractBundleTests { URL configURL = configLocation.getURL(); assertTrue("incorrect configuration location", configURL.toExternalForm().endsWith("testSystemBundle01/")); //$NON-NLS-1$ //$NON-NLS-2$ - try { - equinox.stop(); - } catch (BundleException e) { - fail("Unexpected erorr stopping framework", e); //$NON-NLS-1$ - } - try { - equinox.waitForStop(10000); - } catch (InterruptedException e) { - fail("Unexpected interrupted exception", e); //$NON-NLS-1$ - } + stop(equinox); assertEquals("Wrong state for SystemBundle", Bundle.RESOLVED, equinox.getState()); //$NON-NLS-1$ } @@ -190,16 +181,7 @@ public class SystemBundleTests extends AbstractBundleTests { fail("Failed to start the framework", e); //$NON-NLS-1$ } assertEquals("Wrong state for SystemBundle", Bundle.ACTIVE, equinox.getState()); //$NON-NLS-1$ - try { - equinox.stop(); - } catch (BundleException e) { - fail("Unexpected erorr stopping framework", e); //$NON-NLS-1$ - } - try { - equinox.waitForStop(10000); - } catch (InterruptedException e) { - fail("Unexpected interrupted exception", e); //$NON-NLS-1$ - } + stop(equinox); assertEquals("Wrong state for SystemBundle", Bundle.RESOLVED, equinox.getState()); //$NON-NLS-1$ try { @@ -208,16 +190,7 @@ public class SystemBundleTests extends AbstractBundleTests { fail("Failed to start the framework", e); //$NON-NLS-1$ } assertEquals("Wrong state for SystemBundle", Bundle.ACTIVE, equinox.getState()); //$NON-NLS-1$ - try { - equinox.stop(); - } catch (BundleException e) { - fail("Unexpected erorr stopping framework", e); //$NON-NLS-1$ - } - try { - equinox.waitForStop(10000); - } catch (InterruptedException e) { - fail("Unexpected interrupted exception", e); //$NON-NLS-1$ - } + stop(equinox); assertEquals("Wrong state for SystemBundle", Bundle.RESOLVED, equinox.getState()); //$NON-NLS-1$ } @@ -240,16 +213,7 @@ public class SystemBundleTests extends AbstractBundleTests { assertNotNull("config property is null", configArea); //$NON-NLS-1$ assertTrue("Wrong configuration area", configArea.endsWith("testSystemBundle03/")); //$NON-NLS-1$ //$NON-NLS-2$ // don't do anything; just put the framework back to the RESOLVED state - try { - equinox.stop(); - } catch (BundleException e) { - fail("Unexpected error stopping framework", e); //$NON-NLS-1$ - } - try { - equinox.waitForStop(10000); - } catch (InterruptedException e) { - fail("Unexpected interrupted exception", e); //$NON-NLS-1$ - } + stop(equinox); assertEquals("Wrong state for SystemBundle", Bundle.RESOLVED, equinox.getState()); //$NON-NLS-1$ } @@ -289,16 +253,7 @@ public class SystemBundleTests extends AbstractBundleTests { assertEquals("Wrong state for SystemBundle", Bundle.ACTIVE, equinox.getState()); //$NON-NLS-1$ assertEquals("Wrong state for installed bundle", Bundle.ACTIVE, substitutesA.getState()); //$NON-NLS-1$ // put the framework back to the RESOLVED state - try { - equinox.stop(); - } catch (BundleException e) { - fail("Unexpected erorr stopping framework", e); //$NON-NLS-1$ - } - try { - equinox.waitForStop(10000); - } catch (InterruptedException e) { - fail("Unexpected interrupted exception", e); //$NON-NLS-1$ - } + stop(equinox); assertEquals("Wrong state for SystemBundle", Bundle.RESOLVED, equinox.getState()); //$NON-NLS-1$ } @@ -339,16 +294,7 @@ public class SystemBundleTests extends AbstractBundleTests { } assertEquals("Wrong state for active bundle", Bundle.ACTIVE, substitutesA.getState()); //$NON-NLS-1$ // put the framework back to the RESOLVED state - try { - equinox.stop(); - } catch (BundleException e) { - fail("Unexpected erorr stopping framework", e); //$NON-NLS-1$ - } - try { - equinox.waitForStop(10000); - } catch (InterruptedException e) { - fail("Unexpected interrupted exception", e); //$NON-NLS-1$ - } + stop(equinox); assertEquals("Wrong state for SystemBundle", Bundle.RESOLVED, equinox.getState()); //$NON-NLS-1$ } @@ -389,16 +335,7 @@ public class SystemBundleTests extends AbstractBundleTests { } assertEquals("Wrong state for active bundle", Bundle.ACTIVE, substitutesA.getState()); //$NON-NLS-1$ // put the framework back to the RESOLVED state - try { - equinox.stop(); - } catch (BundleException e) { - fail("Unexpected erorr stopping framework", e); //$NON-NLS-1$ - } - try { - equinox.waitForStop(10000); - } catch (InterruptedException e) { - fail("Unexpected interrupted exception", e); //$NON-NLS-1$ - } + stop(equinox); assertEquals("Wrong state for SystemBundle", Bundle.RESOLVED, equinox.getState()); //$NON-NLS-1$ try { @@ -418,16 +355,7 @@ public class SystemBundleTests extends AbstractBundleTests { // no need to start the bundle again it should have been persistently started assertEquals("Wrong state for active bundle", Bundle.ACTIVE, substitutesA2.getState()); //$NON-NLS-1$ // put the framework back to the RESOLVED state - try { - equinox.stop(); - } catch (BundleException e) { - fail("Unexpected erorr stopping framework", e); //$NON-NLS-1$ - } - try { - equinox.waitForStop(10000); - } catch (InterruptedException e) { - fail("Unexpected interrupted exception", e); //$NON-NLS-1$ - } + stop(equinox); assertEquals("Wrong state for SystemBundle", Bundle.RESOLVED, equinox.getState()); //$NON-NLS-1$ } @@ -481,29 +409,11 @@ public class SystemBundleTests extends AbstractBundleTests { assertEquals("Wrong state for SystemBundle", Bundle.ACTIVE, equinox2.getState()); //$NON-NLS-1$ // put the framework 1 back to the RESOLVED state - try { - equinox1.stop(); - } catch (BundleException e) { - fail("Unexpected erorr stopping framework", e); //$NON-NLS-1$ - } - try { - equinox1.waitForStop(10000); - } catch (InterruptedException e) { - fail("Unexpected interrupted exception", e); //$NON-NLS-1$ - } + stop(equinox1); assertEquals("Wrong state for SystemBundle", Bundle.RESOLVED, equinox1.getState()); //$NON-NLS-1$ // put the framework 2 back to the RESOLVED state - try { - equinox2.stop(); - } catch (BundleException e) { - fail("Unexpected erorr stopping framework", e); //$NON-NLS-1$ - } - try { - equinox2.waitForStop(10000); - } catch (InterruptedException e) { - fail("Unexpected interrupted exception", e); //$NON-NLS-1$ - } + stop(equinox2); assertEquals("Wrong state for SystemBundle", Bundle.RESOLVED, equinox2.getState()); //$NON-NLS-1$ } @@ -551,16 +461,7 @@ public class SystemBundleTests extends AbstractBundleTests { URL configURL = configLocation.getURL(); assertTrue("incorrect configuration location", configURL.toExternalForm().endsWith("testSystemBundle07_01/")); //$NON-NLS-1$ //$NON-NLS-2$ - try { - equinox.stop(); - } catch (BundleException e) { - fail("Unexpected erorr stopping framework", e); //$NON-NLS-1$ - } - try { - equinox.waitForStop(10000); - } catch (InterruptedException e) { - fail("Unexpected interrupted exception", e); //$NON-NLS-1$ - } + stop(equinox); assertEquals("Wrong state for SystemBundle", Bundle.RESOLVED, equinox.getState()); //$NON-NLS-1$ } @@ -577,16 +478,7 @@ public class SystemBundleTests extends AbstractBundleTests { fail("Failed to start the framework", e); //$NON-NLS-1$ } assertEquals("Wrong state for SystemBundle", Bundle.ACTIVE, equinox.getState()); //$NON-NLS-1$ - try { - equinox.stop(); - } catch (BundleException e) { - fail("Unexpected erorr stopping framework", e); //$NON-NLS-1$ - } - try { - equinox.waitForStop(10000); - } catch (InterruptedException e) { - fail("Unexpected interrupted exception", e); //$NON-NLS-1$ - } + stop(equinox); assertEquals("Wrong state for SystemBundle", Bundle.RESOLVED, equinox.getState()); //$NON-NLS-1$ config = OSGiTestsActivator.getContext().getDataFile("testSystemBundle08_2"); //$NON-NLS-1$ @@ -613,16 +505,7 @@ public class SystemBundleTests extends AbstractBundleTests { URL configURL = configLocation.getURL(); assertTrue("incorrect configuration location", configURL.toExternalForm().endsWith("testSystemBundle08_2/")); //$NON-NLS-1$ //$NON-NLS-2$ - try { - equinox.stop(); - } catch (BundleException e) { - fail("Unexpected erorr stopping framework", e); //$NON-NLS-1$ - } - try { - equinox.waitForStop(10000); - } catch (InterruptedException e) { - fail("Unexpected interrupted exception", e); //$NON-NLS-1$ - } + stop(equinox); assertEquals("Wrong state for SystemBundle", Bundle.RESOLVED, equinox.getState()); //$NON-NLS-1$ } @@ -650,16 +533,7 @@ public class SystemBundleTests extends AbstractBundleTests { } catch (BundleException e) { fail("Unexpected exception starting test bundle", e); //$NON-NLS-1$ } - try { - equinox.stop(); - } catch (BundleException e) { - fail("Unexpected erorr stopping framework", e); //$NON-NLS-1$ - } - try { - equinox.waitForStop(10000); - } catch (InterruptedException e) { - fail("Unexpected interrupted exception", e); //$NON-NLS-1$ - } + stop(equinox); assertEquals("Wrong state for SystemBundle", Bundle.RESOLVED, equinox.getState()); //$NON-NLS-1$ } @@ -716,16 +590,7 @@ public class SystemBundleTests extends AbstractBundleTests { // nothing } assertEquals("Wrong state for SystemBundle", Bundle.ACTIVE, equinox.getState()); //$NON-NLS-1$ - try { - equinox.stop(); - } catch (BundleException e) { - fail("Unexpected erorr stopping framework", e); //$NON-NLS-1$ - } - try { - equinox.waitForStop(10000); - } catch (InterruptedException e) { - fail("Unexpected interrupted exception", e); //$NON-NLS-1$ - } + stop(equinox); assertEquals("Wrong state for SystemBundle", Bundle.RESOLVED, equinox.getState()); //$NON-NLS-1$ } @@ -756,16 +621,7 @@ public class SystemBundleTests extends AbstractBundleTests { assertEquals("Wrong number of exports", 1, pkg2.length); //$NON-NLS-1$ assertEquals("Wrong package name", "test.pkg2", pkg2[0].getName()); //$NON-NLS-1$ //$NON-NLS-2$ - try { - equinox.stop(); - } catch (BundleException e) { - fail("Unexpected erorr stopping framework", e); //$NON-NLS-1$ - } - try { - equinox.waitForStop(10000); - } catch (InterruptedException e) { - fail("Unexpected interrupted exception", e); //$NON-NLS-1$ - } + stop(equinox); assertEquals("Wrong state for SystemBundle", Bundle.RESOLVED, equinox.getState()); //$NON-NLS-1$ } @@ -793,16 +649,7 @@ public class SystemBundleTests extends AbstractBundleTests { assertEquals("Wrong stopEvent", FrameworkEvent.WAIT_TIMEDOUT, stopEvent.getType()); //$NON-NLS-1$ assertEquals("Wrong state for SystemBundle", Bundle.ACTIVE, equinox.getState()); //$NON-NLS-1$ - try { - equinox.stop(); - } catch (BundleException e) { - fail("Unexpected erorr stopping framework", e); //$NON-NLS-1$ - } - try { - stopEvent = equinox.waitForStop(10000); - } catch (InterruptedException e) { - fail("Unexpected interrupted exception", e); //$NON-NLS-1$ - } + stopEvent = stop(equinox); assertNotNull("Stop event is null", stopEvent); //$NON-NLS-1$ assertEquals("Wrong stopEvent", FrameworkEvent.STOPPED, stopEvent.getType()); //$NON-NLS-1$ } @@ -844,16 +691,7 @@ public class SystemBundleTests extends AbstractBundleTests { } assertEquals("Wrong state for active bundle", Bundle.ACTIVE, substitutesA.getState()); //$NON-NLS-1$ // put the framework back to the RESOLVED state - try { - equinox.stop(); - } catch (BundleException e) { - fail("Unexpected erorr stopping framework", e); //$NON-NLS-1$ - } - try { - equinox.waitForStop(10000); - } catch (InterruptedException e) { - fail("Unexpected interrupted exception", e); //$NON-NLS-1$ - } + stop(equinox); assertEquals("Wrong state for SystemBundle", Bundle.RESOLVED, equinox.getState()); //$NON-NLS-1$ // initialize the framework again to the same configuration @@ -870,16 +708,7 @@ public class SystemBundleTests extends AbstractBundleTests { // make sure the bundle is there assertNotNull("missing installed bundle", substitutesA); //$NON-NLS-1$ assertEquals("Unexpected symbolic name", "substitutes.a", substitutesA.getSymbolicName()); //$NON-NLS-1$ //$NON-NLS-2$ - try { - equinox.stop(); - } catch (BundleException e) { - fail("Unexpected erorr stopping framework", e); //$NON-NLS-1$ - } - try { - equinox.waitForStop(10000); - } catch (InterruptedException e) { - fail("Unexpected interrupted exception", e); //$NON-NLS-1$ - } + stop(equinox); assertEquals("Wrong state for SystemBundle", Bundle.RESOLVED, equinox.getState()); //$NON-NLS-1$ // initialize the framework again to the same configuration but use clean option @@ -896,16 +725,7 @@ public class SystemBundleTests extends AbstractBundleTests { // make sure the bundle is there assertNull("Unexpected bundle is installed", substitutesA); //$NON-NLS-1$ - try { - equinox.stop(); - } catch (BundleException e) { - fail("Unexpected erorr stopping framework", e); //$NON-NLS-1$ - } - try { - equinox.waitForStop(10000); - } catch (InterruptedException e) { - fail("Unexpected interrupted exception", e); //$NON-NLS-1$ - } + stop(equinox); assertEquals("Wrong state for SystemBundle", Bundle.RESOLVED, equinox.getState()); //$NON-NLS-1$ } @@ -928,18 +748,7 @@ public class SystemBundleTests extends AbstractBundleTests { assertNotNull("StartLevel service is null", st); //$NON-NLS-1$ assertEquals("Unexpected start level", 10, st.getStartLevel()); //$NON-NLS-1$ assertEquals("Wrong state for SystemBundle", Bundle.ACTIVE, equinox.getState()); //$NON-NLS-1$ - try { - equinox.stop(); - } catch (BundleException e) { - fail("Unexpected erorr stopping framework", e); //$NON-NLS-1$ - } - - FrameworkEvent stopEvent = null; - try { - stopEvent = equinox.waitForStop(10000); - } catch (InterruptedException e) { - fail("Unexpected interrupted exception", e); //$NON-NLS-1$ - } + FrameworkEvent stopEvent = stop(equinox); assertNotNull("Stop event is null", stopEvent); //$NON-NLS-1$ assertEquals("Wrong stopEvent", FrameworkEvent.STOPPED, stopEvent.getType()); //$NON-NLS-1$ } @@ -1010,20 +819,7 @@ public class SystemBundleTests extends AbstractBundleTests { } catch (ClassNotFoundException e) { fail("failed to load class", e); //$NON-NLS-1$ } - try { - equinox.stop(); - } catch (BundleException e) { - fail("Unexpected erorr stopping framework", e); //$NON-NLS-1$ - } - - FrameworkEvent stopEvent = null; - try { - stopEvent = equinox.waitForStop(10000); - } catch (InterruptedException e) { - fail("Unexpected interrupted exception", e); //$NON-NLS-1$ - } - assertNotNull("Stop event is null", stopEvent); //$NON-NLS-1$ - assertEquals("Wrong stopEvent", FrameworkEvent.STOPPED, stopEvent.getType()); //$NON-NLS-1$ + stop(equinox, FrameworkEvent.STOPPED); } public void testChangeEE() throws IOException, BundleException { @@ -1054,12 +850,7 @@ public class SystemBundleTests extends AbstractBundleTests { Assert.assertTrue("Could not resolve bundle.", equinox.adapt(FrameworkWiring.class).resolveBundles(Collections.singleton(b))); // put the framework back to the RESOLVED state - equinox.stop(); - try { - equinox.waitForStop(10000); - } catch (InterruptedException e) { - fail("Unexpected interrupted exception", e); //$NON-NLS-1$ - } + stop(equinox); // configure equinox for java 7 configuration.put("osgi.java.profile", javaSE7Profile.toExternalForm()); @@ -1074,12 +865,7 @@ public class SystemBundleTests extends AbstractBundleTests { Assert.assertFalse("Could resolve bundle.", equinox.adapt(FrameworkWiring.class).resolveBundles(Collections.singleton(b))); // put the framework back to the RESOLVED state - equinox.stop(); - try { - equinox.waitForStop(10000); - } catch (InterruptedException e) { - fail("Unexpected interrupted exception", e); //$NON-NLS-1$ - } + stop(equinox); // move back to java 8 configuration.put("osgi.java.profile", javaSE8Profile.toExternalForm()); @@ -1094,12 +880,7 @@ public class SystemBundleTests extends AbstractBundleTests { Assert.assertTrue("Could not resolve bundle.", equinox.adapt(FrameworkWiring.class).resolveBundles(Collections.singleton(b))); // put the framework back to the RESOLVED state - equinox.stop(); - try { - equinox.waitForStop(10000); - } catch (InterruptedException e) { - fail("Unexpected interrupted exception", e); //$NON-NLS-1$ - } + stop(equinox); } public void testMRUBundleFileList() { @@ -1148,16 +929,7 @@ public class SystemBundleTests extends AbstractBundleTests { } } // put the framework back to the RESOLVED state - try { - equinox.stop(); - } catch (BundleException e) { - fail("Unexpected erorr stopping framework", e); //$NON-NLS-1$ - } - try { - equinox.waitForStop(10000); - } catch (InterruptedException e) { - fail("Unexpected interrupted exception", e); //$NON-NLS-1$ - } + stop(equinox); try { equinox.start(); @@ -1209,16 +981,7 @@ public class SystemBundleTests extends AbstractBundleTests { openAllBundleFiles(equinox.getBundleContext()); - try { - equinox.stop(); - } catch (BundleException e) { - fail("Unexpected erorr stopping framework", e); //$NON-NLS-1$ - } - try { - equinox.waitForStop(10000); - } catch (InterruptedException e) { - fail("Unexpected interrupted exception", e); //$NON-NLS-1$ - } + stop(equinox); assertEquals("Wrong state for SystemBundle", Bundle.RESOLVED, equinox.getState()); //$NON-NLS-1$ } @@ -1303,29 +1066,11 @@ public class SystemBundleTests extends AbstractBundleTests { assertFalse("URL is equal: " + entry1.toExternalForm(), entry1.equals(entry2)); //$NON-NLS-1$ // put the framework 1 back to the RESOLVED state - try { - equinox1.stop(); - } catch (BundleException e) { - fail("Unexpected error stopping framework", e); //$NON-NLS-1$ - } - try { - equinox1.waitForStop(10000); - } catch (InterruptedException e) { - fail("Unexpected interrupted exception", e); //$NON-NLS-1$ - } + stop(equinox1); assertEquals("Wrong state for SystemBundle", Bundle.RESOLVED, equinox1.getState()); //$NON-NLS-1$ // put the framework 2 back to the RESOLVED state - try { - equinox2.stop(); - } catch (BundleException e) { - fail("Unexpected erorr stopping framework", e); //$NON-NLS-1$ - } - try { - equinox2.waitForStop(10000); - } catch (InterruptedException e) { - fail("Unexpected interrupted exception", e); //$NON-NLS-1$ - } + stop(equinox2); assertEquals("Wrong state for SystemBundle", Bundle.RESOLVED, equinox2.getState()); //$NON-NLS-1$ } @@ -1397,29 +1142,11 @@ public class SystemBundleTests extends AbstractBundleTests { } // put the framework 1 back to the RESOLVED state - try { - equinox1.stop(); - } catch (BundleException e) { - fail("Unexpected error stopping framework", e); //$NON-NLS-1$ - } - try { - equinox1.waitForStop(10000); - } catch (InterruptedException e) { - fail("Unexpected interrupted exception", e); //$NON-NLS-1$ - } + stop(equinox1); assertEquals("Wrong state for SystemBundle", Bundle.RESOLVED, equinox1.getState()); //$NON-NLS-1$ // put the framework 2 back to the RESOLVED state - try { - equinox2.stop(); - } catch (BundleException e) { - fail("Unexpected erorr stopping framework", e); //$NON-NLS-1$ - } - try { - equinox2.waitForStop(10000); - } catch (InterruptedException e) { - fail("Unexpected interrupted exception", e); //$NON-NLS-1$ - } + stop(equinox2); assertEquals("Wrong state for SystemBundle", Bundle.RESOLVED, equinox2.getState()); //$NON-NLS-1$ handlerReg.unregister(); System.getProperties().remove("test.url"); @@ -1452,17 +1179,14 @@ public class SystemBundleTests extends AbstractBundleTests { assertFalse("UUIDs are the same: " + uuid1_1, uuid1_1.equals(uuid2_1)); + stop(equinox1); + stop(equinox2); + try { - equinox1.stop(); - equinox2.stop(); - equinox1.waitForStop(1000); - equinox2.waitForStop(1000); equinox1.init(); equinox2.init(); } catch (BundleException e) { fail("Failed to re-init frameworks.", e); - } catch (InterruptedException e) { - fail("Failed to stop frameworks.", e); } String uuid1_2 = equinox1.getBundleContext().getProperty(Constants.FRAMEWORK_UUID); @@ -1473,16 +1197,8 @@ public class SystemBundleTests extends AbstractBundleTests { assertFalse("UUIDs are the same: " + uuid1_2, uuid1_2.equals(uuid2_2)); assertFalse("UUIDs are the same: " + uuid2_1, uuid2_1.equals(uuid2_2)); - try { - equinox1.stop(); - equinox2.stop(); - equinox1.waitForStop(1000); - equinox2.waitForStop(1000); - } catch (BundleException e) { - fail("Failed to re-init frameworks.", e); - } catch (InterruptedException e) { - fail("Failed to stop frameworks.", e); - } + stop(equinox1); + stop(equinox2); } private void verifyUUID(String uuid) { @@ -1572,16 +1288,7 @@ public class SystemBundleTests extends AbstractBundleTests { } // put the framework back to the RESOLVED state - try { - equinox.stop(); - } catch (BundleException e) { - fail("Unexpected erorr stopping framework", e); //$NON-NLS-1$ - } - try { - equinox.waitForStop(10000); - } catch (InterruptedException e) { - fail("Unexpected interrupted exception", e); //$NON-NLS-1$ - } + stop(equinox); try { equinox.start(); @@ -1603,16 +1310,7 @@ public class SystemBundleTests extends AbstractBundleTests { fail("Failed to get bundle entries", t); } - try { - equinox.stop(); - } catch (BundleException e) { - fail("Unexpected erorr stopping framework", e); //$NON-NLS-1$ - } - try { - equinox.waitForStop(10000); - } catch (InterruptedException e) { - fail("Unexpected interrupted exception", e); //$NON-NLS-1$ - } + stop(equinox); assertEquals("Wrong state for SystemBundle", Bundle.RESOLVED, equinox.getState()); //$NON-NLS-1$ } @@ -1643,16 +1341,7 @@ public class SystemBundleTests extends AbstractBundleTests { URL resource = tb1.getResource("tb1/resource.txt"); assertNotNull("Resource is null", resource); - try { - equinox.stop(); - } catch (BundleException e) { - fail("Unexpected erorr stopping framework", e); //$NON-NLS-1$ - } - try { - equinox.waitForStop(10000); - } catch (InterruptedException e) { - fail("Unexpected interrupted exception", e); //$NON-NLS-1$ - } + stop(equinox); assertEquals("Wrong state for SystemBundle", Bundle.RESOLVED, equinox.getState()); //$NON-NLS-1$ } finally { testBundleInstaller.shutdown(); @@ -1672,16 +1361,7 @@ public class SystemBundleTests extends AbstractBundleTests { } catch (BundleException e) { fail("Failed to start the framework", e); //$NON-NLS-1$ } - try { - equinox.stop(); - } catch (BundleException e) { - fail("Unexpected erorr stopping framework", e); //$NON-NLS-1$ - } - try { - equinox.waitForStop(10000); - } catch (InterruptedException e) { - fail("Unexpected interrupted exception", e); //$NON-NLS-1$ - } + stop(equinox); assertEquals("Wrong state for SystemBundle", Bundle.RESOLVED, equinox.getState()); //$NON-NLS-1$ } @@ -1742,16 +1422,7 @@ public class SystemBundleTests extends AbstractBundleTests { reg.unregister(); } // put the framework back to the RESOLVED state - try { - equinox.stop(); - } catch (BundleException e) { - fail("Unexpected error stopping framework", e); //$NON-NLS-1$ - } - try { - equinox.waitForStop(10000); - } catch (InterruptedException e) { - fail("Unexpected interrupted exception", e); //$NON-NLS-1$ - } + stop(equinox); try { equinox.start(); @@ -1792,16 +1463,7 @@ public class SystemBundleTests extends AbstractBundleTests { } // put the framework back to the RESOLVED state - try { - equinox.stop(); - } catch (BundleException e) { - fail("Unexpected error stopping framework", e); //$NON-NLS-1$ - } - try { - equinox.waitForStop(10000); - } catch (InterruptedException e) { - fail("Unexpected interrupted exception", e); //$NON-NLS-1$ - } + stop(equinox); try { equinox.start(); @@ -1829,16 +1491,7 @@ public class SystemBundleTests extends AbstractBundleTests { assertEquals("Wrong number of wires for wiring1", 1, packages1.size()); assertEquals("Wrong number of wires for wiring2", 1, packages2.size()); - try { - equinox.stop(); - } catch (BundleException e) { - fail("Unexpected error stopping framework", e); //$NON-NLS-1$ - } - try { - equinox.waitForStop(10000); - } catch (InterruptedException e) { - fail("Unexpected interrupted exception", e); //$NON-NLS-1$ - } + stop(equinox); } private void doTestBug351519Refresh(Boolean refreshDuplicates) { @@ -1913,16 +1566,7 @@ public class SystemBundleTests extends AbstractBundleTests { assertEquals("Refreshed bundles does not include v1", refreshed[0], tb1v1); } - try { - equinox.stop(); - } catch (BundleException e) { - fail("Unexpected erorr stopping framework", e); //$NON-NLS-1$ - } - try { - equinox.waitForStop(10000); - } catch (InterruptedException e) { - fail("Unexpected interrupted exception", e); //$NON-NLS-1$ - } + stop(equinox); assertEquals("Wrong state for SystemBundle", Bundle.RESOLVED, equinox.getState()); //$NON-NLS-1$ } @@ -1950,16 +1594,7 @@ public class SystemBundleTests extends AbstractBundleTests { fail("failed to install and start test bundle", e1); //$NON-NLS-1$ } - try { - equinox.stop(); - } catch (BundleException e) { - fail("Unexpected erorr stopping framework", e); //$NON-NLS-1$ - } - try { - equinox.waitForStop(10000); - } catch (InterruptedException e) { - fail("Unexpected interrupted exception", e); //$NON-NLS-1$ - } + stop(equinox); assertEquals("Wrong state for SystemBundle", Bundle.RESOLVED, equinox.getState()); //$NON-NLS-1$ } @@ -2020,16 +1655,7 @@ public class SystemBundleTests extends AbstractBundleTests { } finally { Thread.currentThread().setContextClassLoader(current); } - try { - equinox.stop(); - } catch (BundleException e) { - fail("Unexpected error stopping framework", e); //$NON-NLS-1$ - } - try { - equinox.waitForStop(10000); - } catch (InterruptedException e) { - fail("Unexpected interrupted exception", e); //$NON-NLS-1$ - } + stop(equinox); } private void checkActive(Bundle b) { @@ -2116,16 +1742,7 @@ public class SystemBundleTests extends AbstractBundleTests { resolverHookReg.unregister(); } // put the framework back to the RESOLVED state - try { - equinox.stop(); - } catch (BundleException e) { - fail("Unexpected error stopping framework", e); //$NON-NLS-1$ - } - try { - equinox.waitForStop(10000); - } catch (InterruptedException e) { - fail("Unexpected interrupted exception", e); //$NON-NLS-1$ - } + stop(equinox); if (!errors.isEmpty()) { fail("Failed to resolve dynamic", errors.iterator().next()); @@ -2180,13 +1797,7 @@ public class SystemBundleTests extends AbstractBundleTests { } } }); - equinox.stop(); - try { - equinox.waitForStop(10000); - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); - fail("Unexpected interruption.", e); - } + stop(equinox); List<Bundle> expectedOrder = Arrays.asList(systemBundle, chainTest, chainTestA, chainTestB, chainTestC, chainTestD); assertEquals("Wrong stopping order", expectedOrder.toArray(), stoppingOrder.toArray()); @@ -2206,13 +1817,7 @@ public class SystemBundleTests extends AbstractBundleTests { equinox.start(); long startTime = System.currentTimeMillis(); - equinox.stop(); - try { - equinox.waitForStop(500); - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); - fail("Unexpected interruption.", e); - } + stop(equinox, true, 500); long stopTime = System.currentTimeMillis() - startTime; if (stopTime > 2000) { fail("waitForStop time took too long: " + stopTime); @@ -2240,14 +1845,7 @@ public class SystemBundleTests extends AbstractBundleTests { assertEquals("Wrong value for test.substitute1", "Some.PASSED.test", systemContext.getProperty("test.substitute1")); // check that non-substitution keeps $ delimiters. assertEquals("Wrong value for test.substitute2", "Some.$test.prop2$.test", systemContext.getProperty("test.substitute2")); - equinox.stop(); - try { - equinox.waitForStop(5000); - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); - fail("Unexpected interruption.", e); - } - + stop(equinox); } public void testDynamicSecurityManager() throws BundleException { @@ -2284,14 +1882,7 @@ public class SystemBundleTests extends AbstractBundleTests { // do nothing } }); - equinox.stop(); - try { - FrameworkEvent event = equinox.waitForStop(10000); - assertEquals("Wrong event.", FrameworkEvent.STOPPED, event.getType()); - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); - fail("Unexpected interruption.", e); - } + stop(equinox); assertEquals("Wrong state for SystemBundle", Bundle.RESOLVED, equinox.getState()); //$NON-NLS-1$ } finally { System.setSecurityManager(null); @@ -2616,8 +2207,7 @@ public class SystemBundleTests extends AbstractBundleTests { fail("Expected to be able to load the class from boot.", e); } long bId = b.getBundleId(); - equinox.stop(); - equinox.waitForStop(5000); + stop(equinox); // remove the setting to ensure false is used for the embedded case configIni.remove(compatBootDelegate); @@ -2667,8 +2257,7 @@ public class SystemBundleTests extends AbstractBundleTests { }; systemContext.addBundleListener(systemBundleListener); - equinox.stop(); - equinox.waitForStop(5000); + stop(equinox); assertEquals("Wrong number of STOPPING events", 1, stoppingEvent.get()); assertEquals("Wrong number of STOPPED events", 1, stoppedEvent.get()); } @@ -2711,9 +2300,7 @@ public class SystemBundleTests extends AbstractBundleTests { assertTrue("Unexpected Export-Package header: " + exportPackage, exportPackage.contains("something.system")); assertTrue("Unexpected Provide-Capability header: " + provideCapability, provideCapability.contains("something.extra")); assertTrue("Unexpected Export-Package header: " + exportPackage, exportPackage.contains("something.extra")); - equinox.stop(); - - equinox.waitForStop(5000); + stop(equinox); configuration.put(EquinoxConfiguration.PROP_SYSTEM_PROVIDE_HEADER, EquinoxConfiguration.SYSTEM_PROVIDE_HEADER_ORIGINAL); equinox = new Equinox(configuration); @@ -2725,9 +2312,7 @@ public class SystemBundleTests extends AbstractBundleTests { assertFalse("Unexpected Export-Package header: " + exportPackage, exportPackage.contains("something.system")); assertFalse("Unexpected Provide-Capability header: " + provideCapability, provideCapability.contains("something.extra")); assertFalse("Unexpected Export-Package header: " + exportPackage, exportPackage.contains("something.extra")); - equinox.stop(); - - equinox.waitForStop(5000); + stop(equinox); configuration.put(EquinoxConfiguration.PROP_SYSTEM_PROVIDE_HEADER, EquinoxConfiguration.SYSTEM_PROVIDE_HEADER_SYSTEM); equinox = new Equinox(configuration); @@ -2739,9 +2324,7 @@ public class SystemBundleTests extends AbstractBundleTests { assertTrue("Unexpected Export-Package header: " + exportPackage, exportPackage.contains("something.system")); assertFalse("Unexpected Provide-Capability header: " + provideCapability, provideCapability.contains("something.extra")); assertFalse("Unexpected Export-Package header: " + exportPackage, exportPackage.contains("something.extra")); - equinox.stop(); - - equinox.waitForStop(5000); + stop(equinox); configuration.put(EquinoxConfiguration.PROP_SYSTEM_PROVIDE_HEADER, EquinoxConfiguration.SYSTEM_PROVIDE_HEADER_SYSTEM_EXTRA); equinox = new Equinox(configuration); @@ -2753,9 +2336,7 @@ public class SystemBundleTests extends AbstractBundleTests { assertTrue("Unexpected Export-Package header: " + exportPackage, exportPackage.contains("something.system")); assertTrue("Unexpected Provide-Capability header: " + provideCapability, provideCapability.contains("something.extra")); assertTrue("Unexpected Export-Package header: " + exportPackage, exportPackage.contains("something.extra")); - equinox.stop(); - - equinox.waitForStop(5000); + stop(equinox); } public void testSystemBundleLoader() { @@ -2841,16 +2422,7 @@ public class SystemBundleTests extends AbstractBundleTests { @SuppressWarnings("deprecation") String osgiEE = equinox.getBundleContext().getProperty(Constants.FRAMEWORK_EXECUTIONENVIRONMENT); // don't do anything; just put the framework back to the RESOLVED state - try { - equinox.stop(); - } catch (BundleException e) { - fail("Unexpected error stopping framework", e); //$NON-NLS-1$ - } - try { - equinox.waitForStop(10000); - } catch (InterruptedException e) { - fail("Unexpected interrupted exception", e); //$NON-NLS-1$ - } + stop(equinox); assertEquals("Wrong state for SystemBundle", Bundle.RESOLVED, equinox.getState()); //$NON-NLS-1$ assertTrue("Wrong osgi EE: expected: " + expectedEEName + " but was: " + osgiEE, osgiEE.endsWith(expectedEEName)); @@ -2987,8 +2559,7 @@ public class SystemBundleTests extends AbstractBundleTests { assertEquals("Requirement directives differ: " + outerReq.getNamespace(), outerReq.getDirectives(), innerReq.getDirectives()); } } finally { - equinox.stop(); - equinox.waitForStop(5000); + stop(equinox); } } @@ -3038,16 +2609,7 @@ public class SystemBundleTests extends AbstractBundleTests { fail("Unexpected update error", e); //$NON-NLS-1$ } - try { - equinox.stop(); - } catch (BundleException e) { - fail("Unexpected erorr stopping framework", e); //$NON-NLS-1$ - } - try { - equinox.waitForStop(10000); - } catch (InterruptedException e) { - fail("Unexpected interrupted exception", e); //$NON-NLS-1$ - } + stop(equinox); assertEquals("Wrong state for SystemBundle", Bundle.RESOLVED, equinox.getState()); //$NON-NLS-1$ } @@ -3063,8 +2625,7 @@ public class SystemBundleTests extends AbstractBundleTests { Equinox equinox = new Equinox(configuration); equinox.start(); checkActiveThreadType(equinox, true); - equinox.stop(); - equinox.waitForStop(10000); + stop(equinox); // test setting to 'normal' // should result in a non-daemon thread @@ -3072,8 +2633,7 @@ public class SystemBundleTests extends AbstractBundleTests { equinox = new Equinox(configuration); equinox.start(); checkActiveThreadType(equinox, false); - equinox.stop(); - equinox.waitForStop(10000); + stop(equinox); // test setting to null (default) // should result in a non-daemon thread @@ -3110,8 +2670,7 @@ public class SystemBundleTests extends AbstractBundleTests { // should be active now assertEquals("Wrong state of bundle.", Bundle.ACTIVE, b.getState()); // put the framework back to the RESOLVED state - equinox.stop(); - equinox.waitForStop(10000); + stop(equinox); // revert back to default behavior configuration.remove(EquinoxConfiguration.PROP_COMPATIBILITY_START_LAZY_ON_FAIL_CLASSLOAD); @@ -3162,14 +2721,7 @@ public class SystemBundleTests extends AbstractBundleTests { // check for substitution assertEquals("Wrong value for test.config", getName(), systemContext.getProperty("test.config")); - equinox.stop(); - try { - equinox.waitForStop(5000); - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); - fail("Unexpected interruption.", e); - } - + stop(equinox); } void checkActiveThreadType(Equinox equinox, boolean expectIsDeamon) { @@ -3209,16 +2761,7 @@ public class SystemBundleTests extends AbstractBundleTests { fail("Failed init", e); } finally { System.setProperty("os.name", origOS); - try { - if (equinox != null) { - equinox.stop(); - equinox.waitForStop(1000); - } - } catch (BundleException e) { - fail("Failed to stop framework.", e); - } catch (InterruptedException e) { - fail("Failed to stop framework.", e); - } + stop(equinox); } } @@ -3242,16 +2785,7 @@ public class SystemBundleTests extends AbstractBundleTests { } catch (BundleException e) { fail("Failed init", e); } finally { - try { - if (equinox != null) { - equinox.stop(); - equinox.waitForStop(1000); - } - } catch (BundleException e) { - fail("Failed to stop framework.", e); - } catch (InterruptedException e) { - fail("Failed to stop framework.", e); - } + stop(equinox); } } @@ -3265,24 +2799,14 @@ public class SystemBundleTests extends AbstractBundleTests { equinox = new Equinox(configuration); equinox.start(); doLoggingOnMultipleListeners(equinox); - equinox.stop(); - equinox.waitForStop(1000); + stop(equinox); equinox.start(); doLoggingOnMultipleListeners(equinox); } catch (BundleException e) { fail("Failed init", e); } finally { - try { - if (equinox != null) { - equinox.stop(); - equinox.waitForStop(1000); - } - } catch (BundleException e) { - fail("Failed to stop framework.", e); - } catch (InterruptedException e) { - fail("Failed to stop framework.", e); - } + stop(equinox); } } @@ -3354,8 +2878,7 @@ public class SystemBundleTests extends AbstractBundleTests { assertNull("Found location.", logEntry.getLocation()); } } finally { - equinox.stop(); - equinox.waitForStop(1000); + stop(equinox); } } @@ -3398,16 +2921,14 @@ public class SystemBundleTests extends AbstractBundleTests { Framework framework = factory.newFramework(configuration); framework.init(); - framework.stop(); - framework.waitForStop(5000); + stop(framework); BundleRevision systemRevision1 = framework.adapt(BundleRevision.class); int capCount1 = systemRevision1.getCapabilities(null).size(); framework = factory.newFramework(configuration); framework.init(); - framework.stop(); - framework.waitForStop(5000); + stop(framework); BundleRevision systemRevision2 = framework.adapt(BundleRevision.class); int capCount2 = systemRevision2.getCapabilities(null).size(); @@ -3545,8 +3066,7 @@ public class SystemBundleTests extends AbstractBundleTests { expectedStopOrder = new ArrayList(expectedStopOrder.subList(0, 3 * (numBundles / 4))); long stopTime = System.currentTimeMillis(); - equinox.stop(); - equinox.waitForStop(20000); + stop(equinox, false, 20000); System.out.println("Stop time: " + (System.currentTimeMillis() - stopTime)); assertEquals("Size on expected order is wrong.", expectedStopOrder.size(), stoppedBundles.size()); @@ -3556,16 +3076,7 @@ public class SystemBundleTests extends AbstractBundleTests { } catch (BundleException e) { fail("Failed init", e); } finally { - try { - if (equinox != null) { - equinox.stop(); - equinox.waitForStop(1000); - } - } catch (BundleException e) { - fail("Failed to stop framework.", e); - } catch (InterruptedException e) { - fail("Failed to stop framework.", e); - } + stop(equinox); } } @@ -3615,16 +3126,7 @@ public class SystemBundleTests extends AbstractBundleTests { } catch (BundleException e) { fail("Failed init", e); } finally { - try { - if (equinox != null) { - equinox.stop(); - equinox.waitForStop(1000); - } - } catch (BundleException e) { - fail("Failed to stop framework.", e); - } catch (InterruptedException e) { - fail("Failed to stop framework.", e); - } + stop(equinox); } } @@ -3740,16 +3242,7 @@ public class SystemBundleTests extends AbstractBundleTests { } catch (BundleException e) { fail("Failed init", e); } finally { - try { - if (equinox != null) { - equinox.stop(); - equinox.waitForStop(1000); - } - } catch (BundleException e) { - fail("Failed to stop framework.", e); - } catch (InterruptedException e) { - fail("Failed to stop framework.", e); - } + stop(equinox); } } @@ -3775,12 +3268,7 @@ public class SystemBundleTests extends AbstractBundleTests { fwkWiring.resolveBundles(Collections.singleton(b)); b.start(); } - equinox.stop(); - try { - equinox.waitForStop(1000); - } catch (InterruptedException e) { - fail("Unexpected interrupted exception", e); //$NON-NLS-1$ - } + stop(equinox); equinox = null; equinox = new Equinox(configuration); equinox.start(); @@ -3797,16 +3285,7 @@ public class SystemBundleTests extends AbstractBundleTests { } } } finally { - try { - if (equinox != null) { - equinox.stop(); - equinox.waitForStop(1000); - } - } catch (BundleException e) { - fail("Failed to stop framework.", e); - } catch (InterruptedException e) { - fail("Failed to stop framework.", e); - } + stop(equinox); } } @@ -3870,16 +3349,7 @@ public class SystemBundleTests extends AbstractBundleTests { Assert.assertEquals("Errors found.", Collections.emptyList(), errors); Assert.assertEquals("Wrong number of bundles.", numBundles + 1, systemContext.getBundles().length); - try { - equinox.stop(); - } catch (BundleException e) { - fail("Unexpected erorr stopping framework", e); //$NON-NLS-1$ - } - try { - equinox.waitForStop(10000); - } catch (InterruptedException e) { - fail("Unexpected interrupted exception", e); //$NON-NLS-1$ - } + stop(equinox); assertEquals("Wrong state for SystemBundle", Bundle.RESOLVED, equinox.getState()); //$NON-NLS-1$ } @@ -3948,16 +3418,7 @@ public class SystemBundleTests extends AbstractBundleTests { } } - try { - equinox.stop(); - } catch (BundleException e) { - fail("Unexpected erorr stopping framework", e); //$NON-NLS-1$ - } - try { - equinox.waitForStop(10000); - } catch (InterruptedException e) { - fail("Unexpected interrupted exception", e); //$NON-NLS-1$ - } + stop(equinox); assertEquals("Wrong state for SystemBundle", Bundle.RESOLVED, equinox.getState()); //$NON-NLS-1$ long timeTaken = TimeUnit.NANOSECONDS.toSeconds(System.nanoTime() - startTime); @@ -4049,16 +3510,7 @@ public class SystemBundleTests extends AbstractBundleTests { executor1.shutdown(); executor2.shutdown(); } - try { - equinox.stop(); - } catch (BundleException e) { - fail("Unexpected erorr stopping framework", e); //$NON-NLS-1$ - } - try { - equinox.waitForStop(10000); - } catch (InterruptedException e) { - fail("Unexpected interrupted exception", e); //$NON-NLS-1$ - } + stop(equinox); assertEquals("Wrong state for SystemBundle", Bundle.RESOLVED, equinox.getState()); //$NON-NLS-1$ if (!errorsAndWarnings.isEmpty()) { @@ -4101,16 +3553,7 @@ public class SystemBundleTests extends AbstractBundleTests { } catch (BundleException e) { fail("Failed init", e); } finally { - try { - if (equinox != null) { - equinox.stop(); - equinox.waitForStop(1000); - } - } catch (BundleException e) { - fail("Failed to stop framework.", e); - } catch (InterruptedException e) { - fail("Failed to stop framework.", e); - } + stop(equinox); } } @@ -4150,16 +3593,7 @@ public class SystemBundleTests extends AbstractBundleTests { } catch (BundleException e) { fail("Unexpected BundleException", e); } finally { - try { - if (equinox != null) { - equinox.stop(); - equinox.waitForStop(1000); - } - } catch (BundleException e) { - fail("Failed to stop framework.", e); - } catch (InterruptedException e) { - fail("Failed to stop framework.", e); - } + stop(equinox); } } @@ -4195,16 +3629,7 @@ public class SystemBundleTests extends AbstractBundleTests { } catch (BundleException e) { fail("Unexpected BundleException", e); } finally { - try { - if (equinox != null) { - equinox.stop(); - equinox.waitForStop(1000); - } - } catch (BundleException e) { - fail("Failed to stop framework.", e); - } catch (InterruptedException e) { - fail("Failed to stop framework.", e); - } + stop(equinox); } } @@ -4333,15 +3758,6 @@ public class SystemBundleTests extends AbstractBundleTests { List<BundleWire> providedWires = equinox.adapt(BundleWiring.class).getProvidedWires(PackageNamespace.PACKAGE_NAMESPACE); Assert.assertEquals("Wrong number of provided wires.", numBundles, providedWires.size()); - try { - equinox.stop(); - } catch (BundleException e) { - fail("Unexpected erorr stopping framework", e); //$NON-NLS-1$ - } - try { - equinox.waitForStop(10000); - } catch (InterruptedException e) { - fail("Unexpected interrupted exception", e); //$NON-NLS-1$ - } + stop(equinox); } } diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/container/TestModuleContainer.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/container/TestModuleContainer.java index 37da06d9a..d1ce33195 100644 --- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/container/TestModuleContainer.java +++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/container/TestModuleContainer.java @@ -3678,7 +3678,7 @@ public class TestModuleContainer extends AbstractTest { tStop2.start(); BundleException stopError = stopExceptions.poll(10, TimeUnit.SECONDS); - startLatch.countDown(); + stopLatch.countDown(); Assert.assertEquals("Wrong cause.", TimeoutException.class, stopError.getCause().getClass()); Assert.assertEquals("Wrong cause.", ThreadInfoReport.class, stopError.getCause().getCause().getClass()); diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/hooks/framework/AbstractFrameworkHookTests.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/hooks/framework/AbstractFrameworkHookTests.java index f7726f3ee..50210a9a6 100644 --- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/hooks/framework/AbstractFrameworkHookTests.java +++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/hooks/framework/AbstractFrameworkHookTests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2013, 2014 IBM Corporation and others. + * Copyright (c) 2013, 2020 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -13,6 +13,8 @@ *******************************************************************************/ package org.eclipse.osgi.tests.hooks.framework; +import static org.eclipse.osgi.tests.bundles.AbstractBundleTests.stop; + import java.io.IOException; import java.net.MalformedURLException; import java.net.URI; @@ -28,7 +30,6 @@ import org.eclipse.osgi.launch.EquinoxFactory; import org.eclipse.osgi.tests.OSGiTestsActivator; import org.eclipse.osgi.tests.bundles.BundleInstaller; import org.osgi.framework.BundleContext; -import org.osgi.framework.FrameworkEvent; import org.osgi.framework.launch.Framework; import org.osgi.framework.launch.FrameworkFactory; @@ -127,34 +128,6 @@ public abstract class AbstractFrameworkHookTests extends CoreTest { setUpClassLoader(); } - protected void stop(Framework framework) throws Exception { - stop(framework, false); - } - - protected void stopQuietly(Framework framework) { - if (framework == null) - return; - try { - stop(framework, true); - } catch (Exception e) { - // ignore; - } - } - - private void stop(Framework framework, boolean quietly) throws Exception { - try { - framework.stop(); - FrameworkEvent event = framework.waitForStop(10000); - if (!quietly) { - assertEquals("The framework was not stopped", FrameworkEvent.STOPPED, event.getType()); - } - } catch (Exception e) { - if (!quietly) { - throw e; - } - } - } - protected void tearDown() throws Exception { bundleInstaller.shutdown(); } diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/hooks/framework/BundleFileWrapperFactoryHookTests.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/hooks/framework/BundleFileWrapperFactoryHookTests.java index e9d66024d..31688f6e5 100644 --- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/hooks/framework/BundleFileWrapperFactoryHookTests.java +++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/hooks/framework/BundleFileWrapperFactoryHookTests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2015, 2016 IBM Corporation and others. + * Copyright (c) 2015, 2020 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -13,7 +13,12 @@ *******************************************************************************/ package org.eclipse.osgi.tests.hooks.framework; -import java.io.*; +import static org.eclipse.osgi.tests.bundles.AbstractBundleTests.stopQuietly; + +import java.io.BufferedReader; +import java.io.File; +import java.io.IOException; +import java.io.InputStreamReader; import java.net.URL; import java.util.HashMap; import java.util.Map; diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/hooks/framework/ClassLoaderHookTests.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/hooks/framework/ClassLoaderHookTests.java index e05aea285..89b6f4fc2 100644 --- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/hooks/framework/ClassLoaderHookTests.java +++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/hooks/framework/ClassLoaderHookTests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2013, 2018 IBM Corporation and others. + * Copyright (c) 2013, 2020 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -13,6 +13,8 @@ *******************************************************************************/ package org.eclipse.osgi.tests.hooks.framework; +import static org.eclipse.osgi.tests.bundles.AbstractBundleTests.stopQuietly; + import java.io.File; import java.net.URL; import java.util.Collection; diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/hooks/framework/ContextFinderTests.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/hooks/framework/ContextFinderTests.java index 1f175fc30..f2b8c73d8 100644 --- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/hooks/framework/ContextFinderTests.java +++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/hooks/framework/ContextFinderTests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2013, 2017 IBM Corporation and others. + * Copyright (c) 2013, 2020 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -13,6 +13,8 @@ *******************************************************************************/ package org.eclipse.osgi.tests.hooks.framework; +import static org.eclipse.osgi.tests.bundles.AbstractBundleTests.stopQuietly; + import java.io.File; import java.io.IOException; import java.net.URL; diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/hooks/framework/DevClassPathWithExtensionTests.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/hooks/framework/DevClassPathWithExtensionTests.java index 3794b9ca9..3cec0aa13 100644 --- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/hooks/framework/DevClassPathWithExtensionTests.java +++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/hooks/framework/DevClassPathWithExtensionTests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2013, 2018 IBM Corporation and others. + * Copyright (c) 2013, 2020 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -13,6 +13,9 @@ *******************************************************************************/ package org.eclipse.osgi.tests.hooks.framework; +import static org.eclipse.osgi.tests.bundles.AbstractBundleTests.stop; +import static org.eclipse.osgi.tests.bundles.AbstractBundleTests.stopQuietly; + import java.io.File; import java.util.Collection; import java.util.Collections; diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/hooks/framework/EmbeddedEquinoxWithURLInClassLoadTests.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/hooks/framework/EmbeddedEquinoxWithURLInClassLoadTests.java index 9ae57c0ce..51ac46842 100644 --- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/hooks/framework/EmbeddedEquinoxWithURLInClassLoadTests.java +++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/hooks/framework/EmbeddedEquinoxWithURLInClassLoadTests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2013, 2018 IBM Corporation and others. + * Copyright (c) 2013, 2020 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -13,6 +13,8 @@ *******************************************************************************/ package org.eclipse.osgi.tests.hooks.framework; +import static org.eclipse.osgi.tests.bundles.AbstractBundleTests.stopQuietly; + import java.io.File; import java.net.MalformedURLException; import java.net.URL; diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/hooks/framework/StorageHookTests.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/hooks/framework/StorageHookTests.java index 49677072a..42945b1ba 100644 --- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/hooks/framework/StorageHookTests.java +++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/hooks/framework/StorageHookTests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2013, 2017 IBM Corporation and others. + * Copyright (c) 2013, 2020 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -13,6 +13,8 @@ *******************************************************************************/ package org.eclipse.osgi.tests.hooks.framework; +import static org.eclipse.osgi.tests.bundles.AbstractBundleTests.stop; +import static org.eclipse.osgi.tests.bundles.AbstractBundleTests.stopQuietly; import static org.junit.Assert.assertNotEquals; import java.io.ByteArrayInputStream; @@ -199,8 +201,7 @@ public class StorageHookTests extends AbstractFrameworkHookTests { assertNotEquals("Path of updated bundle is the same.", path1, path2); - framework.stop(); - framework.waitForStop(5000); + stop(framework); // create new framework object to test loading of persistent capability. framework = createFramework(configuration); @@ -296,8 +297,7 @@ public class StorageHookTests extends AbstractFrameworkHookTests { setFactoryNullStorageHook(true); Bundle b = installBundle(); assertNotNull("Expected to have a bundle after install.", b); - framework.stop(); - framework.waitForStop(5000); + stop(framework); // create new framework to make sure null storage hook works from persistence also. framework = createFramework(configuration); diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/securityadmin/SecurityAdminUnitTests.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/securityadmin/SecurityAdminUnitTests.java index 83d7aba52..3935b9eb1 100644 --- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/securityadmin/SecurityAdminUnitTests.java +++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/securityadmin/SecurityAdminUnitTests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008, 2013 IBM Corporation and others. + * Copyright (c) 2008, 2020 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -955,8 +955,7 @@ public class SecurityAdminUnitTests extends AbstractBundleTests { updateInfos.add(cpa.newConditionalPermissionInfo(info2)); assertTrue("Failed commit", update.commit()); //$NON-NLS-1$ - equinox.stop(); - equinox.waitForStop(10000); + stop(equinox); equinox.init(); cpa = equinox.getBundleContext().getService(equinox.getBundleContext().getServiceReference(ConditionalPermissionAdmin.class)); pa = equinox.getBundleContext().getService(equinox.getBundleContext().getServiceReference(PermissionAdmin.class)); diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/securityadmin/SecurityManagerTests.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/securityadmin/SecurityManagerTests.java index 8068ca031..158ed7f63 100644 --- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/securityadmin/SecurityManagerTests.java +++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/securityadmin/SecurityManagerTests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008, 2013 IBM Corporation and others. + * Copyright (c) 2008, 2020 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -14,21 +14,44 @@ package org.eclipse.osgi.tests.securityadmin; import java.io.File; -import java.security.*; -import java.util.*; +import java.security.AllPermission; +import java.security.CodeSource; +import java.security.Permission; +import java.security.PermissionCollection; +import java.security.Policy; +import java.util.Collection; +import java.util.Dictionary; +import java.util.Enumeration; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.NoSuchElementException; import junit.framework.Test; import junit.framework.TestSuite; import org.eclipse.osgi.launch.Equinox; import org.eclipse.osgi.tests.OSGiTestsActivator; import org.eclipse.osgi.tests.bundles.AbstractBundleTests; -import org.osgi.framework.*; +import org.osgi.framework.Bundle; +import org.osgi.framework.BundleContext; +import org.osgi.framework.BundleException; +import org.osgi.framework.BundlePermission; +import org.osgi.framework.Constants; +import org.osgi.framework.PackagePermission; import org.osgi.framework.hooks.resolver.ResolverHook; import org.osgi.framework.hooks.resolver.ResolverHookFactory; import org.osgi.framework.namespace.PackageNamespace; -import org.osgi.framework.wiring.*; +import org.osgi.framework.wiring.BundleCapability; +import org.osgi.framework.wiring.BundleRequirement; +import org.osgi.framework.wiring.BundleRevision; import org.osgi.resource.Namespace; -import org.osgi.service.condpermadmin.*; -import org.osgi.service.packageadmin.*; +import org.osgi.service.condpermadmin.BundleLocationCondition; +import org.osgi.service.condpermadmin.ConditionInfo; +import org.osgi.service.condpermadmin.ConditionalPermissionAdmin; +import org.osgi.service.condpermadmin.ConditionalPermissionInfo; +import org.osgi.service.condpermadmin.ConditionalPermissionUpdate; +import org.osgi.service.packageadmin.ExportedPackage; +import org.osgi.service.packageadmin.PackageAdmin; +import org.osgi.service.packageadmin.RequiredBundle; import org.osgi.service.permissionadmin.PermissionInfo; import org.osgi.service.startlevel.StartLevel; @@ -131,16 +154,7 @@ public class SecurityManagerTests extends AbstractBundleTests { } assertEquals("Wrong state for SystemBundle", Bundle.ACTIVE, equinox.getState()); //$NON-NLS-1$ // put the framework back to the RESOLVED state - try { - equinox.stop(); - } catch (BundleException e) { - fail("Unexpected erorr stopping framework", e); //$NON-NLS-1$ - } - try { - equinox.waitForStop(10000); - } catch (InterruptedException e) { - fail("Unexpected interrupted exception", e); //$NON-NLS-1$ - } + stop(equinox); assertEquals("Wrong state for SystemBundle", Bundle.RESOLVED, equinox.getState()); //$NON-NLS-1$ assertNull("SecurityManager is not null", System.getSecurityManager()); //$NON-NLS-1$ } @@ -185,13 +199,7 @@ public class SecurityManagerTests extends AbstractBundleTests { fail("Failed to start securityA", e); //$NON-NLS-1$ } finally { // put the framework back to the RESOLVED state - equinox.stop(); - - try { - equinox.waitForStop(10000); - } catch (InterruptedException e) { - fail("Unexpected interrupted exception", e); //$NON-NLS-1$ - } + stop(equinox); } assertEquals("Wrong state for SystemBundle", Bundle.RESOLVED, equinox.getState()); //$NON-NLS-1$ assertNull("SecurityManager is not null", System.getSecurityManager()); //$NON-NLS-1$ @@ -254,13 +262,7 @@ public class SecurityManagerTests extends AbstractBundleTests { } finally { // put the framework back to the RESOLVED state - equinox.stop(); - - try { - equinox.waitForStop(10000); - } catch (InterruptedException e) { - fail("Unexpected interrupted exception", e); //$NON-NLS-1$ - } + stop(equinox); } assertEquals("Wrong state for SystemBundle", Bundle.RESOLVED, equinox.getState()); //$NON-NLS-1$ assertNull("SecurityManager is not null", System.getSecurityManager()); //$NON-NLS-1$ @@ -324,13 +326,7 @@ public class SecurityManagerTests extends AbstractBundleTests { fail("interrupted", e); //$NON-NLS-1$ } finally { // put the framework back to the RESOLVED state - equinox.stop(); - - try { - equinox.waitForStop(10000); - } catch (InterruptedException e) { - fail("Unexpected interrupted exception", e); //$NON-NLS-1$ - } + stop(equinox); } assertEquals("Wrong state for SystemBundle", Bundle.RESOLVED, equinox.getState()); //$NON-NLS-1$ assertNull("SecurityManager is not null", System.getSecurityManager()); //$NON-NLS-1$ @@ -373,13 +369,7 @@ public class SecurityManagerTests extends AbstractBundleTests { assertTrue(pa.resolveBundles(new Bundle[] {linkA, linkAClient})); } finally { // put the framework back to the RESOLVED state - equinox.stop(); - - try { - equinox.waitForStop(10000); - } catch (InterruptedException e) { - fail("Unexpected interrupted exception", e); //$NON-NLS-1$ - } + stop(equinox); } assertEquals("Wrong state for SystemBundle", Bundle.RESOLVED, equinox.getState()); //$NON-NLS-1$ assertNull("SecurityManager is not null", System.getSecurityManager()); //$NON-NLS-1$ @@ -431,13 +421,7 @@ public class SecurityManagerTests extends AbstractBundleTests { fail("Failed to start securityA", e); //$NON-NLS-1$ } finally { // put the framework back to the RESOLVED state - equinox.stop(); - - try { - equinox.waitForStop(10000); - } catch (InterruptedException e) { - fail("Unexpected interrupted exception", e); //$NON-NLS-1$ - } + stop(equinox); } assertEquals("Wrong state for SystemBundle", Bundle.RESOLVED, equinox.getState()); //$NON-NLS-1$ assertNull("SecurityManager is not null", System.getSecurityManager()); //$NON-NLS-1$ @@ -487,16 +471,7 @@ public class SecurityManagerTests extends AbstractBundleTests { } // put the framework back to the RESOLVED state - try { - equinox.stop(); - } catch (BundleException e) { - fail("Unexpected erorr stopping framework", e); //$NON-NLS-1$ - } - try { - equinox.waitForStop(10000); - } catch (InterruptedException e) { - fail("Unexpected interrupted exception", e); //$NON-NLS-1$ - } + stop(equinox); try { equinox.start(); @@ -516,16 +491,7 @@ public class SecurityManagerTests extends AbstractBundleTests { fail("Failed to start security.b bundle", e); //$NON-NLS-1$ } - try { - equinox.stop(); - } catch (BundleException e) { - fail("Unexpected erorr stopping framework", e); //$NON-NLS-1$ - } - try { - equinox.waitForStop(10000); - } catch (InterruptedException e) { - fail("Unexpected interrupted exception", e); //$NON-NLS-1$ - } + stop(equinox); assertEquals("Wrong state for SystemBundle", Bundle.RESOLVED, equinox.getState()); //$NON-NLS-1$ assertNull("SecurityManager is not null", System.getSecurityManager()); //$NON-NLS-1$ } @@ -575,16 +541,7 @@ public class SecurityManagerTests extends AbstractBundleTests { // nothing } assertEquals("Wrong startlevel", 10, sl.getStartLevel()); //$NON-NLS-1$ - try { - equinox.stop(); - } catch (BundleException e) { - fail("Unexpected erorr stopping framework", e); //$NON-NLS-1$ - } - try { - equinox.waitForStop(10000); - } catch (InterruptedException e) { - fail("Unexpected interrupted exception", e); //$NON-NLS-1$ - } + stop(equinox); assertEquals("Wrong state for SystemBundle", Bundle.RESOLVED, equinox.getState()); //$NON-NLS-1$ assertNull("SecurityManager is not null", System.getSecurityManager()); //$NON-NLS-1$ } @@ -630,16 +587,7 @@ public class SecurityManagerTests extends AbstractBundleTests { } // put the framework back to the RESOLVED state - try { - equinox.stop(); - } catch (BundleException e) { - fail("Unexpected erorr stopping framework", e); //$NON-NLS-1$ - } - try { - equinox.waitForStop(10000); - } catch (InterruptedException e) { - fail("Unexpected interrupted exception", e); //$NON-NLS-1$ - } + stop(equinox); // try again from a cached state try { @@ -662,16 +610,7 @@ public class SecurityManagerTests extends AbstractBundleTests { // expected failure } // put the framework back to the RESOLVED state - try { - equinox.stop(); - } catch (BundleException e) { - fail("Unexpected erorr stopping framework", e); //$NON-NLS-1$ - } - try { - equinox.waitForStop(10000); - } catch (InterruptedException e) { - fail("Unexpected interrupted exception", e); //$NON-NLS-1$ - } + stop(equinox); assertEquals("Wrong state for SystemBundle", Bundle.RESOLVED, equinox.getState()); //$NON-NLS-1$ assertNull("SecurityManager is not null", System.getSecurityManager()); //$NON-NLS-1$ } @@ -744,16 +683,7 @@ public class SecurityManagerTests extends AbstractBundleTests { } // put the framework back to the RESOLVED state - try { - equinox.stop(); - } catch (BundleException e) { - fail("Unexpected error stopping framework", e); //$NON-NLS-1$ - } - try { - equinox.waitForStop(10000); - } catch (InterruptedException e) { - fail("Unexpected interrupted exception", e); //$NON-NLS-1$ - } + stop(equinox); assertEquals("Wrong state for SystemBundle", Bundle.RESOLVED, equinox.getState()); //$NON-NLS-1$ assertNull("SecurityManager is not null", System.getSecurityManager()); //$NON-NLS-1$ } diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/framework/EquinoxBundle.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/framework/EquinoxBundle.java index ad6fb1ac2..3dbc4dffe 100644 --- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/framework/EquinoxBundle.java +++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/framework/EquinoxBundle.java @@ -222,7 +222,7 @@ public class EquinoxBundle implements Bundle, BundleReference { SystemBundle.this.getEquinoxContainer().getLogServices().log(EquinoxContainer.NAME, FrameworkLogEntry.ERROR, "Error stopping the framework.", e); //$NON-NLS-1$ } } - }, "Framework stop"); //$NON-NLS-1$ + }, "Framework stop - " + getEquinoxContainer().toString()); //$NON-NLS-1$ t.start(); } } finally { @@ -246,7 +246,7 @@ public class EquinoxBundle implements Bundle, BundleReference { SystemBundle.this.getEquinoxContainer().getLogServices().log(EquinoxContainer.NAME, FrameworkLogEntry.ERROR, "Error updating the framework.", e); //$NON-NLS-1$ } } - }, "Framework update"); //$NON-NLS-1$ + }, "Framework update - " + getEquinoxContainer().toString()); //$NON-NLS-1$ t.start(); } } finally { |