Search in sources :

Example 1 with LogReaderService

use of org.osgi.service.log.LogReaderService in project rt.equinox.framework by eclipse.

the class SystemBundleTests method testOverrideEquinoxConfigAreaProp.

public void testOverrideEquinoxConfigAreaProp() {
    // $NON-NLS-1$
    File config = OSGiTestsActivator.getContext().getDataFile(getName());
    Map configuration = new HashMap();
    configuration.put(Constants.FRAMEWORK_STORAGE, config.getAbsolutePath());
    configuration.put(EquinoxLocations.PROP_CONFIG_AREA, config.getAbsolutePath() + "-override");
    configuration.put(EquinoxConfiguration.PROP_LOG_HISTORY_MAX, "10");
    Equinox equinox = null;
    try {
        equinox = new Equinox(configuration);
        equinox.init();
        BundleContext bc = equinox.getBundleContext();
        LogReaderService logReader = bc.getService(bc.getServiceReference(LogReaderService.class));
        Enumeration<LogEntry> logs = logReader.getLog();
        assertTrue("No logs found.", logs.hasMoreElements());
        LogEntry entry = logs.nextElement();
        assertEquals("Wrong log level.", LogLevel.WARN, entry.getLogLevel());
        assertTrue("Wrong message found: " + entry.getMessage(), entry.getMessage().contains(EquinoxLocations.PROP_CONFIG_AREA));
    } catch (BundleException e) {
        fail("Failed init", e);
    } finally {
        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);
        }
    }
}
Also used : Equinox(org.eclipse.osgi.launch.Equinox) LinkedHashMap(java.util.LinkedHashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) LogReaderService(org.osgi.service.log.LogReaderService) ExtendedLogReaderService(org.eclipse.equinox.log.ExtendedLogReaderService) BundleException(org.osgi.framework.BundleException) File(java.io.File) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) LogEntry(org.osgi.service.log.LogEntry) BundleContext(org.osgi.framework.BundleContext)

Aggregations

File (java.io.File)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ExtendedLogReaderService (org.eclipse.equinox.log.ExtendedLogReaderService)1 Equinox (org.eclipse.osgi.launch.Equinox)1 BundleContext (org.osgi.framework.BundleContext)1 BundleException (org.osgi.framework.BundleException)1 LogEntry (org.osgi.service.log.LogEntry)1 LogReaderService (org.osgi.service.log.LogReaderService)1