use of org.osgi.framework.BundleEvent in project rt.equinox.framework by eclipse.
the class ClassLoadingBundleTests method testClassCircularityError.
public void testClassCircularityError() throws Exception {
// $NON-NLS-1$
Bundle circularityTest = installer.installBundle("circularity.test");
// $NON-NLS-1$
Bundle circularityTestA = installer.installBundle("circularity.test.a");
// $NON-NLS-1$
circularityTest.loadClass("circularity.test.TestCircularity");
Object[] expectedEvents = new Object[2];
expectedEvents[0] = new BundleEvent(BundleEvent.STARTED, circularityTest);
expectedEvents[1] = new BundleEvent(BundleEvent.STARTED, circularityTestA);
Object[] actualEvents = simpleResults.getResults(2);
compareResults(expectedEvents, actualEvents);
}
use of org.osgi.framework.BundleEvent in project rt.equinox.framework by eclipse.
the class ClassLoadingBundleTests method testBug300692_02.
public void testBug300692_02() throws BundleException {
// $NON-NLS-1$
Bundle chainTest = installer.installBundle("chain.test");
// $NON-NLS-1$
Bundle chainTestA = installer.installBundle("chain.test.a");
// $NON-NLS-1$
Bundle chainTestB = installer.installBundle("chain.test.b");
// $NON-NLS-1$
Bundle chainTestC = installer.installBundle("chain.test.c");
// $NON-NLS-1$
Bundle chainTestD = installer.installBundle("chain.test.d");
syncListenerResults.getResults(0);
StartLevel sl = installer.getStartLevel();
int currentSL = sl.getStartLevel();
int testSL = currentSL + 1;
sl.setBundleStartLevel(chainTest, testSL);
sl.setBundleStartLevel(chainTestA, testSL);
sl.setBundleStartLevel(chainTestB, testSL);
sl.setBundleStartLevel(chainTestC, testSL);
sl.setBundleStartLevel(chainTestD, testSL);
installer.resolveBundles(new Bundle[] { chainTest, chainTestA, chainTestB, chainTestC, chainTestD });
Object[] expectedEvents = new Object[5];
expectedEvents[0] = new BundleEvent(BundleEvent.RESOLVED, chainTestD);
expectedEvents[1] = new BundleEvent(BundleEvent.RESOLVED, chainTestC);
expectedEvents[2] = new BundleEvent(BundleEvent.RESOLVED, chainTestB);
expectedEvents[3] = new BundleEvent(BundleEvent.RESOLVED, chainTestA);
expectedEvents[4] = new BundleEvent(BundleEvent.RESOLVED, chainTest);
Object[] actualEvents = syncListenerResults.getResults(5);
compareResults(expectedEvents, actualEvents);
try {
System.setProperty("test.bug300692", "true");
System.setProperty("test.bug300692.listener", "true");
chainTest.start();
sl.setStartLevel(testSL);
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);
expectedEvents = new Object[14];
int i = 0;
expectedEvents[i++] = new BundleEvent(BundleEvent.LAZY_ACTIVATION, chainTestA);
expectedEvents[i++] = new BundleEvent(BundleEvent.LAZY_ACTIVATION, chainTestB);
expectedEvents[i++] = new BundleEvent(BundleEvent.LAZY_ACTIVATION, chainTestC);
expectedEvents[i++] = new BundleEvent(BundleEvent.LAZY_ACTIVATION, chainTestD);
expectedEvents[i++] = new BundleEvent(BundleEvent.STARTING, chainTest);
expectedEvents[i++] = new BundleEvent(BundleEvent.STARTING, chainTestD);
expectedEvents[i++] = new BundleEvent(BundleEvent.STARTED, chainTestD);
expectedEvents[i++] = new BundleEvent(BundleEvent.STARTING, chainTestB);
expectedEvents[i++] = new BundleEvent(BundleEvent.STARTED, chainTestB);
expectedEvents[i++] = new BundleEvent(BundleEvent.STARTING, chainTestC);
expectedEvents[i++] = new BundleEvent(BundleEvent.STARTED, chainTestC);
expectedEvents[i++] = new BundleEvent(BundleEvent.STARTING, chainTestA);
expectedEvents[i++] = new BundleEvent(BundleEvent.STARTED, chainTestA);
expectedEvents[i++] = new BundleEvent(BundleEvent.STARTED, chainTest);
actualFrameworkEvents = syncListenerResults.getResults(14);
compareResults(expectedEvents, actualFrameworkEvents);
} finally {
System.getProperties().remove("test.bug300692");
System.getProperties().remove("test.bug300692.listener");
sl.setStartLevel(currentSL);
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);
}
}
use of org.osgi.framework.BundleEvent in project rt.equinox.framework by eclipse.
the class ClassLoadingBundleTests method testLegacyLazyStart.
public void testLegacyLazyStart() throws Exception {
// $NON-NLS-1$
Bundle legacy = installer.installBundle("legacy.lazystart");
// $NON-NLS-1$
Bundle legacyA = installer.installBundle("legacy.lazystart.a");
// $NON-NLS-1$
Bundle legacyB = installer.installBundle("legacy.lazystart.b");
// $NON-NLS-1$
Bundle legacyC = installer.installBundle("legacy.lazystart.c");
// $NON-NLS-1$
assertTrue("legacy lazy start resolve", installer.resolveBundles(new Bundle[] { legacy, legacyA, legacyB, legacyC }));
// $NON-NLS-1$
((ITestRunner) legacy.loadClass("legacy.lazystart.SimpleLegacy").newInstance()).testIt();
Object[] expectedEvents = new Object[1];
expectedEvents[0] = new BundleEvent(BundleEvent.STARTED, legacyA);
Object[] actualEvents = simpleResults.getResults(1);
compareResults(expectedEvents, actualEvents);
// $NON-NLS-1$
((ITestRunner) legacy.loadClass("legacy.lazystart.TrueExceptionLegacy1").newInstance()).testIt();
// $NON-NLS-1$
assertTrue("exceptions no event", simpleResults.getResults(0).length == 0);
// $NON-NLS-1$
((ITestRunner) legacy.loadClass("legacy.lazystart.TrueExceptionLegacy2").newInstance()).testIt();
expectedEvents = new Object[1];
expectedEvents[0] = new BundleEvent(BundleEvent.STARTED, legacyB);
actualEvents = simpleResults.getResults(1);
compareResults(expectedEvents, actualEvents);
// $NON-NLS-1$
((ITestRunner) legacy.loadClass("legacy.lazystart.FalseExceptionLegacy1").newInstance()).testIt();
// $NON-NLS-1$
assertTrue("exceptions no event", simpleResults.getResults(0).length == 0);
// $NON-NLS-1$
((ITestRunner) legacy.loadClass("legacy.lazystart.FalseExceptionLegacy2").newInstance()).testIt();
expectedEvents = new Object[1];
expectedEvents[0] = new BundleEvent(BundleEvent.STARTED, legacyC);
actualEvents = simpleResults.getResults(1);
compareResults(expectedEvents, actualEvents);
}
use of org.osgi.framework.BundleEvent in project rt.equinox.framework by eclipse.
the class SystemBundleTests method testSystemBundleListener.
public void testSystemBundleListener() throws BundleException, InterruptedException {
File config = OSGiTestsActivator.getContext().getDataFile(getName());
config.mkdirs();
Map<String, Object> configuration = new HashMap<String, Object>();
configuration.put(Constants.FRAMEWORK_STORAGE, config.getAbsolutePath());
Equinox equinox = new Equinox(configuration);
equinox.start();
BundleContext systemContext = equinox.getBundleContext();
final AtomicInteger stoppingEvent = new AtomicInteger();
final AtomicInteger stoppedEvent = new AtomicInteger();
BundleListener systemBundleListener = new SynchronousBundleListener() {
@Override
public void bundleChanged(BundleEvent event) {
if (event.getBundle().getBundleId() == 0) {
switch(event.getType()) {
case BundleEvent.STOPPING:
stoppingEvent.incrementAndGet();
break;
case BundleEvent.STOPPED:
stoppedEvent.incrementAndGet();
default:
break;
}
}
}
};
systemContext.addBundleListener(systemBundleListener);
equinox.stop();
equinox.waitForStop(5000);
assertEquals("Wrong number of STOPPING events", 1, stoppingEvent.get());
assertEquals("Wrong number of STOPPED events", 1, stoppedEvent.get());
}
use of org.osgi.framework.BundleEvent in project opennms by OpenNMS.
the class NCSCriteriaServiceManager method setBundleContext.
public void setBundleContext(BundleContext context) {
m_bundleContext = context;
m_bundleContext.addBundleListener(new BundleListener() {
@Override
public void bundleChanged(BundleEvent event) {
switch(event.getType()) {
case BundleEvent.STOPPING:
removeAllServices();
}
}
});
}
Aggregations