use of org.eclipse.osgi.launch.Equinox in project rt.equinox.framework by eclipse.
the class SystemBundleTests method testBug432632.
public void testBug432632() throws BundleException, IOException {
// $NON-NLS-1$
File config = OSGiTestsActivator.getContext().getDataFile(getName());
config.mkdirs();
// create a config.ini with some system property substitutes
Properties configIni = new Properties();
configIni.setProperty("test.substitute1", "Some.$test.prop1$.test");
configIni.setProperty("test.substitute2", "Some.$test.prop2$.test");
configIni.store(new FileOutputStream(new File(config, "config.ini")), "Test config.ini");
// Only provide substitution for the first prop
System.setProperty("test.prop1", "PASSED");
Map<String, Object> configuration = new HashMap<String, Object>();
configuration.put(Constants.FRAMEWORK_STORAGE, config.getAbsolutePath());
Equinox equinox = new Equinox(configuration);
equinox.init();
BundleContext systemContext = equinox.getBundleContext();
// check for substitution
assertEquals("Wrong value for test.substitute1", "Some.PASSED.test", systemContext.getProperty("test.substitute1"));
// check that non-substitution keeps $ delimiters.
assertEquals("Wrong value for test.substitute2", "Some.$test.prop2$.test", systemContext.getProperty("test.substitute2"));
equinox.stop();
try {
equinox.waitForStop(5000);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
fail("Unexpected interruption.", e);
}
}
use of org.eclipse.osgi.launch.Equinox in project rt.equinox.framework by eclipse.
the class SystemBundleTests method testSystemBundle12.
public void testSystemBundle12() {
// Test stop FrameworkEvent
// $NON-NLS-1$
File config = OSGiTestsActivator.getContext().getDataFile("testSystemBundle12");
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);
}
// test timeout waiting for framework stop
FrameworkEvent stopEvent = null;
try {
stopEvent = equinox.waitForStop(1000);
} catch (InterruptedException e) {
// $NON-NLS-1$
fail("Unexpected interrupted exception", e);
}
// $NON-NLS-1$
assertNotNull("Stop event is null", stopEvent);
// $NON-NLS-1$
assertEquals("Wrong stopEvent", FrameworkEvent.WAIT_TIMEDOUT, stopEvent.getType());
// $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 {
stopEvent = equinox.waitForStop(10000);
} catch (InterruptedException e) {
// $NON-NLS-1$
fail("Unexpected interrupted exception", e);
}
// $NON-NLS-1$
assertNotNull("Stop event is null", stopEvent);
// $NON-NLS-1$
assertEquals("Wrong stopEvent", FrameworkEvent.STOPPED, stopEvent.getType());
}
use of org.eclipse.osgi.launch.Equinox in project rt.equinox.framework by eclipse.
the class SystemBundleTests method testMRUBundleFileListOverflow.
public void testMRUBundleFileListOverflow() throws BundleException, FileNotFoundException, IOException {
// $NON-NLS-1$
File config = OSGiTestsActivator.getContext().getDataFile(getName());
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();
}
File debugOptions = new File(config, "debugOptions");
Properties debugProps = new Properties();
debugProps.setProperty(Debug.OPTION_DEBUG_BUNDLE_FILE, "true");
FileOutputStream debugOut = new FileOutputStream(debugOptions);
debugProps.store(debugOut, "Equinox Debug Options");
debugOut.close();
Map<String, Object> configuration = new HashMap<String, Object>();
configuration.put(EquinoxConfiguration.PROP_FILE_LIMIT, "10");
configuration.put(Constants.FRAMEWORK_STORAGE, config.getAbsolutePath());
// configuration.put(EquinoxConfiguration.PROP_DEBUG, debugOptions.getAbsolutePath());
final Equinox equinox = new Equinox(configuration);
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 BundleContext systemContext = equinox.getBundleContext();
// $NON-NLS-1$
assertNotNull("System context is null", systemContext);
final List<Bundle> bundles = new ArrayList<>();
for (File testBundleFile : testBundles) {
bundles.add(systemContext.installBundle("file:///" + testBundleFile.getAbsolutePath()));
}
// Note that this test uses wall clock timing which is not always consistent
// across testing environments, but we use a limit that should be well within
// reason for the test data size
long startTime = System.nanoTime();
ExecutorService executor = Executors.newFixedThreadPool(10);
try {
for (int i = 0; i < 10; i++) {
executor.execute(new Runnable() {
@Override
public void run() {
List<Bundle> shuffled = new ArrayList<>(bundles);
Collections.shuffle(shuffled);
for (Bundle bundle : shuffled) {
bundle.getEntry("does/not/exist");
}
}
});
}
} finally {
executor.shutdown();
try {
executor.awaitTermination(600, TimeUnit.SECONDS);
} catch (InterruptedException e) {
fail("Interrupted.", e);
}
}
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());
long timeTaken = TimeUnit.NANOSECONDS.toSeconds(System.nanoTime() - startTime);
System.out.println(getName() + " time taken: " + timeTaken);
assertTrue("Test took too long: " + timeTaken, timeTaken < 30);
}
use of org.eclipse.osgi.launch.Equinox in project rt.equinox.framework by eclipse.
the class SystemBundleTests method testBackedBySystemReplaceSystemProperties.
public void testBackedBySystemReplaceSystemProperties() throws BundleException {
// $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.framework.useSystemProperties", "true");
Equinox equinox = new Equinox(configuration);
equinox.start();
ServiceReference<EnvironmentInfo> envRef = equinox.getBundleContext().getServiceReference(EnvironmentInfo.class);
EnvironmentInfo envInfo = equinox.getBundleContext().getService(envRef);
// replace the system properties with a copy
Properties copy = new Properties();
copy.putAll(System.getProperties());
System.setProperties(copy);
// set a system prop for this test after replacement of the properties object
String systemKey = getName() + ".system";
System.setProperty(systemKey, getName());
// make sure context properties reflect the new test prop
assertEquals("Wrong context value", getName(), equinox.getBundleContext().getProperty(systemKey));
// also test EnvironmentInfo properties
assertEquals("Wrong context value", getName(), envInfo.getProperty(systemKey));
assertEquals("Wrong EquinoxConfiguration config value", getName(), ((EquinoxConfiguration) envInfo).getConfiguration(systemKey));
// set environment info prop
String envKey = getName() + ".env";
envInfo.setProperty(envKey, getName());
// make sure the system properties reflect the new test prop
assertEquals("Wrong system value", getName(), System.getProperty(envKey));
equinox.stop();
}
use of org.eclipse.osgi.launch.Equinox in project rt.equinox.framework by eclipse.
the class SystemBundleTests method testOSGiDevSetsCheckConfiguration.
public void testOSGiDevSetsCheckConfiguration() throws BundleException {
String originalCheckConfiguration = System.clearProperty(EquinoxConfiguration.PROP_CHECK_CONFIGURATION);
try {
File config = OSGiTestsActivator.getContext().getDataFile(getName());
Map<String, Object> configuration = new HashMap<String, Object>();
configuration.put(Constants.FRAMEWORK_STORAGE, config.getAbsolutePath());
configuration.put("osgi.dev", "true");
Equinox equinox = new Equinox(configuration);
equinox.start();
BundleContext systemContext = equinox.getBundleContext();
assertEquals("Wrong value for: " + EquinoxConfiguration.PROP_CHECK_CONFIGURATION, "true", systemContext.getProperty(EquinoxConfiguration.PROP_CHECK_CONFIGURATION));
equinox.stop();
} finally {
if (originalCheckConfiguration != null) {
System.setProperty(EquinoxConfiguration.PROP_CHECK_CONFIGURATION, originalCheckConfiguration);
}
}
}
Aggregations