@Test
public void testSequenceRollbackOnCallbackException() throws Exception {

    // Create application that rejects all logons
    final Application application = new UnitTestApplication() {
        @Override
        public void fromApp(Message message, SessionID sessionId) throws FieldNotFound,
                IncorrectDataFormat, IncorrectTagValue, UnsupportedMessageType {
            super.fromApp(message, sessionId);
            throw new RuntimeException("TEST");
        }
        @Override
        public void fromAdmin(Message message, SessionID sessionId) throws FieldNotFound,
                IncorrectDataFormat, IncorrectTagValue, RejectLogon {
            super.fromAdmin(message, sessionId);
            if (message.getHeader().getString(MsgType.FIELD).equals(MsgType.LOGON)) {
                return;
            }
            throw new RuntimeException("TEST");
        }
    };
    final Session session = setUpSession(application, false, new UnitTestResponder());
    final SessionState state = getSessionState(session);
    logonTo(session);
    assertEquals(2, state.getNextSenderMsgSeqNum());
    assertEquals(2, state.getNextTargetMsgSeqNum());
    processMessage(session, createAppMessage(2));
    assertEquals(2, state.getNextSenderMsgSeqNum());
    assertEquals(2, state.getNextTargetMsgSeqNum());
    // To avoid resendRequest
    state.setNextTargetMsgSeqNum(3);
    processMessage(session, createAdminMessage(3));
    assertEquals(2, state.getNextSenderMsgSeqNum());
    assertEquals(3, state.getNextTargetMsgSeqNum());
}