⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 connectionregressiontest.java

📁 mysql5.0 JDBC 驱动 放在glassfish或者tomcat的lib文件夹下就可以了
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
				if (isRunningOnJdk131()) {					assertEquals("WINDOWS-31J", charSetUC);				} else {					assertEquals("CP943", charSetUC);				}			} finally {				if (ms932Conn != null) {					ms932Conn.close();				}				if (shiftJisConn != null) {					shiftJisConn.close();				}				if (windows31JConn != null) {					windows31JConn.close();				}				if (cp943Conn != null) {					cp943Conn.close();				}			}		}	}	/**	 * In some case Connector/J's round-robin function doesn't work.	 * 	 * I had 2 mysqld, node1 "localhost:3306" and node2 "localhost:3307".	 * 	 * 1. node1 is up, node2 is up	 * 	 * 2. java-program connect to node1 by using properties	 * "autoRecconect=true","roundRobinLoadBalance=true","failOverReadOnly=false".	 * 	 * 3. node1 is down, node2 is up	 * 	 * 4. java-program execute a query and fail, but Connector/J's round-robin	 * fashion failover work and if java-program retry a query it can succeed	 * (connection is change to node2 by Connector/j)	 * 	 * 5. node1 is up, node2 is up	 * 	 * 6. node1 is up, node2 is down	 * 	 * 7. java-program execute a query, but this time Connector/J doesn't work	 * althought node1 is up and usable.	 * 	 * 	 * @throws Exception	 */	public void testBug8643() throws Exception {		if (runMultiHostTests()) {			Properties defaultProps = getMasterSlaveProps();			defaultProps.remove(NonRegisteringDriver.HOST_PROPERTY_KEY);			defaultProps.remove(NonRegisteringDriver.PORT_PROPERTY_KEY);			defaultProps.put("autoReconnect", "true");			defaultProps.put("roundRobinLoadBalance", "true");			defaultProps.put("failOverReadOnly", "false");			Connection con = null;			try {				con = DriverManager.getConnection(getMasterSlaveUrl(),						defaultProps);				Statement stmt1 = con.createStatement();				ResultSet rs1 = stmt1						.executeQuery("show variables like 'port'");				rs1.next();				rs1 = stmt1.executeQuery("select connection_id()");				rs1.next();				String originalConnectionId = rs1.getString(1);				this.stmt.executeUpdate("kill " + originalConnectionId);				int numLoops = 8;				SQLException caughtException = null;				while (caughtException == null && numLoops > 0) {					numLoops--;					try {						rs1 = stmt1.executeQuery("show variables like 'port'");					} catch (SQLException sqlEx) {						caughtException = sqlEx;					}				}				assertNotNull(caughtException);				// failover and retry				rs1 = stmt1.executeQuery("show variables like 'port'");				rs1.next();				assertTrue(!((com.mysql.jdbc.Connection) con)						.isMasterConnection());				rs1 = stmt1.executeQuery("select connection_id()");				rs1.next();				String nextConnectionId = rs1.getString(1);				assertTrue(!nextConnectionId.equals(originalConnectionId));				this.stmt.executeUpdate("kill " + nextConnectionId);				numLoops = 8;				caughtException = null;				while (caughtException == null && numLoops > 0) {					numLoops--;					try {						rs1 = stmt1.executeQuery("show variables like 'port'");					} catch (SQLException sqlEx) {						caughtException = sqlEx;					}				}				assertNotNull(caughtException);				// failover and retry				rs1 = stmt1.executeQuery("show variables like 'port'");				rs1.next();				assertTrue(((com.mysql.jdbc.Connection) con)						.isMasterConnection());			} finally {				if (con != null) {					try {						con.close();					} catch (Exception e) {						e.printStackTrace();					}				}			}		}	}	/**	 * Tests fix for BUG#9206, can not use 'UTF-8' for characterSetResults	 * configuration property.	 */	public void testBug9206() throws Exception {		Properties props = new Properties();		props.setProperty("characterSetResults", "UTF-8");		getConnectionWithProps(props).close();	}	/**	 * These two charsets have different names depending on version of MySQL	 * server.	 * 	 * @throws Exception	 *             if the test fails.	 */	public void testNewCharsetsConfiguration() throws Exception {		Properties props = new Properties();		props.setProperty("useUnicode", "true");		props.setProperty("characterEncoding", "EUC_KR");		getConnectionWithProps(props).close();		props = new Properties();		props.setProperty("useUnicode", "true");		props.setProperty("characterEncoding", "KOI8_R");		getConnectionWithProps(props).close();	}	/**	 * Tests fix for BUG#10144 - Memory leak in ServerPreparedStatement if	 * serverPrepare() fails.	 */	public void testBug10144() throws Exception {		if (versionMeetsMinimum(4, 1)) {			Properties props = new Properties();			props.setProperty("emulateUnsupportedPstmts", "false");			props.setProperty("useServerPrepStmts", "true");			Connection bareConn = getConnectionWithProps(props);			int currentOpenStatements = ((com.mysql.jdbc.Connection) bareConn)					.getActiveStatementCount();			try {				bareConn.prepareStatement("Boo!");				fail("Should not've been able to prepare that one!");			} catch (SQLException sqlEx) {				assertEquals(currentOpenStatements,						((com.mysql.jdbc.Connection) bareConn)								.getActiveStatementCount());			} finally {				if (bareConn != null) {					bareConn.close();				}			}		}	}	/**	 * Tests fix for BUG#10496 - SQLException is thrown when using property	 * "characterSetResults"	 */	public void testBug10496() throws Exception {		if (versionMeetsMinimum(5, 0, 3)) {			Properties props = new Properties();			props.setProperty("useUnicode", "true");			props.setProperty("characterEncoding", "WINDOWS-31J");			props.setProperty("characterSetResults", "WINDOWS-31J");			getConnectionWithProps(props).close();			props = new Properties();			props.setProperty("useUnicode", "true");			props.setProperty("characterEncoding", "EUC_JP");			props.setProperty("characterSetResults", "EUC_JP");			getConnectionWithProps(props).close();		}	}	/**	 * Tests fix for BUG#11259, autoReconnect ping causes exception on	 * connection startup.	 * 	 * @throws Exception	 *             if the test fails.	 */	public void testBug11259() throws Exception {		Connection dsConn = null;		try {			Properties props = new Properties();			props.setProperty("autoReconnect", "true");			dsConn = getConnectionWithProps(props);		} finally {			if (dsConn != null) {				dsConn.close();			}		}	}	/**	 * Tests fix for BUG#11879 -- ReplicationConnection won't switch to slave,	 * throws "Catalog can't be null" exception.	 * 	 * @throws Exception	 *             if the test fails	 */	public void testBug11879() throws Exception {		if (runMultiHostTests()) {			Connection replConn = null;			try {				replConn = getMasterSlaveReplicationConnection();				replConn.setReadOnly(true);				replConn.setReadOnly(false);			} finally {				if (replConn != null) {					replConn.close();				}			}		}	}	/**	 * Tests fix for BUG#11976 - maxPerformance.properties mis-spells	 * "elideSetAutoCommits".	 * 	 * @throws Exception	 *             if the test fails.	 */	public void testBug11976() throws Exception {		if (isRunningOnJdk131()) {			return; // test not valid on JDK-1.3.1		}		Properties props = new Properties();		props.setProperty("useConfigs", "maxPerformance");		Connection maxPerfConn = getConnectionWithProps(props);		assertEquals(true, ((com.mysql.jdbc.Connection) maxPerfConn)				.getElideSetAutoCommits());	}	/**	 * Tests fix for BUG#12218, properties shared between master and slave with	 * replication connection.	 * 	 * @throws Exception	 *             if the test fails.	 */	public void testBug12218() throws Exception {		if (runMultiHostTests()) {			Connection replConn = null;			try {				replConn = getMasterSlaveReplicationConnection();				assertTrue(!((ConnectionImpl) ((ReplicationConnection) replConn)						.getMasterConnection()).hasSameProperties(								((ReplicationConnection) replConn)										.getSlavesConnection()));			} finally {				if (replConn != null) {					replConn.close();				}			}		}	}	/**	 * Tests fix for BUG#12229 - explainSlowQueries hangs with server-side	 * prepared statements.	 * 	 * @throws Exception	 *             if the test fails.	 */	public void testBug12229() throws Exception {		createTable("testBug12229", "(`int_field` integer )");		this.stmt.executeUpdate("insert into testBug12229 values (123456),(1)");		Properties props = new Properties();		props.put("profileSQL", "true");		props.put("slowQueryThresholdMillis", "0");		props.put("logSlowQueries", "true");		props.put("explainSlowQueries", "true");		props.put("useServerPrepStmts", "true");		Connection explainConn = getConnectionWithProps(props);		this.pstmt = explainConn				.prepareStatement("SELECT `int_field` FROM `testBug12229` WHERE `int_field` = ?");		this.pstmt.setInt(1, 1);		this.rs = this.pstmt.executeQuery();		assertTrue(this.rs.next());		this.rs = this.pstmt.executeQuery();		assertTrue(this.rs.next());		this.rs = this.pstmt.executeQuery();		assertTrue(this.rs.next());	}	/**	 * Tests fix for BUG#12752 - Cp1251 incorrectly mapped to win1251 for	 * servers newer than 4.0.x.	 * 	 * @throws Exception	 *             if the test fails.	 */	public void testBug12752() throws Exception {		Properties props = new Properties();		props.setProperty("characterEncoding", "Cp1251");		getConnectionWithProps(props).close();	}	/**	 * Tests fix for BUG#12753, sessionVariables=....=...., doesn't work as it's	 * tokenized incorrectly.	 * 	 * @throws Exception	 *             if the test fails.	 */	public void testBug12753() throws Exception {		if (versionMeetsMinimum(4, 1)) {			Properties props = new Properties();			props.setProperty("sessionVariables", "sql_mode=ansi");			Connection sessionConn = null;			try {				sessionConn = getConnectionWithProps(props);				String sqlMode = getMysqlVariable(sessionConn, "sql_mode");				assertTrue(sqlMode.indexOf("ANSI") != -1);			} finally {				if (sessionConn != null) {					sessionConn.close();					sessionConn = null;				}			}		}	}	/**	 * Tests fix for BUG#13048 - maxQuerySizeToLog is not respected.	 * 	 * @throws Exception	 *             if the test fails	 */	public void testBug13048() throws Exception {		Connection profileConn = null;		PrintStream oldErr = System.err;		try {			ByteArrayOutputStream bOut = new ByteArrayOutputStream();			System.setErr(new PrintStream(bOut));			Properties props = new Properties();			props.setProperty("profileSQL", "true");			props.setProperty("maxQuerySizeToLog", "2");			props.setProperty("logger", "com.mysql.jdbc.log.StandardLogger");			profileConn = getConnectionWithProps(props);			StringBuffer queryBuf = new StringBuffer("SELECT '");			for (int i = 0; i < 500; i++) {				queryBuf.append("a");			}			queryBuf.append("'");			this.rs = profileConn.createStatement().executeQuery(					queryBuf.toString());			this.rs.close();			String logString = new String(bOut.toString("ISO8859-1"));			assertTrue(logString.indexOf("... (truncated)") != -1);			bOut = new ByteArrayOutputStream();			System.setErr(new PrintStream(bOut));			this.rs = profileConn.prepareStatement(queryBuf.toString())					.executeQuery();			logString = new String(bOut.toString("ISO8859-1"));			assertTrue(logString.indexOf("... (truncated)") != -1);		} finally {			System.setErr(oldErr);			if (profileConn != null) {				profileConn.close();			}			if (this.rs != null) {				ResultSet toClose = this.rs;				this.rs = null;				toClose.close();			}		}	}	/**	 * Tests fix for BUG#13453 - can't use & or = in URL configuration values	 * (we now allow you to use www-form-encoding).	 * 	 * @throws Exception	 *             if the test fails	 */	public void testBug13453() throws Exception {		StringBuffer urlBuf = new StringBuffer(dbUrl);		if (dbUrl.indexOf('?') == -1) {			urlBuf.append('?');		} else {			urlBuf.append('&');		}		urlBuf.append("sessionVariables=@testBug13453='%25%26+%3D'");		Connection encodedConn = null;		try {			encodedConn = DriverManager.getConnection(urlBuf.toString(), null);			this.rs = encodedConn.createStatement().executeQuery(

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -