Search in sources :

Example 21 with ModuleContainer

use of org.eclipse.osgi.container.ModuleContainer in project rt.equinox.framework by eclipse.

the class TestModuleContainer method testInstallCollision01.

@Test
public void testInstallCollision01() throws BundleException, IOException {
    DummyContainerAdaptor adaptor = createDummyAdaptor();
    ModuleContainer container = adaptor.getContainer();
    installDummyModule("system.bundle.MF", Constants.SYSTEM_BUNDLE_LOCATION, container);
    installDummyModule("b1_v1.MF", "b1_a", container);
    try {
        installDummyModule("b1_v1.MF", "b1_b", container);
        Assert.fail("Expected to fail installation because of a collision.");
    } catch (BundleException e) {
        // expected
        Assert.assertEquals("Wrong exception type.", BundleException.DUPLICATE_BUNDLE_ERROR, e.getType());
    }
}
Also used : DummyContainerAdaptor(org.eclipse.osgi.tests.container.dummys.DummyContainerAdaptor) ModuleContainer(org.eclipse.osgi.container.ModuleContainer) BundleException(org.osgi.framework.BundleException) Test(org.junit.Test)

Example 22 with ModuleContainer

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

Example 23 with ModuleContainer

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

Example 24 with ModuleContainer

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

Example 25 with ModuleContainer

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

Aggregations

ModuleContainer (org.eclipse.osgi.container.ModuleContainer)95 Module (org.eclipse.osgi.container.Module)92 Test (org.junit.Test)87 DummyContainerAdaptor (org.eclipse.osgi.tests.container.dummys.DummyContainerAdaptor)80 ResolutionReport (org.eclipse.osgi.report.resolution.ResolutionReport)36 ModuleWire (org.eclipse.osgi.container.ModuleWire)31 HashMap (java.util.HashMap)24 ModuleWiring (org.eclipse.osgi.container.ModuleWiring)20 ArrayList (java.util.ArrayList)15 DummyModuleDatabase (org.eclipse.osgi.tests.container.dummys.DummyModuleDatabase)12 ModuleRevision (org.eclipse.osgi.container.ModuleRevision)9 DummyModuleEvent (org.eclipse.osgi.tests.container.dummys.DummyModuleDatabase.DummyModuleEvent)9 DummyCollisionHook (org.eclipse.osgi.tests.container.dummys.DummyCollisionHook)7 BundleException (org.osgi.framework.BundleException)7 BundleRequirement (org.osgi.framework.wiring.BundleRequirement)6 DummyContainerEvent (org.eclipse.osgi.tests.container.dummys.DummyModuleDatabase.DummyContainerEvent)5 BundleCapability (org.osgi.framework.wiring.BundleCapability)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 ModuleCapability (org.eclipse.osgi.container.ModuleCapability)4 DummyResolverHookFactory (org.eclipse.osgi.tests.container.dummys.DummyResolverHookFactory)4