Search in sources :

Example 1 with DummyModuleDatabase

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

Example 2 with DummyModuleDatabase

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

the class TestModuleContainer method testLazy01.

@Test
public void testLazy01() 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 lazy1 = installDummyModule("lazy1_v1.MF", "lazy1", container);
    // throw out installed and resolved events
    database.getModuleEvents();
    lazy1.start(StartOptions.USE_ACTIVATION_POLICY);
    List<DummyModuleEvent> actual = database.getModuleEvents();
    List<DummyModuleEvent> expected = new ArrayList<DummyModuleEvent>(Arrays.asList(new DummyModuleEvent(lazy1, ModuleEvent.RESOLVED, State.RESOLVED), new DummyModuleEvent(lazy1, ModuleEvent.LAZY_ACTIVATION, State.LAZY_STARTING)));
    assertEvents(expected, actual, true);
    lazy1.start(StartOptions.LAZY_TRIGGER);
    actual = database.getModuleEvents();
    expected = new ArrayList<DummyModuleEvent>(Arrays.asList(new DummyModuleEvent(lazy1, ModuleEvent.STARTING, State.STARTING), new DummyModuleEvent(lazy1, ModuleEvent.STARTED, State.ACTIVE)));
    assertEvents(expected, actual, true);
    container.refresh(Arrays.asList(lazy1));
    actual = database.getModuleEvents();
    expected = new ArrayList<DummyModuleEvent>(Arrays.asList(new DummyModuleEvent(lazy1, ModuleEvent.STOPPING, State.STOPPING), new DummyModuleEvent(lazy1, ModuleEvent.STOPPED, State.RESOLVED), new DummyModuleEvent(lazy1, ModuleEvent.UNRESOLVED, State.INSTALLED), new DummyModuleEvent(lazy1, ModuleEvent.RESOLVED, State.RESOLVED), new DummyModuleEvent(lazy1, ModuleEvent.LAZY_ACTIVATION, State.LAZY_STARTING)));
    assertEvents(expected, actual, true);
    container.update(lazy1, OSGiManifestBuilderFactory.createBuilder(getManifest("lazy1_v1.MF")), null);
    actual = database.getModuleEvents();
    expected = new ArrayList<DummyModuleEvent>(Arrays.asList(new DummyModuleEvent(lazy1, ModuleEvent.STOPPING, State.STOPPING), new DummyModuleEvent(lazy1, ModuleEvent.STOPPED, State.RESOLVED), new DummyModuleEvent(lazy1, ModuleEvent.UNRESOLVED, State.INSTALLED), new DummyModuleEvent(lazy1, ModuleEvent.UPDATED, State.INSTALLED), new DummyModuleEvent(lazy1, ModuleEvent.RESOLVED, State.RESOLVED), new DummyModuleEvent(lazy1, ModuleEvent.LAZY_ACTIVATION, State.LAZY_STARTING)));
    assertEvents(expected, actual, true);
    container.refresh(Arrays.asList(lazy1));
    actual = database.getModuleEvents();
    expected = new ArrayList<DummyModuleEvent>(Arrays.asList(new DummyModuleEvent(lazy1, ModuleEvent.STOPPING, State.STOPPING), new DummyModuleEvent(lazy1, ModuleEvent.STOPPED, State.RESOLVED), new DummyModuleEvent(lazy1, ModuleEvent.UNRESOLVED, State.INSTALLED), new DummyModuleEvent(lazy1, ModuleEvent.RESOLVED, State.RESOLVED), new DummyModuleEvent(lazy1, ModuleEvent.LAZY_ACTIVATION, State.LAZY_STARTING)));
    assertEvents(expected, actual, true);
}
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 3 with DummyModuleDatabase

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

the class TestModuleContainer method testDynamicImport04.

@Test
public void testDynamicImport04() 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("h1.a", dynamic3.getCurrentRevision());
    Assert.assertNull("Dynamic wire found.", dynamicWire);
    Module h1 = installDummyModule("h1_v1.MF", "h1_v1", container);
    Module f1 = installDummyModule("f1_v1.MF", "f1_v1", container);
    database.getModuleEvents();
    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 provider for the wire 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 provider for the wire 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) DummyModuleDatabase(org.eclipse.osgi.tests.container.dummys.DummyModuleDatabase) Test(org.junit.Test)

Example 4 with DummyModuleDatabase

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

the class TestModuleContainer method testDynamicImport08.

@Test
public void testDynamicImport08() 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 dynamic2 = installDummyModule("dynamic2_v1.MF", "dynamic2_v1", container);
    container.resolve(Arrays.asList(systemBundle, dynamic2), true);
    Module h1 = installDummyModule("h1_v1.MF", "h1_v1", container);
    Module f1 = installDummyModule("f1_v1.MF", "f1_v1", container);
    database.getModuleEvents();
    // make sure h1 is not resolved
    ModuleWiring h1Wiring = h1.getCurrentRevision().getWiring();
    Assert.assertNull("h1 got resolved somehow.", h1Wiring);
    // do not resolve the host first; make sure it gets pulled in while attempting to resolve
    // to a fragment capability.
    ModuleWire dynamicWire = container.resolveDynamic("f1.a", dynamic2.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 provider for the wire found.", h1.getCurrentRevision(), dynamicWire.getProvider());
    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) DummyModuleDatabase(org.eclipse.osgi.tests.container.dummys.DummyModuleDatabase) Test(org.junit.Test)

Example 5 with DummyModuleDatabase

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

the class TestModuleContainer method testEventsStart.

@Test
public void testEventsStart() 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 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();
    c7.start();
    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), 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)

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