Search in sources :

Example 96 with Subsystem

use of org.osgi.service.subsystem.Subsystem in project aries by apache.

the class AutostartTest method testAutostartUnscoped.

@Test
public void testAutostartUnscoped() throws Exception {
    Subsystem subsystem = null;
    try {
        subsystem = installSubsystemFromFile(FEATURE_A);
        restartSubsystemsImplBundle();
        subsystem = findSubsystemService(subsystem.getSubsystemId());
        assertState(Subsystem.State.INSTALLED, subsystem);
        assertBundleState(Bundle.INSTALLED | Bundle.RESOLVED, BUNDLE_A, subsystem);
        startSubsystem(subsystem);
        restartSubsystemsImplBundle();
        subsystem = findSubsystemService(subsystem.getSubsystemId());
        assertState(Subsystem.State.ACTIVE, subsystem);
        assertBundleState(Bundle.ACTIVE, BUNDLE_A, subsystem);
        stopSubsystem(subsystem);
        restartSubsystemsImplBundle();
        subsystem = findSubsystemService(subsystem.getSubsystemId());
        assertState(Subsystem.State.RESOLVED, subsystem);
        assertBundleState(Bundle.RESOLVED, BUNDLE_A, subsystem);
    } finally {
        stopAndUninstallSubsystemSilently(subsystem);
    }
}
Also used : Subsystem(org.osgi.service.subsystem.Subsystem) Test(org.junit.Test)

Example 97 with Subsystem

use of org.osgi.service.subsystem.Subsystem in project aries by apache.

the class AutostartTest method testAutostartChildUnscoped.

@Test
public void testAutostartChildUnscoped() throws Exception {
    Subsystem featureA = null;
    try {
        featureA = installSubsystemFromFile(FEATURE_A);
        Subsystem featureB = installSubsystemFromFile(featureA, FEATURE_B);
        restartSubsystemsImplBundle();
        featureA = findSubsystemService(featureA.getSubsystemId());
        featureB = findSubsystemService(featureB.getSubsystemId());
        assertState(Subsystem.State.INSTALLED, featureA);
        assertBundleState(Bundle.INSTALLED | Bundle.RESOLVED, BUNDLE_A, featureA);
        assertState(Subsystem.State.INSTALLED, featureB);
        assertBundleState(Bundle.INSTALLED | Bundle.RESOLVED, BUNDLE_A, featureB);
        startSubsystem(featureA);
        restartSubsystemsImplBundle();
        featureA = findSubsystemService(featureA.getSubsystemId());
        featureB = findSubsystemService(featureB.getSubsystemId());
        ;
        assertState(Subsystem.State.ACTIVE, featureA);
        assertBundleState(Bundle.ACTIVE, BUNDLE_A, featureA);
        assertState(Subsystem.State.RESOLVED, featureB);
        assertBundleState(Bundle.ACTIVE, BUNDLE_A, featureB);
        startSubsystemFromResolved(featureB);
        restartSubsystemsImplBundle();
        featureA = findSubsystemService(featureA.getSubsystemId());
        featureB = findSubsystemService(featureB.getSubsystemId());
        ;
        assertState(Subsystem.State.ACTIVE, featureA);
        assertBundleState(Bundle.ACTIVE, BUNDLE_A, featureA);
        assertState(Subsystem.State.ACTIVE, featureB);
        assertBundleState(Bundle.ACTIVE, BUNDLE_A, featureB);
        stopSubsystem(featureB);
        restartSubsystemsImplBundle();
        featureA = findSubsystemService(featureA.getSubsystemId());
        featureB = findSubsystemService(featureB.getSubsystemId());
        ;
        assertState(Subsystem.State.ACTIVE, featureA);
        assertBundleState(Bundle.ACTIVE, BUNDLE_A, featureA);
        assertState(Subsystem.State.RESOLVED, featureB);
        assertBundleState(Bundle.ACTIVE, BUNDLE_A, featureB);
        startSubsystemFromResolved(featureB);
        stopSubsystem(featureA);
        restartSubsystemsImplBundle();
        featureA = findSubsystemService(featureA.getSubsystemId());
        featureB = findSubsystemService(featureB.getSubsystemId());
        ;
        assertState(Subsystem.State.RESOLVED, featureA);
        assertBundleState(Bundle.RESOLVED, BUNDLE_A, featureA);
        assertState(Subsystem.State.RESOLVED, featureB);
        assertBundleState(Bundle.RESOLVED, BUNDLE_A, featureA);
    } finally {
        stopAndUninstallSubsystemSilently(featureA);
    }
}
Also used : Subsystem(org.osgi.service.subsystem.Subsystem) Test(org.junit.Test)

Example 98 with Subsystem

use of org.osgi.service.subsystem.Subsystem in project aries by apache.

the class BasicTest method testEmptySubsystem.

/*
     * This tests a subsystem containing only a subsystem manifest which, in
     * turn, contains only a Subsystem-SymbolicName header.
     */
@Test
public void testEmptySubsystem() throws Exception {
    Subsystem emptySubsystem = installSubsystemFromFile("emptySubsystem.esa");
    AssertionError error = null;
    try {
        assertSymbolicName("org.apache.aries.subsystem.itests.subsystem.empty", emptySubsystem);
        // The version should be the default version.
        assertVersion(Version.emptyVersion, emptySubsystem);
        // The type should be the default type.
        assertType(SubsystemConstants.SUBSYSTEM_TYPE_APPLICATION, emptySubsystem);
        // Since the default type is application, which is a scoped subsystem, there will
        // be one constituent representing the region context bundle.
        assertConstituents(1, emptySubsystem);
        assertChildren(0, emptySubsystem);
        startSubsystem(emptySubsystem);
        stopSubsystem(emptySubsystem);
    } catch (AssertionError e) {
        error = e;
        throw e;
    } finally {
        try {
            uninstallSubsystemSilently(emptySubsystem);
        } catch (AssertionError e) {
            if (error == null)
                throw e;
            e.printStackTrace();
        }
    }
}
Also used : Subsystem(org.osgi.service.subsystem.Subsystem) Test(org.junit.Test)

Example 99 with Subsystem

use of org.osgi.service.subsystem.Subsystem in project aries by apache.

the class BasicTest method testEmptyFeature.

@Test
public void testEmptyFeature() throws Exception {
    Subsystem emptyFeature = installSubsystemFromFile("emptyFeature.esa");
    AssertionError error = null;
    try {
        assertSymbolicName("org.apache.aries.subsystem.itests.feature.empty", emptyFeature);
        assertVersion("1.1.2", emptyFeature);
        assertType(SubsystemConstants.SUBSYSTEM_TYPE_FEATURE, emptyFeature);
        assertConstituents(0, emptyFeature);
        assertChildren(0, emptyFeature);
        startSubsystem(emptyFeature);
        stopSubsystem(emptyFeature);
    } catch (AssertionError e) {
        error = e;
        throw e;
    } finally {
        try {
            uninstallSubsystemSilently(emptyFeature);
        } catch (AssertionError e) {
            if (error == null)
                throw e;
            e.printStackTrace();
        }
    }
}
Also used : Subsystem(org.osgi.service.subsystem.Subsystem) Test(org.junit.Test)

Example 100 with Subsystem

use of org.osgi.service.subsystem.Subsystem in project aries by apache.

the class BundleEventHookTest method testIgnoreUninstalledBundleInAsyncInstalledEvent.

/*
     * Because bundle events are queued for later asynchronous processing while
     * the root subsystem is initializing, it is possible to see an installed
     * event for a bundle that has been uninstalled (i.e. the bundle revision
     * will be null). These events should be ignored.
     */
@Test
public void testIgnoreUninstalledBundleInAsyncInstalledEvent() throws Exception {
    final Bundle core = getSubsystemCoreBundle();
    core.stop();
    final AtomicReference<Bundle> a = new AtomicReference<Bundle>();
    bundleContext.addServiceListener(new ServiceListener() {

        @SuppressWarnings("unchecked")
        @Override
        public void serviceChanged(ServiceEvent event) {
            if ((event.getType() & (ServiceEvent.REGISTERED | ServiceEvent.MODIFIED)) == 0)
                return;
            if (a.get() != null)
                // We've been here before and already done what needs doing.
                return;
            ServiceReference sr = (ServiceReference) event.getServiceReference();
            bundleContext.getService(sr);
            try {
                // Queue up the installed event.
                a.set(core.getBundleContext().installBundle(BUNDLE_A, new FileInputStream(BUNDLE_A)));
                // Ensure the bundle will be uninstalled before the event is processed.
                a.get().uninstall();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }, "(&(objectClass=org.osgi.service.subsystem.Subsystem)(subsystem.id=0)(subsystem.state=RESOLVED))");
    try {
        // Before the fix, this would fail due to an NPE resulting from a
        // null bundle revision.
        core.start();
    } catch (BundleException e) {
        e.printStackTrace();
        fail("Subsystems failed to handle an asynchronous bundle installed event after the bundle was uninstalled");
    }
    assertBundleState(a.get(), Bundle.UNINSTALLED);
    Subsystem root = getRootSubsystem();
    assertState(Subsystem.State.ACTIVE, root);
    assertNotConstituent(root, a.get().getSymbolicName());
}
Also used : ServiceListener(org.osgi.framework.ServiceListener) Bundle(org.osgi.framework.Bundle) ServiceEvent(org.osgi.framework.ServiceEvent) Subsystem(org.osgi.service.subsystem.Subsystem) AtomicReference(java.util.concurrent.atomic.AtomicReference) BundleException(org.osgi.framework.BundleException) FileInputStream(java.io.FileInputStream) TimeoutException(java.util.concurrent.TimeoutException) IOException(java.io.IOException) BundleException(org.osgi.framework.BundleException) ServiceReference(org.osgi.framework.ServiceReference) Test(org.junit.Test)

Aggregations

Subsystem (org.osgi.service.subsystem.Subsystem)202 Test (org.junit.Test)151 SubsystemTest (org.apache.aries.subsystem.itests.SubsystemTest)78 AriesSubsystem (org.apache.aries.subsystem.AriesSubsystem)52 SubsystemException (org.osgi.service.subsystem.SubsystemException)50 Bundle (org.osgi.framework.Bundle)48 SubsystemArchiveBuilder (org.apache.aries.subsystem.itests.util.SubsystemArchiveBuilder)31 BundleArchiveBuilder (org.apache.aries.subsystem.itests.util.BundleArchiveBuilder)22 BasicSubsystem (org.apache.aries.subsystem.core.internal.BasicSubsystem)19 IOException (java.io.IOException)13 Hashtable (java.util.Hashtable)9 ServiceReference (org.osgi.framework.ServiceReference)8 File (java.io.File)7 BundleContext (org.osgi.framework.BundleContext)7 ArrayList (java.util.ArrayList)6 TestCapability (org.apache.aries.subsystem.itests.util.TestCapability)6 ByteArrayInputStream (java.io.ByteArrayInputStream)5 FileInputStream (java.io.FileInputStream)5 Callable (java.util.concurrent.Callable)5 BundleException (org.osgi.framework.BundleException)5