Search in sources :

Example 1 with DummyContainerEvent

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

the class TestModuleContainer method testStartLevelDeadlock.

@Test
public void testStartLevelDeadlock() throws BundleException, IOException {
    DummyContainerAdaptor adaptor = createDummyAdaptor();
    ModuleContainer container = adaptor.getContainer();
    container.getFrameworkStartLevel().setInitialBundleStartLevel(2);
    // 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 module
    Map<String, String> manifest = new HashMap<String, String>();
    manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
    manifest.put(Constants.BUNDLE_SYMBOLICNAME, "module.test");
    Module module = installDummyModule(manifest, manifest.get(Constants.BUNDLE_SYMBOLICNAME), container);
    adaptor.setSlowdownEvents(true);
    module.setStartLevel(1);
    module.start();
    List<DummyContainerEvent> events = adaptor.getDatabase().getContainerEvents();
    for (DummyContainerEvent event : events) {
        Assert.assertNotEquals("Found an error: " + event.error, ContainerEvent.ERROR, event.type);
    }
}
Also used : DummyContainerAdaptor(org.eclipse.osgi.tests.container.dummys.DummyContainerAdaptor) ModuleContainer(org.eclipse.osgi.container.ModuleContainer) HashMap(java.util.HashMap) Module(org.eclipse.osgi.container.Module) ResolutionReport(org.eclipse.osgi.report.resolution.ResolutionReport) DummyContainerEvent(org.eclipse.osgi.tests.container.dummys.DummyModuleDatabase.DummyContainerEvent) Test(org.junit.Test)

Example 2 with DummyContainerEvent

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

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

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

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

the class TestModuleContainer method testStoreInvalidAttributes.

@Test
public void testStoreInvalidAttributes() throws BundleException, IOException {
    DummyContainerAdaptor adaptor = createDummyAdaptor();
    ModuleContainer container = adaptor.getContainer();
    // install the system.bundle
    installDummyModule("system.bundle.MF", Constants.SYSTEM_BUNDLE_LOCATION, Constants.SYSTEM_BUNDLE_SYMBOLICNAME, null, null, container);
    Integer testInt = Integer.valueOf(1);
    List<Integer> testIntList = Collections.singletonList(testInt);
    ModuleRevisionBuilder builder = new ModuleRevisionBuilder();
    builder.setSymbolicName("invalid.attr");
    builder.setVersion(Version.valueOf("1.0.0"));
    builder.addCapability("test", Collections.<String, String>emptyMap(), Collections.singletonMap("test", (Object) testInt));
    builder.addCapability("test.list", Collections.<String, String>emptyMap(), Collections.singletonMap("test.list", (Object) testIntList));
    Module invalid = container.install(null, builder.getSymbolicName(), builder, null);
    Object testAttr = invalid.getCurrentRevision().getCapabilities("test").get(0).getAttributes().get("test");
    assertEquals("Wrong test attr", testInt, testAttr);
    Object testAttrList = invalid.getCurrentRevision().getCapabilities("test.list").get(0).getAttributes().get("test.list");
    assertEquals("Wrong test list attr", testIntList, testAttrList);
    ByteArrayOutputStream bytes = new ByteArrayOutputStream();
    DataOutputStream data = new DataOutputStream(bytes);
    adaptor.getDatabase().store(data, true);
    List<DummyContainerEvent> events = adaptor.getDatabase().getContainerEvents();
    // make sure we see the errors
    assertEquals("Wrong number of events.", 2, events.size());
    for (DummyContainerEvent event : events) {
        assertEquals("Wrong type of event.", ContainerEvent.ERROR, event.type);
        assertTrue("Wrong type of exception.", event.error instanceof BundleException);
    }
    // reload into a new container
    adaptor = createDummyAdaptor();
    container = adaptor.getContainer();
    adaptor.getDatabase().load(new DataInputStream(new ByteArrayInputStream(bytes.toByteArray())));
    invalid = container.getModule("invalid.attr");
    assertNotNull("Could not find module.", invalid);
    String testIntString = String.valueOf(testInt);
    List<String> testIntStringList = Collections.singletonList(testIntString);
    testAttr = invalid.getCurrentRevision().getCapabilities("test").get(0).getAttributes().get("test");
    assertEquals("Wrong test attr", testIntString, testAttr);
    testAttrList = invalid.getCurrentRevision().getCapabilities("test.list").get(0).getAttributes().get("test.list");
    assertEquals("Wrong test list attr", testIntStringList, testAttrList);
}
Also used : ModuleContainer(org.eclipse.osgi.container.ModuleContainer) DataOutputStream(java.io.DataOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DataInputStream(java.io.DataInputStream) DummyContainerEvent(org.eclipse.osgi.tests.container.dummys.DummyModuleDatabase.DummyContainerEvent) DummyContainerAdaptor(org.eclipse.osgi.tests.container.dummys.DummyContainerAdaptor) ByteArrayInputStream(java.io.ByteArrayInputStream) ModuleRevisionBuilder(org.eclipse.osgi.container.ModuleRevisionBuilder) BundleException(org.osgi.framework.BundleException) Module(org.eclipse.osgi.container.Module) Test(org.junit.Test)

Aggregations

Module (org.eclipse.osgi.container.Module)5 ModuleContainer (org.eclipse.osgi.container.ModuleContainer)5 DummyContainerAdaptor (org.eclipse.osgi.tests.container.dummys.DummyContainerAdaptor)5 DummyContainerEvent (org.eclipse.osgi.tests.container.dummys.DummyModuleDatabase.DummyContainerEvent)5 Test (org.junit.Test)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 DataInputStream (java.io.DataInputStream)2 DataOutputStream (java.io.DataOutputStream)2 ResolutionReport (org.eclipse.osgi.report.resolution.ResolutionReport)2 DummyModuleDatabase (org.eclipse.osgi.tests.container.dummys.DummyModuleDatabase)2 DummyModuleEvent (org.eclipse.osgi.tests.container.dummys.DummyModuleDatabase.DummyModuleEvent)2 BundleException (org.osgi.framework.BundleException)2 ConcurrentLinkedQueue (java.util.concurrent.ConcurrentLinkedQueue)1 ExecutorService (java.util.concurrent.ExecutorService)1 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)1 ModuleRevisionBuilder (org.eclipse.osgi.container.ModuleRevisionBuilder)1 DummyCollisionHook (org.eclipse.osgi.tests.container.dummys.DummyCollisionHook)1