use of org.apache.aries.subsystem.itests.util.BundleArchiveBuilder in project aries by apache.
the class Aries1383Test method testInterleavingContentDependencies.
@Test
public void testInterleavingContentDependencies() throws Exception {
Subsystem root = getRootSubsystem();
Subsystem c1 = installSubsystem(root, "c1", new SubsystemArchiveBuilder().symbolicName("c1").type(SubsystemConstants.SUBSYSTEM_TYPE_COMPOSITE + ';' + AriesProvisionDependenciesDirective.RESOLVE.toString()).content("c1b1;version=\"[0,0]\"").exportPackage("c1b1").importPackage("c2b1").bundle("c1b1", new BundleArchiveBuilder().symbolicName("c1b1").exportPackage("c1b1").importPackage("c2b1").build()).build(), false);
uninstallableSubsystems.add(c1);
Subsystem c2 = installSubsystem(root, "c2", new SubsystemArchiveBuilder().symbolicName("c2").type(SubsystemConstants.SUBSYSTEM_TYPE_COMPOSITE + ';' + AriesProvisionDependenciesDirective.RESOLVE.toString()).content("c2b1;version=\"[0,0]\"").exportPackage("c2b1").importPackage("c1b1").bundle("c2b1", new BundleArchiveBuilder().symbolicName("c2b1").exportPackage("c2b1").importPackage("c1b1").build()).build(), false);
uninstallableSubsystems.add(c2);
startSubsystem(c1, false);
stoppableSubsystems.add(c1);
assertState(EnumSet.of(State.RESOLVED, State.ACTIVE), c2);
stoppableSubsystems.add(c2);
}
use of org.apache.aries.subsystem.itests.util.BundleArchiveBuilder in project aries by apache.
the class Aries1383Test method test21.
/*
* (21) Install a scoped subsystem, S1, with
* apache-aries-provision-dependencies:=resolve. Install two features, F1 and
* F2, independently as children of S1. F1 has bundle B1 and B2 as content.
* F2 has bundle B2 and B3 as content. B2 is shared content. B1 has a
* dependency on bundle B4, B2 has a dependency on bundle B5. B3 has a
* dependency on bundle B6. Start F1. Dependency bundles B4 and B5 should be
* provisioned but not B6.
*/
@Test
public void test21() throws Exception {
serviceRegistrations.add(bundleContext.registerService(Repository.class, new TestRepository.Builder().resource(new TestRepositoryContent.Builder().capability(new TestCapability.Builder().namespace(IdentityNamespace.IDENTITY_NAMESPACE).attribute(IdentityNamespace.IDENTITY_NAMESPACE, "b1").attribute(IdentityNamespace.CAPABILITY_VERSION_ATTRIBUTE, Version.emptyVersion).attribute(IdentityNamespace.CAPABILITY_TYPE_ATTRIBUTE, IdentityNamespace.TYPE_BUNDLE)).requirement(new TestRequirement.Builder().namespace(PackageNamespace.PACKAGE_NAMESPACE).directive(PackageNamespace.REQUIREMENT_FILTER_DIRECTIVE, "(osgi.wiring.package=b4)")).content(new BundleArchiveBuilder().symbolicName("b1").importPackage("b4").buildAsBytes()).build()).resource(new TestRepositoryContent.Builder().capability(new TestCapability.Builder().namespace(IdentityNamespace.IDENTITY_NAMESPACE).attribute(IdentityNamespace.IDENTITY_NAMESPACE, "b2").attribute(IdentityNamespace.CAPABILITY_VERSION_ATTRIBUTE, Version.emptyVersion).attribute(IdentityNamespace.CAPABILITY_TYPE_ATTRIBUTE, IdentityNamespace.TYPE_BUNDLE)).requirement(new TestRequirement.Builder().namespace(PackageNamespace.PACKAGE_NAMESPACE).directive(PackageNamespace.REQUIREMENT_FILTER_DIRECTIVE, "(osgi.wiring.package=b5)")).content(new BundleArchiveBuilder().symbolicName("b2").importPackage("b5").buildAsBytes()).build()).resource(new TestRepositoryContent.Builder().capability(new TestCapability.Builder().namespace(IdentityNamespace.IDENTITY_NAMESPACE).attribute(IdentityNamespace.IDENTITY_NAMESPACE, "b3").attribute(IdentityNamespace.CAPABILITY_VERSION_ATTRIBUTE, Version.emptyVersion).attribute(IdentityNamespace.CAPABILITY_TYPE_ATTRIBUTE, IdentityNamespace.TYPE_BUNDLE)).requirement(new TestRequirement.Builder().namespace(PackageNamespace.PACKAGE_NAMESPACE).directive(PackageNamespace.REQUIREMENT_FILTER_DIRECTIVE, "(osgi.wiring.package=b6)")).content(new BundleArchiveBuilder().symbolicName("b3").importPackage("b6").buildAsBytes()).build()).resource(new TestRepositoryContent.Builder().capability(new TestCapability.Builder().namespace(IdentityNamespace.IDENTITY_NAMESPACE).attribute(IdentityNamespace.IDENTITY_NAMESPACE, "b4").attribute(IdentityNamespace.CAPABILITY_VERSION_ATTRIBUTE, Version.emptyVersion).attribute(IdentityNamespace.CAPABILITY_TYPE_ATTRIBUTE, IdentityNamespace.TYPE_BUNDLE)).capability(new TestCapability.Builder().namespace(PackageNamespace.PACKAGE_NAMESPACE).attribute(PackageNamespace.PACKAGE_NAMESPACE, "b4")).content(new BundleArchiveBuilder().symbolicName("b4").exportPackage("b4").buildAsBytes()).build()).resource(new TestRepositoryContent.Builder().capability(new TestCapability.Builder().namespace(IdentityNamespace.IDENTITY_NAMESPACE).attribute(IdentityNamespace.IDENTITY_NAMESPACE, "b5").attribute(IdentityNamespace.CAPABILITY_VERSION_ATTRIBUTE, Version.emptyVersion).attribute(IdentityNamespace.CAPABILITY_TYPE_ATTRIBUTE, IdentityNamespace.TYPE_BUNDLE)).capability(new TestCapability.Builder().namespace(PackageNamespace.PACKAGE_NAMESPACE).attribute(PackageNamespace.PACKAGE_NAMESPACE, "b5")).content(new BundleArchiveBuilder().symbolicName("b5").exportPackage("b5").buildAsBytes()).build()).resource(new TestRepositoryContent.Builder().capability(new TestCapability.Builder().namespace(IdentityNamespace.IDENTITY_NAMESPACE).attribute(IdentityNamespace.IDENTITY_NAMESPACE, "b6").attribute(IdentityNamespace.CAPABILITY_VERSION_ATTRIBUTE, Version.emptyVersion).attribute(IdentityNamespace.CAPABILITY_TYPE_ATTRIBUTE, IdentityNamespace.TYPE_BUNDLE)).capability(new TestCapability.Builder().namespace(PackageNamespace.PACKAGE_NAMESPACE).attribute(PackageNamespace.PACKAGE_NAMESPACE, "b6")).content(new BundleArchiveBuilder().symbolicName("b6").exportPackage("b6").buildAsBytes()).build()).build(), null));
Subsystem root = getRootSubsystem();
Subsystem s1 = installSubsystem(root, "s1", new SubsystemArchiveBuilder().symbolicName("s1").type(SubsystemConstants.SUBSYSTEM_TYPE_APPLICATION + ';' + AriesProvisionDependenciesDirective.RESOLVE.toString() + ';' + SubsystemConstants.PROVISION_POLICY_DIRECTIVE + ":=" + SubsystemConstants.PROVISION_POLICY_ACCEPT_DEPENDENCIES).build(), false);
uninstallableSubsystems.add(s1);
startSubsystem(s1, false);
stoppableSubsystems.add(s1);
Subsystem f2 = installSubsystem(s1, "f2", new SubsystemArchiveBuilder().symbolicName("f2").type(SubsystemConstants.SUBSYSTEM_TYPE_FEATURE).content("b2,b3").build(), false);
uninstallableSubsystems.add(f2);
assertChild(s1, "f2", null, SubsystemConstants.SUBSYSTEM_TYPE_FEATURE);
assertConstituent(s1, "f2", null, SubsystemConstants.SUBSYSTEM_TYPE_FEATURE);
assertConstituent(f2, "b2");
assertConstituent(f2, "b3");
Subsystem f1 = installSubsystem(s1, "f1", new SubsystemArchiveBuilder().symbolicName("f1").type(SubsystemConstants.SUBSYSTEM_TYPE_FEATURE).content("b1,b2").build(), false);
uninstallableSubsystems.add(f1);
assertChild(s1, "f1", null, SubsystemConstants.SUBSYSTEM_TYPE_FEATURE);
assertConstituent(s1, "f1", null, SubsystemConstants.SUBSYSTEM_TYPE_FEATURE);
assertConstituent(f1, "b1");
assertConstituent(f1, "b2");
startSubsystem(f1, false);
stoppableSubsystems.add(f1);
assertState(EnumSet.of(State.RESOLVED, State.ACTIVE), f2);
assertConstituent(s1, "b4");
assertConstituent(s1, "b5");
assertConstituent(s1, "b6");
}
use of org.apache.aries.subsystem.itests.util.BundleArchiveBuilder in project aries by apache.
the class Aries1383Test method testComApiComImplAppClient.
@Test
public void testComApiComImplAppClient() throws Exception {
Subsystem root = getRootSubsystem();
final Subsystem shared = installSubsystem(root, "shared", new SubsystemArchiveBuilder().symbolicName("shared").type(SubsystemConstants.SUBSYSTEM_TYPE_COMPOSITE + ';' + AriesProvisionDependenciesDirective.RESOLVE.toString() + ';' + SubsystemConstants.PROVISION_POLICY_DIRECTIVE + ":=" + SubsystemConstants.PROVISION_POLICY_ACCEPT_DEPENDENCIES).importPackage("org.osgi.framework").build(), false);
uninstallableSubsystems.add(shared);
shared.start();
stoppableSubsystems.add(shared);
@SuppressWarnings("unchecked") Callable<Subsystem>[] installCallables = new Callable[] { new Callable<Subsystem>() {
@Override
public Subsystem call() throws Exception {
Subsystem result = installSubsystem(shared, "client", new SubsystemArchiveBuilder().symbolicName("client").type(SubsystemConstants.SUBSYSTEM_TYPE_APPLICATION).bundle("client", new BundleArchiveBuilder().symbolicName("client").importPackage("org.apache.aries.subsystem.itests.defect").requireCapability("osgi.service;filter:=\"(objectClass=" + TestService.class.getName() + ")\";effective:=active").build()).build(), false);
uninstallableSubsystems.add(result);
return result;
}
}, new Callable<Subsystem>() {
@Override
public Subsystem call() throws Exception {
Subsystem result = installSubsystem(shared, "impl", new SubsystemArchiveBuilder().symbolicName("impl").type(SubsystemConstants.SUBSYSTEM_TYPE_COMPOSITE).content("impl;version=\"[0,0]\"").provideCapability("osgi.service;objectClass:List<String>=\"" + TestService.class.getName() + "\"").importPackage("org.osgi.framework").requireBundle("api").bundle("impl", new BundleArchiveBuilder().symbolicName("impl").provideCapability("osgi.service;objectClass:List<String>=\"" + TestService.class.getName() + "\"").importPackage("org.osgi.framework").requireBundle("api").clazz(TestServiceImpl.class).activator(TestServiceImplActivator.class).build()).build(), false);
uninstallableSubsystems.add(result);
return result;
}
}, new Callable<Subsystem>() {
@Override
public Subsystem call() throws Exception {
Subsystem result = installSubsystem(shared, "api", new SubsystemArchiveBuilder().symbolicName("api").type(SubsystemConstants.SUBSYSTEM_TYPE_COMPOSITE).content("api;version=\"[0,0]\"").exportPackage("org.apache.aries.subsystem.itests.defect").provideCapability("osgi.wiring.bundle;osgi.wiring.bundle=api;bundle-version=0").bundle("api", new BundleArchiveBuilder().symbolicName("api").exportPackage("org.apache.aries.subsystem.itests.defect").clazz(TestService.class).build()).build(), false);
uninstallableSubsystems.add(result);
return result;
}
} };
ExecutorService executor = Executors.newFixedThreadPool(3);
List<Future<Subsystem>> installFutures = executor.invokeAll(Arrays.asList(installCallables));
final Subsystem a1 = installFutures.get(0).get();
final Subsystem c1 = installFutures.get(1).get();
final Subsystem c2 = installFutures.get(2).get();
@SuppressWarnings("unchecked") Callable<Void>[] startCallables = new Callable[] { new Callable<Void>() {
@Override
public Void call() throws Exception {
a1.start();
stoppableSubsystems.add(a1);
assertEvent(a1, State.INSTALLED, subsystemEvents.poll(a1.getSubsystemId(), 5000));
assertEvent(a1, State.RESOLVING, subsystemEvents.poll(a1.getSubsystemId(), 5000));
assertEvent(a1, State.RESOLVED, subsystemEvents.poll(a1.getSubsystemId(), 5000));
assertEvent(a1, State.STARTING, subsystemEvents.poll(a1.getSubsystemId(), 5000));
assertEvent(a1, State.ACTIVE, subsystemEvents.poll(a1.getSubsystemId(), 5000));
return null;
}
}, new Callable<Void>() {
@Override
public Void call() throws Exception {
c1.start();
stoppableSubsystems.add(c1);
assertEvent(c1, State.INSTALLED, subsystemEvents.poll(c1.getSubsystemId(), 5000));
assertEvent(c1, State.RESOLVING, subsystemEvents.poll(c1.getSubsystemId(), 5000));
assertEvent(c1, State.RESOLVED, subsystemEvents.poll(c1.getSubsystemId(), 5000));
assertEvent(c1, State.STARTING, subsystemEvents.poll(c1.getSubsystemId(), 5000));
assertEvent(c1, State.ACTIVE, subsystemEvents.poll(c1.getSubsystemId(), 5000));
return null;
}
}, new Callable<Void>() {
@Override
public Void call() throws Exception {
c2.start();
stoppableSubsystems.add(c2);
assertEvent(c2, State.INSTALLED, subsystemEvents.poll(c2.getSubsystemId(), 5000));
assertEvent(c2, State.RESOLVING, subsystemEvents.poll(c2.getSubsystemId(), 5000));
assertEvent(c2, State.RESOLVED, subsystemEvents.poll(c2.getSubsystemId(), 5000));
assertEvent(c2, State.STARTING, subsystemEvents.poll(c2.getSubsystemId(), 5000));
assertEvent(c2, State.ACTIVE, subsystemEvents.poll(c2.getSubsystemId(), 5000));
return null;
}
} };
List<Future<Void>> startFutures = executor.invokeAll(Arrays.asList(startCallables));
startFutures.get(0).get();
startFutures.get(1).get();
startFutures.get(2).get();
}
use of org.apache.aries.subsystem.itests.util.BundleArchiveBuilder in project aries by apache.
the class Aries1383Test method test18.
/*
* (18) Scoped subsystem with a value of apache-aries-provision-dependencies
* that overrides the scoped parent behaves accordingly.
*/
@Test
public void test18() throws Exception {
Subsystem root = getRootSubsystem();
subsystemEvents.clear();
Subsystem parent = root.install("parent", new SubsystemArchiveBuilder().symbolicName("parent").type(SubsystemConstants.SUBSYSTEM_TYPE_APPLICATION + ';' + AriesProvisionDependenciesDirective.INSTALL.toString() + ';' + SubsystemConstants.PROVISION_POLICY_DIRECTIVE + ":=" + SubsystemConstants.PROVISION_POLICY_ACCEPT_DEPENDENCIES).content("bundle1").bundle("bundle1", new BundleArchiveBuilder().symbolicName("bundle1").importPackage("a").build()).bundle("bundle2", new BundleArchiveBuilder().symbolicName("bundle2").exportPackage("a").build()).build());
try {
long id = parent.getSubsystemId();
assertEvent(id, "parent", Version.emptyVersion, SubsystemConstants.SUBSYSTEM_TYPE_APPLICATION, State.INSTALLING, subsystemEvents.poll(id, 5000), ServiceEvent.REGISTERED);
assertEvent(id, "parent", Version.emptyVersion, SubsystemConstants.SUBSYSTEM_TYPE_APPLICATION, State.INSTALLED, subsystemEvents.poll(id, 5000), ServiceEvent.MODIFIED);
assertNull("Unexpected event", subsystemEvents.poll(id, 1));
assertConstituent(parent, "bundle2");
assertConstituent(parent, "bundle1");
parent.start();
Subsystem child = parent.install("child", new SubsystemArchiveBuilder().symbolicName("child").type(SubsystemConstants.SUBSYSTEM_TYPE_APPLICATION + ';' + AriesProvisionDependenciesDirective.RESOLVE.toString()).content("bundle3").bundle("bundle3", new BundleArchiveBuilder().symbolicName("bundle3").importPackage("b").build()).bundle("bundle4", new BundleArchiveBuilder().symbolicName("bundle4").exportPackage("b").build()).build());
id = child.getSubsystemId();
assertEvent(id, "child", Version.emptyVersion, SubsystemConstants.SUBSYSTEM_TYPE_APPLICATION, State.INSTALLING, subsystemEvents.poll(id, 5000), ServiceEvent.REGISTERED);
assertNull("Unexpected event", subsystemEvents.poll(id, 1));
assertNotConstituent(parent, "bundle4");
assertConstituent(child, "bundle3");
child.start();
try {
id = parent.getSubsystemId();
assertEvent(id, "parent", Version.emptyVersion, SubsystemConstants.SUBSYSTEM_TYPE_APPLICATION, State.RESOLVING, subsystemEvents.poll(id, 5000), ServiceEvent.MODIFIED);
assertEvent(id, "parent", Version.emptyVersion, SubsystemConstants.SUBSYSTEM_TYPE_APPLICATION, State.RESOLVED, subsystemEvents.poll(id, 5000), ServiceEvent.MODIFIED);
assertEvent(id, "parent", Version.emptyVersion, SubsystemConstants.SUBSYSTEM_TYPE_APPLICATION, State.STARTING, subsystemEvents.poll(id, 5000), ServiceEvent.MODIFIED);
assertEvent(id, "parent", Version.emptyVersion, SubsystemConstants.SUBSYSTEM_TYPE_APPLICATION, State.ACTIVE, subsystemEvents.poll(id, 5000), ServiceEvent.MODIFIED);
assertNull("Unexpected event", subsystemEvents.poll(id, 1));
id = child.getSubsystemId();
assertEvent(id, "child", Version.emptyVersion, SubsystemConstants.SUBSYSTEM_TYPE_APPLICATION, State.INSTALLED, subsystemEvents.poll(id, 5000), ServiceEvent.MODIFIED);
assertEvent(id, "child", Version.emptyVersion, SubsystemConstants.SUBSYSTEM_TYPE_APPLICATION, State.RESOLVING, subsystemEvents.poll(id, 5000), ServiceEvent.MODIFIED);
assertEvent(id, "child", Version.emptyVersion, SubsystemConstants.SUBSYSTEM_TYPE_APPLICATION, State.RESOLVED, subsystemEvents.poll(id, 5000), ServiceEvent.MODIFIED);
assertEvent(id, "child", Version.emptyVersion, SubsystemConstants.SUBSYSTEM_TYPE_APPLICATION, State.STARTING, subsystemEvents.poll(id, 5000), ServiceEvent.MODIFIED);
assertEvent(id, "child", Version.emptyVersion, SubsystemConstants.SUBSYSTEM_TYPE_APPLICATION, State.ACTIVE, subsystemEvents.poll(id, 5000), ServiceEvent.MODIFIED);
assertNull("Unexpected event", subsystemEvents.poll(id, 1));
assertConstituent(parent, "bundle4");
} finally {
stopSubsystemSilently(parent);
}
} finally {
uninstallSubsystemSilently(parent);
}
}
use of org.apache.aries.subsystem.itests.util.BundleArchiveBuilder in project aries by apache.
the class Aries1383Test method test19.
/*
* (19) Scoped subsystem with only features as parents is able to override
* the value of apache-aries-provision-dependencies.
*/
@Test
public void test19() throws Exception {
Subsystem root = getRootSubsystem();
subsystemEvents.clear();
Subsystem feature1 = installSubsystem(root, "feature1", new SubsystemArchiveBuilder().symbolicName("feature1").type(SubsystemConstants.SUBSYSTEM_TYPE_FEATURE).build());
try {
Subsystem feature2 = installSubsystem(root, "feature2", new SubsystemArchiveBuilder().symbolicName("feature2").type(SubsystemConstants.SUBSYSTEM_TYPE_FEATURE + ';' + AriesProvisionDependenciesDirective.INSTALL.toString()).build());
try {
SubsystemArchiveBuilder applicationArchive = new SubsystemArchiveBuilder().symbolicName("application").type(SubsystemConstants.SUBSYSTEM_TYPE_APPLICATION + ';' + AriesProvisionDependenciesDirective.RESOLVE.toString() + ';' + SubsystemConstants.PROVISION_POLICY_DIRECTIVE + ":=" + SubsystemConstants.PROVISION_POLICY_ACCEPT_DEPENDENCIES).content("bundle1").bundle("bundle1", new BundleArchiveBuilder().symbolicName("bundle1").importPackage("a").build()).bundle("bundle2", new BundleArchiveBuilder().symbolicName("bundle2").exportPackage("a").build());
Subsystem application1 = feature1.install("application", applicationArchive.build());
Subsystem application2 = feature2.install("application", applicationArchive.build());
assertSame("Wrong subsystem", application1, application2);
assertEquals("Wrong subsystem", application1, application2);
assertChild(feature1, "application");
assertChild(feature2, "application");
long id = application1.getSubsystemId();
assertEvent(id, "application", Version.emptyVersion, SubsystemConstants.SUBSYSTEM_TYPE_APPLICATION, State.INSTALLING, subsystemEvents.poll(id, 5000), ServiceEvent.REGISTERED);
assertNull("Unexpected event", subsystemEvents.poll(id, 1));
assertConstituent(application1, "bundle1");
assertNotConstituent(application1, "bundle2");
application1.start();
try {
assertEvent(id, "application", Version.emptyVersion, SubsystemConstants.SUBSYSTEM_TYPE_APPLICATION, State.INSTALLED, subsystemEvents.poll(id, 5000), ServiceEvent.MODIFIED);
assertEvent(id, "application", Version.emptyVersion, SubsystemConstants.SUBSYSTEM_TYPE_APPLICATION, State.RESOLVING, subsystemEvents.poll(id, 5000), ServiceEvent.MODIFIED);
assertEvent(id, "application", Version.emptyVersion, SubsystemConstants.SUBSYSTEM_TYPE_APPLICATION, State.RESOLVED, subsystemEvents.poll(id, 5000), ServiceEvent.MODIFIED);
assertEvent(id, "application", Version.emptyVersion, SubsystemConstants.SUBSYSTEM_TYPE_APPLICATION, State.STARTING, subsystemEvents.poll(id, 5000), ServiceEvent.MODIFIED);
assertEvent(id, "application", Version.emptyVersion, SubsystemConstants.SUBSYSTEM_TYPE_APPLICATION, State.ACTIVE, subsystemEvents.poll(id, 5000), ServiceEvent.MODIFIED);
assertNull("Unexpected event", subsystemEvents.poll(id, 1));
assertConstituent(application1, "bundle2");
} finally {
stopSubsystemSilently(application1);
}
} finally {
uninstallSubsystemSilently(feature2);
}
} finally {
uninstallSubsystemSilently(feature1);
}
}
Aggregations