~ubuntu-branches/ubuntu/karmic/mysql-connector-java/karmic

« back to all changes in this revision

Viewing changes to testsuite/regression/ConnectionRegressionTest.java

  • Committer: Bazaar Package Importer
  • Author(s): Takashi Okamoto
  • Date: 2003-12-30 22:37:53 UTC
  • Revision ID: james.westby@ubuntu.com-20031230223753-5d9n2b0w2ms6puqa
Tags: upstream-3.0.9
ImportĀ upstreamĀ versionĀ 3.0.9

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
   Copyright (C) 2002 MySQL AB
 
3
 
 
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.
 
8
 
 
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.
 
13
 
 
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
 
17
 
 
18
 */
 
19
package testsuite.regression;
 
20
 
 
21
import java.sql.Connection;
 
22
import java.sql.DriverManager;
 
23
import java.sql.SQLException;
 
24
import java.util.Properties;
 
25
 
 
26
import testsuite.BaseTestCase;
 
27
 
 
28
/**
 
29
 * Regression tests for Connections
 
30
 *
 
31
 * @author Mark Matthews
 
32
 * @version $Id: ConnectionRegressionTest.java,v 1.1.2.2 2003/04/25 14:43:51 mmatthew Exp $
 
33
 */
 
34
public class ConnectionRegressionTest extends BaseTestCase {
 
35
 
 
36
        /**
 
37
         * @param name the name of the testcase
 
38
         */
 
39
        public ConnectionRegressionTest(String name) {
 
40
                super(name);
 
41
        }
 
42
 
 
43
        /**
 
44
         * Tests setReadOnly() being reset during failover
 
45
         * 
 
46
         * @throws Exception if an error occurs.
 
47
         */     
 
48
        public void testSetReadOnly() throws Exception {
 
49
                Properties props = new Properties();
 
50
                props.put("autoReconnect", "true");
 
51
                String sepChar = "?";
 
52
                
 
53
                if (BaseTestCase.dbUrl.indexOf("?") != -1) {
 
54
                        sepChar = "&";
 
55
                }
 
56
                
 
57
                Connection reconnectableConn = DriverManager.getConnection(BaseTestCase.dbUrl + sepChar + "autoReconnect=true", props);
 
58
                
 
59
                rs = reconnectableConn.createStatement().executeQuery("SELECT CONNECTION_ID()");
 
60
                rs.next();
 
61
                String connectionId = rs.getString(1);
 
62
                
 
63
                reconnectableConn.setReadOnly(true);
 
64
                boolean isReadOnly = reconnectableConn.isReadOnly();
 
65
                
 
66
 
 
67
                System.out.println("You have 30 seconds to kill connection id " + connectionId + "...");
 
68
                Thread.sleep(30000);
 
69
                System.out.println("Executing statement on reconnectable connection...");
 
70
                
 
71
                try {
 
72
                        reconnectableConn.createStatement().executeQuery("SELECT 1");
 
73
                } catch (SQLException sqlEx) {
 
74
                        ; // ignore
 
75
                }
 
76
                
 
77
                reconnectableConn.createStatement().executeQuery("SELECT 1");
 
78
 
 
79
                assertTrue(reconnectableConn.isReadOnly() == isReadOnly);
 
80
                
 
81
        }
 
82
}