use of org.eclipse.osgi.tests.container.dummys.DummyContainerAdaptor 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.tests.container.dummys.DummyContainerAdaptor 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.tests.container.dummys.DummyContainerAdaptor 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.tests.container.dummys.DummyContainerAdaptor 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());
}
use of org.eclipse.osgi.tests.container.dummys.DummyContainerAdaptor in project rt.equinox.framework by eclipse.
the class TestModuleContainer method testEventsRefresh.
@Test
public void testEventsRefresh() 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);
Module c1 = installDummyModule("c1_v1.MF", "c1_v1", container);
Module c2 = installDummyModule("c2_v1.MF", "c2_v1", container);
Module c3 = installDummyModule("c3_v1.MF", "c3_v1", container);
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);
container.resolve(Arrays.asList(c1, c2, c3, c4, c5, c6, c7), true);
// throw away installed and resolved events
database.getModuleEvents();
container.refresh(Arrays.asList(systemBundle));
List<DummyModuleEvent> actual = database.getModuleEvents();
List<DummyModuleEvent> expected = new ArrayList<DummyModuleEvent>(Arrays.asList(new DummyModuleEvent(systemBundle, ModuleEvent.UNRESOLVED, State.INSTALLED), new DummyModuleEvent(c1, ModuleEvent.UNRESOLVED, State.INSTALLED), new DummyModuleEvent(c2, ModuleEvent.UNRESOLVED, State.INSTALLED), new DummyModuleEvent(c3, ModuleEvent.UNRESOLVED, State.INSTALLED), 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(systemBundle, ModuleEvent.RESOLVED, State.RESOLVED), new DummyModuleEvent(c1, ModuleEvent.RESOLVED, State.RESOLVED), new DummyModuleEvent(c2, ModuleEvent.RESOLVED, State.RESOLVED), new DummyModuleEvent(c3, ModuleEvent.RESOLVED, State.RESOLVED), 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)));
assertEvents(expected, actual, false);
}
Aggregations