use of org.osgi.framework.BundleEvent in project rt.equinox.framework by eclipse.
the class ClassLoadingBundleTests method testOSGiLazyStart.
public void testOSGiLazyStart() throws Exception {
// $NON-NLS-1$
Bundle osgi = installer.installBundle("osgi.lazystart");
// $NON-NLS-1$
Bundle osgiA = installer.installBundle("osgi.lazystart.a");
// $NON-NLS-1$
Bundle osgiB = installer.installBundle("osgi.lazystart.b");
// $NON-NLS-1$
Bundle osgiC = installer.installBundle("osgi.lazystart.c");
// $NON-NLS-1$
assertTrue("osgi lazy start resolve", installer.resolveBundles(new Bundle[] { osgi, osgiA, osgiB, osgiC }));
// $NON-NLS-1$
((ITestRunner) osgi.loadClass("osgi.lazystart.LazySimple").newInstance()).testIt();
Object[] expectedEvents = new Object[1];
expectedEvents[0] = new BundleEvent(BundleEvent.STARTED, osgiA);
Object[] actualEvents = simpleResults.getResults(1);
compareResults(expectedEvents, actualEvents);
// $NON-NLS-1$
((ITestRunner) osgi.loadClass("osgi.lazystart.LazyExclude1").newInstance()).testIt();
// $NON-NLS-1$
assertTrue("exceptions no event", simpleResults.getResults(0).length == 0);
// $NON-NLS-1$
((ITestRunner) osgi.loadClass("osgi.lazystart.LazyExclude2").newInstance()).testIt();
expectedEvents = new Object[1];
expectedEvents[0] = new BundleEvent(BundleEvent.STARTED, osgiB);
actualEvents = simpleResults.getResults(1);
compareResults(expectedEvents, actualEvents);
// $NON-NLS-1$
((ITestRunner) osgi.loadClass("osgi.lazystart.LazyInclude1").newInstance()).testIt();
// $NON-NLS-1$
assertTrue("exceptions no event", simpleResults.getResults(0).length == 0);
// $NON-NLS-1$
((ITestRunner) osgi.loadClass("osgi.lazystart.LazyInclude2").newInstance()).testIt();
expectedEvents = new Object[1];
expectedEvents[0] = new BundleEvent(BundleEvent.STARTED, osgiC);
actualEvents = simpleResults.getResults(1);
compareResults(expectedEvents, actualEvents);
}
use of org.osgi.framework.BundleEvent in project rt.equinox.framework by eclipse.
the class ClassLoadingBundleTests method testStartTransientByLoadClass.
public void testStartTransientByLoadClass() 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 osgiA = installer.installBundle("osgi.lazystart.a");
installer.resolveBundles(new Bundle[] { osgiA });
StartLevel startLevel = installer.getStartLevel();
startLevel.setBundleStartLevel(osgiA, startLevel.getStartLevel() + 10);
// test transient start by loadClass
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);
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);
Object[] expectedEvents = new Object[0];
Object[] actualEvents = simpleResults.getResults(0);
compareResults(expectedEvents, actualEvents);
// now load a class from it before the start-level is met. This should result in no events
// $NON-NLS-1$
osgiA.loadClass("osgi.lazystart.a.ATest");
expectedEvents = new Object[0];
actualEvents = simpleResults.getResults(0);
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.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);
// now load a class while 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);
// $NON-NLS-1$
osgiA.loadClass("osgi.lazystart.a.ATest");
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.framework.BundleEvent in project rt.equinox.framework by eclipse.
the class ClassLoadingBundleTests method testBug258659_01.
public void testBug258659_01() throws Exception {
// install a bundle
// $NON-NLS-1$
Bundle osgiA = installer.installBundle("osgi.lazystart.a");
SynchronousBundleListener testLoadClassListener = new SynchronousBundleListener() {
public void bundleChanged(BundleEvent event) {
if (event.getType() == BundleEvent.LAZY_ACTIVATION)
try {
// $NON-NLS-1$
event.getBundle().loadClass("osgi.lazystart.a.ATest");
} catch (ClassNotFoundException e) {
simpleResults.addEvent(e);
}
}
};
OSGiTestsActivator.getContext().addBundleListener(testLoadClassListener);
try {
osgiA.start(Bundle.START_ACTIVATION_POLICY);
Object[] expectedEvents = new Object[1];
expectedEvents[0] = new BundleEvent(BundleEvent.STARTED, osgiA);
Object[] actualEvents = simpleResults.getResults(1);
compareResults(expectedEvents, actualEvents);
} finally {
OSGiTestsActivator.getContext().removeBundleListener(testLoadClassListener);
}
}
use of org.osgi.framework.BundleEvent in project rt.equinox.framework by eclipse.
the class ClassLoadingBundleTests method testBug258659_02.
public void testBug258659_02() throws Exception {
// install a bundle
// $NON-NLS-1$
Bundle osgiA = installer.installBundle("osgi.lazystart.a");
osgiA.start(Bundle.START_ACTIVATION_POLICY);
SynchronousBundleListener testLoadClassListener = new SynchronousBundleListener() {
public void bundleChanged(BundleEvent event) {
if (event.getType() == BundleEvent.LAZY_ACTIVATION)
try {
// $NON-NLS-1$
event.getBundle().loadClass("osgi.lazystart.a.ATest");
} catch (ClassNotFoundException e) {
simpleResults.addEvent(e);
}
}
};
OSGiTestsActivator.getContext().addBundleListener(testLoadClassListener);
try {
installer.refreshPackages(new Bundle[] { osgiA });
Object[] expectedEvents = new Object[1];
expectedEvents[0] = new BundleEvent(BundleEvent.STARTED, osgiA);
Object[] actualEvents = simpleResults.getResults(1);
compareResults(expectedEvents, actualEvents);
} finally {
OSGiTestsActivator.getContext().removeBundleListener(testLoadClassListener);
}
}
use of org.osgi.framework.BundleEvent in project rt.equinox.framework by eclipse.
the class ClassLoadingBundleTests method testBug213791.
public void testBug213791() throws Exception {
// install a bundle and call start(START_ACTIVATION_POLICY) twice
// $NON-NLS-1$
Bundle osgiA = installer.installBundle("osgi.lazystart.a");
installer.resolveBundles(new Bundle[] { osgiA });
if (osgiA.getState() == Bundle.STARTING)
osgiA.stop();
osgiA.start(Bundle.START_ACTIVATION_POLICY);
Object[] expectedEvents = new Object[0];
Object[] actualEvents = simpleResults.getResults(0);
compareResults(expectedEvents, actualEvents);
osgiA.start(Bundle.START_ACTIVATION_POLICY);
expectedEvents = new Object[0];
actualEvents = simpleResults.getResults(0);
compareResults(expectedEvents, actualEvents);
// $NON-NLS-1$
osgiA.loadClass("osgi.lazystart.a.ATest");
expectedEvents = new Object[1];
expectedEvents[0] = new BundleEvent(BundleEvent.STARTED, osgiA);
actualEvents = simpleResults.getResults(1);
compareResults(expectedEvents, actualEvents);
}
Aggregations