Search in sources :

Example 1 with DummyDebugOptions

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

the class TestModuleContainer method testUses1Dynamic.

@Test
public void testUses1Dynamic() throws BundleException, IOException {
    DummyContainerAdaptor adaptor = createDummyAdaptor(new DummyDebugOptions(Collections.singletonMap("org.eclipse.osgi/resolver/report", "true")));
    ModuleContainer container = adaptor.getContainer();
    Module systemBundle = installDummyModule("system.bundle.MF", Constants.SYSTEM_BUNDLE_LOCATION, container);
    container.resolve(Arrays.asList(systemBundle), true);
    Module uses_a = installDummyModule("uses.a.MF", "a", container);
    Module uses_b = installDummyModule("uses.b.MF", "b", container);
    Module uses_c_dynamic = installDummyModule("uses.c.dynamic.MF", "c", container);
    container.resolve(null, false);
    Assert.assertEquals("a should resolve.", State.RESOLVED, uses_a.getState());
    Assert.assertEquals("b should resolve.", State.RESOLVED, uses_b.getState());
    Assert.assertEquals("c should resolve.", State.RESOLVED, uses_c_dynamic.getState());
    ModuleWire dynamicWire = container.resolveDynamic("uses1", uses_c_dynamic.getCurrentRevision());
    Assert.assertNotNull("No dynamic wire.", dynamicWire);
    PrintStream originalOut = Debug.out;
    ByteArrayOutputStream bytesOut = new ByteArrayOutputStream();
    PrintStream testOut = new PrintStream(bytesOut);
    Debug.out = testOut;
    try {
        dynamicWire = container.resolveDynamic("uses2", uses_c_dynamic.getCurrentRevision());
        Assert.assertNull("Dynamic wire found.", dynamicWire);
    } finally {
        Debug.out = originalOut;
        testOut.close();
    }
    String traceOutput = bytesOut.toString();
    Assert.assertTrue("Wrong traceOutput: " + traceOutput, traceOutput.startsWith("org.osgi.service.resolver.ResolutionException"));
}
Also used : DummyContainerAdaptor(org.eclipse.osgi.tests.container.dummys.DummyContainerAdaptor) PrintStream(java.io.PrintStream) ModuleWire(org.eclipse.osgi.container.ModuleWire) ModuleContainer(org.eclipse.osgi.container.ModuleContainer) DummyDebugOptions(org.eclipse.osgi.tests.container.dummys.DummyDebugOptions) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Module(org.eclipse.osgi.container.Module) Test(org.junit.Test)

Example 2 with DummyDebugOptions

use of org.eclipse.osgi.tests.container.dummys.DummyDebugOptions 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 DummyDebugOptions (org.eclipse.osgi.tests.container.dummys.DummyDebugOptions)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 PrintStream (java.io.PrintStream)1 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 DummyResolverHookFactory (org.eclipse.osgi.tests.container.dummys.DummyResolverHookFactory)1 Test (org.junit.Test)1