Ejemplo n.º 1
0
  public void testOneSessionLoggedOnOneSessionNotLoggedOne() throws Exception {
    SessionID sessionID1 = new SessionID(FixVersions.BEGINSTRING_FIX40, "TW", "ISLD");
    SessionSettings settings = setUpSessionSettings(sessionID1);
    DefaultSessionFactory sessionFactory =
        new DefaultSessionFactory(
            new UnitTestApplication(),
            new MemoryStoreFactory(),
            new ScreenLogFactory(true, true, true));

    SessionConnector connector = new SessionConnectorUnderTest(settings, sessionFactory);

    Session session1 = connector.createSession(sessionID1);
    assertNotNull(session1);

    // test add/remove
    SessionConnectorListener connectorListener = new SessionConnectorListener();
    connector.addPropertyChangeListener(connectorListener);
    connector.removePropertyChangeListener(connectorListener);

    Map<SessionID, Session> sessions = new HashMap<>();
    sessions.put(session1.getSessionID(), session1);
    connector.setSessions(sessions);

    assertEquals(0, propertyChangeEvents.size());

    assertEquals(1, connector.getManagedSessions().size());
    assertEquals(session1, connector.getManagedSessions().get(0));

    assertFalse(connector.isLoggedOn());

    Field stateField = session1.getClass().getDeclaredField("state");
    stateField.setAccessible(true);
    SessionState state = (SessionState) stateField.get(session1);

    state.setLogonSent(true);
    state.setLogonReceived(true);
    assertTrue(connector.isLoggedOn());

    SessionID sessionID2 = new SessionID(FixVersions.BEGINSTRING_FIX40, "TW", "ISLD1");
    settings.setString(
        sessionID2,
        SessionFactory.SETTING_CONNECTION_TYPE,
        SessionFactory.ACCEPTOR_CONNECTION_TYPE);
    Session session2 = connector.createSession(sessionID2);
    assertNotNull(session2);
    sessions.put(session2.getSessionID(), session2);
    assertFalse(connector.isLoggedOn());
  }
Ejemplo n.º 2
0
  public void testConnector() throws Exception {
    SessionID sessionID = new SessionID(FixVersions.BEGINSTRING_FIX40, "TW", "ISLD");
    SessionSettings settings = setUpSessionSettings(sessionID);
    DefaultSessionFactory sessionFactory =
        new DefaultSessionFactory(
            new UnitTestApplication(),
            new MemoryStoreFactory(),
            new ScreenLogFactory(true, true, true));

    SessionConnector connector = new SessionConnectorUnderTest(settings, sessionFactory);

    connector.addPropertyChangeListener(new SessionConnectorListener());

    Session session = connector.createSession(sessionID);
    assertNotNull(session);

    Map<SessionID, Session> sessions = Collections.singletonMap(session.getSessionID(), session);
    connector.setSessions(sessions);

    assertEquals(1, propertyChangeEvents.size());

    assertEquals(1, connector.getManagedSessions().size());
    assertEquals(session, connector.getManagedSessions().get(0));

    assertFalse(connector.isLoggedOn());

    Field stateField = session.getClass().getDeclaredField("state");
    stateField.setAccessible(true);
    SessionState state = (SessionState) stateField.get(session);

    state.setLogonSent(true);
    state.setLogonReceived(true);
    assertTrue(connector.isLoggedOn());

    assertTrue(session.isEnabled());
    connector.logoutAllSessions(true);
    assertFalse(session.isEnabled());

    assertEquals(9999, connector.getIntSetting(Acceptor.SETTING_SOCKET_ACCEPT_PORT));

    assertNotNull(connector.getScheduledExecutorService());
    assertEquals(settings, connector.getSettings());
  }