Search in sources :

Example 21 with StartLevel

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

Example 22 with StartLevel

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

Aggregations

StartLevel (org.osgi.service.startlevel.StartLevel)22 Bundle (org.osgi.framework.Bundle)12 FrameworkEvent (org.osgi.framework.FrameworkEvent)10 BundleEvent (org.osgi.framework.BundleEvent)7 ServiceReference (org.osgi.framework.ServiceReference)7 PackageAdmin (org.osgi.service.packageadmin.PackageAdmin)6 Endpoint (javax.xml.ws.Endpoint)4 BundleContext (org.osgi.framework.BundleContext)4 Logger (org.apache.aries.jmx.Logger)3 Test (org.junit.Test)3 BundleException (org.osgi.framework.BundleException)3 File (java.io.File)2 HashMap (java.util.HashMap)2 ExecutorService (java.util.concurrent.ExecutorService)2 MBeanServer (javax.management.MBeanServer)2 NotCompliantMBeanException (javax.management.NotCompliantMBeanException)2 ObjectName (javax.management.ObjectName)2 Equinox (org.eclipse.osgi.launch.Equinox)2 BundleListener (org.osgi.framework.BundleListener)2 Field (java.lang.reflect.Field)1