use of org.eclipse.osgi.container.Module in project rt.equinox.framework by eclipse.
the class TestModuleContainer method testDynamicWithExport.
@Test
public void testDynamicWithExport() throws BundleException, IOException {
DummyContainerAdaptor adaptor = createDummyAdaptor();
ModuleContainer container = adaptor.getContainer();
// install the system.bundle
Module systemBundle = installDummyModule("system.bundle.MF", Constants.SYSTEM_BUNDLE_LOCATION, Constants.SYSTEM_BUNDLE_SYMBOLICNAME, null, null, container);
ResolutionReport report = container.resolve(Arrays.asList(systemBundle), true);
Assert.assertNull("Failed to resolve system.bundle.", report.getResolutionException());
// install an importer
Map<String, String> optionalImporterManifest = new HashMap<String, String>();
optionalImporterManifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
optionalImporterManifest.put(Constants.BUNDLE_SYMBOLICNAME, "importer");
optionalImporterManifest.put(Constants.EXPORT_PACKAGE, "exporter");
optionalImporterManifest.put(Constants.DYNAMICIMPORT_PACKAGE, "exporter");
Module optionalImporterModule = installDummyModule(optionalImporterManifest, "optionalImporter", container);
// unsatisfied optional and dynamic imports do not fail a resolve.
report = container.resolve(Arrays.asList(optionalImporterModule), true);
Assert.assertNull("Failed to resolve system.bundle.", report.getResolutionException());
// dynamic and optional imports are same. Optional import is not satisfied we should only see the dynamic import
List<BundleRequirement> importReqsList = optionalImporterModule.getCurrentRevision().getWiring().getRequirements(PackageNamespace.PACKAGE_NAMESPACE);
assertEquals("Wrong number of imports.", 1, importReqsList.size());
assertEquals("Import was not dynamic", PackageNamespace.RESOLUTION_DYNAMIC, importReqsList.get(0).getDirectives().get(Namespace.REQUIREMENT_RESOLUTION_DIRECTIVE));
ModuleWire dynamicWire = container.resolveDynamic("exporter", optionalImporterModule.getCurrentRevision());
Assert.assertNull("Expected no dynamic wire.", dynamicWire);
}
use of org.eclipse.osgi.container.Module in project rt.equinox.framework by eclipse.
the class TestModuleContainer method testUpdateCollision01.
@Test
public void testUpdateCollision01() throws BundleException, IOException {
DummyContainerAdaptor adaptor = createDummyAdaptor();
ModuleContainer container = adaptor.getContainer();
Module b1_v1 = installDummyModule("b1_v1.MF", "b1_v1", container);
installDummyModule("b1_v2.MF", "b1_v2", container);
try {
container.update(b1_v1, OSGiManifestBuilderFactory.createBuilder(getManifest("b1_v2.MF")), null);
Assert.fail("Expected to fail update because of a collision.");
} catch (BundleException e) {
// expected
Assert.assertEquals("Wrong exception type.", BundleException.DUPLICATE_BUNDLE_ERROR, e.getType());
}
}
use of org.eclipse.osgi.container.Module in project rt.equinox.framework by eclipse.
the class TestModuleContainer method testDynamicImport06.
@Test
public void testDynamicImport06() throws BundleException, IOException {
DummyContainerAdaptor adaptor = createDummyAdaptor();
ModuleContainer container = adaptor.getContainer();
Module systemBundle = installDummyModule("system.bundle.MF", Constants.SYSTEM_BUNDLE_LOCATION, container);
container.resolve(Arrays.asList(systemBundle), true);
Module dynamic3 = installDummyModule("dynamic2_v1.MF", "dynamic2_v1", container);
container.resolve(Arrays.asList(systemBundle, dynamic3), true);
Module f1 = installDummyModule("f1_v1.MF", "f1_v1", container);
ModuleWire dynamicWire;
dynamicWire = container.resolveDynamic("h1.a", dynamic3.getCurrentRevision());
Assert.assertNull("Dynamic wire found.", dynamicWire);
dynamicWire = container.resolveDynamic("f1.a", dynamic3.getCurrentRevision());
Assert.assertNull("Dynamic wire found.", dynamicWire);
Module h1 = installDummyModule("h1_v1.MF", "h1_v1", container);
dynamicWire = container.resolveDynamic("h1.a", dynamic3.getCurrentRevision());
Assert.assertNotNull("Dynamic wire not found.", dynamicWire);
Assert.assertEquals("Wrong package found.", "h1.a", dynamicWire.getCapability().getAttributes().get(PackageNamespace.PACKAGE_NAMESPACE));
Assert.assertEquals("Wrong host revision found.", h1.getCurrentRevision(), dynamicWire.getProvider());
dynamicWire = container.resolveDynamic("f1.a", dynamic3.getCurrentRevision());
Assert.assertNotNull("Dynamic wire not found.", dynamicWire);
Assert.assertEquals("Wrong package found.", "f1.a", dynamicWire.getCapability().getAttributes().get(PackageNamespace.PACKAGE_NAMESPACE));
Assert.assertEquals("Wrong host revision found.", h1.getCurrentRevision(), dynamicWire.getProvider());
ModuleWiring h1Wiring = h1.getCurrentRevision().getWiring();
Assert.assertNotNull("h1 wiring is null.", h1Wiring);
ModuleWiring f1Wiring = f1.getCurrentRevision().getWiring();
Assert.assertNotNull("f1 wiring is null.", f1Wiring);
}
use of org.eclipse.osgi.container.Module in project rt.equinox.framework by eclipse.
the class TestModuleContainer method testSettings01.
@Test
public void testSettings01() throws BundleException, IOException {
DummyContainerAdaptor adaptor = createDummyAdaptor();
ModuleContainer container = adaptor.getContainer();
DummyModuleDatabase database = adaptor.getDatabase();
Module systemBundle = installDummyModule("system.bundle.MF", Constants.SYSTEM_BUNDLE_LOCATION, container);
container.resolve(Arrays.asList(systemBundle), true);
// actually launch the container
systemBundle.start();
container.getFrameworkStartLevel().setInitialBundleStartLevel(2);
Module c4 = installDummyModule("c4_v1.MF", "c4_v1", container);
Module lazy1 = installDummyModule("lazy1_v1.MF", "lazy1", container);
container.resolve(Arrays.asList(c4, lazy1), true);
Assert.assertEquals("Wrong startlevel.", 2, c4.getStartLevel());
Assert.assertEquals("Wrong startlevel.", 2, lazy1.getStartLevel());
c4.setStartLevel(3);
lazy1.setStartLevel(3);
Assert.assertEquals("Wrong startlevel.", 3, c4.getStartLevel());
Assert.assertEquals("Wrong startlevel.", 3, lazy1.getStartLevel());
database.getModuleEvents();
c4.start();
lazy1.start(StartOptions.USE_ACTIVATION_POLICY);
List<DummyModuleEvent> actual = database.getModuleEvents();
Assert.assertEquals("Did not expect any events.", 0, actual.size());
database.getContainerEvents();
container.getFrameworkStartLevel().setStartLevel(3);
List<DummyContainerEvent> actualContainerEvents = database.getContainerEvents(1);
List<DummyContainerEvent> expectedContainerEvents = new ArrayList<DummyContainerEvent>(Arrays.asList(new DummyContainerEvent(ContainerEvent.START_LEVEL, systemBundle, null)));
Assert.assertEquals("Wrong container events.", expectedContainerEvents, actualContainerEvents);
actual = database.getModuleEvents(3);
List<DummyModuleEvent> expected = new ArrayList<DummyModuleEvent>(Arrays.asList(new DummyModuleEvent(lazy1, ModuleEvent.LAZY_ACTIVATION, State.LAZY_STARTING), new DummyModuleEvent(c4, ModuleEvent.STARTING, State.STARTING), new DummyModuleEvent(c4, ModuleEvent.STARTED, State.ACTIVE)));
assertEvents(expected, actual, true);
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
DataOutputStream data = new DataOutputStream(bytes);
database.store(data, true);
systemBundle.stop();
// reload into a new container
adaptor = createDummyAdaptor();
container = adaptor.getContainer();
database = adaptor.getDatabase();
database.load(new DataInputStream(new ByteArrayInputStream(bytes.toByteArray())));
systemBundle = container.getModule(0);
Assert.assertNotNull("System bundle is null.", systemBundle);
Assert.assertTrue("System bundle should always use activation policy.", systemBundle.isActivationPolicyUsed());
Assert.assertTrue("System bundle should always have its auto-start flag set.", systemBundle.isPersistentlyStarted());
c4 = container.getModule(c4.getId());
Assert.assertNotNull("c4 is null", c4);
lazy1 = container.getModule(lazy1.getId());
Assert.assertNotNull("lazy1 is null", lazy1);
Assert.assertFalse("c4 has activation policy set.", c4.isActivationPolicyUsed());
Assert.assertTrue("c4 is not auto started.", c4.isPersistentlyStarted());
Assert.assertEquals("c4 has wrong start-level", 3, c4.getStartLevel());
Assert.assertTrue("lazy1 is using activation policy.", lazy1.isActivationPolicyUsed());
Assert.assertTrue("lazy1 is not auto started.", lazy1.isPersistentlyStarted());
Assert.assertEquals("lazy1 has wrong start-level", 3, lazy1.getStartLevel());
// relaunch the container
systemBundle.start();
actualContainerEvents = database.getContainerEvents();
expectedContainerEvents = new ArrayList<DummyContainerEvent>(Arrays.asList(new DummyContainerEvent(ContainerEvent.START_LEVEL, systemBundle, null), new DummyContainerEvent(ContainerEvent.STARTED, systemBundle, null)));
actual = database.getModuleEvents(2);
expected = new ArrayList<DummyModuleEvent>(Arrays.asList(new DummyModuleEvent(systemBundle, ModuleEvent.STARTING, State.STARTING), new DummyModuleEvent(systemBundle, ModuleEvent.STARTED, State.ACTIVE)));
assertEvents(expected, actual, true);
container.getFrameworkStartLevel().setStartLevel(3);
actualContainerEvents = database.getContainerEvents(1);
expectedContainerEvents = new ArrayList<DummyContainerEvent>(Arrays.asList(new DummyContainerEvent(ContainerEvent.START_LEVEL, systemBundle, null)));
Assert.assertEquals("Wrong container events.", expectedContainerEvents, actualContainerEvents);
actual = database.getModuleEvents(3);
expected = new ArrayList<DummyModuleEvent>(Arrays.asList(new DummyModuleEvent(lazy1, ModuleEvent.LAZY_ACTIVATION, State.LAZY_STARTING), new DummyModuleEvent(c4, ModuleEvent.STARTING, State.STARTING), new DummyModuleEvent(c4, ModuleEvent.STARTED, State.ACTIVE)));
assertEvents(expected, actual, true);
}
use of org.eclipse.osgi.container.Module in project rt.equinox.framework by eclipse.
the class TestModuleContainer method testSystemBundleFragmentRequiresOtherFragment.
@Test
public void testSystemBundleFragmentRequiresOtherFragment() throws BundleException, IOException {
// install the system.bundle
Module systemBundle = createContainerWithSystemBundle(true);
ModuleContainer container = systemBundle.getContainer();
// install an system.bundle fragment that provides a capability
Map<String, String> systemFragManifest1 = new HashMap<String, String>();
systemFragManifest1.put(Constants.BUNDLE_MANIFESTVERSION, "2");
systemFragManifest1.put(Constants.BUNDLE_SYMBOLICNAME, "systemFrag1");
systemFragManifest1.put(Constants.FRAGMENT_HOST, Constants.SYSTEM_BUNDLE_SYMBOLICNAME);
systemFragManifest1.put(Constants.PROVIDE_CAPABILITY, "fragment.capability; fragment.capability=test");
Module systemFrag1 = installDummyModule(systemFragManifest1, "systemFrag1", container);
// install an system.bundle fragment that requires a fragment capability
Map<String, String> systemFragManifest2 = new HashMap<String, String>();
systemFragManifest2.put(Constants.BUNDLE_MANIFESTVERSION, "2");
systemFragManifest2.put(Constants.BUNDLE_SYMBOLICNAME, "systemFrag2");
systemFragManifest2.put(Constants.FRAGMENT_HOST, Constants.SYSTEM_BUNDLE_SYMBOLICNAME);
systemFragManifest2.put(Constants.REQUIRE_CAPABILITY, "fragment.capability; filter:=\"(fragment.capability=test)\"");
Module systemFrag2 = installDummyModule(systemFragManifest2, "systemFrag2", container);
ResolutionReport report = container.resolve(Arrays.asList(systemFrag2), true);
Assert.assertNull("Failed to resolve system.bundle.", report.getResolutionException());
List<ModuleWire> hostWires = systemBundle.getCurrentRevision().getWiring().getProvidedModuleWires(HostNamespace.HOST_NAMESPACE);
assertEquals("Wrong number of fragments.", 2, hostWires.size());
List<ModuleWire> systemBundleRequiredWires = systemBundle.getCurrentRevision().getWiring().getRequiredModuleWires(null);
assertEquals("Wrong number of wires.", 1, systemBundleRequiredWires.size());
assertEquals("Wrong requirer.", systemBundle.getCurrentRevision(), systemBundleRequiredWires.get(0).getRequirer());
assertEquals("Wrong requirement.", systemFrag2.getCurrentRevision(), systemBundleRequiredWires.get(0).getRequirement().getRevision());
assertEquals("Wrong provider.", systemBundle.getCurrentRevision(), systemBundleRequiredWires.get(0).getProvider());
assertEquals("Wrong capability.", systemFrag1.getCurrentRevision(), systemBundleRequiredWires.get(0).getCapability().getRevision());
List<ModuleWire> fragRequiredWires = systemFrag2.getCurrentRevision().getWiring().getRequiredModuleWires(null);
assertEquals("Wrong number of required wires.", 1, fragRequiredWires.size());
assertWires(fragRequiredWires, hostWires);
}
Aggregations