Search in sources :

Example 61 with BundleEvent

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);
}
Also used : Bundle(org.osgi.framework.Bundle) BundleEvent(org.osgi.framework.BundleEvent)

Example 62 with BundleEvent

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);
}
Also used : FrameworkEvent(org.osgi.framework.FrameworkEvent) Bundle(org.osgi.framework.Bundle) StartLevel(org.osgi.service.startlevel.StartLevel) BundleEvent(org.osgi.framework.BundleEvent)

Example 63 with BundleEvent

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);
    }
}
Also used : Bundle(org.osgi.framework.Bundle) BundleEvent(org.osgi.framework.BundleEvent) SynchronousBundleListener(org.osgi.framework.SynchronousBundleListener)

Example 64 with BundleEvent

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);
    }
}
Also used : Bundle(org.osgi.framework.Bundle) BundleEvent(org.osgi.framework.BundleEvent) SynchronousBundleListener(org.osgi.framework.SynchronousBundleListener)

Example 65 with BundleEvent

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);
}
Also used : Bundle(org.osgi.framework.Bundle) BundleEvent(org.osgi.framework.BundleEvent)

Aggregations

BundleEvent (org.osgi.framework.BundleEvent)83 Bundle (org.osgi.framework.Bundle)49 Test (org.junit.Test)24 SynchronousBundleListener (org.osgi.framework.SynchronousBundleListener)17 BundleListener (org.osgi.framework.BundleListener)15 FeatureDTO (com.amitinside.featureflags.dto.FeatureDTO)11 File (java.io.File)10 IOException (java.io.IOException)10 BundleException (org.osgi.framework.BundleException)10 BundleContext (org.osgi.framework.BundleContext)9 FrameworkEvent (org.osgi.framework.FrameworkEvent)7 StartLevel (org.osgi.service.startlevel.StartLevel)7 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)5 List (java.util.List)5 BundleTracker (org.osgi.util.tracker.BundleTracker)5 Map (java.util.Map)4 ServiceReference (org.osgi.framework.ServiceReference)4 BundleTrackerCustomizer (org.osgi.util.tracker.BundleTrackerCustomizer)4 FileInputStream (java.io.FileInputStream)3