Methods Summary |
---|
public void | closeTest()
Logger root = Logger.getRootLogger();
Layout layout = new SimpleLayout();
VectorAppender vectorAppender = new VectorAppender();
AsyncAppender asyncAppender = new AsyncAppender();
asyncAppender.setName("async-CloseTest");
asyncAppender.addAppender(vectorAppender);
root.addAppender(asyncAppender);
root.debug("m1");
asyncAppender.close();
root.debug("m2");
Vector v = vectorAppender.getVector();
assertEquals(v.size(), 1);
|
public void | setUp()
|
public void | tearDown()
LogManager.shutdown();
|
public void | test2()
Logger root = Logger.getRootLogger();
Layout layout = new SimpleLayout();
VectorAppender vectorAppender = new VectorAppender();
AsyncAppender asyncAppender = new AsyncAppender();
asyncAppender.setName("async-test2");
asyncAppender.addAppender(vectorAppender);
root.addAppender(asyncAppender);
root.debug("m1");
asyncAppender.close();
root.debug("m2");
Vector v = vectorAppender.getVector();
assertEquals(v.size(), 1);
assertTrue(vectorAppender.isClosed());
|
public void | test3()
int LEN = 200;
Logger root = Logger.getRootLogger();
Layout layout = new SimpleLayout();
VectorAppender vectorAppender = new VectorAppender();
AsyncAppender asyncAppender = new AsyncAppender();
asyncAppender.setName("async-test3");
asyncAppender.addAppender(vectorAppender);
root.addAppender(asyncAppender);
for(int i = 0; i < LEN; i++) {
root.debug("message"+i);
}
System.out.println("Done loop.");
System.out.flush();
asyncAppender.close();
root.debug("m2");
Vector v = vectorAppender.getVector();
assertEquals(v.size(), LEN);
assertTrue(vectorAppender.isClosed());
|
public void | testBadAppender()Tests that a bad appender will switch async back to sync.
See bug 23021
Appender nullPointerAppender = new NullPointerAppender();
AsyncAppender asyncAppender = new AsyncAppender();
asyncAppender.addAppender(nullPointerAppender);
asyncAppender.setBufferSize(5);
asyncAppender.activateOptions();
Logger root = Logger.getRootLogger();
root.addAppender(nullPointerAppender);
try {
root.info("Message");
Thread.sleep(10);
root.info("Message");
fail("Should have thrown exception");
} catch(NullPointerException ex) {
}
|
public void | testLocationInfoFalse()Tests location processing when buffer is full and locationInfo=false.
See bug 41186.
BlockableVectorAppender blockableAppender = new BlockableVectorAppender();
AsyncAppender async = new AsyncAppender();
async.addAppender(blockableAppender);
async.setBufferSize(5);
async.setLocationInfo(false);
async.setBlocking(false);
async.activateOptions();
Logger rootLogger = Logger.getRootLogger();
rootLogger.addAppender(async);
Greeter greeter = new Greeter(rootLogger, 100);
synchronized(blockableAppender.getMonitor()) {
greeter.run();
rootLogger.error("That's all folks.");
}
async.close();
Vector events = blockableAppender.getVector();
LoggingEvent initialEvent = (LoggingEvent) events.get(0);
LoggingEvent discardEvent = (LoggingEvent) events.get(events.size() - 1);
PatternLayout layout = new PatternLayout();
layout.setConversionPattern("%C:%L %m%n");
layout.activateOptions();
String initialStr = layout.format(initialEvent);
assertEquals("?:? ", initialStr.substring(0, 4));
String discardStr = layout.format(discardEvent);
assertEquals("?:? ", discardStr.substring(0, 4));
|
public void | testLocationInfoTrue()Tests location processing when buffer is full and locationInfo=true.
See bug 41186.
BlockableVectorAppender blockableAppender = new BlockableVectorAppender();
AsyncAppender async = new AsyncAppender();
async.addAppender(blockableAppender);
async.setBufferSize(5);
async.setLocationInfo(true);
async.setBlocking(false);
async.activateOptions();
Logger rootLogger = Logger.getRootLogger();
rootLogger.addAppender(async);
Greeter greeter = new Greeter(rootLogger, 100);
synchronized(blockableAppender.getMonitor()) {
greeter.run();
rootLogger.error("That's all folks.");
}
async.close();
Vector events = blockableAppender.getVector();
LoggingEvent initialEvent = (LoggingEvent) events.get(0);
LoggingEvent discardEvent = (LoggingEvent) events.get(events.size() - 1);
PatternLayout layout = new PatternLayout();
layout.setConversionPattern("%C:%L %m%n");
layout.activateOptions();
String initialStr = layout.format(initialEvent);
assertEquals(AsyncAppenderTestCase.class.getName(),
initialStr.substring(0, AsyncAppenderTestCase.class.getName().length()));
String discardStr = layout.format(discardEvent);
assertEquals("?:? ", discardStr.substring(0, 4));
|