Search in sources :

Example 6 with DummyModuleDatabase

use of org.eclipse.osgi.tests.container.dummys.DummyModuleDatabase in project rt.equinox.framework by eclipse.

the class TestModuleContainer method createTestContainerAndGetTimestamp.

private long createTestContainerAndGetTimestamp() throws BundleException, IOException, InterruptedException {
    // wait here to ensure current time really has increased
    Thread.sleep(100);
    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();
    // install some bundles and set some settings
    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);
    // set some settings
    Assert.assertEquals("Wrong startlevel.", 2, c4.getStartLevel());
    Assert.assertEquals("Wrong startlevel.", 2, lazy1.getStartLevel());
    return database.getTimestamp();
}
Also used : DummyContainerAdaptor(org.eclipse.osgi.tests.container.dummys.DummyContainerAdaptor) ModuleContainer(org.eclipse.osgi.container.ModuleContainer) Module(org.eclipse.osgi.container.Module) DummyModuleDatabase(org.eclipse.osgi.tests.container.dummys.DummyModuleDatabase)

Example 7 with DummyModuleDatabase

use of org.eclipse.osgi.tests.container.dummys.DummyModuleDatabase 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 8 with DummyModuleDatabase

use of org.eclipse.osgi.tests.container.dummys.DummyModuleDatabase 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);
}
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 9 with DummyModuleDatabase

use of org.eclipse.osgi.tests.container.dummys.DummyModuleDatabase in project rt.equinox.framework by eclipse.

the class TestModuleContainer method testRemovalPending.

@Test
public void testRemovalPending() 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 c4 = installDummyModule("c4_v1.MF", "c4_v1", container);
    Module c6 = installDummyModule("c6_v1.MF", "c6_v1", container);
    Module c7 = installDummyModule("c7_v1.MF", "c7_v1", container);
    container.resolve(Arrays.asList(c7), true);
    // throw out installed and resolved events
    database.getModuleEvents();
    ModuleRevision c4Revision0 = c4.getCurrentRevision();
    // updating to identical content
    container.update(c4, OSGiManifestBuilderFactory.createBuilder(getManifest("c4_v1.MF")), null);
    container.resolve(Arrays.asList(c4), true);
    Collection<ModuleRevision> removalPending = container.getRemovalPending();
    Assert.assertEquals("Wrong number of removal pending", 1, removalPending.size());
    Assert.assertTrue("Wrong module removalPending: " + removalPending, removalPending.contains(c4Revision0));
    ModuleRevision c6Revision0 = c6.getCurrentRevision();
    // updating to identical content
    container.update(c6, OSGiManifestBuilderFactory.createBuilder(getManifest("c6_v1.MF")), null);
    container.resolve(Arrays.asList(c6), true);
    removalPending = container.getRemovalPending();
    Assert.assertEquals("Wrong number of removal pending", 2, removalPending.size());
    Assert.assertTrue("Wrong module removalPending: " + removalPending, removalPending.containsAll(Arrays.asList(c4Revision0, c6Revision0)));
    // update again with identical content
    container.update(c4, OSGiManifestBuilderFactory.createBuilder(getManifest("c4_v1.MF")), null);
    container.update(c6, OSGiManifestBuilderFactory.createBuilder(getManifest("c6_v1.MF")), null);
    container.resolve(Arrays.asList(c4, c6), true);
    // Again we only have two since the previous current revisions did not have any dependents
    removalPending = container.getRemovalPending();
    Assert.assertEquals("Wrong number of removal pending", 2, removalPending.size());
    Assert.assertTrue("Wrong module removalPending: " + removalPending, removalPending.containsAll(Arrays.asList(c4Revision0, c6Revision0)));
    container.refresh(null);
    removalPending = container.getRemovalPending();
    Assert.assertEquals("Wrong number of removal pending", 0, removalPending.size());
    List<DummyModuleEvent> actual = database.getModuleEvents();
    List<DummyModuleEvent> expected = new ArrayList<DummyModuleEvent>(Arrays.asList(new DummyModuleEvent(c4, ModuleEvent.UNRESOLVED, State.INSTALLED), new DummyModuleEvent(c4, ModuleEvent.UPDATED, State.INSTALLED), new DummyModuleEvent(c4, ModuleEvent.RESOLVED, State.RESOLVED), new DummyModuleEvent(c6, ModuleEvent.UNRESOLVED, State.INSTALLED), new DummyModuleEvent(c6, ModuleEvent.UPDATED, State.INSTALLED), new DummyModuleEvent(c6, ModuleEvent.RESOLVED, State.RESOLVED), new DummyModuleEvent(c4, ModuleEvent.UNRESOLVED, State.INSTALLED), new DummyModuleEvent(c4, ModuleEvent.UPDATED, State.INSTALLED), new DummyModuleEvent(c6, ModuleEvent.UNRESOLVED, State.INSTALLED), new DummyModuleEvent(c6, ModuleEvent.UPDATED, State.INSTALLED), new DummyModuleEvent(c4, ModuleEvent.RESOLVED, State.RESOLVED), new DummyModuleEvent(c6, ModuleEvent.RESOLVED, State.RESOLVED), new DummyModuleEvent(c4, 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(c6, ModuleEvent.RESOLVED, State.RESOLVED), new DummyModuleEvent(c7, ModuleEvent.RESOLVED, State.RESOLVED)));
    assertEvents(expected, actual, false);
    // uninstall c4
    c4Revision0 = c4.getCurrentRevision();
    container.uninstall(c4);
    removalPending = container.getRemovalPending();
    Assert.assertEquals("Wrong number of removal pending", 1, removalPending.size());
    Assert.assertTrue("Wrong module removalPending: " + removalPending, removalPending.containsAll(Arrays.asList(c4Revision0)));
    container.refresh(null);
    actual = database.getModuleEvents();
    expected = new ArrayList<DummyModuleEvent>(Arrays.asList(new DummyModuleEvent(c4, ModuleEvent.UNRESOLVED, State.INSTALLED), new DummyModuleEvent(c4, ModuleEvent.UNINSTALLED, State.UNINSTALLED), new DummyModuleEvent(c6, ModuleEvent.UNRESOLVED, State.INSTALLED), new DummyModuleEvent(c7, ModuleEvent.UNRESOLVED, State.INSTALLED)));
    assertEvents(expected, actual, false);
    // Test bug 411833
    // install c4 again and resolve c6
    c4 = installDummyModule("c4_v1.MF", "c4_v1", container);
    container.resolve(Arrays.asList(c6), true);
    // throw out installed and resolved events
    database.getModuleEvents();
    removalPending = container.getRemovalPending();
    Assert.assertEquals("Wrong number of removal pending", 0, removalPending.size());
    c4Revision0 = c4.getCurrentRevision();
    // uninstall c4, but refresh c6 instead
    // this should result in removal pending c4 to be removed.
    container.uninstall(c4);
    removalPending = container.getRemovalPending();
    Assert.assertEquals("Wrong number of removal pending", 1, removalPending.size());
    Assert.assertTrue("Wrong module removalPending: " + removalPending, removalPending.containsAll(Arrays.asList(c4Revision0)));
    container.refresh(Collections.singletonList(c6));
    actual = database.getModuleEvents();
    expected = new ArrayList<DummyModuleEvent>(Arrays.asList(new DummyModuleEvent(c4, ModuleEvent.UNRESOLVED, State.INSTALLED), new DummyModuleEvent(c4, ModuleEvent.UNINSTALLED, State.UNINSTALLED), new DummyModuleEvent(c6, ModuleEvent.UNRESOLVED, State.INSTALLED), new DummyModuleEvent(c7, ModuleEvent.UNRESOLVED, State.INSTALLED)));
    assertEvents(expected, actual, false);
    removalPending = container.getRemovalPending();
    Assert.assertEquals("Wrong number of removal pending", 0, removalPending.size());
}
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) ModuleRevision(org.eclipse.osgi.container.ModuleRevision) DummyModuleDatabase(org.eclipse.osgi.tests.container.dummys.DummyModuleDatabase) Test(org.junit.Test)

Example 10 with DummyModuleDatabase

use of org.eclipse.osgi.tests.container.dummys.DummyModuleDatabase in project rt.equinox.framework by eclipse.

the class TestModuleContainer method testDynamicImport03.

@Test
public void testDynamicImport03() 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 dynamic3 = installDummyModule("dynamic2_v1.MF", "dynamic2_v1", container);
    container.resolve(Arrays.asList(systemBundle, dynamic3), true);
    ModuleWire dynamicWire = container.resolveDynamic("c1.a", dynamic3.getCurrentRevision());
    Assert.assertNull("Dynamic wire found.", dynamicWire);
    Module c1v1 = installDummyModule("c1_v1.MF", "c1_v1", container);
    database.getModuleEvents();
    dynamicWire = container.resolveDynamic("c1.a", dynamic3.getCurrentRevision());
    Assert.assertNotNull("Dynamic wire not found.", dynamicWire);
    Assert.assertEquals("Wrong package found.", "c1.a", dynamicWire.getCapability().getAttributes().get(PackageNamespace.PACKAGE_NAMESPACE));
    Assert.assertEquals("Wrong provider for the wire found.", c1v1.getCurrentRevision(), dynamicWire.getProvider());
    ModuleWiring c1v1Wiring = c1v1.getCurrentRevision().getWiring();
    Assert.assertNotNull("c1 wiring is null.", c1v1Wiring);
    Module c1v2 = installDummyModule("c1_v2.MF", "c1_v2", container);
    container.resolve(Arrays.asList(c1v2), true);
    database.getModuleEvents();
    dynamicWire = container.resolveDynamic("c1.b", dynamic3.getCurrentRevision());
    Assert.assertNotNull("Dynamic wire not found.", dynamicWire);
    Assert.assertEquals("Wrong package found.", "c1.b", dynamicWire.getCapability().getAttributes().get(PackageNamespace.PACKAGE_NAMESPACE));
    Assert.assertEquals("Wrong provider.", c1v1.getCurrentRevision(), dynamicWire.getProvider());
}
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) DummyModuleDatabase(org.eclipse.osgi.tests.container.dummys.DummyModuleDatabase) Test(org.junit.Test)

Aggregations

Module (org.eclipse.osgi.container.Module)12 ModuleContainer (org.eclipse.osgi.container.ModuleContainer)12 DummyContainerAdaptor (org.eclipse.osgi.tests.container.dummys.DummyContainerAdaptor)12 DummyModuleDatabase (org.eclipse.osgi.tests.container.dummys.DummyModuleDatabase)12 Test (org.junit.Test)10 ArrayList (java.util.ArrayList)8 DummyModuleEvent (org.eclipse.osgi.tests.container.dummys.DummyModuleDatabase.DummyModuleEvent)8 ModuleWire (org.eclipse.osgi.container.ModuleWire)3 ModuleWiring (org.eclipse.osgi.container.ModuleWiring)3 DummyContainerEvent (org.eclipse.osgi.tests.container.dummys.DummyModuleDatabase.DummyContainerEvent)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 DataInputStream (java.io.DataInputStream)1 DataOutputStream (java.io.DataOutputStream)1 HashMap (java.util.HashMap)1 ModuleRevision (org.eclipse.osgi.container.ModuleRevision)1 DummyCollisionHook (org.eclipse.osgi.tests.container.dummys.DummyCollisionHook)1