use of org.eclipse.osgi.launch.Equinox in project rt.equinox.framework by eclipse.
the class SystemBundleTests method testDaemonActiveThread.
public void testDaemonActiveThread() throws BundleException, InterruptedException {
File config = OSGiTestsActivator.getContext().getDataFile(getName());
config.mkdirs();
Map<String, Object> configuration = new HashMap<String, Object>();
configuration.put(Constants.FRAMEWORK_STORAGE, config.getAbsolutePath());
// test setting to anything other than 'normal'
// should result in a daemon thread
configuration.put(EquinoxConfiguration.PROP_ACTIVE_THREAD_TYPE, "daemon");
Equinox equinox = new Equinox(configuration);
equinox.start();
checkActiveThreadType(equinox, true);
equinox.stop();
equinox.waitForStop(10000);
// test setting to 'normal'
// should result in a non-daemon thread
configuration.put(EquinoxConfiguration.PROP_ACTIVE_THREAD_TYPE, EquinoxConfiguration.ACTIVE_THREAD_TYPE_NORMAL);
equinox = new Equinox(configuration);
equinox.start();
checkActiveThreadType(equinox, false);
equinox.stop();
equinox.waitForStop(10000);
// test setting to null (default)
// should result in a non-daemon thread
configuration.remove(EquinoxConfiguration.PROP_ACTIVE_THREAD_TYPE);
equinox = new Equinox(configuration);
equinox.start();
checkActiveThreadType(equinox, false);
equinox.stop();
}
use of org.eclipse.osgi.launch.Equinox in project rt.equinox.framework by eclipse.
the class SystemBundleTests method testSystemBundleListener.
public void testSystemBundleListener() throws BundleException, InterruptedException {
File config = OSGiTestsActivator.getContext().getDataFile(getName());
config.mkdirs();
Map<String, Object> configuration = new HashMap<String, Object>();
configuration.put(Constants.FRAMEWORK_STORAGE, config.getAbsolutePath());
Equinox equinox = new Equinox(configuration);
equinox.start();
BundleContext systemContext = equinox.getBundleContext();
final AtomicInteger stoppingEvent = new AtomicInteger();
final AtomicInteger stoppedEvent = new AtomicInteger();
BundleListener systemBundleListener = new SynchronousBundleListener() {
@Override
public void bundleChanged(BundleEvent event) {
if (event.getBundle().getBundleId() == 0) {
switch(event.getType()) {
case BundleEvent.STOPPING:
stoppingEvent.incrementAndGet();
break;
case BundleEvent.STOPPED:
stoppedEvent.incrementAndGet();
default:
break;
}
}
}
};
systemContext.addBundleListener(systemBundleListener);
equinox.stop();
equinox.waitForStop(5000);
assertEquals("Wrong number of STOPPING events", 1, stoppingEvent.get());
assertEquals("Wrong number of STOPPED events", 1, stoppedEvent.get());
}
use of org.eclipse.osgi.launch.Equinox in project rt.equinox.framework by eclipse.
the class SystemBundleTests method testSystemBundle05_1.
public void testSystemBundle05_1() {
// create/install/start/stop test
// $NON-NLS-1$
File config = OSGiTestsActivator.getContext().getDataFile("testSystemBundle05_1");
Map<String, Object> configuration = new HashMap<String, Object>();
configuration.put(Constants.FRAMEWORK_STORAGE, config.getAbsolutePath());
Equinox equinox = new Equinox(configuration);
try {
equinox.init();
} catch (BundleException e) {
// $NON-NLS-1$
fail("Unexpected exception in init()", e);
}
// should be in the STARTING state
// $NON-NLS-1$
assertEquals("Wrong state for SystemBundle", Bundle.STARTING, equinox.getState());
BundleContext systemContext = equinox.getBundleContext();
// $NON-NLS-1$
assertNotNull("System context is null", systemContext);
// try installing a bundle before starting
Bundle substitutesA = null;
try {
// $NON-NLS-1$
substitutesA = systemContext.installBundle(installer.getBundleLocation("substitutes.a"));
} catch (BundleException e1) {
// $NON-NLS-1$
fail("failed to install a bundle", e1);
}
// start framework first
try {
equinox.start();
} catch (BundleException e) {
// $NON-NLS-1$
fail("Failed to start the framework", e);
}
// $NON-NLS-1$
assertEquals("Wrong state for SystemBundle", Bundle.ACTIVE, equinox.getState());
// $NON-NLS-1$
assertEquals("Wrong state for installed bundle", Bundle.INSTALLED, substitutesA.getState());
try {
substitutesA.start();
} catch (BundleException e1) {
// $NON-NLS-1$
fail("Failed to start a bundle", e1);
}
// $NON-NLS-1$
assertEquals("Wrong state for active bundle", Bundle.ACTIVE, substitutesA.getState());
// put the framework back to the RESOLVED state
try {
equinox.stop();
} catch (BundleException e) {
// $NON-NLS-1$
fail("Unexpected erorr stopping framework", e);
}
try {
equinox.waitForStop(10000);
} catch (InterruptedException e) {
// $NON-NLS-1$
fail("Unexpected interrupted exception", e);
}
// $NON-NLS-1$
assertEquals("Wrong state for SystemBundle", Bundle.RESOLVED, equinox.getState());
}
use of org.eclipse.osgi.launch.Equinox in project rt.equinox.framework by eclipse.
the class SystemBundleTests method testBundleIDLock.
public void testBundleIDLock() {
// $NON-NLS-1$
File config = OSGiTestsActivator.getContext().getDataFile(getName());
Map<String, Object> configuration = new HashMap<String, Object>();
configuration.put(EquinoxConfiguration.PROP_FILE_LIMIT, "10");
configuration.put(Constants.FRAMEWORK_STORAGE, config.getAbsolutePath());
final Equinox equinox = new Equinox(configuration);
try {
equinox.init();
} catch (BundleException e) {
// $NON-NLS-1$
fail("Unexpected exception in init()", e);
}
// should be in the STARTING state
// $NON-NLS-1$
assertEquals("Wrong state for SystemBundle", Bundle.STARTING, equinox.getState());
final BundleContext systemContext = equinox.getBundleContext();
// $NON-NLS-1$
assertNotNull("System context is null", systemContext);
try {
equinox.start();
} catch (BundleException e) {
// $NON-NLS-1$
fail("Failed to start the framework", e);
}
// $NON-NLS-1$
assertEquals("Wrong state for SystemBundle", Bundle.ACTIVE, equinox.getState());
final int numBundles = 5000;
final File[] testBundles;
try {
// $NON-NLS-1$
testBundles = createBundles(new File(config, "bundles"), numBundles);
} catch (IOException e) {
// $NON-NLS-1$
fail("Unexpected error creating budnles", e);
throw new RuntimeException();
}
ExecutorService executor = Executors.newFixedThreadPool(50);
final List<Throwable> errors = new CopyOnWriteArrayList<Throwable>();
try {
for (int i = 0; i < testBundles.length; i++) {
final File testBundleFile = testBundles[i];
executor.execute(new Runnable() {
@Override
public void run() {
try {
systemContext.installBundle("file:///" + testBundleFile.getAbsolutePath());
} catch (BundleException e) {
e.printStackTrace();
errors.add(e);
}
}
});
}
} finally {
executor.shutdown();
try {
executor.awaitTermination(600, TimeUnit.SECONDS);
} catch (InterruptedException e) {
fail("Interrupted.", e);
}
}
Assert.assertEquals("Errors found.", Collections.emptyList(), errors);
Assert.assertEquals("Wrong number of bundles.", numBundles + 1, systemContext.getBundles().length);
try {
equinox.stop();
} catch (BundleException e) {
// $NON-NLS-1$
fail("Unexpected erorr stopping framework", e);
}
try {
equinox.waitForStop(10000);
} catch (InterruptedException e) {
// $NON-NLS-1$
fail("Unexpected interrupted exception", e);
}
// $NON-NLS-1$
assertEquals("Wrong state for SystemBundle", Bundle.RESOLVED, equinox.getState());
}
use of org.eclipse.osgi.launch.Equinox in project rt.equinox.framework by eclipse.
the class SystemBundleTests method testBug375784.
public void testBug375784() {
// Create a framework with osgi.context.bootdelegation=true configuration
// $NON-NLS-1$
File config = OSGiTestsActivator.getContext().getDataFile(getName());
Map<String, Object> configuration = new HashMap<String, Object>();
configuration.put(Constants.FRAMEWORK_STORAGE, config.getAbsolutePath());
configuration.put("osgi.context.bootdelegation", "true");
Equinox equinox = new Equinox(configuration);
try {
equinox.start();
} catch (BundleException e) {
// $NON-NLS-1$
fail("Unexpected exception in init()", e);
}
BundleContext systemContext = equinox.getBundleContext();
// $NON-NLS-1$
assertNotNull("System context is null", systemContext);
// try installing a bundle before starting
Bundle tb1;
try {
// $NON-NLS-1$
tb1 = systemContext.installBundle(installer.getBundleLocation("test.bug375784"));
tb1.start();
} catch (BundleException e1) {
// $NON-NLS-1$
fail("failed to install and start test bundle", e1);
}
try {
equinox.stop();
} catch (BundleException e) {
// $NON-NLS-1$
fail("Unexpected erorr stopping framework", e);
}
try {
equinox.waitForStop(10000);
} catch (InterruptedException e) {
// $NON-NLS-1$
fail("Unexpected interrupted exception", e);
}
// $NON-NLS-1$
assertEquals("Wrong state for SystemBundle", Bundle.RESOLVED, equinox.getState());
}
Aggregations