Search in sources :

Example 1 with DummyResolverHookFactory

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

the class TestModuleContainer method testDynamicImportMiss01.

@Test
public void testDynamicImportMiss01() throws BundleException, IOException {
    DummyContainerAdaptor adaptor = createDummyAdaptor();
    ModuleContainer container = adaptor.getContainer();
    Module systemBundle = installDummyModule("system.bundle.MF", Constants.SYSTEM_BUNDLE_LOCATION, null, null, "osgi.ee; osgi.ee=JavaSE; version:Version=\"1.5.0\"", container);
    container.resolve(Arrays.asList(systemBundle), true);
    Module c1 = installDummyModule("c1_v1.MF", "c1_v1", container);
    Module dynamic1 = installDummyModule("dynamic1_v1.MF", "dynamic1_v1", container);
    container.resolve(Arrays.asList(c1, dynamic1), true);
    DummyResolverHookFactory factory = (DummyResolverHookFactory) adaptor.getResolverHookFactory();
    DummyResolverHook hook = (DummyResolverHook) factory.getHook();
    hook.getResolutionReports().clear();
    ModuleWire dynamicWire = container.resolveDynamic("org.osgi.framework", dynamic1.getCurrentRevision());
    Assert.assertNotNull("No dynamic wire found.", dynamicWire);
    Assert.assertEquals("Wrong package found.", "org.osgi.framework", dynamicWire.getCapability().getAttributes().get(PackageNamespace.PACKAGE_NAMESPACE));
    Assert.assertEquals("Wrong provider for the wire found.", systemBundle.getCurrentRevision(), dynamicWire.getProvider());
    Assert.assertEquals("Wrong number of reports.", 1, hook.getResolutionReports().size());
    hook.getResolutionReports().clear();
    dynamicWire = container.resolveDynamic("does.not.exist", dynamic1.getCurrentRevision());
    Assert.assertNull("Unexpected Dynamic wire found.", dynamicWire);
    Assert.assertEquals("Wrong number of reports.", 1, hook.getResolutionReports().size());
    // Try again; no report should be generated a second time
    hook.getResolutionReports().clear();
    dynamicWire = container.resolveDynamic("does.not.exist", dynamic1.getCurrentRevision());
    Assert.assertNull("Unexpected Dynamic wire found.", dynamicWire);
    Assert.assertEquals("Wrong number of reports.", 0, hook.getResolutionReports().size());
}
Also used : DummyContainerAdaptor(org.eclipse.osgi.tests.container.dummys.DummyContainerAdaptor) ModuleWire(org.eclipse.osgi.container.ModuleWire) ModuleContainer(org.eclipse.osgi.container.ModuleContainer) Module(org.eclipse.osgi.container.Module) DummyResolverHookFactory(org.eclipse.osgi.tests.container.dummys.DummyResolverHookFactory) DummyResolverHook(org.eclipse.osgi.tests.container.dummys.DummyResolverHook) Test(org.junit.Test)

Example 2 with DummyResolverHookFactory

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

Aggregations

Module (org.eclipse.osgi.container.Module)2 ModuleContainer (org.eclipse.osgi.container.ModuleContainer)2 DummyContainerAdaptor (org.eclipse.osgi.tests.container.dummys.DummyContainerAdaptor)2 DummyResolverHookFactory (org.eclipse.osgi.tests.container.dummys.DummyResolverHookFactory)2 HashMap (java.util.HashMap)1 ExecutorService (java.util.concurrent.ExecutorService)1 RejectedExecutionHandler (java.util.concurrent.RejectedExecutionHandler)1 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)1 ScheduledThreadPoolExecutor (java.util.concurrent.ScheduledThreadPoolExecutor)1 SynchronousQueue (java.util.concurrent.SynchronousQueue)1 ThreadFactory (java.util.concurrent.ThreadFactory)1 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)1 ModuleWire (org.eclipse.osgi.container.ModuleWire)1 ResolutionReport (org.eclipse.osgi.report.resolution.ResolutionReport)1 DummyCollisionHook (org.eclipse.osgi.tests.container.dummys.DummyCollisionHook)1 DummyDebugOptions (org.eclipse.osgi.tests.container.dummys.DummyDebugOptions)1 DummyResolverHook (org.eclipse.osgi.tests.container.dummys.DummyResolverHook)1 Test (org.junit.Test)1