DynamicAcceptorSessionProvider implements AcceptorSessionProvider { public synchronized Session getSession(SessionID sessionID, SessionConnector sessionConnector) { Session s = Session.lookupSession(sessionID); if (s == null) { try { SessionID templateID = lookupTemplateID(sessionID); if (templateID == null) { throw new ConfigError("Unable to find a session template for " + sessionID); } SessionSettings dynamicSettings = new SessionSettings(); copySettings(dynamicSettings, settings.getDefaultProperties()); copySettings(dynamicSettings, settings.getSessionProperties(templateID)); dynamicSettings.setString(BEGINSTRING, sessionID.getBeginString()); dynamicSettings.setString(SENDERCOMPID, sessionID.getSenderCompID()); optionallySetValue(dynamicSettings, SENDERSUBID, sessionID.getSenderSubID()); optionallySetValue(dynamicSettings, SENDERLOCID, sessionID.getSenderLocationID()); dynamicSettings.setString(TARGETCOMPID, sessionID.getTargetCompID()); optionallySetValue(dynamicSettings, TARGETSUBID, sessionID.getTargetSubID()); optionallySetValue(dynamicSettings, TARGETLOCID, sessionID.getTargetLocationID()); s = sessionFactory.create(sessionID, dynamicSettings); if (sessionConnector != null) { sessionConnector.addDynamicSession(s); } } catch (ConfigError e) { throw new QFJException(e); } } return s; } DynamicAcceptorSessionProvider(final SessionSettings settings,
            final SessionID templateID, quickfix.Application application,
            MessageStoreFactory messageStoreFactory, LogFactory logFactory,
            MessageFactory messageFactory);  DynamicAcceptorSessionProvider(final SessionSettings settings,
            List<TemplateMapping> templateMappings, quickfix.Application application,
            MessageStoreFactory messageStoreFactory, LogFactory logFactory,
            MessageFactory messageFactory); synchronized Session getSession(SessionID sessionID, SessionConnector sessionConnector); static final String WILDCARD; }
@Test public void testSessionCreation() throws Exception { try (Session session1 = provider.getSession(new SessionID("FIX.4.2", "SENDER", "SENDERSUB", "SENDERLOC", "TARGET", "TARGETSUB", "TARGETLOC", null), null)) { SessionID sessionID1 = session1.getSessionID(); assertEquals("wrong FIX version", "FIX.4.2", sessionID1.getBeginString()); assertEquals("wrong sender", "SENDER", sessionID1.getSenderCompID()); assertEquals("wrong senderSub", "SENDERSUB", sessionID1.getSenderSubID()); assertEquals("wrong senderLoc", "SENDERLOC", sessionID1.getSenderLocationID()); assertEquals("wrong target", "TARGET", sessionID1.getTargetCompID()); assertEquals("wrong targetSub", "TARGETSUB", sessionID1.getTargetSubID()); assertEquals("wrong targetLoc", "TARGETLOC", sessionID1.getTargetLocationID()); assertFalse("wrong setting", session1.getResetOnLogout()); assertFalse("wrong setting", session1.getRefreshOnLogon()); assertFalse("wrong setting", session1.getCheckCompID()); } try (Session session2 = provider.getSession(new SessionID("FIX.4.4", "S1", "T"), null)) { SessionID sessionID2 = session2.getSessionID(); assertEquals("wrong FIX version", "FIX.4.4", sessionID2.getBeginString()); assertEquals("wrong sender", "S1", sessionID2.getSenderCompID()); assertEquals("wrong target", "T", sessionID2.getTargetCompID()); assertTrue("wrong setting", session2.getResetOnLogout()); assertFalse("wrong setting", session2.getRefreshOnLogon()); assertTrue("wrong setting", session2.getCheckCompID()); } try (Session session3 = provider.getSession(new SessionID("FIX.4.4", "X", "Y"), null)) { SessionID sessionID3 = session3.getSessionID(); assertEquals("wrong FIX version", "FIX.4.4", sessionID3.getBeginString()); assertEquals("wrong sender", "X", sessionID3.getSenderCompID()); assertEquals("wrong target", "Y", sessionID3.getTargetCompID()); assertFalse("wrong setting", session3.getResetOnLogout()); assertTrue("wrong setting", session3.getRefreshOnLogon()); assertTrue("wrong setting", session3.getCheckCompID()); } }
@Test public void testSessionTemplateNotFound() throws Exception { try { provider.getSession(new SessionID("FIX.4.3", "S", "T"), null); fail("No exception thrown"); } catch (QFJException e) { } }
@Test public void testSimpleConstructor() throws Exception { provider = new DynamicAcceptorSessionProvider(settings, new SessionID("FIX.4.2", "ANY", "ANY"), application, messageStoreFactory, logFactory, messageFactory); try (Session session = provider.getSession(new SessionID("FIX.4.2", "S", "T"), null)) { assertNotNull(session); } }
@Test public void testDynamicSessionIsAddedToSessionConnector() throws Exception { MySessionConnector connector = new MySessionConnector(settings, null); SessionID id1 = new SessionID("FIX.4.2", "me", "SENDERSUB", "SENDERLOC", "you", "TARGETSUB", "TARGETLOC", null); Session session = provider.getSession(id1, connector); assertEquals(1, connector.sessions.size()); session = provider.getSession(id1, connector); assertEquals(1, connector.sessions.size()); session.close(); SessionID id2 = new SessionID("FIX.4.2", "SENDER2", "SENDERSUB", "SENDERLOC", "TARGET2", "TARGETSUB", "TARGETLOC", null); Session session2 = provider.getSession(id2, connector); assertEquals(2, connector.sessions.size()); 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(); 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(); }