Mercurial > hg > monetdb-java
annotate tests/ConnectionTests.java @ 925:4dfdb62e3e9d
Extend JDBC_API_Tester program with optional second startup argument '-skipMALoutput'.
This allows the JDBC_API_Tester program to be called to skip the comparing the MAL output of tests which return MAL output such as PLAN, EXPLAIN and TRACE statements.
It is intended for internal development use only.
author | Martin van Dinther <martin.van.dinther@monetdbsolutions.com> |
---|---|
date | Thu, 08 Aug 2024 15:26:28 +0200 (8 months ago) |
parents | c2164decf7f1 |
children | d416e9b6b3d0 |
rev | line source |
---|---|
677
e73c4a1f41c6
Add missing Copyright header info
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
674
diff
changeset
|
1 /* |
833
e890195256ac
Update copyright for the new year, move to MonetDB Foundation, add SPDX.
Sjoerd Mullender <sjoerd@acm.org>
parents:
716
diff
changeset
|
2 * SPDX-License-Identifier: MPL-2.0 |
e890195256ac
Update copyright for the new year, move to MonetDB Foundation, add SPDX.
Sjoerd Mullender <sjoerd@acm.org>
parents:
716
diff
changeset
|
3 * |
677
e73c4a1f41c6
Add missing Copyright header info
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
674
diff
changeset
|
4 * This Source Code Form is subject to the terms of the Mozilla Public |
e73c4a1f41c6
Add missing Copyright header info
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
674
diff
changeset
|
5 * License, v. 2.0. If a copy of the MPL was not distributed with this |
e73c4a1f41c6
Add missing Copyright header info
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
674
diff
changeset
|
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/. |
e73c4a1f41c6
Add missing Copyright header info
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
674
diff
changeset
|
7 * |
833
e890195256ac
Update copyright for the new year, move to MonetDB Foundation, add SPDX.
Sjoerd Mullender <sjoerd@acm.org>
parents:
716
diff
changeset
|
8 * Copyright 2024 MonetDB Foundation; |
e890195256ac
Update copyright for the new year, move to MonetDB Foundation, add SPDX.
Sjoerd Mullender <sjoerd@acm.org>
parents:
716
diff
changeset
|
9 * Copyright August 2008 - 2023 MonetDB B.V.; |
e890195256ac
Update copyright for the new year, move to MonetDB Foundation, add SPDX.
Sjoerd Mullender <sjoerd@acm.org>
parents:
716
diff
changeset
|
10 * Copyright 1997 - July 2008 CWI. |
677
e73c4a1f41c6
Add missing Copyright header info
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
674
diff
changeset
|
11 */ |
e73c4a1f41c6
Add missing Copyright header info
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
674
diff
changeset
|
12 |
674
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
13 import java.sql.Connection; |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
14 import java.sql.DriverManager; |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
15 import java.sql.ResultSet; |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
16 import java.sql.SQLException; |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
17 import java.sql.Statement; |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
18 import java.util.Properties; |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
19 import java.util.SimpleTimeZone; |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
20 import java.util.TimeZone; |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
21 |
917
c2164decf7f1
Add final to classes
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
833
diff
changeset
|
22 public final class ConnectionTests { |
674
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
23 |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
24 private final String url; |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
25 private final Properties connProps; |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
26 private final TimeZone timeZone; |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
27 |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
28 public ConnectionTests(String url, Properties props, TimeZone timeZone) { |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
29 this.url = url; |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
30 Properties myProps = null; |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
31 if (props != null) { |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
32 myProps = new Properties(); |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
33 myProps.putAll(props); |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
34 } |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
35 this.connProps = myProps; |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
36 this.timeZone = timeZone; |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
37 } |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
38 |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
39 public ConnectionTests(String url) { |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
40 this(url, null, null); |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
41 } |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
42 |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
43 public ConnectionTests withSuffix(String suffix) { |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
44 String newUrl = url; |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
45 |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
46 if (newUrl.contains("?")) { |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
47 newUrl += "&"; |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
48 } else { |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
49 newUrl += "?"; |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
50 } |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
51 newUrl += suffix; |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
52 |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
53 return new ConnectionTests(newUrl, this.connProps, this.timeZone); |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
54 } |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
55 |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
56 public ConnectionTests withProp(String key, String value) { |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
57 ConnectionTests sub = new ConnectionTests(this.url, new Properties(), this.timeZone); |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
58 if (this.connProps != null) |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
59 sub.connProps.putAll(this.connProps); |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
60 sub.connProps.setProperty(key, value); |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
61 return sub; |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
62 } |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
63 |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
64 public ConnectionTests withTimeZone(int offsetMinutes) { |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
65 TimeZone tz = new SimpleTimeZone(offsetMinutes * 60 * 1000, "Custom" + offsetMinutes); |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
66 return new ConnectionTests(this.url, this.connProps, tz); |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
67 } |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
68 |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
69 public static void main(String[] args) throws SQLException, Failure { |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
70 String url = args[0]; |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
71 runTests(url); |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
72 } |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
73 |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
74 public static void runTests(String url) throws SQLException, Failure { |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
75 ConnectionTests tester = new ConnectionTests(url); |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
76 |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
77 tester.checkAutoCommit(true); |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
78 tester.withSuffix("autocommit=true").checkAutoCommit(true); |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
79 tester.withSuffix("autocommit=false").checkAutoCommit(false); |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
80 tester.withProp("autocommit", "true").checkAutoCommit(true); |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
81 tester.withProp("autocommit", "false").checkAutoCommit(false); |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
82 |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
83 tester.testTimeZone(); |
681
32e7ac7b979e
Tests should always cleanup their created objects, so added cleanup() method.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
678
diff
changeset
|
84 |
32e7ac7b979e
Tests should always cleanup their created objects, so added cleanup() method.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
678
diff
changeset
|
85 tester.cleanup(); |
674
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
86 } |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
87 |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
88 Connection connect() throws SQLException { |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
89 TimeZone restore = null; |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
90 try { |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
91 if (this.timeZone != null) { |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
92 restore = TimeZone.getDefault(); |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
93 TimeZone.setDefault(this.timeZone); |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
94 } |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
95 if (connProps != null) { |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
96 return DriverManager.getConnection(url, connProps); |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
97 } else { |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
98 return DriverManager.getConnection(url); |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
99 } |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
100 } finally { |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
101 if (restore != null) { |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
102 TimeZone.setDefault(restore); |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
103 } |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
104 } |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
105 } |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
106 |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
107 private void checkAutoCommit(boolean expectAutocommit) throws SQLException, Failure { |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
108 // Create and fill the table, leave one row uncommitted. |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
109 try (Connection conn = connect(); Statement stmt = conn.createStatement()) { |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
110 // Does the connection itself believe to be in the correct mode? |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
111 boolean autocommitEnabled = conn.getAutoCommit(); |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
112 if (autocommitEnabled != expectAutocommit) { |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
113 throw new Failure("Expected autocommit to start as " + expectAutocommit + ", got " + autocommitEnabled); |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
114 } |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
115 |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
116 // Let's test how it works out in practice |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
117 stmt.execute("DROP TABLE IF EXISTS connectiontests"); |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
118 stmt.execute("CREATE TABLE connectiontests(i INT)"); |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
119 stmt.execute("INSERT INTO connectiontests VALUES (42)"); |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
120 if (!expectAutocommit) |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
121 conn.commit(); |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
122 // This will only be committed in autocommit mode |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
123 stmt.execute("INSERT INTO connectiontests VALUES (99)"); |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
124 } |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
125 |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
126 // Check whether the uncommitted row is there or not |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
127 try (Connection conn = connect(); Statement stmt = conn.createStatement()) { |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
128 try (ResultSet rs = stmt.executeQuery("SELECT COUNT(i) FROM connectiontests")) { |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
129 rs.next(); |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
130 int n = rs.getInt(1); |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
131 if (expectAutocommit) { |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
132 if (n != 2) { |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
133 throw new Failure("Expected 2 rows because autocommit should be on, got " + n); |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
134 } |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
135 } else { |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
136 if (n != 1) { |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
137 throw new Failure("Expected 1 row because autocommit should be off, got " + n); |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
138 } |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
139 } |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
140 } |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
141 } |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
142 } |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
143 |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
144 private void testTimeZone() throws SQLException, Failure { |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
145 try (Connection conn = connect(); Statement stmt = conn.createStatement()) { |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
146 stmt.execute("DROP TABLE IF EXISTS connectiontests_ts"); |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
147 stmt.execute("CREATE TABLE connectiontests_ts(ts TIMESTAMP WITH TIME ZONE)"); |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
148 stmt.execute("INSERT INTO connectiontests_ts VALUES (str_to_timestamp(100, '%s'))"); |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
149 } |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
150 |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
151 this.withTimeZone(0).verifyTimeZoneSuffix("+00:00"); |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
152 this.withTimeZone(240).verifyTimeZoneSuffix("+04:00"); |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
153 this.withTimeZone(270).verifyTimeZoneSuffix("+04:30"); |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
154 } |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
155 |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
156 private void verifyTimeZoneSuffix(String suffix) throws SQLException, Failure { |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
157 try (Connection conn = connect(); Statement stmt = conn.createStatement()) { |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
158 ResultSet rs = stmt.executeQuery("SELECT * FROM connectiontests_ts"); |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
159 rs.next(); |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
160 String s = rs.getString(1); |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
161 if (!s.endsWith(suffix)) { |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
162 String msg = String.format("Expected suffix '%s', got timestamp '%s'", suffix, s); |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
163 throw new Failure(msg); |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
164 } |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
165 } |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
166 } |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
167 |
681
32e7ac7b979e
Tests should always cleanup their created objects, so added cleanup() method.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
678
diff
changeset
|
168 private void cleanup() throws SQLException { |
32e7ac7b979e
Tests should always cleanup their created objects, so added cleanup() method.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
678
diff
changeset
|
169 try (Connection conn = connect(); Statement stmt = conn.createStatement()) { |
32e7ac7b979e
Tests should always cleanup their created objects, so added cleanup() method.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
678
diff
changeset
|
170 stmt.execute("DROP TABLE IF EXISTS connectiontests"); |
32e7ac7b979e
Tests should always cleanup their created objects, so added cleanup() method.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
678
diff
changeset
|
171 stmt.execute("DROP TABLE IF EXISTS connectiontests_ts"); |
32e7ac7b979e
Tests should always cleanup their created objects, so added cleanup() method.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
678
diff
changeset
|
172 } |
32e7ac7b979e
Tests should always cleanup their created objects, so added cleanup() method.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
678
diff
changeset
|
173 } |
32e7ac7b979e
Tests should always cleanup their created objects, so added cleanup() method.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
678
diff
changeset
|
174 |
674
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
175 public class Failure extends Exception { |
678
b25d838b4bcf
Resolve javac compilation warning:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
677
diff
changeset
|
176 private static final long serialVersionUID = 1L; |
b25d838b4bcf
Resolve javac compilation warning:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
677
diff
changeset
|
177 |
674
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
178 public Failure(String msg) { |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
179 super(msg); |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
180 } |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
181 |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
182 @Override |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
183 public String getMessage() { |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
184 StringBuilder msg = new StringBuilder(); |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
185 msg.append("When connected to "); |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
186 msg.append(url); |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
187 if (timeZone != null) { |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
188 msg.append(", in time zone "); |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
189 msg.append(timeZone.getID()); |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
190 msg.append(" ("); |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
191 msg.append(timeZone.getDisplayName()); |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
192 msg.append(")"); |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
193 } else { |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
194 msg.append(", in the default time zone"); |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
195 } |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
196 if (connProps != null) { |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
197 msg.append(", with "); |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
198 msg.append(connProps.size()); |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
199 msg.append(" properties"); |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
200 connProps.forEach((k, v) -> { |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
201 msg.append(", "); |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
202 msg.append(k); |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
203 msg.append("="); |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
204 msg.append(v); |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
205 }); |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
206 } |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
207 msg.append(": "); |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
208 msg.append(super.getMessage()); |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
209 return msg.toString(); |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
210 } |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
211 } |
b885de91095d
Add tests for autocommit and timezone handshake options
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff
changeset
|
212 } |