开发者

Occasional Date or timezone discrepancy in hudson or maven with jodatime

开发者 https://www.devze.com 2023-02-04 14:00 出处:网络
I hope following explanation will make sense because it\'s a weird problem we\'re facing and hard to describe.

I hope following explanation will make sense because it's a weird problem we're facing and hard to describe.

We have a maven project which gets build in hudson and that contains some unit tests where dates are used and asserted. The hudson server runs on solaris. Now, occasionally (like 30% of the times) the unit tests using dates fail because 3,5 hours are deducted from the specified time in the unit test and hence asserts start failing. The other 70% everything works fine although nothing at all changed in the code and we run the hudson job several times an hour.

I add following code to a unittest to check the time:

@Test
public void testDate() {
    System.out.println("new DateMidnight(2011, 1, 5).toDate();");
    System.out.println(new DateMidnight(2011, 1, 5).toDate());
    System.out.println(new DateMidnight(2011, 1, 5).toDate().getTime());

    Calendar cal = Calendar.getInstance();
    cal.set(Calendar.YEAR, 2011);
    cal.set(Calendar.MONTH, 0);
   开发者_StackOverflow社区 cal.set(Calendar.DAY_OF_MONTH, 5);
    cal.set(Calendar.HOUR, 0);
    cal.set(Calendar.MINUTE, 0);
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.MILLISECOND, 0);
    System.out.println("cal.getTime();");
    System.out.println(cal.getTime());
    System.out.println(cal.getTime().getTime());
}

So basically it should print the same thing when using jodatime or plain old Calendar. This is the case in 70% of the runs; for the other 30% I get following printouts:

Running TestSuite
new DateMidnight(2011, 1, 5).toDate();
Tue Jan 04 21:30:00 MET 2011
1294173000000
cal.getTime();
Wed Jan 05 12:00:00 MET 2011
1294225200000

So, Calendar keeps the correct date and time but jodatime deducts 3,5 hours.

Local maven tests never appear the pose this problem and we can't figure out what could be the cause of it. Especially, we can't think of a single reason why the tests sometimes pass and sometimes fail without changing any code nor hudson or server setting.

Also, we run the maven install with cobertura which means that the unit tests are run twice. It happens also that they pass the first time and fail the second time or the other way around or that they fail both times.

Thanks for any solutions or tips to track down the cause,

Stijn


You may also be running into some version of SUREFIRE-533, which should be solvable by setting the TZ environment variable in the environment that is running hudson. Please report back on the issue if this helps.


Perhaps Hudson is running on 3 servers, and 1 has a different version of the time zone data in the JDK from the other 2? (check the JVM version in detail). Remember that Joda-Time also has its own version of the time-zone data, and the two may be different.


The problem seems to be fixed now.

We've upgraded our jodatime version from 5.14.2 to 5.14.6. Since then I ran the build on auto each half hour so after about a 100 runs we never encountered this problem again.

0

精彩评论

暂无评论...
验证码 换一张
取 消