Search in sources :

Example 1 with Query

use of com.mysql.cj.Query in project aws-mysql-jdbc by awslabs.

the class ConnectionRegressionTest method testBug97714.

/**
 * Test fix for Bug#97714 (30570249), Contribution: Expose elapsed time for query interceptor to avoid hacky thread local implementations.
 *
 * @throws Exception
 */
@Test
public void testBug97714() throws Exception {
    assumeFalse(isServerRunningOnWindows(), "SLEEP() is not precise enough on Windows.");
    boolean useSPS = false;
    do {
        final String testCase = String.format("Case: [useServerPrepStmts: %s]", useSPS ? "Y" : "N");
        Properties props = new Properties();
        props.setProperty(PropertyKey.sslMode.getKeyName(), SslMode.DISABLED.name());
        props.setProperty(PropertyKey.allowPublicKeyRetrieval.getKeyName(), "true");
        props.setProperty(PropertyKey.useServerPrepStmts.getKeyName(), Boolean.toString(useSPS));
        Connection testConn = getConnectionWithProps(props);
        // Statement
        Statement testStmt = testConn.createStatement();
        assertEquals(StatementImpl.class, testStmt.getClass(), testCase);
        this.rs = testStmt.executeQuery("SELECT SLEEP(0.25)");
        assertTrue(((Query) testStmt).getExecuteTime() >= 250, testCase);
        // PreparedStatement
        PreparedStatement testPstmt = testConn.prepareStatement("SELECT SLEEP(0.25)");
        assertEquals(useSPS ? ServerPreparedStatement.class : ClientPreparedStatement.class, testPstmt.getClass(), testCase);
        this.rs = testPstmt.executeQuery();
        assertTrue(((Query) testPstmt).getExecuteTime() >= 250, testCase);
        testConn.close();
    } while (useSPS = !useSPS);
}
Also used : ClientPreparedStatement(com.mysql.cj.jdbc.ClientPreparedStatement) Query(com.mysql.cj.Query) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) ServerPreparedStatement(com.mysql.cj.jdbc.ServerPreparedStatement) ClientPreparedStatement(com.mysql.cj.jdbc.ClientPreparedStatement) ReplicationConnection(com.mysql.cj.jdbc.ha.ReplicationConnection) MysqlPooledConnection(com.mysql.cj.jdbc.MysqlPooledConnection) SuspendableXAConnection(com.mysql.cj.jdbc.SuspendableXAConnection) Connection(java.sql.Connection) XAConnection(javax.sql.XAConnection) PooledConnection(javax.sql.PooledConnection) MysqlXAConnection(com.mysql.cj.jdbc.MysqlXAConnection) JdbcConnection(com.mysql.cj.jdbc.JdbcConnection) MysqlConnection(com.mysql.cj.MysqlConnection) PreparedStatement(java.sql.PreparedStatement) ServerPreparedStatement(com.mysql.cj.jdbc.ServerPreparedStatement) ClientPreparedStatement(com.mysql.cj.jdbc.ClientPreparedStatement) ServerPreparedStatement(com.mysql.cj.jdbc.ServerPreparedStatement) Properties(java.util.Properties) Test(org.junit.jupiter.api.Test)

Example 2 with Query

use of com.mysql.cj.Query in project JavaSegundasQuintas by ecteruel.

the class ConnectionRegressionTest method testBug97714.

/**
 * Test fix for Bug#97714 (30570249), Contribution: Expose elapsed time for query interceptor to avoid hacky thread local implementations.
 *
 * @throws Exception
 */
@Test
public void testBug97714() throws Exception {
    assumeFalse(isServerRunningOnWindows(), "SLEEP() is not precise enough on Windows.");
    boolean useSPS = false;
    do {
        final String testCase = String.format("Case: [useServerPrepStmts: %s]", useSPS ? "Y" : "N");
        Properties props = new Properties();
        props.setProperty(PropertyKey.sslMode.getKeyName(), "DISABLED");
        props.setProperty(PropertyKey.allowPublicKeyRetrieval.getKeyName(), "true");
        props.setProperty(PropertyKey.useServerPrepStmts.getKeyName(), Boolean.toString(useSPS));
        Connection testConn = getConnectionWithProps(props);
        // Statement
        Statement testStmt = testConn.createStatement();
        assertEquals(StatementImpl.class, testStmt.getClass(), testCase);
        this.rs = testStmt.executeQuery("SELECT SLEEP(0.25)");
        assertTrue(((Query) testStmt).getExecuteTime() >= 250, testCase);
        // PreparedStatement
        PreparedStatement testPstmt = testConn.prepareStatement("SELECT SLEEP(0.25)");
        assertEquals(useSPS ? ServerPreparedStatement.class : ClientPreparedStatement.class, testPstmt.getClass(), testCase);
        this.rs = testPstmt.executeQuery();
        assertTrue(((Query) testPstmt).getExecuteTime() >= 250, testCase);
        testConn.close();
    } while (useSPS = !useSPS);
}
Also used : ClientPreparedStatement(com.mysql.cj.jdbc.ClientPreparedStatement) Query(com.mysql.cj.Query) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) ServerPreparedStatement(com.mysql.cj.jdbc.ServerPreparedStatement) ClientPreparedStatement(com.mysql.cj.jdbc.ClientPreparedStatement) ReplicationConnection(com.mysql.cj.jdbc.ha.ReplicationConnection) MysqlPooledConnection(com.mysql.cj.jdbc.MysqlPooledConnection) SuspendableXAConnection(com.mysql.cj.jdbc.SuspendableXAConnection) Connection(java.sql.Connection) XAConnection(javax.sql.XAConnection) PooledConnection(javax.sql.PooledConnection) MysqlXAConnection(com.mysql.cj.jdbc.MysqlXAConnection) JdbcConnection(com.mysql.cj.jdbc.JdbcConnection) MysqlConnection(com.mysql.cj.MysqlConnection) PreparedStatement(java.sql.PreparedStatement) ServerPreparedStatement(com.mysql.cj.jdbc.ServerPreparedStatement) ClientPreparedStatement(com.mysql.cj.jdbc.ClientPreparedStatement) ServerPreparedStatement(com.mysql.cj.jdbc.ServerPreparedStatement) Properties(java.util.Properties) Test(org.junit.jupiter.api.Test)

Example 3 with Query

use of com.mysql.cj.Query in project ABC by RuiPinto96274.

the class ConnectionRegressionTest method testBug97714.

/**
 * Test fix for Bug#97714 (30570249), Contribution: Expose elapsed time for query interceptor to avoid hacky thread local implementations.
 *
 * @throws Exception
 */
@Test
public void testBug97714() throws Exception {
    assumeFalse(isServerRunningOnWindows(), "SLEEP() is not precise enough on Windows.");
    boolean useSPS = false;
    do {
        final String testCase = String.format("Case: [useServerPrepStmts: %s]", useSPS ? "Y" : "N");
        Properties props = new Properties();
        props.setProperty(PropertyKey.sslMode.getKeyName(), "DISABLED");
        props.setProperty(PropertyKey.allowPublicKeyRetrieval.getKeyName(), "true");
        props.setProperty(PropertyKey.useServerPrepStmts.getKeyName(), Boolean.toString(useSPS));
        Connection testConn = getConnectionWithProps(props);
        // Statement
        Statement testStmt = testConn.createStatement();
        assertEquals(StatementImpl.class, testStmt.getClass(), testCase);
        this.rs = testStmt.executeQuery("SELECT SLEEP(0.25)");
        assertTrue(((Query) testStmt).getExecuteTime() >= 250, testCase);
        // PreparedStatement
        PreparedStatement testPstmt = testConn.prepareStatement("SELECT SLEEP(0.25)");
        assertEquals(useSPS ? ServerPreparedStatement.class : ClientPreparedStatement.class, testPstmt.getClass(), testCase);
        this.rs = testPstmt.executeQuery();
        assertTrue(((Query) testPstmt).getExecuteTime() >= 250, testCase);
        testConn.close();
    } while (useSPS = !useSPS);
}
Also used : ClientPreparedStatement(com.mysql.cj.jdbc.ClientPreparedStatement) Query(com.mysql.cj.Query) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) ServerPreparedStatement(com.mysql.cj.jdbc.ServerPreparedStatement) ClientPreparedStatement(com.mysql.cj.jdbc.ClientPreparedStatement) ReplicationConnection(com.mysql.cj.jdbc.ha.ReplicationConnection) MysqlPooledConnection(com.mysql.cj.jdbc.MysqlPooledConnection) SuspendableXAConnection(com.mysql.cj.jdbc.SuspendableXAConnection) Connection(java.sql.Connection) XAConnection(javax.sql.XAConnection) PooledConnection(javax.sql.PooledConnection) MysqlXAConnection(com.mysql.cj.jdbc.MysqlXAConnection) JdbcConnection(com.mysql.cj.jdbc.JdbcConnection) MysqlConnection(com.mysql.cj.MysqlConnection) PreparedStatement(java.sql.PreparedStatement) ServerPreparedStatement(com.mysql.cj.jdbc.ServerPreparedStatement) ClientPreparedStatement(com.mysql.cj.jdbc.ClientPreparedStatement) ServerPreparedStatement(com.mysql.cj.jdbc.ServerPreparedStatement) Properties(java.util.Properties) Test(org.junit.jupiter.api.Test)

Aggregations

MysqlConnection (com.mysql.cj.MysqlConnection)3 Query (com.mysql.cj.Query)3 ClientPreparedStatement (com.mysql.cj.jdbc.ClientPreparedStatement)3 JdbcConnection (com.mysql.cj.jdbc.JdbcConnection)3 MysqlPooledConnection (com.mysql.cj.jdbc.MysqlPooledConnection)3 MysqlXAConnection (com.mysql.cj.jdbc.MysqlXAConnection)3 ServerPreparedStatement (com.mysql.cj.jdbc.ServerPreparedStatement)3 SuspendableXAConnection (com.mysql.cj.jdbc.SuspendableXAConnection)3 ReplicationConnection (com.mysql.cj.jdbc.ha.ReplicationConnection)3 Connection (java.sql.Connection)3 PreparedStatement (java.sql.PreparedStatement)3 Statement (java.sql.Statement)3 Properties (java.util.Properties)3 PooledConnection (javax.sql.PooledConnection)3 XAConnection (javax.sql.XAConnection)3 Test (org.junit.jupiter.api.Test)3