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

📄 connectionregressiontest.java

📁 mysql5.0 JDBC 驱动 放在glassfish或者tomcat的lib文件夹下就可以了
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
	 */	public void testBug25514() throws Exception {		for (int i = 0; i < 10; i++) {			getConnectionWithProps((Properties)null).close();		}				ThreadGroup root = Thread.currentThread().getThreadGroup().getParent();		while (root.getParent() != null) {	        root = root.getParent();	    }		int numThreadsNamedTimer = findNamedThreadCount(root, "Timer");		if (numThreadsNamedTimer == 0) {			numThreadsNamedTimer = findNamedThreadCount(root, "MySQL Statement Cancellation Timer");		}				// Notice that this seems impossible to test on JDKs prior to 1.5, as there is no		// reliable way to find the TimerThread, so we have to rely on new JDKs for this 		// test.		assertTrue("More than one timer for cancel was created", numThreadsNamedTimer <= 1);	}		private int findNamedThreadCount(ThreadGroup group, String nameStart) {				int count = 0;		        int numThreads = group.activeCount();        Thread[] threads = new Thread[numThreads*2];        numThreads = group.enumerate(threads, false);            for (int i=0; i<numThreads; i++) {            if (threads[i].getName().startsWith(nameStart)) {            	count++;            }        }        int numGroups = group.activeGroupCount();        ThreadGroup[] groups = new ThreadGroup[numGroups*2];        numGroups = group.enumerate(groups, false);            for (int i=0; i<numGroups; i++) {        	count += findNamedThreadCount(groups[i], nameStart);        }        return count;	}		/**	 * Ensures that we don't miss getters/setters for driver properties in	 * ConnectionProperties so that names given in documentation work with 	 * DataSources which will use JavaBean-style names and reflection to 	 * set the values (and often fail silently! when the method isn't available).	 * 	 * @throws Exception	 */	public void testBug23626() throws Exception {		Class clazz = this.conn.getClass();				DriverPropertyInfo[] dpi = new NonRegisteringDriver().getPropertyInfo(dbUrl, null);		StringBuffer missingSettersBuf = new StringBuffer();		StringBuffer missingGettersBuf = new StringBuffer();				Class[][] argTypes = {new Class[] { String.class }, new Class[] {Integer.TYPE}, new Class[] {Long.TYPE}, new Class[] {Boolean.TYPE}};				for (int i = 0; i < dpi.length; i++) {						String propertyName = dpi[i].name;					if (propertyName.equals("HOST") || propertyName.equals("PORT") 					|| propertyName.equals("DBNAME") || propertyName.equals("user") ||					propertyName.equals("password")) {				continue;			}								StringBuffer mutatorName = new StringBuffer("set");			mutatorName.append(Character.toUpperCase(propertyName.charAt(0)));			mutatorName.append(propertyName.substring(1));							StringBuffer accessorName = new StringBuffer("get");			accessorName.append(Character.toUpperCase(propertyName.charAt(0)));			accessorName.append(propertyName.substring(1));						try {				clazz.getMethod(accessorName.toString(), null);			} catch (NoSuchMethodException nsme) {				missingGettersBuf.append(accessorName.toString());				missingGettersBuf.append("\n");			}						boolean foundMethod = false;						for (int j = 0; j < argTypes.length; j++) {				try {					clazz.getMethod(mutatorName.toString(), argTypes[j]);					foundMethod = true;					break;				} catch (NoSuchMethodException nsme) {									}			}						if (!foundMethod) {				missingSettersBuf.append(mutatorName);				missingSettersBuf.append("\n");			}		}				assertEquals("Missing setters for listed configuration properties.", "", missingSettersBuf.toString());		assertEquals("Missing getters for listed configuration properties.", "", missingSettersBuf.toString());	}		/**	 * Tests fix for BUG#25545 - Client flags not sent correctly during handshake	 * when using SSL.	 * 	 * Requires test certificates from testsuite/ssl-test-certs to be installed	 * on the server being tested.	 * 	 * @throws Exception if the test fails.	 */	public void testBug25545() throws Exception {		if (!versionMeetsMinimum(5, 0)) {			return;		}				if (isRunningOnJdk131()) {			return;		}			createProcedure("testBug25545", "() BEGIN SELECT 1; END");				String trustStorePath = "src/testsuite/ssl-test-certs/test-cert-store";				System.setProperty("javax.net.ssl.keyStore", trustStorePath);		System.setProperty("javax.net.ssl.keyStorePassword","password");		System.setProperty("javax.net.ssl.trustStore", trustStorePath);		System.setProperty("javax.net.ssl.trustStorePassword","password");						Connection sslConn = null;				try {			Properties props = new Properties();			props.setProperty("useSSL", "true");			props.setProperty("requireSSL", "true");						sslConn = getConnectionWithProps(props);			sslConn.prepareCall("{ call testBug25545()}").execute();		} finally {			if (sslConn != null) {				sslConn.close();			}		}	}		/**	 * Tests fix for BUG#27655 - getTransactionIsolation() uses	 * "SHOW VARIABLES LIKE" which is very inefficient on MySQL-5.0+	 * 	 * @throws Exception	 */	public void testBug27655() throws Exception {		StringBuffer logBuf = new StringBuffer();		Properties props = new Properties();		props.setProperty("profileSQL", "true");		props.setProperty("logger", "StandardLogger");		StandardLogger.bufferedLog = logBuf;				Connection loggedConn = null;				try {			loggedConn = getConnectionWithProps(props);			loggedConn.getTransactionIsolation();						if (versionMeetsMinimum(4, 0, 3)) {				assertEquals(-1, logBuf.toString().indexOf("SHOW VARIABLES LIKE 'tx_isolation'"));			}		} finally {			if (loggedConn != null) {				loggedConn.close();			}		}	}		/**	 * Tests fix for issue where a failed-over connection would let	 * an application call setReadOnly(false), when that call 	 * should be ignored until the connection is reconnected to a 	 * writable master.	 * 	 * @throws Exception if the test fails.	 */	public void testFailoverReadOnly() throws Exception {		Properties props = getMasterSlaveProps();		props.setProperty("autoReconnect", "true");			Connection failoverConn = null;		Statement failoverStmt = 			null;				try {			failoverConn = getConnectionWithProps(getMasterSlaveUrl(), props);						((com.mysql.jdbc.Connection)failoverConn).setPreferSlaveDuringFailover(true);						failoverStmt = failoverConn.createStatement();						String masterConnectionId = getSingleIndexedValueWithQuery(failoverConn, 1, "SELECT connection_id()").toString();						this.stmt.execute("KILL " + masterConnectionId);						// die trying, so we get the next host			for (int i = 0; i < 100; i++) {				try {					failoverStmt.executeQuery("SELECT 1");				} catch (SQLException sqlEx) {					break;				}			}						String slaveConnectionId = getSingleIndexedValueWithQuery(failoverConn, 1, "SELECT connection_id()").toString();						assertTrue("Didn't get a new physical connection",					!masterConnectionId.equals(slaveConnectionId));						failoverConn.setReadOnly(false); // this should be ignored						assertTrue(failoverConn.isReadOnly());						((com.mysql.jdbc.Connection)failoverConn).setPreferSlaveDuringFailover(false);						this.stmt.execute("KILL " + slaveConnectionId); // we can't issue this on our own connection :p						// die trying, so we get the next host			for (int i = 0; i < 100; i++) {				try {					failoverStmt.executeQuery("SELECT 1");				} catch (SQLException sqlEx) {					break;				}			}						String newMasterId = getSingleIndexedValueWithQuery(failoverConn, 1, "SELECT connection_id()").toString();						assertTrue("Didn't get a new physical connection",					!slaveConnectionId.equals(newMasterId));						failoverConn.setReadOnly(false);						assertTrue(!failoverConn.isReadOnly());		} finally {			if (failoverStmt != null) {				failoverStmt.close();			}						if (failoverConn != null) {				failoverConn.close();			}		}	}		public void testPropertiesDescriptionsKeys() throws Exception {		DriverPropertyInfo[] dpi = new NonRegisteringDriver().getPropertyInfo(				dbUrl, null);		for (int i = 0; i < dpi.length; i++) {			String description = dpi[i].description;			String propertyName = dpi[i].name;			if (description.indexOf("Missing error message for key '") != -1					|| description.startsWith("!")) {				fail("Missing message for configuration property "						+ propertyName);			}			if (description.length() < 10) {				fail("Suspiciously short description for configuration property "						+ propertyName);			}		}	}		public void testBug29106() throws Exception {		ClassLoader cl = Thread.currentThread().getContextClassLoader(); 		Class checkerClass = cl.loadClass("com.mysql.jdbc.integration.jboss.MysqlValidConnectionChecker");		((MysqlValidConnectionChecker)checkerClass.newInstance()).isValidConnection(this.conn);	}		public void testBug29852() throws Exception {    	Connection lbConn = getLoadBalancedConnection();    	assertTrue(!lbConn.getClass().getName().startsWith("com.mysql.jdbc"));    	lbConn.close();    }	private Connection getLoadBalancedConnection(int badHostLocation, 			String badHost, Properties props) throws SQLException {		int indexOfHostStart = dbUrl.indexOf("://") + 3;    	int indexOfHostEnd = dbUrl.indexOf("/", indexOfHostStart);    	    	String firstHost = dbUrl.substring(indexOfHostStart, indexOfHostEnd);    	    	if (firstHost.length() == 0) {    		firstHost = "localhost:3306";    	}    	    	String dbAndConfigs = dbUrl.substring(indexOfHostEnd);    	    	if (badHost != null) {    		badHost = badHost + ",";    	}    	    	String hostsString = null;    	    	switch (badHostLocation) {    	case 1:    		hostsString = badHost + firstHost;    		break;    	case 2:    		hostsString = firstHost + "," + badHost + firstHost;    		break;    	case 3:    		hostsString = firstHost + "," + badHost;    		break;    	default:    			throw new IllegalArgumentException();    	}    	    	Connection lbConn = DriverManager.getConnection("jdbc:mysql:loadbalance://" + hostsString + dbAndConfigs, props);		    	return lbConn;	}		private Connection getLoadBalancedConnection() throws SQLException {		return getLoadBalancedConnection(1, "", null);	}		private Connection getLoadBalancedConnection(Properties props) throws SQLException {		return getLoadBalancedConnection(1, "", props);	}			/**	 * Test of a new feature to fix BUG 22643, specifying a	 * "validation query" in your connection pool that starts	 * with "slash-star ping slash-star" _exactly_ will cause the driver to " +	 * instead send a ping to the server (much lighter weight), and when using	 * a ReplicationConnection or a LoadBalancedConnection, will send	 * the ping across all active connections.	 * 	 * @throws Exception	 */	public void testBug22643() throws Exception {		checkPingQuery(this.conn);				Connection replConnection = getMasterSlaveReplicationConnection();				try {			checkPingQuery(replConnection);		} finally {			if (replConnection != null) {				replConnection.close();			}		}				Connection lbConn = getLoadBalancedConnection();				try {			checkPingQuery(lbConn);		} finally {			if (lbConn != null) {				lbConn.close();			}		}	}	private void checkPingQuery(Connection c) throws SQLException {		// Yes, I know we're sending 2, and looking for 1		// that's part of the test, since we don't _really_		// send the query to the server!		String aPingQuery = "/* ping */ SELECT 2";		Statement pingStmt = c.createStatement();		PreparedStatement pingPStmt = null;				try {			this.rs = pingStmt.executeQuery(aPingQuery);			assertTrue(this.rs.next());			assertEquals(this.rs.getInt(1), 1);						assertTrue(pingStmt.execute(aPingQuery));			this.rs = pingStmt.getResultSet();			assertTrue(this.rs.next());			assertEquals(this.rs.getInt(1), 1);						pingPStmt = c.prepareStatement(aPingQuery);						assertTrue(pingPStmt.execute());			this.rs = pingPStmt.getResultSet();			assertTrue(this.rs.next());			assertEquals(this.rs.getInt(1), 1);						this.rs = pingPStmt.executeQuery();			assertTrue(this.rs.next());			assertEquals(this.rs.getInt(1), 1);		} finally {			closeMemberJDBCResources();		}	}		public void testBug31053() throws Exception {		Properties props = new Properties();		props.setProperty("connectTimeout", "2000");		props.setProperty("loadBalanceStrategy", "random");				Connection lbConn = getLoadBalancedConnection(2, "localhost:23", props);				lbConn.setAutoCommit(false);				for (int i = 0; i < 10; i++) {			lbConn.commit();		}	}		public void testBug32877() throws Exception {		Properties props = new Properties();		props.setProperty("connectTimeout", "2000");		props.setProperty("loadBalanceStrategy", "bestResponseTime");				Connection lbConn = getLoadBalancedConnection(1, "localhost:23", props);				lbConn.setAutoCommit(false);				long begin = System.currentTimeMillis();				for (int i = 0; i < 4; i++) {			lbConn.commit();		}				assertTrue(System.currentTimeMillis() - begin < 10000);	}		/**	 * Tests fix for BUG#33734 - NullPointerException when using client-side	 * prepared statements and enabling caching of prepared statements (only present	 * in nightly builds of 5.1).	 * 	 * @throws Exception	 */	public void testBug33734() throws Exception {		Connection testConn = getConnectionWithProps("cachePrepStmts=true,useServerPrepStmts=false");		try {			testConn.prepareStatement("SELECT 1");		} finally {			testConn.close();		}	}		/** 34703 [NEW]: isValild() aborts Connection on timeout */		public void testBug34703() throws Exception {		if (!com.mysql.jdbc.Util.isJdbc4()) {			return;		}				Method isValid = java.sql.Connection.class.getMethod("isValid", new Class[] {Integer.TYPE});						Connec

⌨️ 快捷键说明

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