[QFJ-30] Weekly session does not work Created: 19/Jun/06  Updated: 12/Sep/06  Resolved: 15/Jul/06

Status: Closed
Project: QuickFIX/J
Component/s: Engine
Affects Version/s: 1.0.0 Final
Fix Version/s: 1.0.2

Type: Bug Priority: Major
Reporter: Christian Braeuner Assignee: Steve Bate
Resolution: Fixed Votes: 0
Labels: None
Environment:

Windows XP, Sun JVM 1.4.2_06



 Description   

When a weekly session is configured, quickfixj would stop and start sessions on other weekdays than the one configured. In my particular case I have a session that is reset on a Friday afternoon, so quickfixj was configured for a weekly session lasting from Friday 16:00 to Friday next week 13:00. Errors in the calculation made it log out, reset and log in on other weekdays as well.

Here are suggested code changes:

SessionSchedule.java line 221:
int time1Range = timestamp1.get(Calendar.DAY_OF_WEEK) - startDay;
int time2Range = timestamp2.get(Calendar.DAY_OF_WEEK) - startDay;

if (time1Range == 0) {
Calendar timeOnly = getTimeOnly(timestamp1, calendar1);
if (timeOnly.before(startTime))

{ time1Range = 7; }
  • } else if (time1Range < 0) { * time1Range +=7 ; }

if (time2Range == 0) {
Calendar timeOnly = getTimeOnly(timestamp2, calendar2);
if (timeOnly.before(startTime))

{ time2Range = 7; }
  • } else if (time2Range < 0) { * time2Range +=7 ; }

SessionSchedule.java line 262:

if (startDay == endDay) {

  • //Session can go from 13:00-15:00 or from 15:00 - 13:00 ( incl. 7 days)
  • if (startTime.before(endTime)) { * if (currentDay != startDay || currentTime.before(startTime) || currentTime.after(endTime)) * return false; * }

    else

    { * if (currentDay == startDay && currentTime.before(startTime) && currentTime.after(endTime)) * return false; * }

} else if (startDay < endDay) {

Christian



 Comments   
Comment by Steve Bate [ 15/Jul/06 ]

I've redesigned the SessionSchedule class and changed the algorithm for calculating weekly schedules. I also added a test to look for problems with week-long schedule by periodically checking the schedule throughout a simulated weeklong time period. I used your schedule as the test case. It appears to work well now. The changes are on the branch: QFJ_RELEASE_1_0_x (and merged to the trunk).

Comment by Christian Braeuner [ 24/Aug/06 ]

Hi Steve,

unfortunately there are different problems with the new SessionSchedule it seems. I've had 2 resets during in the middle of the active weekly schedule. My schedule is from Friday 22:00 to Friday next week 18:00, i.e. there is only a 4h down time in which the session is reset.
I'll try and reproduce it, when I've got some spare time, but as my version works, I'll revert back to that one for the time being.

Comment by Christian Braeuner [ 04/Sep/06 ]

Hi Steve,

sorry, I wasn't clear on my previous comment. I have tried your version 1.0.2 and your change has got a different problem now in that the weekly session is reset when it shouldn't .

Comment by Steve Bate [ 04/Sep/06 ]

Hi Christian,

I'd really like to know what's happening here (I'm guessing you feel the same way ). I have a unit test that scans an entire week every at an interval of 5 seconds (configurable if we want 1 second test resolution, but the test is then slow) and ensures the session schedule gives the correct information about session boundaries. The test is SessionScheduleTest.testWeeklyPeriodically(). Do you have any ideas about how to use a test case to reproduce the problem you are seeing?

Comment by Christian Braeuner [ 04/Sep/06 ]

Hi Steve,

Thanks for your efforts so far. I could have something to do with boundary conditions when it switches over, but have you tried combining that with different "last session creation time" values? I am sure it has something to do with different combinations of local time, last session creation time and the active schedule.
Here are some combinations that I'd try out:

Session schedule Last created Now Active Reset
Wed 14:00 - Wed 12:00 Mon 09:00 this week Mon 09:00 this week Y N
Wed 14:00 - Wed 12:00 Mon 09:00 this week Mon 13:00 this week Y N
Wed 14:00 - Wed 12:00 Mon 09:00 this week Mon 15:00 this week Y N
Wed 14:00 - Wed 12:00 Mon 09:00 this week Wed 09:00 this week Y N
Wed 14:00 - Wed 12:00 Mon 09:00 this week Wed 13:00 this week N Y
Wed 14:00 - Wed 12:00 Mon 09:00 this week Wed 15:00 this week Y Y
Wed 14:00 - Wed 12:00 Mon 09:00 this week Fri 09:00 this week Y Y
Wed 14:00 - Wed 12:00 Mon 09:00 this week Fri 13:00 this week Y Y
Wed 14:00 - Wed 12:00 Mon 09:00 this week Fri 13:00 this week Y Y

Then combine 'now' times above with different 'last created' times below
.... Fri 09:00 2 wks ago varied 'now' as above all 'Y'
.... Mon 09:00 last week .... as above all 'Y'
.... Wed 09:00 last week .... as above all 'Y'
.... Wed 15:00 last week .... as above as above
.... Fri 09:00 last week .... as above as above
.... Mon 09:00 this week .... as above as above
.... Wed 09:00 this week .... as above as above
.... Wed 13:00 this week .... as above as above
.... Wed 15:00 this week .... as above all 'N'
.... Thu 09:00 this week .... as above all 'N'

You can also combine the combinations above with different weekly session schedules, but the one above is the case I am using. I am using the standard time zone, i.e. UTC.
Suggestions for different schedules would be

Wed 14:00 - Wed 12:00
Wed 14:00 - Tue 18:00
Wed 14:00 - Tue 12:00
Wed 14:00 - Fri 18:00
Wed 14:00 - Fri 12:00
and then inverting the times, i.e.
Wed 12:00 - Wed 14:00 etc.

I think that would exhaustively cover all possible combinations that I can think of. I haven't looked at your unit tests, but I guess you are doing something similar and my hope is that you've missed something out. Maybe you can compare your schedules with mine and hopefully we'll find a gap in the existing tests that my connection fails on. Otherwise it is going to be difficult to explain and I'd have to try your version again, put some debug output in there and hope it fails soon. But it is safer to reproduce it with a full set of tests.

Comment by Steve Bate [ 12/Sep/06 ]

Hello,

I've tried many different combinations of tests and I still can't reproduce the problem. I currently have a test case that tests a range of schedule start/end combinations, session creation times and current times. There are literally thousands of tests and I'm almost sure they include all the cases you listed above. I also created tests specifically for many, but not all, of the specific scenarios you listed and they passed. I'm beginning to wonder if the problem is at a higher level, possibly in the session logic that uses the session schedule.

Generated at Mon May 20 05:03:22 UTC 2024 using JIRA 7.5.2#75007-sha1:9f5725bb824792b3230a5d8716f0c13e296a3cae.