|
27 | 27 | import quickfix.field.Text; |
28 | 28 | import quickfix.field.converter.UtcTimeOnlyConverter; |
29 | 29 | import quickfix.field.converter.UtcTimestampConverter; |
| 30 | +import quickfix.field.ResetSeqNumFlag; |
30 | 31 | import quickfix.fix44.Heartbeat; |
31 | 32 | import quickfix.fix44.Logon; |
32 | 33 | import quickfix.fix44.Logout; |
@@ -2761,6 +2762,83 @@ public void initiatorSession_ShouldWaitForLogoutTimeoutBeforeDisconnecting_WhenS |
2761 | 2762 | assertFor244(application, responder, 1, 0, 1, true); |
2762 | 2763 | } |
2763 | 2764 |
|
| 2765 | + /** |
| 2766 | + * https://github.com/quickfix-j/quickfixj/issues/474 |
| 2767 | + * */ |
| 2768 | + @Test |
| 2769 | + public void msgseqnum_getting_reset_in_rejected_logon_scenario_fix() throws Exception { |
| 2770 | + |
| 2771 | + final UnitTestApplication application = new UnitTestApplication(){ |
| 2772 | + int logonCount = 0; |
| 2773 | + @Override |
| 2774 | + public void fromAdmin(Message message, SessionID sessionId) throws FieldNotFound, |
| 2775 | + IncorrectDataFormat, IncorrectTagValue, RejectLogon { |
| 2776 | + super.fromAdmin(message, sessionId); |
| 2777 | + if (message.getHeader().getString(MsgType.FIELD).equals(Logon.MSGTYPE)) { |
| 2778 | + logonCount += 1; |
| 2779 | + } |
| 2780 | + if (logonCount == 2) { |
| 2781 | + logonCount += 1; |
| 2782 | + throw new RejectLogon("RejectLogon"); |
| 2783 | + } |
| 2784 | + } |
| 2785 | + }; |
| 2786 | + |
| 2787 | + final SessionID sessionID = new SessionID( |
| 2788 | + FixVersions.BEGINSTRING_FIX44, "SENDER", "TARGET"); |
| 2789 | + |
| 2790 | + Session initSession = createSession(sessionID, application, true, |
| 2791 | + true, true); |
| 2792 | + final SessionState state = getSessionState(initSession); |
| 2793 | + |
| 2794 | + final UnitTestResponder responder = new UnitTestResponder(); |
| 2795 | + |
| 2796 | + try{ |
| 2797 | + initSession.setResponder(responder); |
| 2798 | + initSession.next(); |
| 2799 | + logonTo(initSession); |
| 2800 | + |
| 2801 | + Message logon = application.toAdminMessages.get(0); |
| 2802 | + assertEquals(MsgType.LOGON, logon.getHeader().getString(MsgType.FIELD)); |
| 2803 | + |
| 2804 | + |
| 2805 | + assertEquals(2, state.getNextSenderMsgSeqNum()); |
| 2806 | + assertTrue(initSession.isLoggedOn()); |
| 2807 | + |
| 2808 | + initSession.generateHeartbeat(); |
| 2809 | + initSession.next(createHeartbeatMessage(2)); |
| 2810 | + assertEquals(3, state.getNextSenderMsgSeqNum()); |
| 2811 | + |
| 2812 | + initSession.generateHeartbeat(); |
| 2813 | + initSession.next(createHeartbeatMessage(3)); |
| 2814 | + assertEquals(4, state.getNextSenderMsgSeqNum()); |
| 2815 | + |
| 2816 | + initSession.logout(); |
| 2817 | + initSession.next(); |
| 2818 | + |
| 2819 | + assertEquals(5, state.getNextSenderMsgSeqNum()); |
| 2820 | + assertEquals(4, state.getNextTargetMsgSeqNum()); |
| 2821 | + |
| 2822 | + |
| 2823 | + } catch (Exception e) { |
| 2824 | + throw new Exception(e);} |
| 2825 | + |
| 2826 | + try { |
| 2827 | + initSession.logon(); |
| 2828 | + |
| 2829 | + // logon message which will get rejected |
| 2830 | + initSession.next(); |
| 2831 | + logonTo(initSession,1,true); |
| 2832 | + |
| 2833 | + } catch (Exception e){ |
| 2834 | + throw e; |
| 2835 | + } |
| 2836 | + |
| 2837 | + assertEquals(6, state.getNextSenderMsgSeqNum()); |
| 2838 | + assertEquals(4, state.getNextTargetMsgSeqNum()); |
| 2839 | + |
| 2840 | + } |
| 2841 | + |
2764 | 2842 | /** |
2765 | 2843 | * https://github.com/quickfix-j/quickfixj/issues/244 |
2766 | 2844 | * */ |
@@ -2945,6 +3023,18 @@ private void logonTo(Session session, int sequence) throws FieldNotFound, |
2945 | 3023 | session.next(receivedLogon); |
2946 | 3024 | } |
2947 | 3025 |
|
| 3026 | + private void logonTo(Session session, int sequence, boolean resetSeqNumFlag) throws FieldNotFound, |
| 3027 | + RejectLogon, IncorrectDataFormat, IncorrectTagValue, |
| 3028 | + UnsupportedMessageType, IOException, InvalidMessage { |
| 3029 | + final Logon receivedLogon = new Logon(); |
| 3030 | + setUpHeader(session.getSessionID(), receivedLogon, true, sequence); |
| 3031 | + receivedLogon.setInt(HeartBtInt.FIELD, 30); |
| 3032 | + receivedLogon.setInt(EncryptMethod.FIELD, 0); |
| 3033 | + receivedLogon.setBoolean(ResetSeqNumFlag.FIELD, resetSeqNumFlag); |
| 3034 | + receivedLogon.toString(); // calculate length and checksum |
| 3035 | + session.next(receivedLogon); |
| 3036 | + } |
| 3037 | + |
2948 | 3038 | private void logoutFrom(Session session, int sequence) |
2949 | 3039 | throws FieldNotFound, RejectLogon, IncorrectDataFormat, |
2950 | 3040 | IncorrectTagValue, UnsupportedMessageType, IOException, |
|
0 commit comments