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);
}
}
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);
}
}
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();
}
}
}
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();
}
}
}
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());
}
Aggregations