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