From: Mike Fowler <mike@mlfowler.com>
To: pgsql-jdbc@postgresql.org
Subject: Re: Failing test in org.postgresql.test.jdbc2.DateTest
Date: Mon, 28 Feb 2011 10:23:17 +0000
Message-ID: <4D6B7795.1060400@mlfowler.com> (raw)
In-Reply-To: <4D655262.5060804@mlfowler.com>
References: <4D6538EA.8080905@mlfowler.com>
<4D655262.5060804@mlfowler.com>
On 23/02/11 18:30, Mike Fowler wrote:
> On 23/02/11 16:42, I wrote:
>>
>> I've attached a patch to do just that and it's been tested with the
>> following JDKs:
>>
>> 1.4.2_19
>> 1.5.0_22
>> 1.6.0_21
>>
>> Regards,
>>
> Oops, hold the phone. The test still broke on 1.6 but I didn't notice
> the error as the "build succeeded". The year value 23456 causes the
> test to fail as the maximum year in java.sql.date is 9999. However,
> when I change the year to 3456 the test fails:
>
> [junit] expected:<3456-01-01> but was:<456-01-01>
Turns out there was another place where a date was being set to
23456-01-01, which was misinterpreted by the 1.6 java.sql.Date. Attached
is the patch that brings all the date tests in line with the published
API. This has been tested on the three JDKs as noted above, and for all
three the test output is:
runtest:
[mkdir] Created dir: /home/mike/oss/pgjdbc/build/testresults
[junit] Testsuite: org.postgresql.test.jdbc2.Jdbc2TestSuite
[junit] Tests run: 293, Failures: 0, Errors: 0, Time elapsed:
61.521 sec
[junit]
[junit] Testsuite: org.postgresql.test.jdbc2.optional.OptionalTestSuite
[junit] Tests run: 40, Failures: 0, Errors: 0, Time elapsed: 3.564 sec
[junit]
[junit] Testsuite: org.postgresql.test.jdbc3.Jdbc3TestSuite
[junit] Tests run: 66, Failures: 0, Errors: 0, Time elapsed: 5.959 sec
[junit]
[junit] Testsuite: org.postgresql.test.xa.XATestSuite
[junit] Tests run: 0, Failures: 0, Errors: 0, Time elapsed: 0.072 sec
[junit]
[junit] ------------- Standard Output ---------------
[junit] Skipping XA tests because max_prepared_transactions = 0.
[junit] ------------- ---------------- ---------------
Regards,
--
Mike Fowler
Registered Linux user: 379787
Attachments:dateTest-v2.patch (text/x-diff, 4.2K) download
Index: org/postgresql/test/jdbc2/DateTest.java
===================================================================
RCS file: /cvsroot/jdbc/pgjdbc/org/postgresql/test/jdbc2/DateTest.java,v
retrieving revision 1.14
diff -c -r1.14 DateTest.java
*** org/postgresql/test/jdbc2/DateTest.java 8 Jan 2008 06:56:31 -0000 1.14
--- org/postgresql/test/jdbc2/DateTest.java 28 Feb 2011 10:17:35 -0000
***************
*** 63,69 ****
assertEquals(1, stmt.executeUpdate(TestUtil.insertSQL("testdate", "'1971-12-15'")));
assertEquals(1, stmt.executeUpdate(TestUtil.insertSQL("testdate", "'1984-12-03'")));
assertEquals(1, stmt.executeUpdate(TestUtil.insertSQL("testdate", "'2000-01-01'")));
! assertEquals(1, stmt.executeUpdate(TestUtil.insertSQL("testdate", "'23456-01-01'")));
assertEquals(1, stmt.executeUpdate(TestUtil.insertSQL("testdate", "'0101-01-01 BC'")));
/* dateTest() contains all of the tests */
--- 63,69 ----
assertEquals(1, stmt.executeUpdate(TestUtil.insertSQL("testdate", "'1971-12-15'")));
assertEquals(1, stmt.executeUpdate(TestUtil.insertSQL("testdate", "'1984-12-03'")));
assertEquals(1, stmt.executeUpdate(TestUtil.insertSQL("testdate", "'2000-01-01'")));
! assertEquals(1, stmt.executeUpdate(TestUtil.insertSQL("testdate", "'3456-01-01'")));
assertEquals(1, stmt.executeUpdate(TestUtil.insertSQL("testdate", "'0101-01-01 BC'")));
/* dateTest() contains all of the tests */
***************
*** 108,123 ****
ps.setObject(1, "1934-02-28", java.sql.Types.DATE);
assertEquals(1, ps.executeUpdate());
! ps.setObject(1, "1969-04-3", java.sql.Types.DATE);
assertEquals(1, ps.executeUpdate());
ps.setObject(1, "1982-08-03", java.sql.Types.DATE);
assertEquals(1, ps.executeUpdate());
! ps.setObject(1, "2012-3-15", java.sql.Types.DATE);
assertEquals(1, ps.executeUpdate());
! ps.setObject(1, java.sql.Date.valueOf("1912-5-1"), java.sql.Types.DATE);
assertEquals(1, ps.executeUpdate());
ps.setObject(1, java.sql.Date.valueOf("1971-12-15"), java.sql.Types.DATE);
--- 108,123 ----
ps.setObject(1, "1934-02-28", java.sql.Types.DATE);
assertEquals(1, ps.executeUpdate());
! ps.setObject(1, "1969-04-03", java.sql.Types.DATE);
assertEquals(1, ps.executeUpdate());
ps.setObject(1, "1982-08-03", java.sql.Types.DATE);
assertEquals(1, ps.executeUpdate());
! ps.setObject(1, "2012-03-15", java.sql.Types.DATE);
assertEquals(1, ps.executeUpdate());
! ps.setObject(1, java.sql.Date.valueOf("1912-05-01"), java.sql.Types.DATE);
assertEquals(1, ps.executeUpdate());
ps.setObject(1, java.sql.Date.valueOf("1971-12-15"), java.sql.Types.DATE);
***************
*** 126,135 ****
ps.setObject(1, java.sql.Date.valueOf("1984-12-03"), java.sql.Types.DATE);
assertEquals(1, ps.executeUpdate());
! ps.setObject(1, java.sql.Date.valueOf("2000-1-1"), java.sql.Types.DATE);
assertEquals(1, ps.executeUpdate());
! ps.setObject(1, java.sql.Date.valueOf("23456-1-1"), java.sql.Types.DATE);
assertEquals(1, ps.executeUpdate());
// We can't use valueOf on BC dates.
--- 126,135 ----
ps.setObject(1, java.sql.Date.valueOf("1984-12-03"), java.sql.Types.DATE);
assertEquals(1, ps.executeUpdate());
! ps.setObject(1, java.sql.Date.valueOf("2000-01-01"), java.sql.Types.DATE);
assertEquals(1, ps.executeUpdate());
! ps.setObject(1, java.sql.Date.valueOf("3456-01-01"), java.sql.Types.DATE);
assertEquals(1, ps.executeUpdate());
// We can't use valueOf on BC dates.
***************
*** 240,246 ****
assertTrue(rs.next());
d = rs.getDate(1);
assertNotNull(d);
! assertEquals(makeDate(23456, 1, 1), d);
assertTrue(rs.next());
d = rs.getDate(1);
--- 240,246 ----
assertTrue(rs.next());
d = rs.getDate(1);
assertNotNull(d);
! assertEquals(makeDate(3456, 1, 1), d);
assertTrue(rs.next());
d = rs.getDate(1);
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-jdbc@postgresql.org
Cc: mike@mlfowler.com
Subject: Re: Failing test in org.postgresql.test.jdbc2.DateTest
In-Reply-To: <4D6B7795.1060400@mlfowler.com>
References: <4D6538EA.8080905@mlfowler.com> <4D655262.5060804@mlfowler.com> <4D6B7795.1060400@mlfowler.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox