Search in sources :

Example 1 with MemoryHandler

use of java.util.logging.MemoryHandler in project robovm by robovm.

the class OldMemoryHandlerTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    manager.reset();
    initProps();
    manager.readConfiguration(propertiesToInputStream(props));
    handler = new MemoryHandler();
}
Also used : MemoryHandler(java.util.logging.MemoryHandler)

Example 2 with MemoryHandler

use of java.util.logging.MemoryHandler in project j2objc by google.

the class MemoryHandlerTest method setUp.

/*
	 * @see TestCase#setUp()
	 */
protected void setUp() throws Exception {
    super.setUp();
    manager.reset();
    initProps();
    manager.readConfiguration(EnvironmentHelper.PropertiesToInputStream(props));
    handler = new MemoryHandler();
    errSubstituteStream = new NullOutputStream();
    System.setErr(new PrintStream(errSubstituteStream));
}
Also used : PrintStream(java.io.PrintStream) MemoryHandler(java.util.logging.MemoryHandler) NullOutputStream(org.apache.harmony.logging.tests.java.util.logging.HandlerTest.NullOutputStream)

Example 3 with MemoryHandler

use of java.util.logging.MemoryHandler in project jdk8u_jdk by JetBrains.

the class MemoryHandlerTest method main.

public static void main(String... args) throws IOException {
    // load logging.propertes for the test
    String tstSrc = System.getProperty("test.src", ".");
    File fname = new File(tstSrc, LM_PROP_FNAME);
    String prop = fname.getCanonicalPath();
    System.setProperty(CFG_FILE_PROP, prop);
    LogManager.getLogManager();
    // create a logger
    logger = Logger.getLogger(MemoryHandlerTest.class.getName());
    // don't have parent handlers get log messages
    logger.setUseParentHandlers(false);
    //
    // Test 1,2: create a CustomMemoryHandler which in the config has
    // specified a target of CustomTargetHandler.  (1) Make sure that it
    // is created and (2) that the target handler is loaded.
    //
    CustomMemoryHandler cmh = new CustomMemoryHandler();
    try {
        logger.addHandler(cmh);
    } catch (RuntimeException rte) {
        throw new RuntimeException("Test Failed: did not load java.util.logging.ConsoleHandler as expected", rte);
    }
    // should have loaded our target handler
    if (CustomTargetHandler.numLoaded != 1) {
        throw new RuntimeException("Test failed: did not load CustomTargetHandler as expected");
    }
    //
    // Test 3: try to add a handler with no target.  This should fail with
    // an exception
    CustomMemoryHandlerNoTarget cmhnt = null;
    try {
        cmhnt = new CustomMemoryHandlerNoTarget();
    } catch (RuntimeException re) {
        // expected -- no target specified
        System.out.println("Info: " + re.getMessage() + " as expected.");
    }
    if (cmhnt != null) {
        throw new RuntimeException("Test Failed: erroneously loaded CustomMemoryHandlerNoTarget");
    }
    // Test 4: log a message and check that the target handler is actually used
    logger.log(Level.WARNING, "Unused");
    if (CustomTargetHandler.numPublished != 1) {
        throw new RuntimeException("Test failed: CustomTargetHandler was not used");
    }
    // Test 5: make sure that SimpleTargetHandler hasn't been erroneously called
    if (SimpleTargetHandler.numPublished != 0) {
        throw new RuntimeException("Test failed: SimpleTargetHandler has been used");
    }
    // Test 6: try using SimpleTargetHanlder via standard MemoryHandler
    // (which has target set to SimpleTargetHandler)
    MemoryHandler mh = new MemoryHandler();
    mh.publish(new LogRecord(Level.INFO, "Unused msg to MemoryHandler"));
    // see if it made it to the SimpleTargetHandler
    if (SimpleTargetHandler.numPublished != 1) {
        throw new RuntimeException("Test failed: SimpleTargetHandler was not used");
    }
}
Also used : LogRecord(java.util.logging.LogRecord) MemoryHandler(java.util.logging.MemoryHandler) File(java.io.File)

Example 4 with MemoryHandler

use of java.util.logging.MemoryHandler in project j2objc by google.

the class MemoryHandlerTest method testMemoryHandlerInvalidProps.

public void testMemoryHandlerInvalidProps() throws IOException {
    // null target
    try {
        props.remove("java.util.logging.MemoryHandler.target");
        manager.readConfiguration(EnvironmentHelper.PropertiesToInputStream(props));
        handler = new MemoryHandler();
        fail("should throw RuntimeException: target must be set");
    } catch (RuntimeException e) {
    }
    // invalid target
    try {
        props.put("java.util.logging.MemoryHandler.target", "badname");
        manager.readConfiguration(EnvironmentHelper.PropertiesToInputStream(props));
        handler = new MemoryHandler();
        fail("should throw RuntimeException: target must be valid");
    } catch (RuntimeException e) {
    }
    // invalid formatter
    initProps();
    props.put("java.util.logging.MemoryHandler.formatter", "badname");
    manager.readConfiguration(EnvironmentHelper.PropertiesToInputStream(props));
    handler = new MemoryHandler();
    assertTrue(handler.getFormatter() instanceof SimpleFormatter);
    // invalid level
    initProps();
    props.put("java.util.logging.MemoryHandler.level", "badname");
    manager.readConfiguration(EnvironmentHelper.PropertiesToInputStream(props));
    handler = new MemoryHandler();
    assertEquals(handler.getLevel(), Level.ALL);
    // invalid pushlevel
    initProps();
    props.put("java.util.logging.MemoryHandler.push", "badname");
    manager.readConfiguration(EnvironmentHelper.PropertiesToInputStream(props));
    handler = new MemoryHandler();
    assertEquals(handler.getPushLevel(), Level.SEVERE);
    // invalid filter
    initProps();
    props.put("java.util.logging.MemoryHandler.filter", "badname");
    manager.readConfiguration(EnvironmentHelper.PropertiesToInputStream(props));
    handler = new MemoryHandler();
    assertNull(handler.getFilter());
    // invalid size
    initProps();
    props.put("java.util.logging.MemoryHandler.size", "-1");
    manager.readConfiguration(EnvironmentHelper.PropertiesToInputStream(props));
    handler = new MemoryHandler();
    initProps();
    props.put("java.util.logging.MemoryHandler.size", "badsize");
    manager.readConfiguration(EnvironmentHelper.PropertiesToInputStream(props));
    handler = new MemoryHandler();
}
Also used : SimpleFormatter(java.util.logging.SimpleFormatter) MemoryHandler(java.util.logging.MemoryHandler)

Example 5 with MemoryHandler

use of java.util.logging.MemoryHandler in project j2objc by google.

the class MemoryHandlerTest method testMemoryHandlerHandlerintLevel.

/*
	 * Class under test for void MemoryHandler(Handler, int, Level)
	 */
public void testMemoryHandlerHandlerintLevel() {
    handler = new MemoryHandler(target, 2, Level.FINEST);
    assertTrue(handler.getFilter() instanceof MockFilter);
    assertTrue(handler.getFormatter() instanceof MockFormatter);
    assertNull(handler.getEncoding());
    assertNotNull(handler.getErrorManager());
    assertEquals(handler.getLevel(), Level.FINE);
    assertEquals(handler.getPushLevel(), Level.FINEST);
    assertNull(target.getFormatter());
    try {
        handler = new MemoryHandler(null, 2, Level.FINEST);
        fail("should throw NullPointerException");
    } catch (NullPointerException e) {
    }
    try {
        handler = new MemoryHandler(target, 2, null);
        fail("should throw NullPointerException");
    } catch (NullPointerException e) {
    }
    try {
        handler = new MemoryHandler(target, 0, Level.FINEST);
        fail("should throw IllegalArgumentException");
    } catch (IllegalArgumentException e) {
    }
    try {
        handler = new MemoryHandler(target, -1, Level.FINEST);
        fail("should throw IllegalArgumentException");
    } catch (IllegalArgumentException e) {
    }
}
Also used : MemoryHandler(java.util.logging.MemoryHandler)

Aggregations

MemoryHandler (java.util.logging.MemoryHandler)8 SimpleFormatter (java.util.logging.SimpleFormatter)2 NoOpJULHandler (org.apache.logging.log4j.perf.util.NoOpJULHandler)2 Setup (org.openjdk.jmh.annotations.Setup)2 File (java.io.File)1 PrintStream (java.io.PrintStream)1 LogRecord (java.util.logging.LogRecord)1 NullOutputStream (org.apache.harmony.logging.tests.java.util.logging.HandlerTest.NullOutputStream)1