Search in sources :

Example 31 with Equinox

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();
}
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)

Example 32 with Equinox

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

Example 33 with Equinox

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

Example 34 with Equinox

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

Example 35 with Equinox

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