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());
}
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();
}
Aggregations