use of org.eclipse.osgi.container.Module in project rt.equinox.framework by eclipse.
the class TestModuleContainer method testR3.
@Test
public void testR3() 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());
// R3 bundle
Map<String, String> exporterManifest = new HashMap<String, String>();
exporterManifest = new HashMap<String, String>();
exporterManifest.put(Constants.BUNDLE_SYMBOLICNAME, "exporter");
exporterManifest.put(Constants.EXPORT_PACKAGE, "exporter; version=\"1.1\"");
Module moduleExport = installDummyModule(exporterManifest, "exporter", container);
report = container.resolve(Arrays.asList(moduleExport, moduleExport), true);
Assert.assertNull("Failed to resolve", report.getResolutionException());
List<BundleRequirement> reqs = moduleExport.getCurrentRevision().getWiring().getRequirements(PackageNamespace.PACKAGE_NAMESPACE);
assertEquals("Wrong number of imports.", 0, reqs.size());
// R3 bundle
exporterManifest.clear();
exporterManifest.put(Constants.BUNDLE_SYMBOLICNAME, "dynamicExporter");
exporterManifest.put(Constants.EXPORT_PACKAGE, "exporter; version=\"1.0\"");
exporterManifest.put(Constants.DYNAMICIMPORT_PACKAGE, "exporter");
Module moduleWithDynExport = installDummyModule(exporterManifest, "dynamicExporter", container);
report = container.resolve(Arrays.asList(moduleWithDynExport), true);
Assert.assertNull("Failed to resolve", report.getResolutionException());
reqs = moduleWithDynExport.getCurrentRevision().getWiring().getRequirements(PackageNamespace.PACKAGE_NAMESPACE);
assertEquals("Wrong number of imports.", 2, reqs.size());
report = container.resolve(Arrays.asList(moduleWithDynExport), true);
Assert.assertNull("Failed to resolve", report.getResolutionException());
reqs = moduleWithDynExport.getCurrentRevision().getWiring().getRequirements(PackageNamespace.PACKAGE_NAMESPACE);
assertEquals("Wrong number of imports.", 2, reqs.size());
ModuleWiring wiring = moduleWithDynExport.getCurrentRevision().getWiring();
List<ModuleWire> packageWires = wiring.getRequiredModuleWires(PackageNamespace.PACKAGE_NAMESPACE);
Assert.assertEquals("Unexpected number of wires", 1, packageWires.size());
Assert.assertEquals("Wrong exporter", packageWires.get(0).getProviderWiring().getRevision(), moduleExport.getCurrentRevision());
}
use of org.eclipse.osgi.container.Module in project rt.equinox.framework by eclipse.
the class TestModuleContainer method testResolveDeadlock.
@Test
public void testResolveDeadlock() throws BundleException, IOException, InterruptedException {
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());
systemBundle.start();
// install a bunch of modules
Map<String, String> manifest = new HashMap<String, String>();
List<Module> modules = new ArrayList<Module>();
for (int i = 0; i < 5; i++) {
manifest.clear();
manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
manifest.put(Constants.BUNDLE_SYMBOLICNAME, "module." + i);
modules.add(installDummyModule(manifest, manifest.get(Constants.BUNDLE_SYMBOLICNAME), container));
}
adaptor.setSlowdownEvents(true);
final ConcurrentLinkedQueue<BundleException> startErrors = new ConcurrentLinkedQueue<BundleException>();
final ExecutorService executor = Executors.newFixedThreadPool(10);
try {
for (final Module module : modules) {
executor.execute(new Runnable() {
@Override
public void run() {
try {
module.start();
} catch (BundleException e) {
startErrors.offer(e);
e.printStackTrace();
}
}
});
}
} finally {
executor.shutdown();
executor.awaitTermination(5, TimeUnit.MINUTES);
systemBundle.stop();
}
Assert.assertNull("Found a error.", startErrors.poll());
List<DummyContainerEvent> events = adaptor.getDatabase().getContainerEvents();
for (DummyContainerEvent event : events) {
Assert.assertNotEquals("Found an error.", ContainerEvent.ERROR, event.type);
}
}
use of org.eclipse.osgi.container.Module in project rt.equinox.framework by eclipse.
the class TestModuleContainer method testEventsStartRefresh.
@Test
public void testEventsStartRefresh() 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();
Module c4 = installDummyModule("c4_v1.MF", "c4_v1", container);
Module c5 = installDummyModule("c5_v1.MF", "c5_v1", container);
Module c6 = installDummyModule("c6_v1.MF", "c6_v1", container);
Module c7 = installDummyModule("c7_v1.MF", "c7_v1", container);
c7.start();
// discard events
database.getModuleEvents();
container.refresh(Arrays.asList(c4));
List<DummyModuleEvent> actual = database.getModuleEvents();
List<DummyModuleEvent> expected = new ArrayList<DummyModuleEvent>(Arrays.asList(new DummyModuleEvent(c7, ModuleEvent.STOPPING, State.STOPPING), new DummyModuleEvent(c7, ModuleEvent.STOPPED, State.RESOLVED), new DummyModuleEvent(c4, ModuleEvent.UNRESOLVED, State.INSTALLED), new DummyModuleEvent(c5, ModuleEvent.UNRESOLVED, State.INSTALLED), new DummyModuleEvent(c6, ModuleEvent.UNRESOLVED, State.INSTALLED), new DummyModuleEvent(c7, ModuleEvent.UNRESOLVED, State.INSTALLED), new DummyModuleEvent(c4, ModuleEvent.RESOLVED, State.RESOLVED), new DummyModuleEvent(c5, ModuleEvent.RESOLVED, State.RESOLVED), new DummyModuleEvent(c6, ModuleEvent.RESOLVED, State.RESOLVED), new DummyModuleEvent(c7, ModuleEvent.RESOLVED, State.RESOLVED), new DummyModuleEvent(c7, ModuleEvent.STARTING, State.STARTING), new DummyModuleEvent(c7, ModuleEvent.STARTED, State.ACTIVE)));
assertEvents(expected, actual, false);
}
use of org.eclipse.osgi.container.Module in project rt.equinox.framework by eclipse.
the class TestModuleContainer method testBug483849.
@Test
public void testBug483849() throws BundleException, IOException {
DummyContainerAdaptor adaptor = createDummyAdaptor();
ModuleContainer container = adaptor.getContainer();
// install and resolve host bundle
Module host = installDummyModule("bug483849.host.MF", "host", container);
ResolutionReport report = container.resolve(Arrays.asList(host), true);
Assert.assertNull("Failed to resolve host.", report.getResolutionException());
// install and dynamically attach a fragment that exports a package and resolve an importer
Module frag = installDummyModule("bug483849.frag.MF", "frag", container);
Module importer = installDummyModule("bug483849.importer.MF", "importer", container);
report = container.resolve(Arrays.asList(frag, importer), true);
Assert.assertNull("Failed to resolve test fragment and importer.", report.getResolutionException());
// get the count of package exports
ModuleWiring wiring = host.getCurrentRevision().getWiring();
int originalPackageCnt = wiring.getCapabilities(PackageNamespace.PACKAGE_NAMESPACE).size();
// update the host to generate a new revision
Map<String, String> updateManifest = getManifest("bug483849.host.MF");
ModuleRevisionBuilder updateBuilder = OSGiManifestBuilderFactory.createBuilder(updateManifest);
container.update(host, updateBuilder, null);
// refresh host which should force the importer to re-resolve to the new revision
report = container.refresh(Collections.singleton(host));
ModuleWiring importerWiring = importer.getCurrentRevision().getWiring();
Assert.assertNotNull("No wiring for importer.", importerWiring);
List<ModuleWire> importerPackageWires = importerWiring.getRequiredModuleWires(PackageNamespace.PACKAGE_NAMESPACE);
Assert.assertEquals("Wrong number of importer package Wires.", 1, importerPackageWires.size());
Assert.assertEquals("Wrong provider wiring.", host.getCurrentRevision().getWiring(), importerPackageWires.iterator().next().getProviderWiring());
Assert.assertEquals("Wrong provider revision.", host.getCurrentRevision(), importerPackageWires.iterator().next().getProviderWiring().getRevision());
wiring = host.getCurrentRevision().getWiring();
List<BundleCapability> packages = wiring.getCapabilities(PackageNamespace.PACKAGE_NAMESPACE);
Assert.assertEquals("Wrong number of host packages.", originalPackageCnt, packages.size());
}
use of org.eclipse.osgi.container.Module in project rt.equinox.framework by eclipse.
the class TestModuleContainer method testOptionalSubstituted.
@Test
public void testOptionalSubstituted() 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 sub_n = installDummyModule("sub.n.MF", "n", container);
Module sub_l = installDummyModule("sub.l.MF", "l", container);
Module sub_m = installDummyModule("sub.m.MF", "m", container);
container.resolve(null, false);
Assert.assertEquals("l should resolve.", State.RESOLVED, sub_l.getState());
Assert.assertEquals("m should resolve.", State.RESOLVED, sub_m.getState());
Assert.assertEquals("n should resolve.", State.RESOLVED, sub_n.getState());
}
Aggregations