Search in sources :

Example 66 with Module

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());
}
Also used : ModuleWire(org.eclipse.osgi.container.ModuleWire) ModuleContainer(org.eclipse.osgi.container.ModuleContainer) HashMap(java.util.HashMap) ResolutionReport(org.eclipse.osgi.report.resolution.ResolutionReport) BundleRequirement(org.osgi.framework.wiring.BundleRequirement) DummyContainerAdaptor(org.eclipse.osgi.tests.container.dummys.DummyContainerAdaptor) ModuleWiring(org.eclipse.osgi.container.ModuleWiring) Module(org.eclipse.osgi.container.Module) Test(org.junit.Test)

Example 67 with Module

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);
    }
}
Also used : ModuleContainer(org.eclipse.osgi.container.ModuleContainer) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ResolutionReport(org.eclipse.osgi.report.resolution.ResolutionReport) DummyContainerEvent(org.eclipse.osgi.tests.container.dummys.DummyModuleDatabase.DummyContainerEvent) DummyContainerAdaptor(org.eclipse.osgi.tests.container.dummys.DummyContainerAdaptor) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) ExecutorService(java.util.concurrent.ExecutorService) BundleException(org.osgi.framework.BundleException) Module(org.eclipse.osgi.container.Module) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) Test(org.junit.Test)

Example 68 with Module

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);
}
Also used : DummyContainerAdaptor(org.eclipse.osgi.tests.container.dummys.DummyContainerAdaptor) ModuleContainer(org.eclipse.osgi.container.ModuleContainer) ArrayList(java.util.ArrayList) Module(org.eclipse.osgi.container.Module) DummyModuleEvent(org.eclipse.osgi.tests.container.dummys.DummyModuleDatabase.DummyModuleEvent) DummyModuleDatabase(org.eclipse.osgi.tests.container.dummys.DummyModuleDatabase) Test(org.junit.Test)

Example 69 with Module

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());
}
Also used : ModuleWire(org.eclipse.osgi.container.ModuleWire) ModuleContainer(org.eclipse.osgi.container.ModuleContainer) ResolutionReport(org.eclipse.osgi.report.resolution.ResolutionReport) DummyContainerAdaptor(org.eclipse.osgi.tests.container.dummys.DummyContainerAdaptor) ModuleWiring(org.eclipse.osgi.container.ModuleWiring) ModuleRevisionBuilder(org.eclipse.osgi.container.ModuleRevisionBuilder) Module(org.eclipse.osgi.container.Module) BundleCapability(org.osgi.framework.wiring.BundleCapability) Test(org.junit.Test)

Example 70 with Module

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());
}
Also used : DummyContainerAdaptor(org.eclipse.osgi.tests.container.dummys.DummyContainerAdaptor) ModuleContainer(org.eclipse.osgi.container.ModuleContainer) Module(org.eclipse.osgi.container.Module) Test(org.junit.Test)

Aggregations

Module (org.eclipse.osgi.container.Module)119 ModuleContainer (org.eclipse.osgi.container.ModuleContainer)92 Test (org.junit.Test)84 DummyContainerAdaptor (org.eclipse.osgi.tests.container.dummys.DummyContainerAdaptor)79 ResolutionReport (org.eclipse.osgi.report.resolution.ResolutionReport)36 ModuleWire (org.eclipse.osgi.container.ModuleWire)32 HashMap (java.util.HashMap)23 ArrayList (java.util.ArrayList)22 ModuleWiring (org.eclipse.osgi.container.ModuleWiring)22 ModuleRevision (org.eclipse.osgi.container.ModuleRevision)21 DummyModuleDatabase (org.eclipse.osgi.tests.container.dummys.DummyModuleDatabase)12 Generation (org.eclipse.osgi.storage.BundleInfo.Generation)10 BundleException (org.osgi.framework.BundleException)10 DummyModuleEvent (org.eclipse.osgi.tests.container.dummys.DummyModuleDatabase.DummyModuleEvent)9 ModuleRevisionBuilder (org.eclipse.osgi.container.ModuleRevisionBuilder)7 ByteArrayInputStream (java.io.ByteArrayInputStream)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6 DataInputStream (java.io.DataInputStream)6 ModuleCapability (org.eclipse.osgi.container.ModuleCapability)6 DummyCollisionHook (org.eclipse.osgi.tests.container.dummys.DummyCollisionHook)6