diff --git a/quickfixj-core/src/test/java/quickfix/SessionTest.java b/quickfixj-core/src/test/java/quickfix/SessionTest.java index 42832e5e4c..1e00cde3ee 100644 --- a/quickfixj-core/src/test/java/quickfix/SessionTest.java +++ b/quickfixj-core/src/test/java/quickfix/SessionTest.java @@ -53,6 +53,7 @@ import static org.junit.Assert.*; import static org.mockito.Mockito.*; import static quickfix.SessionFactoryTestSupport.createSession; +import quickfix.field.NextExpectedMsgSeqNum; /** * Note: most session tests are in the form of acceptance tests. @@ -898,7 +899,7 @@ public void testLogonIsAnsweredWithLogoutOnException() throws Exception { session.setResponder(responder); session.logon(); session.next(); - setUpHeader(session.getSessionID(), logonRequest, true, 3); + setUpHeader(session.getSessionID(), logonRequest, true, 4); logonRequest.setString(EncryptMethod.FIELD, "99"); logonRequest.toString(); // calculate length and checksum session.next(logonRequest); @@ -909,6 +910,21 @@ public void testLogonIsAnsweredWithLogoutOnException() throws Exception { assertEquals(MsgType.LOGOUT, application.lastToAdminMessage().getHeader().getString(MsgType.FIELD)); assertEquals(5, session.getStore().getNextTargetMsgSeqNum()); assertEquals(5, session.getStore().getNextSenderMsgSeqNum()); + session.setResponder(responder); + session.logon(); + session.next(); + setUpHeader(session.getSessionID(), logonRequest, true, 5); + logonRequest.setString(EncryptMethod.FIELD, "0"); + logonRequest.setString(NextExpectedMsgSeqNum.FIELD, "XXX"); + logonRequest.toString(); // calculate length and checksum + session.next(logonRequest); + // session should not be logged on due to IncorrectTagValue + assertFalse(session.isLoggedOn()); + + assertEquals(5, application.lastToAdminMessage().getHeader().getInt(MsgSeqNum.FIELD)); + assertEquals(MsgType.LOGOUT, application.lastToAdminMessage().getHeader().getString(MsgType.FIELD)); + assertEquals(6, session.getStore().getNextTargetMsgSeqNum()); + assertEquals(6, session.getStore().getNextSenderMsgSeqNum()); } } diff --git a/quickfixj-core/src/test/java/quickfix/mina/SingleThreadedEventHandlingStrategyTest.java b/quickfixj-core/src/test/java/quickfix/mina/SingleThreadedEventHandlingStrategyTest.java index 8ece76a852..7ca7807487 100644 --- a/quickfixj-core/src/test/java/quickfix/mina/SingleThreadedEventHandlingStrategyTest.java +++ b/quickfixj-core/src/test/java/quickfix/mina/SingleThreadedEventHandlingStrategyTest.java @@ -332,13 +332,8 @@ private void assertQFJMessageProcessorThreads(int expected) { } dumpAllThreads = bean.dumpAllThreads(false, false); qfjMPThreads = getMessageProcessorThreads(dumpAllThreads); - for (ThreadInfo threadInfo : dumpAllThreads) { - if (qfjMPThreads > 1) { - if (SingleThreadedEventHandlingStrategy.MESSAGE_PROCESSOR_THREAD_NAME.equals(threadInfo - .getThreadName())) { - printStackTraces(threadInfo); - } - } else { + if (qfjMPThreads != expected) { + for (ThreadInfo threadInfo : dumpAllThreads) { printStackTraces(threadInfo); } } diff --git a/quickfixj-core/src/test/java/quickfix/mina/acceptor/DynamicAcceptorSessionProviderTest.java b/quickfixj-core/src/test/java/quickfix/mina/acceptor/DynamicAcceptorSessionProviderTest.java index 47cd208138..6d44c6ef18 100644 --- a/quickfixj-core/src/test/java/quickfix/mina/acceptor/DynamicAcceptorSessionProviderTest.java +++ b/quickfixj-core/src/test/java/quickfix/mina/acceptor/DynamicAcceptorSessionProviderTest.java @@ -19,7 +19,6 @@ package quickfix.mina.acceptor; -import junit.framework.TestCase; import org.quickfixj.QFJException; import quickfix.Application; import quickfix.ConfigError; @@ -40,11 +39,23 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.TemporaryFolder; +import quickfix.FileStoreFactory; +import quickfix.Message; +import quickfix.fix42.NewOrderSingle; import static quickfix.mina.acceptor.DynamicAcceptorSessionProvider.TemplateMapping; import static quickfix.mina.acceptor.DynamicAcceptorSessionProvider.WILDCARD; -public class DynamicAcceptorSessionProviderTest extends TestCase { +public class DynamicAcceptorSessionProviderTest { private DynamicAcceptorSessionProvider provider; private SessionSettings settings; private List templateMappings; @@ -52,9 +63,11 @@ public class DynamicAcceptorSessionProviderTest extends TestCase { private MessageStoreFactory messageStoreFactory; private LogFactory logFactory; private MessageFactory messageFactory; + @Rule + public TemporaryFolder tempFolder = new TemporaryFolder(); - @Override - protected void setUp() throws Exception { + @Before + public void setUp() throws Exception { settings = new SessionSettings(); templateMappings = new ArrayList<>(); application = new UnitTestApplication(); @@ -79,6 +92,7 @@ protected void setUp() throws Exception { messageStoreFactory, logFactory, messageFactory); } + @Test public void testSessionCreation() throws Exception { try (Session session1 = provider.getSession(new SessionID("FIX.4.2", "SENDER", "SENDERSUB", @@ -124,6 +138,7 @@ private void setUpSettings(SessionID templateID, String key, String value) { settings.setString(templateID, key, value); } + @Test public void testSessionTemplateNotFound() throws Exception { try { provider.getSession(new SessionID("FIX.4.3", "S", "T"), null); @@ -133,10 +148,12 @@ public void testSessionTemplateNotFound() throws Exception { } } + @Test public void testToString() throws Exception { templateMappings.toString(); // be sure there are no NPEs, etc. } - + + @Test public void testSimpleConstructor() throws Exception { provider = new DynamicAcceptorSessionProvider(settings, new SessionID("FIX.4.2", "ANY", "ANY"), application, messageStoreFactory, logFactory, messageFactory); @@ -149,6 +166,7 @@ public void testSimpleConstructor() throws Exception { /** * Verify that if a new session comes in it gets added to the list in session connector */ + @Test public void testDynamicSessionIsAddedToSessionConnector() throws Exception { MySessionConnector connector = new MySessionConnector(settings, null); @@ -168,6 +186,44 @@ public void testDynamicSessionIsAddedToSessionConnector() throws Exception { session2.close(); } + @Test + public void testDynamicSessionIsAddedToSessionConnectorAndFileStoreIsKept() throws Exception { + SessionID id = new SessionID("FIX.4.4", "SENDER", "TARGET"); + SessionID templateId = new SessionID("FIX.4.4", "ANY", "ANY"); + SessionSettings ownSettings = new SessionSettings(); + ownSettings.setString(id, "FileStorePath", tempFolder.getRoot().getAbsolutePath()); + ownSettings.setString(templateId, "ConnectionType", "acceptor"); + ownSettings.setString(templateId, "StartTime", "00:00:00"); + ownSettings.setString(templateId, "EndTime", "00:00:00"); + + templateMappings.clear(); // only use own template + templateMappings.add(new TemplateMapping(new SessionID("FIX.4.4", WILDCARD, WILDCARD, + WILDCARD, WILDCARD, WILDCARD, WILDCARD, WILDCARD), templateId)); + + MessageStoreFactory ownMessageStoreFactory = new FileStoreFactory(ownSettings); + provider = new DynamicAcceptorSessionProvider(ownSettings, templateMappings, application, + ownMessageStoreFactory, logFactory, messageFactory); + + MySessionConnector connector = new MySessionConnector(ownSettings, null); + Session session2 = provider.getSession(id, connector); + assertEquals(1, connector.sessions.size()); + + assertEquals(1, session2.getStore().getNextSenderMsgSeqNum() ); + Message message = new NewOrderSingle(); + session2.send(message); + assertEquals(2, session2.getStore().getNextSenderMsgSeqNum() ); + session2.close(); + + session2 = provider.getSession(id, connector); + assertEquals(1, connector.sessions.size()); + + assertEquals(2, session2.getStore().getNextSenderMsgSeqNum() ); + message = new NewOrderSingle(); + session2.send(message); + assertEquals(3, session2.getStore().getNextSenderMsgSeqNum() ); + session2.close(); + } + private static class MySessionConnector extends SessionConnector { private final HashMap sessions = new HashMap<>();