Search in sources :

Example 6 with StartLevel

use of org.osgi.service.startlevel.StartLevel in project rt.equinox.framework by eclipse.

the class SecurityManagerTests method testBug287750.

public void testBug287750() {
    File config = OSGiTestsActivator.getContext().getDataFile(getName());
    Map<String, Object> configuration = new HashMap<String, Object>();
    configuration.put(Constants.FRAMEWORK_STORAGE, config.getAbsolutePath());
    configuration.put(Constants.FRAMEWORK_SECURITY, Constants.FRAMEWORK_SECURITY_OSGI);
    Equinox equinox = new Equinox(configuration);
    try {
        equinox.init();
    } catch (BundleException e) {
        // $NON-NLS-1$
        fail("Unexpected exception on init()", e);
    }
    // $NON-NLS-1$
    assertNotNull("SecurityManager is null", System.getSecurityManager());
    // should be in the STARTING state
    // $NON-NLS-1$
    assertEquals("Wrong state for SystemBundle", Bundle.STARTING, equinox.getState());
    try {
        equinox.start();
    } catch (BundleException e) {
        // $NON-NLS-1$
        fail("Failed to start the framework", e);
    }
    // $NON-NLS-1$
    assertEquals("Wrong state for SystemBundle", Bundle.ACTIVE, equinox.getState());
    BundleContext systemContext = equinox.getBundleContext();
    // $NON-NLS-1$
    assertNotNull("System context is null", systemContext);
    Bundle testBundle = null;
    try {
        // $NON-NLS-1$
        String locationTestBundle = installer.getBundleLocation("test.bug287750");
        testBundle = systemContext.installBundle(locationTestBundle);
    } catch (BundleException e) {
        // $NON-NLS-1$
        fail("Failed to install security test bundles", e);
    }
    try {
        testBundle.start();
    } catch (BundleException e) {
        // $NON-NLS-1$
        fail("Failed to start security.b bundle", e);
    }
    StartLevel sl = (StartLevel) systemContext.getService(systemContext.getServiceReference(StartLevel.class.getName()));
    if (sl.getStartLevel() != 10)
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e1) {
        // nothing
        }
    // $NON-NLS-1$
    assertEquals("Wrong startlevel", 10, sl.getStartLevel());
    try {
        equinox.stop();
    } catch (BundleException e) {
        // $NON-NLS-1$
        fail("Unexpected erorr stopping framework", e);
    }
    try {
        equinox.waitForStop(10000);
    } catch (InterruptedException e) {
        // $NON-NLS-1$
        fail("Unexpected interrupted exception", e);
    }
    // $NON-NLS-1$
    assertEquals("Wrong state for SystemBundle", Bundle.RESOLVED, equinox.getState());
    // $NON-NLS-1$
    assertNull("SecurityManager is not null", System.getSecurityManager());
}
Also used : Equinox(org.eclipse.osgi.launch.Equinox) StartLevel(org.osgi.service.startlevel.StartLevel) File(java.io.File)

Example 7 with StartLevel

use of org.osgi.service.startlevel.StartLevel in project rt.equinox.framework by eclipse.

the class ClassLoadingBundleTests method testStartTransient.

public void testStartTransient() 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 Bundle.start(START_TRANSIENT)
    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 call start(START_TRANSIENT) before the start-level is met.  This should result in no events
    try {
        osgiA.start(Bundle.START_TRANSIENT);
        // $NON-NLS-1$
        assertFalse("Bundle is started!!", osgiA.getState() == Bundle.ACTIVE);
    } catch (BundleException e) {
        // $NON-NLS-1$
        assertEquals("Expected invalid operation", BundleException.START_TRANSIENT_ERROR, e.getType());
    }
    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);
    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[0];
    actualEvents = simpleResults.getResults(0);
    compareResults(expectedEvents, actualEvents);
    // now call start(START_TRANSIENT) 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);
    osgiA.start(Bundle.START_TRANSIENT);
    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) BundleException(org.osgi.framework.BundleException)

Example 8 with StartLevel

use of org.osgi.service.startlevel.StartLevel in project rt.equinox.framework by eclipse.

the class ClassLoadingBundleTests method testBug300692_01.

public void testBug300692_01() 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");
        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");
        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);
    }
}
Also used : FrameworkEvent(org.osgi.framework.FrameworkEvent) Bundle(org.osgi.framework.Bundle) StartLevel(org.osgi.service.startlevel.StartLevel) BundleEvent(org.osgi.framework.BundleEvent) Endpoint(javax.xml.ws.Endpoint)

Example 9 with StartLevel

use of org.osgi.service.startlevel.StartLevel in project rt.equinox.framework by eclipse.

the class ClassLoadingBundleTests method testBug408629.

public void testBug408629() 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 });
    // eager start chainTestD
    chainTestD.start();
    Object[] expectedEvents1 = new Object[5];
    expectedEvents1[0] = new BundleEvent(BundleEvent.RESOLVED, chainTestD);
    expectedEvents1[1] = new BundleEvent(BundleEvent.RESOLVED, chainTestC);
    expectedEvents1[2] = new BundleEvent(BundleEvent.RESOLVED, chainTestB);
    expectedEvents1[3] = new BundleEvent(BundleEvent.RESOLVED, chainTestA);
    expectedEvents1[4] = new BundleEvent(BundleEvent.RESOLVED, chainTest);
    Object[] actualEvents = syncListenerResults.getResults(5);
    compareResults(expectedEvents1, 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);
        expectedEvents1 = new Object[14];
        Object[] expectedEvents2 = new Object[14];
        int i1 = 0;
        int i2 = 0;
        expectedEvents1[i1++] = new BundleEvent(BundleEvent.LAZY_ACTIVATION, chainTestA);
        expectedEvents2[i2++] = new BundleEvent(BundleEvent.LAZY_ACTIVATION, chainTestA);
        expectedEvents1[i1++] = new BundleEvent(BundleEvent.LAZY_ACTIVATION, chainTestB);
        expectedEvents2[i2++] = new BundleEvent(BundleEvent.LAZY_ACTIVATION, chainTestB);
        expectedEvents1[i1++] = new BundleEvent(BundleEvent.LAZY_ACTIVATION, chainTestC);
        expectedEvents2[i2++] = new BundleEvent(BundleEvent.LAZY_ACTIVATION, chainTestC);
        expectedEvents1[i1++] = new BundleEvent(BundleEvent.STARTING, chainTest);
        expectedEvents2[i2++] = new BundleEvent(BundleEvent.STARTING, chainTest);
        expectedEvents1[i1++] = new BundleEvent(BundleEvent.LAZY_ACTIVATION, chainTestD);
        expectedEvents1[i1++] = new BundleEvent(BundleEvent.STARTING, chainTestB);
        expectedEvents2[i2++] = new BundleEvent(BundleEvent.STARTING, chainTestB);
        expectedEvents1[i1++] = new BundleEvent(BundleEvent.STARTED, chainTestB);
        expectedEvents2[i2++] = new BundleEvent(BundleEvent.STARTED, chainTestB);
        expectedEvents2[i2++] = new BundleEvent(BundleEvent.LAZY_ACTIVATION, chainTestD);
        expectedEvents1[i1++] = new BundleEvent(BundleEvent.STARTING, chainTestD);
        expectedEvents2[i2++] = new BundleEvent(BundleEvent.STARTING, chainTestD);
        expectedEvents1[i1++] = new BundleEvent(BundleEvent.STARTED, chainTestD);
        expectedEvents2[i2++] = new BundleEvent(BundleEvent.STARTED, chainTestD);
        expectedEvents1[i1++] = new BundleEvent(BundleEvent.STARTING, chainTestC);
        expectedEvents2[i2++] = new BundleEvent(BundleEvent.STARTING, chainTestC);
        expectedEvents1[i1++] = new BundleEvent(BundleEvent.STARTED, chainTestC);
        expectedEvents2[i2++] = new BundleEvent(BundleEvent.STARTED, chainTestC);
        expectedEvents1[i1++] = new BundleEvent(BundleEvent.STARTING, chainTestA);
        expectedEvents2[i2++] = new BundleEvent(BundleEvent.STARTING, chainTestA);
        expectedEvents1[i1++] = new BundleEvent(BundleEvent.STARTED, chainTestA);
        expectedEvents2[i2++] = new BundleEvent(BundleEvent.STARTED, chainTestA);
        expectedEvents1[i1++] = new BundleEvent(BundleEvent.STARTED, chainTest);
        expectedEvents2[i2++] = new BundleEvent(BundleEvent.STARTED, chainTest);
        actualFrameworkEvents = syncListenerResults.getResults(14);
        try {
            compareResults(expectedEvents1, actualFrameworkEvents);
        } catch (AssertionFailedError e) {
            // try the second alternative
            compareResults(expectedEvents2, 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);
    }
}
Also used : FrameworkEvent(org.osgi.framework.FrameworkEvent) Bundle(org.osgi.framework.Bundle) StartLevel(org.osgi.service.startlevel.StartLevel) BundleEvent(org.osgi.framework.BundleEvent) AssertionFailedError(junit.framework.AssertionFailedError) Endpoint(javax.xml.ws.Endpoint)

Example 10 with StartLevel

use of org.osgi.service.startlevel.StartLevel in project rt.equinox.framework by eclipse.

the class ClassLoadingBundleTests method testBug306181.

public void testBug306181() throws BundleException {
    StartLevel sl = installer.getStartLevel();
    int origSL = sl.getStartLevel();
    int origBundleSL = sl.getInitialBundleStartLevel();
    int newSL = origSL + 1;
    sl.setInitialBundleStartLevel(newSL);
    try {
        Bundle a = installer.installBundle("test.bug306181a");
        Bundle b = installer.installBundle("test.bug306181b");
        sl.setBundleStartLevel(a, newSL);
        sl.setBundleStartLevel(b, newSL);
        installer.resolveBundles(new Bundle[] { a, b });
        a.start();
        b.start(Bundle.START_ACTIVATION_POLICY);
        sl.setStartLevel(newSL);
        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);
        assertEquals("Bundle A is not active", Bundle.ACTIVE, a.getState());
        assertEquals("Bundle B is not active", Bundle.STARTING, b.getState());
        ServiceReference[] regs = a.getRegisteredServices();
        if (regs != null && regs.length > 0) {
            fail(OSGiTestsActivator.getContext().getService(regs[0]).toString());
        }
    } finally {
        sl.setInitialBundleStartLevel(origBundleSL);
        sl.setStartLevel(origSL);
        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);
    }
}
Also used : FrameworkEvent(org.osgi.framework.FrameworkEvent) Bundle(org.osgi.framework.Bundle) StartLevel(org.osgi.service.startlevel.StartLevel) Endpoint(javax.xml.ws.Endpoint) ServiceReference(org.osgi.framework.ServiceReference)

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