Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion quickfixj-core/src/test/java/quickfix/SessionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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);
Expand All @@ -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());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

package quickfix.mina.acceptor;

import junit.framework.TestCase;
import org.quickfixj.QFJException;
import quickfix.Application;
import quickfix.ConfigError;
Expand All @@ -40,21 +39,35 @@
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<TemplateMapping> templateMappings;
private Application application;
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();
Expand All @@ -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",
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);

Expand All @@ -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<SessionID, Session> sessions = new HashMap<>();

Expand Down