@Test public void shouldConnectAfterStartTimePoint() { initiateConnection(); replyCompletes(); sessionScheduler.doWork(); verify(reply).resultIfPresent(); reset(library, reply); }
public int doWork() { switch (state) { case DISCONNECTED: { if (duringDay) { reply = library.initiate(sessionConfiguration); state = State.CONNECTING; return 1; } return 0; } case CONNECTING: { switch (reply.state()) { case COMPLETED: { session = reply.resultIfPresent(); state = State.CONNECTED; scheduleEnd(); return 1; } case ERRORED: { errorHandler.onError(reply.error()); reply = null; state = State.DISCONNECTED; return 1; } case TIMED_OUT: { errorHandler.onError(new TimeoutException("Timeout connected to Session")); reply = null; state = State.DISCONNECTED; return 1; } } return 0; } case CONNECTED: { if (!duringDay) { final long position = session.logoutAndDisconnect(); if (position > 0) { state = State.DISCONNECTING; } return 1; } else if (!session.isConnected()) { session = null; state = State.DISCONNECTED; return 1; } return 0; } case DISCONNECTING: { if (session.state() == SessionState.DISCONNECTED) { session = null; state = State.DISCONNECTED; return 1; } return 0; } } return 0; }
SessionScheduler { public int doWork() { switch (state) { case DISCONNECTED: { if (duringDay) { reply = library.initiate(sessionConfiguration); state = State.CONNECTING; return 1; } return 0; } case CONNECTING: { switch (reply.state()) { case COMPLETED: { session = reply.resultIfPresent(); state = State.CONNECTED; scheduleEnd(); return 1; } case ERRORED: { errorHandler.onError(reply.error()); reply = null; state = State.DISCONNECTED; return 1; } case TIMED_OUT: { errorHandler.onError(new TimeoutException("Timeout connected to Session")); reply = null; state = State.DISCONNECTED; return 1; } } return 0; } case CONNECTED: { if (!duringDay) { final long position = session.logoutAndDisconnect(); if (position > 0) { state = State.DISCONNECTING; } return 1; } else if (!session.isConnected()) { session = null; state = State.DISCONNECTED; return 1; } return 0; } case DISCONNECTING: { if (session.state() == SessionState.DISCONNECTED) { session = null; state = State.DISCONNECTED; return 1; } return 0; } } return 0; } }
SessionScheduler { public int doWork() { switch (state) { case DISCONNECTED: { if (duringDay) { reply = library.initiate(sessionConfiguration); state = State.CONNECTING; return 1; } return 0; } case CONNECTING: { switch (reply.state()) { case COMPLETED: { session = reply.resultIfPresent(); state = State.CONNECTED; scheduleEnd(); return 1; } case ERRORED: { errorHandler.onError(reply.error()); reply = null; state = State.DISCONNECTED; return 1; } case TIMED_OUT: { errorHandler.onError(new TimeoutException("Timeout connected to Session")); reply = null; state = State.DISCONNECTED; return 1; } } return 0; } case CONNECTED: { if (!duringDay) { final long position = session.logoutAndDisconnect(); if (position > 0) { state = State.DISCONNECTING; } return 1; } else if (!session.isConnected()) { session = null; state = State.DISCONNECTED; return 1; } return 0; } case DISCONNECTING: { if (session.state() == SessionState.DISCONNECTED) { session = null; state = State.DISCONNECTED; return 1; } return 0; } } return 0; } SessionScheduler(
        final Clock clock,
        final FixLibrary library,
        final SessionConfiguration sessionConfiguration,
        final ZoneId timezone,
        final DayOfWeek startDay,
        final DayOfWeek endDay,
        final LocalTime startTime,
        final LocalTime endTime,
        final ErrorHandler errorHandler); }
SessionScheduler { public int doWork() { switch (state) { case DISCONNECTED: { if (duringDay) { reply = library.initiate(sessionConfiguration); state = State.CONNECTING; return 1; } return 0; } case CONNECTING: { switch (reply.state()) { case COMPLETED: { session = reply.resultIfPresent(); state = State.CONNECTED; scheduleEnd(); return 1; } case ERRORED: { errorHandler.onError(reply.error()); reply = null; state = State.DISCONNECTED; return 1; } case TIMED_OUT: { errorHandler.onError(new TimeoutException("Timeout connected to Session")); reply = null; state = State.DISCONNECTED; return 1; } } return 0; } case CONNECTED: { if (!duringDay) { final long position = session.logoutAndDisconnect(); if (position > 0) { state = State.DISCONNECTING; } return 1; } else if (!session.isConnected()) { session = null; state = State.DISCONNECTED; return 1; } return 0; } case DISCONNECTING: { if (session.state() == SessionState.DISCONNECTED) { session = null; state = State.DISCONNECTED; return 1; } return 0; } } return 0; } SessionScheduler(
        final Clock clock,
        final FixLibrary library,
        final SessionConfiguration sessionConfiguration,
        final ZoneId timezone,
        final DayOfWeek startDay,
        final DayOfWeek endDay,
        final LocalTime startTime,
        final LocalTime endTime,
        final ErrorHandler errorHandler); static SessionScheduler nonStopSession(
        final FixLibrary library,
        final SessionConfiguration sessionConfiguration,
        final String timezoneName,
        final String startDayName,
        final String endDayName,
        final ErrorHandler errorHandler); static SessionScheduler fromRawConfig(
        final FixLibrary library,
        final SessionConfiguration sessionConfiguration,
        final String timezoneName,
        final String startDayName,
        final String endDayName,
        final String startTimeConfiguration,
        final String endTimeConfiguration,
        final ErrorHandler errorHandler); boolean duringDay(); int doWork(); }
SessionScheduler { public int doWork() { switch (state) { case DISCONNECTED: { if (duringDay) { reply = library.initiate(sessionConfiguration); state = State.CONNECTING; return 1; } return 0; } case CONNECTING: { switch (reply.state()) { case COMPLETED: { session = reply.resultIfPresent(); state = State.CONNECTED; scheduleEnd(); return 1; } case ERRORED: { errorHandler.onError(reply.error()); reply = null; state = State.DISCONNECTED; return 1; } case TIMED_OUT: { errorHandler.onError(new TimeoutException("Timeout connected to Session")); reply = null; state = State.DISCONNECTED; return 1; } } return 0; } case CONNECTED: { if (!duringDay) { final long position = session.logoutAndDisconnect(); if (position > 0) { state = State.DISCONNECTING; } return 1; } else if (!session.isConnected()) { session = null; state = State.DISCONNECTED; return 1; } return 0; } case DISCONNECTING: { if (session.state() == SessionState.DISCONNECTED) { session = null; state = State.DISCONNECTED; return 1; } return 0; } } return 0; } SessionScheduler(
        final Clock clock,
        final FixLibrary library,
        final SessionConfiguration sessionConfiguration,
        final ZoneId timezone,
        final DayOfWeek startDay,
        final DayOfWeek endDay,
        final LocalTime startTime,
        final LocalTime endTime,
        final ErrorHandler errorHandler); static SessionScheduler nonStopSession(
        final FixLibrary library,
        final SessionConfiguration sessionConfiguration,
        final String timezoneName,
        final String startDayName,
        final String endDayName,
        final ErrorHandler errorHandler); static SessionScheduler fromRawConfig(
        final FixLibrary library,
        final SessionConfiguration sessionConfiguration,
        final String timezoneName,
        final String startDayName,
        final String endDayName,
        final String startTimeConfiguration,
        final String endTimeConfiguration,
        final ErrorHandler errorHandler); boolean duringDay(); int doWork();  }