2
Copyright (C) 2002 MySQL AB
4
This program is free software; you can redistribute it and/or modify
5
it under the terms of the GNU General Public License as published by
6
the Free Software Foundation; either version 2 of the License, or
7
(at your option) any later version.
9
This program is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
GNU General Public License for more details.
14
You should have received a copy of the GNU General Public License
15
along with this program; if not, write to the Free Software
16
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
package testsuite.regression;
21
import java.sql.Connection;
22
import java.sql.DriverManager;
23
import java.sql.SQLException;
24
import java.util.Properties;
26
import testsuite.BaseTestCase;
29
* Regression tests for Connections
31
* @author Mark Matthews
32
* @version $Id: ConnectionRegressionTest.java,v 1.1.2.2 2003/04/25 14:43:51 mmatthew Exp $
34
public class ConnectionRegressionTest extends BaseTestCase {
37
* @param name the name of the testcase
39
public ConnectionRegressionTest(String name) {
44
* Tests setReadOnly() being reset during failover
46
* @throws Exception if an error occurs.
48
public void testSetReadOnly() throws Exception {
49
Properties props = new Properties();
50
props.put("autoReconnect", "true");
53
if (BaseTestCase.dbUrl.indexOf("?") != -1) {
57
Connection reconnectableConn = DriverManager.getConnection(BaseTestCase.dbUrl + sepChar + "autoReconnect=true", props);
59
rs = reconnectableConn.createStatement().executeQuery("SELECT CONNECTION_ID()");
61
String connectionId = rs.getString(1);
63
reconnectableConn.setReadOnly(true);
64
boolean isReadOnly = reconnectableConn.isReadOnly();
67
System.out.println("You have 30 seconds to kill connection id " + connectionId + "...");
69
System.out.println("Executing statement on reconnectable connection...");
72
reconnectableConn.createStatement().executeQuery("SELECT 1");
73
} catch (SQLException sqlEx) {
77
reconnectableConn.createStatement().executeQuery("SELECT 1");
79
assertTrue(reconnectableConn.isReadOnly() == isReadOnly);