}
@Test
public void testAppenderReconfigurationTakesPlaceImediatelly() throws Exception {
final String sql = "select count(*) from customers";
P6TestLogger oldAppenderRef = null;
// precondition - logging via P6TestLogger works OK
{
assertEquals(P6TestLogger.class.getName(), P6SpyOptions.getActiveInstance().getAppender());
super.clearLogEntries();
statement.executeQuery(sql);
oldAppenderRef = (P6TestLogger) P6SpyOptions.getActiveInstance().getAppenderInstance();
assertNotNull(oldAppenderRef.getLastEntry());
assertTrue(oldAppenderRef.getLastEntry().contains(sql));
}
super.clearLogEntries();
// let's log via StdoutLogger
P6SpyOptions.getActiveInstance().setAppender(StdoutLogger.class.getName());
assertEquals(StdoutLogger.class.getName(), P6SpyOptions.getActiveInstance().getAppender());
statement.executeQuery(sql);
// old appender should not be in use any more!
assertNull(oldAppenderRef.getLastEntry());
// cleanup stuff - go for the default logger
{
P6SpyOptions.getActiveInstance().setAppender(P6TestLogger.class.getName());
}