use of org.eclipse.osgi.tests.container.dummys.DummyContainerAdaptor in project rt.equinox.framework by eclipse.
the class TestModuleContainer method testEventsStart.
@Test
public void testEventsStart() throws BundleException, IOException {
DummyContainerAdaptor adaptor = createDummyAdaptor();
ModuleContainer container = adaptor.getContainer();
DummyModuleDatabase database = adaptor.getDatabase();
Module systemBundle = installDummyModule("system.bundle.MF", Constants.SYSTEM_BUNDLE_LOCATION, container);
container.resolve(Arrays.asList(systemBundle), true);
// actually launch the container
systemBundle.start();
Module c1 = installDummyModule("c1_v1.MF", "c1_v1", container);
Module c2 = installDummyModule("c2_v1.MF", "c2_v1", container);
Module c3 = installDummyModule("c3_v1.MF", "c3_v1", container);
Module c4 = installDummyModule("c4_v1.MF", "c4_v1", container);
Module c5 = installDummyModule("c5_v1.MF", "c5_v1", container);
Module c6 = installDummyModule("c6_v1.MF", "c6_v1", container);
Module c7 = installDummyModule("c7_v1.MF", "c7_v1", container);
// throw away installed events
database.getModuleEvents();
c7.start();
List<DummyModuleEvent> actual = database.getModuleEvents();
List<DummyModuleEvent> expected = new ArrayList<DummyModuleEvent>(Arrays.asList(new DummyModuleEvent(c1, ModuleEvent.RESOLVED, State.RESOLVED), new DummyModuleEvent(c2, ModuleEvent.RESOLVED, State.RESOLVED), new DummyModuleEvent(c3, ModuleEvent.RESOLVED, State.RESOLVED), new DummyModuleEvent(c4, ModuleEvent.RESOLVED, State.RESOLVED), new DummyModuleEvent(c5, ModuleEvent.RESOLVED, State.RESOLVED), new DummyModuleEvent(c6, ModuleEvent.RESOLVED, State.RESOLVED), new DummyModuleEvent(c7, ModuleEvent.RESOLVED, State.RESOLVED), new DummyModuleEvent(c7, ModuleEvent.STARTING, State.STARTING), new DummyModuleEvent(c7, ModuleEvent.STARTED, State.ACTIVE)));
assertEvents(expected, actual, false);
}
use of org.eclipse.osgi.tests.container.dummys.DummyContainerAdaptor in project rt.equinox.framework by eclipse.
the class TestModuleContainer method createTestContainerAndGetTimestamp.
private long createTestContainerAndGetTimestamp() throws BundleException, IOException, InterruptedException {
// wait here to ensure current time really has increased
Thread.sleep(100);
DummyContainerAdaptor adaptor = createDummyAdaptor();
ModuleContainer container = adaptor.getContainer();
DummyModuleDatabase database = adaptor.getDatabase();
Module systemBundle = installDummyModule("system.bundle.MF", Constants.SYSTEM_BUNDLE_LOCATION, container);
container.resolve(Arrays.asList(systemBundle), true);
// actually launch the container
systemBundle.start();
// install some bundles and set some settings
container.getFrameworkStartLevel().setInitialBundleStartLevel(2);
Module c4 = installDummyModule("c4_v1.MF", "c4_v1", container);
Module lazy1 = installDummyModule("lazy1_v1.MF", "lazy1", container);
container.resolve(Arrays.asList(c4, lazy1), true);
// set some settings
Assert.assertEquals("Wrong startlevel.", 2, c4.getStartLevel());
Assert.assertEquals("Wrong startlevel.", 2, lazy1.getStartLevel());
return database.getTimestamp();
}
use of org.eclipse.osgi.tests.container.dummys.DummyContainerAdaptor in project rt.equinox.framework by eclipse.
the class TestModuleContainer method testExecutionEnvironment.
@Test
public void testExecutionEnvironment() throws BundleException, IOException {
DummyContainerAdaptor adaptor = createDummyAdaptor();
ModuleContainer container = adaptor.getContainer();
String extraCapabilities = "osgi.ee; osgi.ee=JavaSE; version:List<Version>=\"1.3, 1.4, 1.5, 1.6, 1.7\"";
installDummyModule("system.bundle.MF", Constants.SYSTEM_BUNDLE_LOCATION, null, null, extraCapabilities, container);
container.resolve(null, false);
Module ee1 = installDummyModule("ee1_v1.MF", "ee1", container);
Module ee2 = installDummyModule("ee2_v1.MF", "ee2", container);
Module ee3 = installDummyModule("ee3_v1.MF", "ee3", container);
container.resolve(Arrays.asList(ee1, ee2), true);
container.resolve(Arrays.asList(ee3), false);
ModuleWiring ee1Wiring = ee1.getCurrentRevision().getWiring();
ModuleWiring ee2Wiring = ee2.getCurrentRevision().getWiring();
ModuleWiring ee3Wiring = ee3.getCurrentRevision().getWiring();
Assert.assertNotNull("ee1 is not resolved", ee1Wiring);
Assert.assertNotNull("ee2 is not resolved", ee2Wiring);
Assert.assertNull("ee3 is resolved", ee3Wiring);
// make sure the fragment ee requirement did not get merged into the host
List<ModuleRequirement> ee1Requirements = ee1Wiring.getModuleRequirements(ExecutionEnvironmentNamespace.EXECUTION_ENVIRONMENT_NAMESPACE);
Assert.assertEquals("Wrong number of requirements", 1, ee1Requirements.size());
List<ModuleWire> ee1Wires = ee1Wiring.getRequiredModuleWires(ExecutionEnvironmentNamespace.EXECUTION_ENVIRONMENT_NAMESPACE);
Assert.assertEquals("Wrong number of wires", 1, ee1Wires.size());
List<ModuleRequirement> ee2Requirements = ee2Wiring.getModuleRequirements(ExecutionEnvironmentNamespace.EXECUTION_ENVIRONMENT_NAMESPACE);
Assert.assertEquals("Wrong number of requirements", 1, ee2Requirements.size());
List<ModuleWire> ee2Wires = ee2Wiring.getRequiredModuleWires(ExecutionEnvironmentNamespace.EXECUTION_ENVIRONMENT_NAMESPACE);
Assert.assertEquals("Wrong number of wires", 1, ee2Wires.size());
}
use of org.eclipse.osgi.tests.container.dummys.DummyContainerAdaptor 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.DummyContainerAdaptor in project rt.equinox.framework by eclipse.
the class TestModuleContainer method testR3.
@Test
public void testR3() throws BundleException, IOException {
DummyContainerAdaptor adaptor = createDummyAdaptor();
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());
// R3 bundle
Map<String, String> exporterManifest = new HashMap<String, String>();
exporterManifest = new HashMap<String, String>();
exporterManifest.put(Constants.BUNDLE_SYMBOLICNAME, "exporter");
exporterManifest.put(Constants.EXPORT_PACKAGE, "exporter; version=\"1.1\"");
Module moduleExport = installDummyModule(exporterManifest, "exporter", container);
report = container.resolve(Arrays.asList(moduleExport, moduleExport), true);
Assert.assertNull("Failed to resolve", report.getResolutionException());
List<BundleRequirement> reqs = moduleExport.getCurrentRevision().getWiring().getRequirements(PackageNamespace.PACKAGE_NAMESPACE);
assertEquals("Wrong number of imports.", 0, reqs.size());
// R3 bundle
exporterManifest.clear();
exporterManifest.put(Constants.BUNDLE_SYMBOLICNAME, "dynamicExporter");
exporterManifest.put(Constants.EXPORT_PACKAGE, "exporter; version=\"1.0\"");
exporterManifest.put(Constants.DYNAMICIMPORT_PACKAGE, "exporter");
Module moduleWithDynExport = installDummyModule(exporterManifest, "dynamicExporter", container);
report = container.resolve(Arrays.asList(moduleWithDynExport), true);
Assert.assertNull("Failed to resolve", report.getResolutionException());
reqs = moduleWithDynExport.getCurrentRevision().getWiring().getRequirements(PackageNamespace.PACKAGE_NAMESPACE);
assertEquals("Wrong number of imports.", 2, reqs.size());
report = container.resolve(Arrays.asList(moduleWithDynExport), true);
Assert.assertNull("Failed to resolve", report.getResolutionException());
reqs = moduleWithDynExport.getCurrentRevision().getWiring().getRequirements(PackageNamespace.PACKAGE_NAMESPACE);
assertEquals("Wrong number of imports.", 2, reqs.size());
ModuleWiring wiring = moduleWithDynExport.getCurrentRevision().getWiring();
List<ModuleWire> packageWires = wiring.getRequiredModuleWires(PackageNamespace.PACKAGE_NAMESPACE);
Assert.assertEquals("Unexpected number of wires", 1, packageWires.size());
Assert.assertEquals("Wrong exporter", packageWires.get(0).getProviderWiring().getRevision(), moduleExport.getCurrentRevision());
}
Aggregations