/** Sets up the initiator with a JdbcLogger that errors out on connection
- to test bug http://www.quickfixj.org/jira/browse/QFJ-89
- JdbcLogger will error out b/c we don't create the necessary tables
- @throws Exception
*/
public void testBadLogger() throws Exception {
SessionSettings settings = new SessionSettings();
JdbcTestSupport.setHypersonicSettings(settings);
JdbcLogFactory logFactory = new MyJdbcLogFactory(settings);
try
{
new Session(new UnitTestApplication(), new MemoryStoreFactory(), new SessionID("begin", "sender", "target"), null, null,
logFactory, new DefaultMessageFactory(), 30);
}
catch(NullPointerException ex)
{
fail("misconfigured logger shouldn't generate an NPE");
}
}
private class MyJdbcLogFactory extends JdbcLogFactory {
public MyJdbcLogFactory(SessionSettings settings)
{
super(settings);
}
public Log create(SessionID sessionID) {
try
{
return new MyJdbcLogger(getSettings(), sessionID);
}
catch (Exception ignored)
{
return null;
}
}
public Log create() {
try {
return new MyJdbcLogger(getSettings(), null);
} catch (Exception ignored) { return null; }
}
}
private static class MyJdbcLogger extends JdbcLog {
private static int nOnEvents = 0;
public MyJdbcLogger(SessionSettings settings, SessionID sessionID) throws ConfigError, SQLException, FieldConvertError, ClassNotFoundException
{
super(settings, sessionID);
}
public void onEvent(String value) {
if(nOnEvents == 0)
{
nOnEvents++;
super.onEvent(value);
}
else
{
// otherwise, no-op - we are misconfigured, after all, failing again will cause a recursive log attempt and we'll have a stack overflow
}
}
}
Incidentally, if i just use the regular JdbcLogger we end up getting an out-of-memory exception, since we'll keep trying to log a failure every time we get an NPE, and since it'll be recursive at some point we run out of memory
|