* Meant to cover the full functionality of our {@link PerformanceLogger}.
*/
@Test
public void test() throws InterruptedException
{
final PerformanceLogger plog = new PerformanceLogger();
Thread.sleep(1);
plog.logElapsed();
assertThat(logString(), containsString(TestPerformanceLogger.class.getSimpleName()));
assertThat(logString(), containsString("test"));
new InnerClass(plog);
plog.logElapsed("asdf");
assertThat(logString(), containsString("asdf"));
assertThat(logString(), containsString(InnerClass.class.getSimpleName()));
new Object()
{
{
plog.logElapsedAndRestart("obj");
}
void strangeConstructIndeed()
{
plog.logElapsed("strange");
}
}.strangeConstructIndeed();
assertThat(logString(), containsString("obj"));
assertThat(logString(), containsString("strangeConstructIndeed"));
new Runnable()
{
@Override
public void run()
{
plog.logElapsed("running away");
}
}.run();
assertThat(logString(), containsString("running"));
PerformanceLogger plog2 = new PerformanceLogger(1000);
plog2.logElapsed("should-never-be-logged");
assertThat(logString(), not(containsString("should-never-be-logged")));
Thread.sleep(1500);
plog2.logElapsed("should-be-logged");
assertThat(logString(), containsString("should-be-logged"));
Logger logbackLogger = (Logger) LoggerFactory.getLogger(PerformanceLogger.class);
logbackLogger.setLevel(Level.ERROR);
plog.logElapsedAndRestart("do-not-log-me");