use of org.eclipse.osgi.launch.Equinox in project rt.equinox.framework by eclipse.
the class SystemBundleTests method testLazyTriggerOnLoadError.
public void testLazyTriggerOnLoadError() throws InterruptedException, BundleException {
// create/start/stop/start/stop test
// $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(EquinoxConfiguration.PROP_COMPATIBILITY_START_LAZY_ON_FAIL_CLASSLOAD, "true");
Equinox equinox = new Equinox(configuration);
equinox.start();
BundleContext systemContext = equinox.getBundleContext();
// $NON-NLS-1$
assertNotNull("System context is null", systemContext);
// install a lazy activated bundle
// $NON-NLS-1$
Bundle b = systemContext.installBundle(installer.getBundleLocation("chain.test.d"));
b.start(Bundle.START_ACTIVATION_POLICY);
assertEquals("Wrong state of bundle.", Bundle.STARTING, b.getState());
try {
// trigger the start by loading non existing class
b.loadClass("does.not.exist.Clazz");
fail("Expected class load error");
} catch (ClassNotFoundException e) {
// expected
}
// should be active now
assertEquals("Wrong state of bundle.", Bundle.ACTIVE, b.getState());
// put the framework back to the RESOLVED state
equinox.stop();
equinox.waitForStop(10000);
// revert back to default behavior
configuration.remove(EquinoxConfiguration.PROP_COMPATIBILITY_START_LAZY_ON_FAIL_CLASSLOAD);
equinox = new Equinox(configuration);
equinox.start();
b = equinox.getBundleContext().getBundle(b.getBundleId());
assertEquals("Wrong state of bundle.", Bundle.STARTING, b.getState());
try {
// loading non-existing class should NOT trigger lazy activation now
b.loadClass("does.not.exist.Clazz");
fail("Expected class load error");
} catch (ClassNotFoundException e) {
// expected
}
// should still be in STARTING state.
assertEquals("Wrong state of bundle.", Bundle.STARTING, b.getState());
equinox.stop();
}
use of org.eclipse.osgi.launch.Equinox in project rt.equinox.framework by eclipse.
the class SystemBundleTests method testContextBootDelegation.
public void testContextBootDelegation() throws BundleException {
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();
try {
Bundle b = systemContext.installBundle(installer.getBundleLocation("test.bug471551"));
b.start();
} catch (BundleException e) {
// $NON-NLS-1$
fail("Unexpected error", e);
}
equinox.stop();
}
use of org.eclipse.osgi.launch.Equinox in project rt.equinox.framework by eclipse.
the class SystemBundleTests method testBug258209_1.
public void testBug258209_1() throws BundleException {
// create a framework to test thread context class loaders
// $NON-NLS-1$
File config = OSGiTestsActivator.getContext().getDataFile(getName());
Map<String, Object> configuration = new HashMap<String, Object>();
configuration.put(Constants.FRAMEWORK_STORAGE, config.getAbsolutePath());
ClassLoader current = Thread.currentThread().getContextClassLoader();
Equinox equinox = new Equinox(configuration);
equinox.init();
Thread.currentThread().setContextClassLoader(current);
BundleContext systemContext = equinox.getBundleContext();
// $NON-NLS-1$
Bundle testTCCL = systemContext.installBundle(installer.getBundleLocation("test.tccl"));
equinox.adapt(FrameworkWiring.class).resolveBundles(Arrays.asList(testTCCL));
try {
testTCCL.start();
} catch (BundleException e) {
// $NON-NLS-1$
fail("Unexpected exception starting bundle", e);
}
// $NON-NLS-1$
assertEquals("Unexpected state", Bundle.RESOLVED, testTCCL.getState());
// this will start the framework on the current thread; test that the correct tccl is used
equinox.start();
// $NON-NLS-1$
assertEquals("Unexpected state", Bundle.ACTIVE, testTCCL.getState());
// test that the correct tccl is used for framework update
try {
equinox.update();
checkActive(testTCCL);
} catch (Exception e) {
// $NON-NLS-1$
fail("Unexpected exception", e);
}
systemContext = equinox.getBundleContext();
// $NON-NLS-1$
assertEquals("Unexpected state", Bundle.ACTIVE, testTCCL.getState());
// test that the correct tccl is used for refresh packages
equinox.adapt(FrameworkWiring.class).refreshBundles(Arrays.asList(testTCCL));
checkActive(testTCCL);
// $NON-NLS-1$
assertEquals("Unexpected state", Bundle.ACTIVE, testTCCL.getState());
// use the tccl service to start the test bundle.
ClassLoader serviceTCCL = null;
try {
// $NON-NLS-1$
serviceTCCL = (ClassLoader) systemContext.getService(systemContext.getServiceReferences(ClassLoader.class.getName(), "(equinox.classloader.type=contextClassLoader)")[0]);
} catch (InvalidSyntaxException e) {
// $NON-NLS-1$
fail("Unexpected", e);
}
current = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(serviceTCCL);
try {
testTCCL.stop();
testTCCL.start();
} catch (BundleException e) {
// $NON-NLS-1$
fail("Unepected", e);
} finally {
Thread.currentThread().setContextClassLoader(current);
}
try {
equinox.stop();
} catch (BundleException e) {
// $NON-NLS-1$
fail("Unexpected error stopping framework", e);
}
try {
equinox.waitForStop(10000);
} catch (InterruptedException e) {
// $NON-NLS-1$
fail("Unexpected interrupted exception", e);
}
}
use of org.eclipse.osgi.launch.Equinox in project rt.equinox.framework by eclipse.
the class SystemBundleTests method testSystemBundle02.
public void testSystemBundle02() {
// create/start/stop/start/stop test
// $NON-NLS-1$
File config = OSGiTestsActivator.getContext().getDataFile("testSystemBundle02");
Map<String, Object> configuration = new HashMap<String, Object>();
configuration.put(Constants.FRAMEWORK_STORAGE, config.getAbsolutePath());
Equinox equinox = new Equinox(configuration);
try {
equinox.init();
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());
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());
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());
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 testWindowsAlias.
public void testWindowsAlias() {
String origOS = System.getProperty("os.name");
// $NON-NLS-1$
File config = OSGiTestsActivator.getContext().getDataFile(getName());
Map configuration = new HashMap();
configuration.put(Constants.FRAMEWORK_STORAGE, config.getAbsolutePath());
System.setProperty("os.name", "Windows 5000");
Equinox equinox = null;
try {
equinox = new Equinox(configuration);
equinox.init();
Assert.assertEquals("Wrong framework os name value", "win32", equinox.getBundleContext().getProperty(Constants.FRAMEWORK_OS_NAME));
} catch (BundleException e) {
fail("Failed init", e);
} finally {
System.setProperty("os.name", origOS);
try {
if (equinox != null) {
equinox.stop();
equinox.waitForStop(1000);
}
} catch (BundleException e) {
fail("Failed to stop framework.", e);
} catch (InterruptedException e) {
fail("Failed to stop framework.", e);
}
}
}
Aggregations