<commit_before>// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.jdisc.core;

import com.yahoo.jdisc.test.TestDriver;
import org.junit.Test;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
import org.osgi.service.log.LogEntry;
import org.osgi.service.log.LogReaderService;

import java.util.Enumeration;
import java.util.logging.Level;
import java.util.logging.Logger;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;


/**
 * @author <a href="mailto:<EMAIL>"><NAME></a>
 */
public class OsgiLogServiceIntegrationTest {

    @Test
    @SuppressWarnings("unchecked")
    public void requireThatAllSupportedLogFrameworksAreConfigured() throws Exception {
        // need to explicitly set log level of root logger since integration suite now provides a logger config file,
        // which disables that setLevel() call of the OsgiLogManager.
        Logger.getLogger("").setLevel(Level.INFO);

        long now = System.currentTimeMillis();
        TestDriver driver = TestDriver.newApplicationBundleInstance("app-h-log.jar", false);
        BundleContext ctx = driver.osgiFramework().bundleContext();
        ServiceReference<?> ref = ctx.getServiceReference(LogReaderService.class.getName());
        LogReaderService reader = (LogReaderService)ctx.getService(ref);
        Enumeration<LogEntry> log = (Enumeration<LogEntry>)reader.getLog();

        assertEntry(Level.INFO, "[jdk14] hello world", null, now, log);
        assertEntry(Level.INFO, "[slf4j] hello world", null, now, log);
        assertEntry(Level.INFO, "[log4j] hello world", null, now, log);
        assertEntry(Level.INFO, "[jcl] hello world", null, now, log);

        assertTrue(driver.close());
    }

    private static void assertEntry(Level expectedLevel, String expectedMessage, Throwable expectedException,
                                    long expectedTimeGE, Enumeration<LogEntry> log)
    {
        assertTrue(log.hasMoreElements());
        LogEntry entry = log.nextElement();
        assertNotNull(entry);
        System.err.println("log entry: "+entry.getMessage()+" bundle="+entry.getBundle());
        assertNull(entry.getBundle());
        assertNotNull(entry.getServiceReference());
        assertEquals(OsgiLogHandler.toServiceLevel(expectedLevel), entry.getLevel());
        assertEquals(expectedMessage, entry.getMessage());
        assertEquals(expectedException, entry.getException());
        assertTrue(expectedTimeGE <= entry.getTime());
    }
}
<commit_msg>see if we can get more information on spurious failures<commit_after>// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.jdisc.core;

import com.yahoo.jdisc.test.TestDriver;
import org.junit.Test;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
import org.osgi.service.log.LogEntry;
import org.osgi.service.log.LogReaderService;

import java.util.Enumeration;
import java.util.logging.Level;
import java.util.logging.Logger;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;


/**
 * @author <a href="mailto:<EMAIL>"><NAME></a>
 */
public class OsgiLogServiceIntegrationTest {

    @Test
    @SuppressWarnings("unchecked")
    public void requireThatAllSupportedLogFrameworksAreConfigured() throws Exception {
        // need to explicitly set log level of root logger since integration suite now provides a logger config file,
        // which disables that setLevel() call of the OsgiLogManager.
        Logger.getLogger("").setLevel(Level.INFO);

        long now = System.currentTimeMillis();
        TestDriver driver = TestDriver.newApplicationBundleInstance("app-h-log.jar", false);
        BundleContext ctx = driver.osgiFramework().bundleContext();
        ServiceReference<?> ref = ctx.getServiceReference(LogReaderService.class.getName());
        LogReaderService reader = (LogReaderService)ctx.getService(ref);
        Enumeration<LogEntry> log = (Enumeration<LogEntry>)reader.getLog();

        assertEntry(Level.INFO, "[jdk14] hello world", null, now, log);
        assertEntry(Level.INFO, "[slf4j] hello world", null, now, log);
        assertEntry(Level.INFO, "[log4j] hello world", null, now, log);
        assertEntry(Level.INFO, "[jcl] hello world", null, now, log);

        assertTrue(driver.close());
    }

    private static void assertEntry(Level expectedLevel, String expectedMessage, Throwable expectedException,
                                    long expectedTimeGE, Enumeration<LogEntry> log)
    {
        assertTrue(log.hasMoreElements());
        LogEntry entry = log.nextElement();
        assertNotNull(entry);
        System.err.println("log entry: "+entry.getMessage()+" bundle="+entry.getBundle());
        assertEquals(expectedMessage, entry.getMessage());
        assertNull(entry.getBundle());
        assertNotNull(entry.getServiceReference());
        assertEquals(OsgiLogHandler.toServiceLevel(expectedLevel), entry.getLevel());
        assertEquals(expectedException, entry.getException());
        assertTrue(expectedTimeGE <= entry.getTime());
    }
}

{'fraction_non_alphanumeric': 0.11449541284403669, 'fraction_numerical': 0.003669724770642202, 'mean_word_length': 3.9196750902527078, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1700439', 'n_tokens_mistral': 1487, 'n_tokens_neox': 1451, 'n_words': 353}