Search in sources :

Example 46 with Equinox

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);
    }
}
Also used : Equinox(org.eclipse.osgi.launch.Equinox) LinkedHashMap(java.util.LinkedHashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) FileOutputStream(java.io.FileOutputStream) Properties(java.util.Properties) File(java.io.File) BundleContext(org.osgi.framework.BundleContext)

Example 47 with Equinox

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());
}
Also used : Equinox(org.eclipse.osgi.launch.Equinox) LinkedHashMap(java.util.LinkedHashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) FrameworkEvent(org.osgi.framework.FrameworkEvent) BundleException(org.osgi.framework.BundleException) File(java.io.File)

Example 48 with Equinox

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);
}
Also used : LinkedHashMap(java.util.LinkedHashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) Bundle(org.osgi.framework.Bundle) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) IOException(java.io.IOException) Properties(java.util.Properties) Equinox(org.eclipse.osgi.launch.Equinox) FileOutputStream(java.io.FileOutputStream) ExecutorService(java.util.concurrent.ExecutorService) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) List(java.util.List) BundleException(org.osgi.framework.BundleException) File(java.io.File) BundleContext(org.osgi.framework.BundleContext)

Example 49 with Equinox

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();
}
Also used : Equinox(org.eclipse.osgi.launch.Equinox) LinkedHashMap(java.util.LinkedHashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) EnvironmentInfo(org.eclipse.osgi.service.environment.EnvironmentInfo) Properties(java.util.Properties) File(java.io.File)

Example 50 with Equinox

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);
        }
    }
}
Also used : Equinox(org.eclipse.osgi.launch.Equinox) LinkedHashMap(java.util.LinkedHashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) File(java.io.File) BundleContext(org.osgi.framework.BundleContext)

Aggregations

Equinox (org.eclipse.osgi.launch.Equinox)105 File (java.io.File)88 HashMap (java.util.HashMap)61 LinkedHashMap (java.util.LinkedHashMap)58 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)58 BundleException (org.osgi.framework.BundleException)52 BundleContext (org.osgi.framework.BundleContext)51 Bundle (org.osgi.framework.Bundle)43 IOException (java.io.IOException)18 FileNotFoundException (java.io.FileNotFoundException)11 URL (java.net.URL)10 Location (org.eclipse.osgi.service.datalocation.Location)10 Properties (java.util.Properties)8 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)8 FrameworkEvent (org.osgi.framework.FrameworkEvent)8 InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)8 BundleWiring (org.osgi.framework.wiring.BundleWiring)8 ArrayList (java.util.ArrayList)7 ExecutionException (java.util.concurrent.ExecutionException)6 FileOutputStream (java.io.FileOutputStream)5