Skip to content

Commit ce22941

Browse files
authored
- amended some tests (#191)
- minor corrections
1 parent ee4b8ea commit ce22941

File tree

3 files changed

+80
-13
lines changed

3 files changed

+80
-13
lines changed

quickfixj-core/src/test/java/quickfix/SessionTest.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
import static org.junit.Assert.*;
5454
import static org.mockito.Mockito.*;
5555
import static quickfix.SessionFactoryTestSupport.createSession;
56+
import quickfix.field.NextExpectedMsgSeqNum;
5657

5758
/**
5859
* Note: most session tests are in the form of acceptance tests.
@@ -898,7 +899,7 @@ public void testLogonIsAnsweredWithLogoutOnException() throws Exception {
898899
session.setResponder(responder);
899900
session.logon();
900901
session.next();
901-
setUpHeader(session.getSessionID(), logonRequest, true, 3);
902+
setUpHeader(session.getSessionID(), logonRequest, true, 4);
902903
logonRequest.setString(EncryptMethod.FIELD, "99");
903904
logonRequest.toString(); // calculate length and checksum
904905
session.next(logonRequest);
@@ -909,6 +910,21 @@ public void testLogonIsAnsweredWithLogoutOnException() throws Exception {
909910
assertEquals(MsgType.LOGOUT, application.lastToAdminMessage().getHeader().getString(MsgType.FIELD));
910911
assertEquals(5, session.getStore().getNextTargetMsgSeqNum());
911912
assertEquals(5, session.getStore().getNextSenderMsgSeqNum());
913+
session.setResponder(responder);
914+
session.logon();
915+
session.next();
916+
setUpHeader(session.getSessionID(), logonRequest, true, 5);
917+
logonRequest.setString(EncryptMethod.FIELD, "0");
918+
logonRequest.setString(NextExpectedMsgSeqNum.FIELD, "XXX");
919+
logonRequest.toString(); // calculate length and checksum
920+
session.next(logonRequest);
921+
// session should not be logged on due to IncorrectTagValue
922+
assertFalse(session.isLoggedOn());
923+
924+
assertEquals(5, application.lastToAdminMessage().getHeader().getInt(MsgSeqNum.FIELD));
925+
assertEquals(MsgType.LOGOUT, application.lastToAdminMessage().getHeader().getString(MsgType.FIELD));
926+
assertEquals(6, session.getStore().getNextTargetMsgSeqNum());
927+
assertEquals(6, session.getStore().getNextSenderMsgSeqNum());
912928
}
913929
}
914930

quickfixj-core/src/test/java/quickfix/mina/SingleThreadedEventHandlingStrategyTest.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -332,13 +332,8 @@ private void assertQFJMessageProcessorThreads(int expected) {
332332
}
333333
dumpAllThreads = bean.dumpAllThreads(false, false);
334334
qfjMPThreads = getMessageProcessorThreads(dumpAllThreads);
335-
for (ThreadInfo threadInfo : dumpAllThreads) {
336-
if (qfjMPThreads > 1) {
337-
if (SingleThreadedEventHandlingStrategy.MESSAGE_PROCESSOR_THREAD_NAME.equals(threadInfo
338-
.getThreadName())) {
339-
printStackTraces(threadInfo);
340-
}
341-
} else {
335+
if (qfjMPThreads != expected) {
336+
for (ThreadInfo threadInfo : dumpAllThreads) {
342337
printStackTraces(threadInfo);
343338
}
344339
}

quickfixj-core/src/test/java/quickfix/mina/acceptor/DynamicAcceptorSessionProviderTest.java

Lines changed: 61 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919

2020
package quickfix.mina.acceptor;
2121

22-
import junit.framework.TestCase;
2322
import org.quickfixj.QFJException;
2423
import quickfix.Application;
2524
import quickfix.ConfigError;
@@ -40,21 +39,35 @@
4039
import java.util.ArrayList;
4140
import java.util.HashMap;
4241
import java.util.List;
42+
import static org.junit.Assert.assertEquals;
43+
import static org.junit.Assert.assertFalse;
44+
import static org.junit.Assert.assertNotNull;
45+
import static org.junit.Assert.assertTrue;
46+
import static org.junit.Assert.fail;
47+
import org.junit.Before;
48+
import org.junit.Rule;
49+
import org.junit.Test;
50+
import org.junit.rules.TemporaryFolder;
51+
import quickfix.FileStoreFactory;
52+
import quickfix.Message;
53+
import quickfix.fix42.NewOrderSingle;
4354

4455
import static quickfix.mina.acceptor.DynamicAcceptorSessionProvider.TemplateMapping;
4556
import static quickfix.mina.acceptor.DynamicAcceptorSessionProvider.WILDCARD;
4657

47-
public class DynamicAcceptorSessionProviderTest extends TestCase {
58+
public class DynamicAcceptorSessionProviderTest {
4859
private DynamicAcceptorSessionProvider provider;
4960
private SessionSettings settings;
5061
private List<TemplateMapping> templateMappings;
5162
private Application application;
5263
private MessageStoreFactory messageStoreFactory;
5364
private LogFactory logFactory;
5465
private MessageFactory messageFactory;
66+
@Rule
67+
public TemporaryFolder tempFolder = new TemporaryFolder();
5568

56-
@Override
57-
protected void setUp() throws Exception {
69+
@Before
70+
public void setUp() throws Exception {
5871
settings = new SessionSettings();
5972
templateMappings = new ArrayList<>();
6073
application = new UnitTestApplication();
@@ -79,6 +92,7 @@ protected void setUp() throws Exception {
7992
messageStoreFactory, logFactory, messageFactory);
8093
}
8194

95+
@Test
8296
public void testSessionCreation() throws Exception {
8397

8498
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) {
124138
settings.setString(templateID, key, value);
125139
}
126140

141+
@Test
127142
public void testSessionTemplateNotFound() throws Exception {
128143
try {
129144
provider.getSession(new SessionID("FIX.4.3", "S", "T"), null);
@@ -133,10 +148,12 @@ public void testSessionTemplateNotFound() throws Exception {
133148
}
134149
}
135150

151+
@Test
136152
public void testToString() throws Exception {
137153
templateMappings.toString(); // be sure there are no NPEs, etc.
138154
}
139-
155+
156+
@Test
140157
public void testSimpleConstructor() throws Exception {
141158
provider = new DynamicAcceptorSessionProvider(settings, new SessionID("FIX.4.2", "ANY",
142159
"ANY"), application, messageStoreFactory, logFactory, messageFactory);
@@ -149,6 +166,7 @@ public void testSimpleConstructor() throws Exception {
149166
/**
150167
* Verify that if a new session comes in it gets added to the list in session connector
151168
*/
169+
@Test
152170
public void testDynamicSessionIsAddedToSessionConnector() throws Exception {
153171
MySessionConnector connector = new MySessionConnector(settings, null);
154172

@@ -168,6 +186,44 @@ public void testDynamicSessionIsAddedToSessionConnector() throws Exception {
168186
session2.close();
169187
}
170188

189+
@Test
190+
public void testDynamicSessionIsAddedToSessionConnectorAndFileStoreIsKept() throws Exception {
191+
SessionID id = new SessionID("FIX.4.4", "SENDER", "TARGET");
192+
SessionID templateId = new SessionID("FIX.4.4", "ANY", "ANY");
193+
SessionSettings ownSettings = new SessionSettings();
194+
ownSettings.setString(id, "FileStorePath", tempFolder.getRoot().getAbsolutePath());
195+
ownSettings.setString(templateId, "ConnectionType", "acceptor");
196+
ownSettings.setString(templateId, "StartTime", "00:00:00");
197+
ownSettings.setString(templateId, "EndTime", "00:00:00");
198+
199+
templateMappings.clear(); // only use own template
200+
templateMappings.add(new TemplateMapping(new SessionID("FIX.4.4", WILDCARD, WILDCARD,
201+
WILDCARD, WILDCARD, WILDCARD, WILDCARD, WILDCARD), templateId));
202+
203+
MessageStoreFactory ownMessageStoreFactory = new FileStoreFactory(ownSettings);
204+
provider = new DynamicAcceptorSessionProvider(ownSettings, templateMappings, application,
205+
ownMessageStoreFactory, logFactory, messageFactory);
206+
207+
MySessionConnector connector = new MySessionConnector(ownSettings, null);
208+
Session session2 = provider.getSession(id, connector);
209+
assertEquals(1, connector.sessions.size());
210+
211+
assertEquals(1, session2.getStore().getNextSenderMsgSeqNum() );
212+
Message message = new NewOrderSingle();
213+
session2.send(message);
214+
assertEquals(2, session2.getStore().getNextSenderMsgSeqNum() );
215+
session2.close();
216+
217+
session2 = provider.getSession(id, connector);
218+
assertEquals(1, connector.sessions.size());
219+
220+
assertEquals(2, session2.getStore().getNextSenderMsgSeqNum() );
221+
message = new NewOrderSingle();
222+
session2.send(message);
223+
assertEquals(3, session2.getStore().getNextSenderMsgSeqNum() );
224+
session2.close();
225+
}
226+
171227
private static class MySessionConnector extends SessionConnector {
172228
private final HashMap<SessionID, Session> sessions = new HashMap<>();
173229

0 commit comments

Comments
 (0)