use of org.osgi.service.startlevel.StartLevel in project rt.equinox.framework by eclipse.
the class ClassLoadingBundleTests method testStopTransient.
public void testStopTransient() throws Exception {
// $NON-NLS-1$
Bundle osgiA = installer.installBundle("osgi.lazystart.a");
installer.resolveBundles(new Bundle[] { osgiA });
StartLevel startLevel = installer.getStartLevel();
startLevel.setBundleStartLevel(osgiA, startLevel.getStartLevel() + 10);
// persistently start the bundle
osgiA.start();
// test that the bundle is started when start-level is met
startLevel.setStartLevel(startLevel.getStartLevel() + 15);
Object[] expectedFrameworkEvents = new Object[1];
expectedFrameworkEvents[0] = new FrameworkEvent(FrameworkEvent.STARTLEVEL_CHANGED, OSGiTestsActivator.getContext().getBundle(0), null);
Object[] actualFrameworkEvents = frameworkListenerResults.getResults(1);
compareResults(expectedFrameworkEvents, actualFrameworkEvents);
Object[] expectedEvents = new Object[1];
expectedEvents[0] = new BundleEvent(BundleEvent.STARTED, osgiA);
Object[] actualEvents = simpleResults.getResults(1);
compareResults(expectedEvents, actualEvents);
startLevel.setStartLevel(startLevel.getStartLevel() - 15);
expectedFrameworkEvents = new Object[1];
expectedFrameworkEvents[0] = new FrameworkEvent(FrameworkEvent.STARTLEVEL_CHANGED, OSGiTestsActivator.getContext().getBundle(0), null);
actualFrameworkEvents = frameworkListenerResults.getResults(1);
compareResults(expectedFrameworkEvents, actualFrameworkEvents);
expectedEvents = new Object[1];
expectedEvents[0] = new BundleEvent(BundleEvent.STOPPED, osgiA);
actualEvents = simpleResults.getResults(1);
compareResults(expectedEvents, actualEvents);
// now call stop(STOP_TRANSIENT) while the start-level is met.
startLevel.setStartLevel(startLevel.getStartLevel() + 15);
expectedFrameworkEvents = new Object[1];
expectedFrameworkEvents[0] = new FrameworkEvent(FrameworkEvent.STARTLEVEL_CHANGED, OSGiTestsActivator.getContext().getBundle(0), null);
actualFrameworkEvents = frameworkListenerResults.getResults(1);
compareResults(expectedFrameworkEvents, actualFrameworkEvents);
expectedEvents = new Object[1];
expectedEvents[0] = new BundleEvent(BundleEvent.STARTED, osgiA);
actualEvents = simpleResults.getResults(1);
compareResults(expectedEvents, actualEvents);
osgiA.stop(Bundle.STOP_TRANSIENT);
expectedEvents = new Object[1];
expectedEvents[0] = new BundleEvent(BundleEvent.STOPPED, osgiA);
actualEvents = simpleResults.getResults(1);
compareResults(expectedEvents, actualEvents);
startLevel.setStartLevel(startLevel.getStartLevel() - 15);
expectedFrameworkEvents = new Object[1];
expectedFrameworkEvents[0] = new FrameworkEvent(FrameworkEvent.STARTLEVEL_CHANGED, OSGiTestsActivator.getContext().getBundle(0), null);
actualFrameworkEvents = frameworkListenerResults.getResults(1);
compareResults(expectedFrameworkEvents, actualFrameworkEvents);
// now make sure the bundle still restarts when start-level is met
startLevel.setStartLevel(startLevel.getStartLevel() + 15);
expectedFrameworkEvents = new Object[1];
expectedFrameworkEvents[0] = new FrameworkEvent(FrameworkEvent.STARTLEVEL_CHANGED, OSGiTestsActivator.getContext().getBundle(0), null);
actualFrameworkEvents = frameworkListenerResults.getResults(1);
compareResults(expectedFrameworkEvents, actualFrameworkEvents);
expectedEvents = new Object[1];
expectedEvents[0] = new BundleEvent(BundleEvent.STARTED, osgiA);
actualEvents = simpleResults.getResults(1);
compareResults(expectedEvents, actualEvents);
startLevel.setStartLevel(startLevel.getStartLevel() - 15);
expectedFrameworkEvents = new Object[1];
expectedFrameworkEvents[0] = new FrameworkEvent(FrameworkEvent.STARTLEVEL_CHANGED, OSGiTestsActivator.getContext().getBundle(0), null);
actualFrameworkEvents = frameworkListenerResults.getResults(1);
compareResults(expectedFrameworkEvents, actualFrameworkEvents);
expectedEvents = new Object[1];
expectedEvents[0] = new BundleEvent(BundleEvent.STOPPED, osgiA);
actualEvents = simpleResults.getResults(1);
compareResults(expectedEvents, actualEvents);
}
use of org.osgi.service.startlevel.StartLevel in project rt.equinox.framework by eclipse.
the class ClassLoadingBundleTests method testStartResolve.
public void testStartResolve() throws Exception {
// install a bundle and set its start-level high, then crank up the framework start-level. This should result in no events
// $NON-NLS-1$
Bundle test = installer.installBundle("test");
StartLevel startLevel = installer.getStartLevel();
startLevel.setBundleStartLevel(test, startLevel.getStartLevel() + 10);
try {
test.start();
} catch (BundleException e) {
// $NON-NLS-1$
fail("Unexpected exception", e);
}
// $NON-NLS-1$
assertEquals("Wrong state", Bundle.INSTALLED, test.getState());
startLevel.setStartLevel(startLevel.getStartLevel() + 15);
Object[] expectedFrameworkEvents = new Object[1];
expectedFrameworkEvents[0] = new FrameworkEvent(FrameworkEvent.STARTLEVEL_CHANGED, OSGiTestsActivator.getContext().getBundle(0), null);
Object[] actualFrameworkEvents = frameworkListenerResults.getResults(1);
compareResults(expectedFrameworkEvents, actualFrameworkEvents);
// $NON-NLS-1$
assertEquals("Wrong state", Bundle.ACTIVE, test.getState());
}
Aggregations