Changeset: fdda745ccb7c for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=fdda745ccb7c
Modified Files:
java/tests/Test_PStimezone.java
sql/jdbc/tests/Tests/Test_PStimezone.stable.out
Branch: Apr2011
Log Message:
JDBC: rework PStimezone test to make sense
Next to making this test sort of understandable in its output, also make
the test resistant against local settings (timezone) by forcing it to
use Africa/Windhoek as default timezone.
The test is now structured as follows:
- for a timestamp, timestamp with time zone, time and time with time zone
- the same date (01-01-1970 00:00:00 UTC) is inserted
* without any given calendar information (hence uses default Windhoek)
* with UTC timezone
* with America/Los_Angeles timezone
* with arbitrary GMT+04:15 timezone (rounded to +04:00 it seems)
- query the dates and retrieve them
* as String (aka what the server sent to us over MAPI)
* without any given calendar information (default Windhoek)
* with America/Los_Angeles timezone
* with UTC timezone
For all fields with time zone, the same output regardless the timezone
should be there, since its all translated back to the local environment,
and properly maintained over zones by the server/client.
For all fields without time zone, offsets occur, but when writing and
reading is done with the same timezone, the output should be equal.
diffs (231 lines):
diff --git a/java/tests/Test_PStimezone.java b/java/tests/Test_PStimezone.java
--- a/java/tests/Test_PStimezone.java
+++ b/java/tests/Test_PStimezone.java
@@ -19,6 +19,7 @@
import java.sql.*;
import java.util.*;
+import java.text.*;
public class Test_PStimezone {
public static void main(String[] args) throws Exception {
@@ -55,38 +56,57 @@
System.out.println(" failed :)");
}
- System.out.print("2. inserting a records...");
-
+ System.out.println("2. inserting records...");
+
+ // make sure this test is reproducable regardless
timezone
+ // setting, by overriding the VM's default
+
TimeZone.setDefault(TimeZone.getTimeZone("Africa/Windhoek"));
+
+ SimpleDateFormat tsz =
+ new SimpleDateFormat("yyyy-MM-dd
HH:mm:ss.SSSZ");
+ SimpleDateFormat tz =
+ new SimpleDateFormat("HH:mm:ss.SSSZ");
+
+ java.sql.Timestamp ts = new java.sql.Timestamp(0L);
+ java.sql.Time t = new java.sql.Time(0L);
+
Calendar c = Calendar.getInstance();
- c.setTime(new java.util.Date(0L));
-
- pstmt.setTimestamp(1, new
java.sql.Timestamp(c.getTime().getTime()));
- pstmt.setTimestamp(2, new
java.sql.Timestamp(c.getTime().getTime()));
- pstmt.setTime(3, new
java.sql.Time(c.getTime().getTime()));
- pstmt.setTime(4, new
java.sql.Time(c.getTime().getTime()));
+ tsz.setTimeZone(c.getTimeZone());
+ tz.setTimeZone(tsz.getTimeZone());
+ System.out.println("inserting (" +
c.getTimeZone().getID() + ") " + tsz.format(ts) + ", " + tz.format(t));
+
+ pstmt.setTimestamp(1, ts);
+ pstmt.setTimestamp(2, ts);
+ pstmt.setTime(3, t);
+ pstmt.setTime(4, t);
pstmt.executeUpdate();
- pstmt.setTimestamp(1, new
java.sql.Timestamp(c.getTime().getTime()), c);
- pstmt.setTimestamp(2, new
java.sql.Timestamp(c.getTime().getTime()), c);
- pstmt.setTime(3, new
java.sql.Time(c.getTime().getTime()), c);
- pstmt.setTime(4, new
java.sql.Time(c.getTime().getTime()), c);
+ c.setTimeZone(TimeZone.getTimeZone("UTC"));
+
+ System.out.println("inserting with calendar timezone "
+ c.getTimeZone().getID());
+ pstmt.setTimestamp(1, ts, c);
+ pstmt.setTimestamp(2, ts, c);
+ pstmt.setTime(3, t, c);
+ pstmt.setTime(4, t, c);
pstmt.executeUpdate();
- c.setTimeZone(TimeZone.getTimeZone("PST"));
- pstmt.setTimestamp(1, new
java.sql.Timestamp(c.getTime().getTime()));
- pstmt.setTimestamp(2, new
java.sql.Timestamp(c.getTime().getTime()), c);
- pstmt.setTime(3, new
java.sql.Time(c.getTime().getTime()));
- pstmt.setTime(4, new
java.sql.Time(c.getTime().getTime()), c);
+
c.setTimeZone(TimeZone.getTimeZone("America/Los_Angeles"));
+ System.out.println("inserting with calendar timezone "
+ c.getTimeZone().getID());
+ pstmt.setTimestamp(1, ts, c);
+ pstmt.setTimestamp(2, ts);
+ pstmt.setTime(3, t, c);
+ pstmt.setTime(4, t);
pstmt.executeUpdate();
c.setTimeZone(TimeZone.getTimeZone("GMT+04:15"));
- pstmt.setTimestamp(1, new
java.sql.Timestamp(c.getTime().getTime()), c);
- pstmt.setTimestamp(2, new
java.sql.Timestamp(c.getTime().getTime()));
- pstmt.setTime(3, new
java.sql.Time(c.getTime().getTime()), c);
- pstmt.setTime(4, new
java.sql.Time(c.getTime().getTime()));
+ System.out.println("inserting with calendar timezone "
+ c.getTimeZone().getID());
+ pstmt.setTimestamp(1, ts);
+ pstmt.setTimestamp(2, ts, c);
+ pstmt.setTime(3, t);
+ pstmt.setTime(4, t, c);
pstmt.executeUpdate();
- System.out.println(" passed :)");
+ System.out.println("done");
System.out.print("3. closing PreparedStatement...");
pstmt.close();
System.out.println(" passed :)");
@@ -96,19 +116,43 @@
rs = pstmt.executeQuery();
System.out.println(" passed :)");
+ // The tz fields should basically always be the same
+ // (exactly 1st Jan 1970) since whatever timezone is
used,
+ // the server retains it, and Java restores it.
+ // The zoneless fields will show differences since the
time
+ // is inserted translated to the given timezones, and
+ // retrieved as in they were given in those timezones.
When
+ // the insert zone matches the retrieve zone, Java
should
+ // eventually see 1st Jan 1970.
while (rs.next()) {
-// System.out.println(rs.getString("ts") + "\t" +
rs.getString("tsz"));
- System.out.println(rs.getTimestamp("ts") + "\t"
+ rs.getTimestamp("tsz"));
- c.setTimeZone(TimeZone.getTimeZone("PST"));
- System.out.println(rs.getTimestamp("ts", c) +
"\t" + rs.getTimestamp("tsz", c));
-
c.setTimeZone(TimeZone.getTimeZone("GMT+00:00"));
- System.out.println(rs.getTimestamp("ts", c) +
"\t" + rs.getTimestamp("tsz", c));
-// System.out.println(rs.getString("t") + "\t" +
rs.getString("tz"));
- System.out.println(rs.getTime("t") + "\t" +
rs.getTime("tz"));
- c.setTimeZone(TimeZone.getTimeZone("PST"));
- System.out.println(rs.getTime("t", c) + "\t" +
rs.getTime("tz", c));
-
c.setTimeZone(TimeZone.getTimeZone("GMT+00:00"));
- System.out.println(rs.getTime("t", c) + "\t" +
rs.getTime("tz", c));
+ System.out.println("retrieved row
(String):\n\t" +
+ rs.getString("ts") + " \t" +
+ rs.getString("tsz") + "\t" +
+ rs.getString("t") + "
\t" +
+ rs.getString("tz"));
+
+ tsz.setTimeZone(TimeZone.getDefault());
+ tz.setTimeZone(tsz.getTimeZone());
+ System.out.println("default (" +
tsz.getTimeZone().getID() + "):\n\t" +
+
tsz.format(rs.getTimestamp("ts")) + "\t" +
+
tsz.format(rs.getTimestamp("tsz")) + " \t" +
+ tz.format(rs.getTime("t")) +
"\t" +
+ tz.format(rs.getTime("tz")));
+
+
c.setTimeZone(TimeZone.getTimeZone("America/Los_Angeles"));
+ System.out.println(c.getTimeZone().getID() +
":\n\t" +
+ rs.getTimestamp("ts", c) + "
\t" +
+ rs.getTimestamp("tsz", c) + "
\t" +
+ rs.getTime("t", c) + "
\t" +
+ rs.getTime("tz", c) + " ");
+
+ c.setTimeZone(TimeZone.getTimeZone("UTC"));
+ System.out.println(c.getTimeZone().getID() +
":\n\t" +
+ rs.getTimestamp("ts", c) + "
\t" +
+ rs.getTimestamp("tsz", c) + "
\t" +
+ rs.getTime("t", c) + "
\t" +
+ rs.getTime("tz", c) + " ");
+
System.out.println();
SQLWarning w = rs.getWarnings();
while (w != null) {
diff --git a/sql/jdbc/tests/Tests/Test_PStimezone.stable.out
b/sql/jdbc/tests/Tests/Test_PStimezone.stable.out
--- a/sql/jdbc/tests/Tests/Test_PStimezone.stable.out
+++ b/sql/jdbc/tests/Tests/Test_PStimezone.stable.out
@@ -26,39 +26,52 @@
0. false false
1. empty call... failed :)
-2. inserting a records... passed :)
+2. inserting records...
+inserting (Africa/Windhoek) 1970-01-01 02:00:00.000+0200, 02:00:00.000+0200
+inserting with calendar timezone UTC
+inserting with calendar timezone America/Los_Angeles
+inserting with calendar timezone GMT+04:15
+done
3. closing PreparedStatement... passed :)
4. selecting records... passed :)
-1970-01-01 01:00:00.0 1970-01-01 02:00:00.0
-1970-01-01 10:00:00.0 1970-01-01 02:00:00.0
-1970-01-01 02:00:00.0 1970-01-01 02:00:00.0
-01:00:00 02:00:00
-10:00:00 02:00:00
-02:00:00 02:00:00
+retrieved row (String):
+ 1970-01-01 02:00:00.000000 1970-01-01 02:00:00.000000+02:00
02:00:00 02:00:00+02:00
+default (Africa/Windhoek):
+ 1970-01-01 02:00:00.000+0200 1970-01-01 02:00:00.000+0200
02:00:00.000+0200 02:00:00.000+0200
+America/Los_Angeles:
+ 1970-01-01 12:00:00.0 1970-01-01 02:00:00.0
12:00:00 02:00:00
+UTC:
+ 1970-01-01 04:00:00.0 1970-01-01 02:00:00.0
04:00:00 02:00:00
-1970-01-01 00:00:00.0 1970-01-01 01:00:00.0
-1970-01-01 09:00:00.0 1970-01-01 01:00:00.0
-1970-01-01 01:00:00.0 1970-01-01 01:00:00.0
-00:00:00 01:00:00
-09:00:00 01:00:00
-01:00:00 01:00:00
+retrieved row (String):
+ 1970-01-01 00:00:00.000000 1970-01-01 02:00:00.000000+02:00
00:00:00 02:00:00+02:00
+default (Africa/Windhoek):
+ 1970-01-01 00:00:00.000+0200 1970-01-01 02:00:00.000+0200
00:00:00.000+0200 02:00:00.000+0200
+America/Los_Angeles:
+ 1970-01-01 10:00:00.0 1970-01-01 02:00:00.0
10:00:00 02:00:00
+UTC:
+ 1970-01-01 02:00:00.0 1970-01-01 02:00:00.0
02:00:00 02:00:00
-1970-01-01 01:00:00.0 1970-01-01 01:00:00.0
-1970-01-01 10:00:00.0 1970-01-01 01:00:00.0
-1970-01-01 02:00:00.0 1970-01-01 01:00:00.0
-01:00:00 01:00:00
-10:00:00 01:00:00
-02:00:00 01:00:00
+retrieved row (String):
+ 1969-12-31 16:00:00.000000 1970-01-01 02:00:00.000000+02:00
16:00:00 02:00:00+02:00
+default (Africa/Windhoek):
+ 1969-12-31 16:00:00.000+0200 1970-01-01 02:00:00.000+0200
16:00:00.000+0200 02:00:00.000+0200
+America/Los_Angeles:
+ 1970-01-01 02:00:00.0 1970-01-01 02:00:00.0
02:00:00 02:00:00
+UTC:
+ 1969-12-31 18:00:00.0 1970-01-01 02:00:00.0
18:00:00 02:00:00
-1970-01-01 00:00:00.0 1970-01-01 02:00:00.0
-1970-01-01 09:00:00.0 1970-01-01 02:00:00.0
-1970-01-01 01:00:00.0 1970-01-01 02:00:00.0
-00:00:00 02:00:00
-09:00:00 02:00:00
-01:00:00 02:00:00
+retrieved row (String):
+ 1970-01-01 02:00:00.000000 1970-01-01 02:00:00.000000+02:00
02:00:00 02:00:00+02:00
+default (Africa/Windhoek):
+ 1970-01-01 02:00:00.000+0200 1970-01-01 02:00:00.000+0200
02:00:00.000+0200 02:00:00.000+0200
+America/Los_Angeles:
+ 1970-01-01 12:00:00.0 1970-01-01 02:00:00.0
12:00:00 02:00:00
+UTC:
+ 1970-01-01 04:00:00.0 1970-01-01 02:00:00.0
04:00:00 02:00:00
-# 09:09:18 >
-# 09:09:18 > Done.
-# 09:09:18 >
+# 15:09:12 >
+# 15:09:12 > Done.
+# 15:09:12 >
_______________________________________________
Checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list