Search in sources :

Example 11 with DummyModuleDatabase

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

the class TestModuleContainer method doTestEventsStartLevel.

private void doTestEventsStartLevel(int beginningStartLevel) throws BundleException, IOException {
    Map<String, String> configuration = new HashMap<String, String>();
    configuration.put(Constants.FRAMEWORK_BEGINNING_STARTLEVEL, String.valueOf(beginningStartLevel));
    DummyContainerAdaptor adaptor = new DummyContainerAdaptor(new DummyCollisionHook(false), configuration);
    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);
    database.getModuleEvents();
    c1.setStartLevel(70);
    c2.setStartLevel(60);
    c3.setStartLevel(50);
    c4.setStartLevel(40);
    c5.setStartLevel(30);
    c6.setStartLevel(20);
    c7.setStartLevel(10);
    c1.start();
    c2.start();
    c3.start();
    c4.start();
    c5.start();
    c6.start();
    c7.start();
    List<DummyModuleEvent> actualModuleEvents = database.getModuleEvents();
    Assert.assertEquals("Expecting no events.", 0, actualModuleEvents.size());
    systemBundle.start();
    if (beginningStartLevel == 1) {
        actualModuleEvents = database.getModuleEvents(2);
        List<DummyModuleEvent> expectedModuleEvents = new ArrayList<DummyModuleEvent>(Arrays.asList(new DummyModuleEvent(systemBundle, ModuleEvent.STARTING, State.STARTING), new DummyModuleEvent(systemBundle, ModuleEvent.STARTED, State.ACTIVE)));
        assertEvents(expectedModuleEvents, actualModuleEvents, true);
        List<DummyContainerEvent> actualContainerEvents = database.getContainerEvents();
        List<DummyContainerEvent> expectedContainerEvents = new ArrayList<DummyContainerEvent>(Arrays.asList(new DummyContainerEvent(ContainerEvent.STARTED, systemBundle, null)));
        Assert.assertEquals("Wrong container events.", expectedContainerEvents, actualContainerEvents);
        container.getFrameworkStartLevel().setStartLevel(100);
        actualModuleEvents = database.getModuleEvents(14);
        expectedModuleEvents = new ArrayList<DummyModuleEvent>(Arrays.asList(new DummyModuleEvent(c7, ModuleEvent.STARTING, State.STARTING), new DummyModuleEvent(c7, ModuleEvent.STARTED, State.ACTIVE), new DummyModuleEvent(c6, ModuleEvent.STARTING, State.STARTING), new DummyModuleEvent(c6, ModuleEvent.STARTED, State.ACTIVE), new DummyModuleEvent(c5, ModuleEvent.STARTING, State.STARTING), new DummyModuleEvent(c5, ModuleEvent.STARTED, State.ACTIVE), new DummyModuleEvent(c4, ModuleEvent.STARTING, State.STARTING), new DummyModuleEvent(c4, ModuleEvent.STARTED, State.ACTIVE), new DummyModuleEvent(c3, ModuleEvent.STARTING, State.STARTING), new DummyModuleEvent(c3, ModuleEvent.STARTED, State.ACTIVE), new DummyModuleEvent(c2, ModuleEvent.STARTING, State.STARTING), new DummyModuleEvent(c2, ModuleEvent.STARTED, State.ACTIVE), new DummyModuleEvent(c1, ModuleEvent.STARTING, State.STARTING), new DummyModuleEvent(c1, ModuleEvent.STARTED, State.ACTIVE)));
        actualContainerEvents = database.getContainerEvents(1);
        expectedContainerEvents = new ArrayList<DummyContainerEvent>(Arrays.asList(new DummyContainerEvent(ContainerEvent.START_LEVEL, systemBundle, null)));
        Assert.assertEquals("Wrong container events.", expectedContainerEvents, actualContainerEvents);
    } else {
        actualModuleEvents = database.getModuleEvents(16);
        List<DummyModuleEvent> expectedModuleEvents = new ArrayList<DummyModuleEvent>(Arrays.asList(new DummyModuleEvent(systemBundle, ModuleEvent.STARTING, State.STARTING), new DummyModuleEvent(c7, ModuleEvent.STARTING, State.STARTING), new DummyModuleEvent(c7, ModuleEvent.STARTED, State.ACTIVE), new DummyModuleEvent(c6, ModuleEvent.STARTING, State.STARTING), new DummyModuleEvent(c6, ModuleEvent.STARTED, State.ACTIVE), new DummyModuleEvent(c5, ModuleEvent.STARTING, State.STARTING), new DummyModuleEvent(c5, ModuleEvent.STARTED, State.ACTIVE), new DummyModuleEvent(c4, ModuleEvent.STARTING, State.STARTING), new DummyModuleEvent(c4, ModuleEvent.STARTED, State.ACTIVE), new DummyModuleEvent(c3, ModuleEvent.STARTING, State.STARTING), new DummyModuleEvent(c3, ModuleEvent.STARTED, State.ACTIVE), new DummyModuleEvent(c2, ModuleEvent.STARTING, State.STARTING), new DummyModuleEvent(c2, ModuleEvent.STARTED, State.ACTIVE), new DummyModuleEvent(c1, ModuleEvent.STARTING, State.STARTING), new DummyModuleEvent(c1, ModuleEvent.STARTED, State.ACTIVE), new DummyModuleEvent(systemBundle, ModuleEvent.STARTED, State.ACTIVE)));
        assertEvents(expectedModuleEvents, actualModuleEvents, true);
        List<DummyContainerEvent> actualContainerEvents = database.getContainerEvents();
        List<DummyContainerEvent> expectedContainerEvents = new ArrayList<DummyContainerEvent>(Arrays.asList(new DummyContainerEvent(ContainerEvent.STARTED, systemBundle, null)));
        Assert.assertEquals("Wrong container events.", expectedContainerEvents, actualContainerEvents);
    }
    if (beginningStartLevel == 1) {
        container.getFrameworkStartLevel().setStartLevel(1);
        actualModuleEvents = database.getModuleEvents(14);
        List<DummyModuleEvent> expectedModuleEvents = new ArrayList<DummyModuleEvent>(Arrays.asList(new DummyModuleEvent(c1, ModuleEvent.STOPPING, State.STOPPING), new DummyModuleEvent(c1, ModuleEvent.STOPPED, State.RESOLVED), new DummyModuleEvent(c2, ModuleEvent.STOPPING, State.STOPPING), new DummyModuleEvent(c2, ModuleEvent.STOPPED, State.RESOLVED), new DummyModuleEvent(c3, ModuleEvent.STOPPING, State.STOPPING), new DummyModuleEvent(c3, ModuleEvent.STOPPED, State.RESOLVED), new DummyModuleEvent(c4, ModuleEvent.STOPPING, State.STOPPING), new DummyModuleEvent(c4, ModuleEvent.STOPPED, State.RESOLVED), new DummyModuleEvent(c5, ModuleEvent.STOPPING, State.STOPPING), new DummyModuleEvent(c5, ModuleEvent.STOPPED, State.RESOLVED), new DummyModuleEvent(c6, ModuleEvent.STOPPING, State.STOPPING), new DummyModuleEvent(c6, ModuleEvent.STOPPED, State.RESOLVED), new DummyModuleEvent(c7, ModuleEvent.STOPPING, State.STOPPING), new DummyModuleEvent(c7, ModuleEvent.STOPPED, State.RESOLVED)));
        assertEvents(expectedModuleEvents, actualModuleEvents, true);
        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);
    }
    systemBundle.stop();
    if (beginningStartLevel == 1) {
        actualModuleEvents = database.getModuleEvents(2);
        List<DummyModuleEvent> expectedModuleEvents = new ArrayList<DummyModuleEvent>(Arrays.asList(new DummyModuleEvent(systemBundle, ModuleEvent.STOPPING, State.STOPPING), new DummyModuleEvent(systemBundle, ModuleEvent.STOPPED, State.RESOLVED)));
        assertEvents(expectedModuleEvents, actualModuleEvents, true);
    } else {
        actualModuleEvents = database.getModuleEvents(16);
        List<DummyModuleEvent> expectedModuleEvents = new ArrayList<DummyModuleEvent>(Arrays.asList(new DummyModuleEvent(systemBundle, ModuleEvent.STOPPING, State.STOPPING), new DummyModuleEvent(c1, ModuleEvent.STOPPING, State.STOPPING), new DummyModuleEvent(c1, ModuleEvent.STOPPED, State.RESOLVED), new DummyModuleEvent(c2, ModuleEvent.STOPPING, State.STOPPING), new DummyModuleEvent(c2, ModuleEvent.STOPPED, State.RESOLVED), new DummyModuleEvent(c3, ModuleEvent.STOPPING, State.STOPPING), new DummyModuleEvent(c3, ModuleEvent.STOPPED, State.RESOLVED), new DummyModuleEvent(c4, ModuleEvent.STOPPING, State.STOPPING), new DummyModuleEvent(c4, ModuleEvent.STOPPED, State.RESOLVED), new DummyModuleEvent(c5, ModuleEvent.STOPPING, State.STOPPING), new DummyModuleEvent(c5, ModuleEvent.STOPPED, State.RESOLVED), new DummyModuleEvent(c6, ModuleEvent.STOPPING, State.STOPPING), new DummyModuleEvent(c6, ModuleEvent.STOPPED, State.RESOLVED), new DummyModuleEvent(c7, ModuleEvent.STOPPING, State.STOPPING), new DummyModuleEvent(c7, ModuleEvent.STOPPED, State.RESOLVED), new DummyModuleEvent(systemBundle, ModuleEvent.STOPPED, State.RESOLVED)));
        assertEvents(expectedModuleEvents, actualModuleEvents, true);
    }
    List<DummyContainerEvent> actualContainerEvents = database.getContainerEvents();
    List<DummyContainerEvent> expectedContainerEvents = new ArrayList<DummyContainerEvent>(Arrays.asList(new DummyContainerEvent(ContainerEvent.STOPPED, systemBundle, null)));
    Assert.assertEquals("Wrong container events.", expectedContainerEvents, actualContainerEvents);
}
Also used : HashMap(java.util.HashMap) DummyCollisionHook(org.eclipse.osgi.tests.container.dummys.DummyCollisionHook) ModuleContainer(org.eclipse.osgi.container.ModuleContainer) ArrayList(java.util.ArrayList) 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) Module(org.eclipse.osgi.container.Module) DummyModuleEvent(org.eclipse.osgi.tests.container.dummys.DummyModuleDatabase.DummyModuleEvent)

Example 12 with DummyModuleDatabase

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

the class TestModuleContainer method testEventsResolved.

@Test
public void testEventsResolved() 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);
    // throw away installed events
    database.getModuleEvents();
    container.resolve(Arrays.asList(c1, c2, c3, c4, c5, c6, c7), true);
    List<DummyModuleEvent> actual = database.getModuleEvents();
    List<DummyModuleEvent> expected = new ArrayList<DummyModuleEvent>(Arrays.asList(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)

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