Search in sources :

Example 1 with DummyCollisionHook

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

the class TestModuleContainer method doTestStartOnResolve.

private void doTestStartOnResolve(boolean enabled) throws BundleException, IOException {
    Map<String, String> configuration = new HashMap<String, String>();
    if (!enabled) {
        configuration.put(EquinoxConfiguration.PROP_MODULE_AUTO_START_ON_RESOLVE, Boolean.toString(false));
    }
    DummyContainerAdaptor adaptor = new DummyContainerAdaptor(new DummyCollisionHook(false), configuration);
    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);
        manifest.put(Constants.IMPORT_PACKAGE, "export");
        Module module = installDummyModule(manifest, manifest.get(Constants.BUNDLE_SYMBOLICNAME), container);
        try {
            module.start();
            fail("expected a bundle exception.");
        } catch (BundleException e) {
        // do nothing
        }
        modules.add(module);
    }
    manifest.clear();
    manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
    manifest.put(Constants.BUNDLE_SYMBOLICNAME, "exporter");
    manifest.put(Constants.EXPORT_PACKAGE, "export");
    installDummyModule(manifest, manifest.get(Constants.BUNDLE_SYMBOLICNAME), container);
    report = container.resolve(Collections.<Module>emptySet(), false);
    Assert.assertNull("Found a error.", report.getResolutionException());
    State expectedState = enabled ? State.ACTIVE : State.RESOLVED;
    for (Module module : modules) {
        Assert.assertEquals("Wrong state.", expectedState, module.getState());
    }
}
Also used : HashMap(java.util.HashMap) DummyCollisionHook(org.eclipse.osgi.tests.container.dummys.DummyCollisionHook) ModuleContainer(org.eclipse.osgi.container.ModuleContainer) ArrayList(java.util.ArrayList) ResolutionReport(org.eclipse.osgi.report.resolution.ResolutionReport) DummyContainerAdaptor(org.eclipse.osgi.tests.container.dummys.DummyContainerAdaptor) State(org.eclipse.osgi.container.Module.State) BundleException(org.osgi.framework.BundleException) Module(org.eclipse.osgi.container.Module)

Example 2 with DummyCollisionHook

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

the class TestModuleContainer method testSingleton04.

@Test
public void testSingleton04() throws BundleException, IOException {
    final Collection<BundleRevision> disabled = new ArrayList<BundleRevision>();
    ResolverHookFactory resolverHookFactory = new ResolverHookFactory() {

        @Override
        public ResolverHook begin(Collection<BundleRevision> triggers) {
            return new ResolverHook() {

                @Override
                public void filterSingletonCollisions(BundleCapability singleton, Collection<BundleCapability> collisionCandidates) {
                // nothing
                }

                @Override
                public void filterResolvable(Collection<BundleRevision> candidates) {
                    candidates.removeAll(disabled);
                }

                @Override
                public void filterMatches(BundleRequirement requirement, Collection<BundleCapability> candidates) {
                // nothing
                }

                @Override
                public void end() {
                // nothing
                }
            };
        }
    };
    DummyContainerAdaptor adaptor = new DummyContainerAdaptor(new DummyCollisionHook(false), Collections.<String, String>emptyMap(), resolverHookFactory);
    ModuleContainer container = adaptor.getContainer();
    Module s1_v1 = installDummyModule("singleton1_v1.MF", "s1_v1", container);
    Module s1_v2 = installDummyModule("singleton1_v2.MF", "s1_v2", container);
    Module s1_v3 = installDummyModule("singleton1_v3.MF", "s1_v3", container);
    Module s2_v1 = installDummyModule("singleton2_v1.MF", "s1_v1", container);
    Module s2_v2 = installDummyModule("singleton2_v2.MF", "s1_v2", container);
    Module s2_v3 = installDummyModule("singleton2_v3.MF", "s1_v3", container);
    container.resolve(null, false);
    Assert.assertFalse("Singleton v1 is resolved.", Module.RESOLVED_SET.contains(s1_v1.getState()));
    Assert.assertFalse("Singleton v2 is resolved.", Module.RESOLVED_SET.contains(s1_v2.getState()));
    Assert.assertTrue("Singleton v3 is not resolved.", Module.RESOLVED_SET.contains(s1_v3.getState()));
    Assert.assertFalse("client v1 is resolved.", Module.RESOLVED_SET.contains(s2_v1.getState()));
    Assert.assertFalse("client v2 is resolved.", Module.RESOLVED_SET.contains(s2_v2.getState()));
    Assert.assertTrue("client v3 is not resolved.", Module.RESOLVED_SET.contains(s2_v3.getState()));
    // now disable s1_v3
    disabled.add(s1_v3.getCurrentRevision());
    container.refresh(Arrays.asList(s1_v3));
    Assert.assertFalse("Singleton v1 is resolved.", Module.RESOLVED_SET.contains(s1_v1.getState()));
    Assert.assertTrue("Singleton v2 is not resolved.", Module.RESOLVED_SET.contains(s1_v2.getState()));
    Assert.assertFalse("Singleton v3 is resolved.", Module.RESOLVED_SET.contains(s1_v3.getState()));
    Assert.assertFalse("client v1 is resolved.", Module.RESOLVED_SET.contains(s2_v1.getState()));
    Assert.assertTrue("client v2 is not resolved.", Module.RESOLVED_SET.contains(s2_v2.getState()));
    Assert.assertFalse("client v3 is resolved.", Module.RESOLVED_SET.contains(s2_v3.getState()));
    // now disable s1_v2
    disabled.add(s1_v2.getCurrentRevision());
    container.refresh(Arrays.asList(s1_v2));
    Assert.assertTrue("Singleton v1 is not resolved.", Module.RESOLVED_SET.contains(s1_v1.getState()));
    Assert.assertFalse("Singleton v2 is resolved.", Module.RESOLVED_SET.contains(s1_v2.getState()));
    Assert.assertFalse("Singleton v3 is resolved.", Module.RESOLVED_SET.contains(s1_v3.getState()));
    Assert.assertTrue("client v1 is not resolved.", Module.RESOLVED_SET.contains(s2_v1.getState()));
    Assert.assertFalse("client v2 is resolved.", Module.RESOLVED_SET.contains(s2_v2.getState()));
    Assert.assertFalse("client v3 is resolved.", Module.RESOLVED_SET.contains(s2_v3.getState()));
}
Also used : ResolverHookFactory(org.osgi.framework.hooks.resolver.ResolverHookFactory) DummyResolverHookFactory(org.eclipse.osgi.tests.container.dummys.DummyResolverHookFactory) DummyContainerAdaptor(org.eclipse.osgi.tests.container.dummys.DummyContainerAdaptor) DummyResolverHook(org.eclipse.osgi.tests.container.dummys.DummyResolverHook) ResolverHook(org.osgi.framework.hooks.resolver.ResolverHook) DummyCollisionHook(org.eclipse.osgi.tests.container.dummys.DummyCollisionHook) ModuleContainer(org.eclipse.osgi.container.ModuleContainer) BundleRevision(org.osgi.framework.wiring.BundleRevision) ArrayList(java.util.ArrayList) Collection(java.util.Collection) BundleCapability(org.osgi.framework.wiring.BundleCapability) Module(org.eclipse.osgi.container.Module) BundleRequirement(org.osgi.framework.wiring.BundleRequirement) Test(org.junit.Test)

Example 3 with DummyCollisionHook

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

the class TestModuleContainer method testInstallCollision02.

@Test
public void testInstallCollision02() throws BundleException, IOException {
    DummyContainerAdaptor adaptor = new DummyContainerAdaptor(new DummyCollisionHook(true), Collections.<String, String>emptyMap());
    ModuleContainer container = adaptor.getContainer();
    installDummyModule("system.bundle.MF", Constants.SYSTEM_BUNDLE_LOCATION, container);
    installDummyModule("b1_v1.MF", "b1_a", container);
    installDummyModule("b1_v1.MF", "b1_b", container);
}
Also used : DummyContainerAdaptor(org.eclipse.osgi.tests.container.dummys.DummyContainerAdaptor) DummyCollisionHook(org.eclipse.osgi.tests.container.dummys.DummyCollisionHook) ModuleContainer(org.eclipse.osgi.container.ModuleContainer) Test(org.junit.Test)

Example 4 with DummyCollisionHook

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

the class TestModuleContainer method testUsesTimeout.

// DISABLE see bug 498064 @Test
public void testUsesTimeout() throws BundleException {
    // Always want to go to zero threads when idle
    int coreThreads = 0;
    // use the number of processors - 1 because we use the current thread when rejected
    int maxThreads = Math.max(Runtime.getRuntime().availableProcessors() - 1, 1);
    // idle timeout; make it short to get rid of threads quickly after resolve
    int idleTimeout = 5;
    // use sync queue to force thread creation
    BlockingQueue<Runnable> queue = new SynchronousQueue<Runnable>();
    // try to name the threads with useful name
    ThreadFactory threadFactory = new ThreadFactory() {

        @Override
        public Thread newThread(Runnable r) {
            // $NON-NLS-1$
            Thread t = new Thread(r, "Resolver thread - UNIT TEST");
            t.setDaemon(true);
            return t;
        }
    };
    // use a rejection policy that simply runs the task in the current thread once the max threads is reached
    RejectedExecutionHandler rejectHandler = new RejectedExecutionHandler() {

        @Override
        public void rejectedExecution(Runnable r, ThreadPoolExecutor exe) {
            r.run();
        }
    };
    ExecutorService executor = new ThreadPoolExecutor(coreThreads, maxThreads, idleTimeout, TimeUnit.SECONDS, queue, threadFactory, rejectHandler);
    ScheduledExecutorService timeoutExecutor = new ScheduledThreadPoolExecutor(1);
    Map<String, String> configuration = new HashMap<String, String>();
    configuration.put(EquinoxConfiguration.PROP_RESOLVER_BATCH_TIMEOUT, "5000");
    Map<String, String> debugOpts = Collections.emptyMap();
    DummyContainerAdaptor adaptor = new DummyContainerAdaptor(new DummyCollisionHook(false), configuration, new DummyResolverHookFactory(), new DummyDebugOptions(debugOpts));
    adaptor.setResolverExecutor(executor);
    adaptor.setTimeoutExecutor(timeoutExecutor);
    ModuleContainer container = adaptor.getContainer();
    for (int i = 1; i <= 1000; i++) {
        for (Map<String, String> manifest : getUsesTimeoutManifests("test" + i)) {
            installDummyModule(manifest, manifest.get(Constants.BUNDLE_SYMBOLICNAME), container);
        }
    }
    ResolutionReport report = container.resolve(container.getModules(), true);
    Assert.assertNull("Found resolution errors.", report.getResolutionException());
    for (Module module : container.getModules()) {
        Assert.assertEquals("Wrong state of module: " + module, State.RESOLVED, module.getState());
    }
    executor.shutdown();
    timeoutExecutor.shutdown();
    System.gc();
    System.gc();
    System.gc();
}
Also used : ThreadFactory(java.util.concurrent.ThreadFactory) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) RejectedExecutionHandler(java.util.concurrent.RejectedExecutionHandler) HashMap(java.util.HashMap) DummyCollisionHook(org.eclipse.osgi.tests.container.dummys.DummyCollisionHook) ModuleContainer(org.eclipse.osgi.container.ModuleContainer) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) DummyDebugOptions(org.eclipse.osgi.tests.container.dummys.DummyDebugOptions) ResolutionReport(org.eclipse.osgi.report.resolution.ResolutionReport) DummyContainerAdaptor(org.eclipse.osgi.tests.container.dummys.DummyContainerAdaptor) SynchronousQueue(java.util.concurrent.SynchronousQueue) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) ExecutorService(java.util.concurrent.ExecutorService) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) Module(org.eclipse.osgi.container.Module) DummyResolverHookFactory(org.eclipse.osgi.tests.container.dummys.DummyResolverHookFactory)

Example 5 with DummyCollisionHook

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

the class TestModuleContainer method testUpdateCollision03.

@Test
public void testUpdateCollision03() throws BundleException, IOException {
    DummyContainerAdaptor adaptor = new DummyContainerAdaptor(new DummyCollisionHook(true), Collections.<String, String>emptyMap());
    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);
    } catch (BundleException e) {
        Assert.assertNull("Expected to succeed update to same revision.", e);
    }
}
Also used : DummyContainerAdaptor(org.eclipse.osgi.tests.container.dummys.DummyContainerAdaptor) DummyCollisionHook(org.eclipse.osgi.tests.container.dummys.DummyCollisionHook) ModuleContainer(org.eclipse.osgi.container.ModuleContainer) BundleException(org.osgi.framework.BundleException) Module(org.eclipse.osgi.container.Module) Test(org.junit.Test)

Aggregations

ModuleContainer (org.eclipse.osgi.container.ModuleContainer)7 DummyCollisionHook (org.eclipse.osgi.tests.container.dummys.DummyCollisionHook)7 DummyContainerAdaptor (org.eclipse.osgi.tests.container.dummys.DummyContainerAdaptor)7 Module (org.eclipse.osgi.container.Module)6 Test (org.junit.Test)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 DummyResolverHookFactory (org.eclipse.osgi.tests.container.dummys.DummyResolverHookFactory)3 Collection (java.util.Collection)2 ResolutionReport (org.eclipse.osgi.report.resolution.ResolutionReport)2 DummyResolverHook (org.eclipse.osgi.tests.container.dummys.DummyResolverHook)2 BundleException (org.osgi.framework.BundleException)2 ResolverHook (org.osgi.framework.hooks.resolver.ResolverHook)2 ResolverHookFactory (org.osgi.framework.hooks.resolver.ResolverHookFactory)2 BundleCapability (org.osgi.framework.wiring.BundleCapability)2 BundleRequirement (org.osgi.framework.wiring.BundleRequirement)2 ExecutorService (java.util.concurrent.ExecutorService)1 RejectedExecutionHandler (java.util.concurrent.RejectedExecutionHandler)1 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)1 ScheduledThreadPoolExecutor (java.util.concurrent.ScheduledThreadPoolExecutor)1