Search in sources :

Example 1 with LRUCache

use of com.mysql.cj.util.LRUCache in project JavaSegundasQuintas by ecteruel.

the class StatementRegressionTest method testBug87429.

/**
 * Tests fix for Bug#87429 - repeated close of ServerPreparedStatement causes memory leak.
 *
 * Original de-cache on double close() behavior modified by:
 * WL#11101 - Remove de-cache and close of SSPSs on double call to close().
 *
 * @throws Exception
 */
@Test
public void testBug87429() throws Exception {
    Field stmtsCacheField = ConnectionImpl.class.getDeclaredField("serverSideStatementCache");
    stmtsCacheField.setAccessible(true);
    ToIntFunction<Connection> getStmtsCacheSize = (c) -> {
        try {
            LRUCache<?, ?> stmtsCacheObj = (LRUCache<?, ?>) stmtsCacheField.get(c);
            return stmtsCacheObj == null ? -1 : stmtsCacheObj.size();
        } catch (IllegalArgumentException | IllegalAccessException e) {
            fail("Fail getting the statemets cache size.");
            return -1;
        }
    };
    final String sql1 = "SELECT 1, ?";
    final String sql2 = "SELECT 2, ?";
    boolean useSPS = false;
    boolean cachePS = false;
    do {
        Properties props = new Properties();
        props.setProperty(PropertyKey.useSSL.getKeyName(), "false");
        props.setProperty(PropertyKey.allowPublicKeyRetrieval.getKeyName(), "true");
        props.setProperty(PropertyKey.useServerPrepStmts.getKeyName(), Boolean.toString(useSPS));
        props.setProperty(PropertyKey.cachePrepStmts.getKeyName(), Boolean.toString(cachePS));
        props.setProperty(PropertyKey.prepStmtCacheSize.getKeyName(), "5");
        boolean cachedSPS = useSPS && cachePS;
        JdbcConnection testConn = (JdbcConnection) getConnectionWithProps(props);
        // Single PreparedStatement, closed multiple times.
        for (int i = 0; i < 100; i++) {
            this.pstmt = testConn.prepareStatement(sql1);
            assertTrue(this.pstmt.isPoolable());
            assertEquals(1, testConn.getActiveStatementCount());
            assertEquals(cachedSPS ? 0 : -1, getStmtsCacheSize.applyAsInt(testConn));
            // Close & cache.
            this.pstmt.close();
            assertEquals(cachedSPS ? 1 : 0, testConn.getActiveStatementCount());
            assertEquals(cachedSPS ? 1 : -1, getStmtsCacheSize.applyAsInt(testConn));
            // No-op.
            this.pstmt.close();
            assertEquals(cachedSPS ? 1 : 0, testConn.getActiveStatementCount());
            assertEquals(cachedSPS ? 1 : -1, getStmtsCacheSize.applyAsInt(testConn));
            // No-op.
            this.pstmt.close();
            assertEquals(cachedSPS ? 1 : 0, testConn.getActiveStatementCount());
            assertEquals(cachedSPS ? 1 : -1, getStmtsCacheSize.applyAsInt(testConn));
            try {
                // De-caches the statement or no-op if not cached.
                this.pstmt.setPoolable(false);
            } catch (SQLException e) {
                assertFalse(cachedSPS, "Exception [" + e.getMessage() + "] not expected.");
            }
            // No-op.
            this.pstmt.close();
            assertEquals(0, testConn.getActiveStatementCount());
            assertEquals(cachedSPS ? 0 : -1, getStmtsCacheSize.applyAsInt(testConn));
        }
        testConn.close();
        assertEquals(0, testConn.getActiveStatementCount());
        assertEquals(cachedSPS ? 0 : -1, getStmtsCacheSize.applyAsInt(testConn));
        testConn = (JdbcConnection) getConnectionWithProps(props);
        // Multiple PreparedStatements interchanged, two queries, closed multiple times.
        for (int i = 0; i < 100; i++) {
            for (int j = 1; j <= 4; j++) {
                PreparedStatement pstmt1 = testConn.prepareStatement(j == 1 ? sql2 : sql1);
                PreparedStatement pstmt2 = testConn.prepareStatement(j == 2 ? sql2 : sql1);
                PreparedStatement pstmt3 = testConn.prepareStatement(j == 3 ? sql2 : sql1);
                PreparedStatement pstmt4 = testConn.prepareStatement(j == 4 ? sql2 : sql1);
                assertEquals(4, testConn.getActiveStatementCount());
                // Close and cache statements successively.
                pstmt4.close();
                // No-op.
                pstmt4.close();
                assertEquals(cachedSPS ? 4 : 3, testConn.getActiveStatementCount());
                pstmt3.close();
                // No-op.
                pstmt3.close();
                assertEquals(cachedSPS ? (j >= 3 ? 4 : 3) : 2, testConn.getActiveStatementCount());
                pstmt2.close();
                // No-op.
                pstmt2.close();
                assertEquals(cachedSPS ? (j >= 2 ? 3 : 2) : 1, testConn.getActiveStatementCount());
                pstmt1.close();
                // No-op.
                pstmt1.close();
                assertEquals(cachedSPS ? 2 : 0, testConn.getActiveStatementCount());
                // No-ops.
                pstmt4.close();
                pstmt4.close();
                pstmt3.close();
                pstmt3.close();
                pstmt2.close();
                pstmt2.close();
                pstmt1.close();
                pstmt1.close();
                assertEquals(cachedSPS ? 2 : 0, testConn.getActiveStatementCount());
                // De-cache statements successively.
                try {
                    // De-caches the statement or no-op if not cached.
                    pstmt4.setPoolable(false);
                } catch (SQLException e) {
                    assertFalse(cachedSPS && j == 4, "Exception [" + e.getMessage() + "] not expected.");
                }
                // No-op.
                pstmt4.close();
                assertEquals(cachedSPS ? (j < 4 ? 2 : 1) : 0, testConn.getActiveStatementCount());
                try {
                    // De-caches the statement or no-op if not cached.
                    pstmt3.setPoolable(false);
                } catch (SQLException e) {
                    assertFalse(cachedSPS && j == 3, "Exception [" + e.getMessage() + "] not expected.");
                }
                // No-op.
                pstmt3.close();
                assertEquals(cachedSPS ? (j < 3 ? 2 : 1) : 0, testConn.getActiveStatementCount());
                try {
                    // De-caches the statement or no-op if not cached.
                    pstmt2.setPoolable(false);
                } catch (SQLException e) {
                    assertFalse(cachedSPS && j == 2, "Exception [" + e.getMessage() + "] not expected.");
                }
                // No-op.
                pstmt2.close();
                assertEquals(cachedSPS ? 1 : 0, testConn.getActiveStatementCount());
                try {
                    // De-caches the statement or no-op if not cached.
                    pstmt1.setPoolable(false);
                } catch (SQLException e) {
                    assertFalse(cachedSPS, "Exception [" + e.getMessage() + "] not expected.");
                }
                // No-op.
                pstmt1.close();
                assertEquals(0, testConn.getActiveStatementCount());
            }
        }
        testConn.close();
        assertEquals(0, testConn.getActiveStatementCount());
    } while ((useSPS = !useSPS) || (cachePS = !cachePS));
}
Also used : Arrays(java.util.Arrays) BaseTestCase(testsuite.BaseTestCase) CharArrayReader(java.io.CharArrayReader) SerialBlob(javax.sql.rowset.serial.SerialBlob) Disabled(org.junit.jupiter.api.Disabled) NativeServerSession(com.mysql.cj.protocol.a.NativeServerSession) JdbcStatement(com.mysql.cj.jdbc.JdbcStatement) BigDecimal(java.math.BigDecimal) Future(java.util.concurrent.Future) ReplicationConnection(com.mysql.cj.jdbc.ha.ReplicationConnection) MysqlXADataSource(com.mysql.cj.jdbc.MysqlXADataSource) Assumptions.assumeFalse(org.junit.jupiter.api.Assumptions.assumeFalse) ResultSet(java.sql.ResultSet) Map(java.util.Map) BigInteger(java.math.BigInteger) CharsetMappingWrapper(com.mysql.cj.CharsetMappingWrapper) NClob(java.sql.NClob) WrongArgumentException(com.mysql.cj.exceptions.WrongArgumentException) CJCommunicationsException(com.mysql.cj.exceptions.CJCommunicationsException) DataTruncation(java.sql.DataTruncation) GregorianCalendar(java.util.GregorianCalendar) ClientPreparedQuery(com.mysql.cj.ClientPreparedQuery) ParameterBindings(com.mysql.cj.jdbc.ParameterBindings) JdbcPreparedStatement(com.mysql.cj.jdbc.JdbcPreparedStatement) Reader(java.io.Reader) Assertions.assertNotSame(org.junit.jupiter.api.Assertions.assertNotSame) PreparedStatement(java.sql.PreparedStatement) ZoneId(java.time.ZoneId) Executors(java.util.concurrent.Executors) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) RowId(java.sql.RowId) Ref(java.sql.Ref) ResultSetScannerInterceptor(com.mysql.cj.jdbc.interceptors.ResultSetScannerInterceptor) Assertions.fail(org.junit.jupiter.api.Assertions.fail) MysqlErrorNumbers(com.mysql.cj.exceptions.MysqlErrorNumbers) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) ByteArrayOutputStream(java.io.ByteArrayOutputStream) UnreliableSocketFactory(testsuite.UnreliableSocketFactory) BatchUpdateException(java.sql.BatchUpdateException) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) LocalDateTime(java.time.LocalDateTime) SimpleDateFormat(java.text.SimpleDateFormat) Callable(java.util.concurrent.Callable) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) SQLException(java.sql.SQLException) Calendar(java.util.Calendar) Assumptions.assumeTrue(org.junit.jupiter.api.Assumptions.assumeTrue) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Clob(java.sql.Clob) Properties(java.util.Properties) ColumnDefinition(com.mysql.cj.protocol.ColumnDefinition) Log(com.mysql.cj.log.Log) ToIntFunction(java.util.function.ToIntFunction) ConnectionImpl(com.mysql.cj.jdbc.ConnectionImpl) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) Field(java.lang.reflect.Field) File(java.io.File) Assertions.assertSame(org.junit.jupiter.api.Assertions.assertSame) ExecutionException(java.util.concurrent.ExecutionException) StringReader(java.io.StringReader) Statement(java.sql.Statement) Connection(java.sql.Connection) Time(java.sql.Time) ExceptionFactory(com.mysql.cj.exceptions.ExceptionFactory) URL(java.net.URL) XAConnection(javax.sql.XAConnection) CachedResultSetMetaData(com.mysql.cj.jdbc.result.CachedResultSetMetaData) SQLXML(java.sql.SQLXML) TimeoutException(java.util.concurrent.TimeoutException) Array(java.sql.Array) CompletionService(java.util.concurrent.CompletionService) ResultSetInternalMethods(com.mysql.cj.jdbc.result.ResultSetInternalMethods) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) ByteArrayInputStream(java.io.ByteArrayInputStream) Locale(java.util.Locale) LocalTime(java.time.LocalTime) JdbcConnection(com.mysql.cj.jdbc.JdbcConnection) StatementsTest(testsuite.simple.StatementsTest) SQLWarning(java.sql.SQLWarning) Resultset(com.mysql.cj.protocol.Resultset) ServerSession(com.mysql.cj.protocol.ServerSession) TimeZone(java.util.TimeZone) Timestamp(java.sql.Timestamp) Query(com.mysql.cj.Query) MysqlConnectionPoolDataSource(com.mysql.cj.jdbc.MysqlConnectionPoolDataSource) Session(com.mysql.cj.Session) Test(org.junit.jupiter.api.Test) List(java.util.List) LocalDate(java.time.LocalDate) Writer(java.io.Writer) CallableStatement(java.sql.CallableStatement) MySQLTimeoutException(com.mysql.cj.jdbc.exceptions.MySQLTimeoutException) ResultSetMetaData(java.sql.ResultSetMetaData) ExecutorCompletionService(java.util.concurrent.ExecutorCompletionService) Types(java.sql.Types) ServerPreparedStatement(com.mysql.cj.jdbc.ServerPreparedStatement) SQLSyntaxErrorException(java.sql.SQLSyntaxErrorException) ServerPreparedQuery(com.mysql.cj.ServerPreparedQuery) ClientPreparedStatement(com.mysql.cj.jdbc.ClientPreparedStatement) CommunicationsException(com.mysql.cj.jdbc.exceptions.CommunicationsException) ExecutorService(java.util.concurrent.ExecutorService) PrintStream(java.io.PrintStream) FileWriter(java.io.FileWriter) LRUCache(com.mysql.cj.util.LRUCache) TimeUtil(com.mysql.cj.util.TimeUtil) Date(java.sql.Date) DatabaseTerm(com.mysql.cj.conf.PropertyDefinitions.DatabaseTerm) TimeUnit(java.util.concurrent.TimeUnit) StatementImpl(com.mysql.cj.jdbc.StatementImpl) BaseQueryInterceptor(testsuite.BaseQueryInterceptor) MysqlConnection(com.mysql.cj.MysqlConnection) Blob(java.sql.Blob) ResultsetRows(com.mysql.cj.protocol.ResultsetRows) PropertyKey(com.mysql.cj.conf.PropertyKey) QueryInterceptor(com.mysql.cj.interceptors.QueryInterceptor) InputStream(java.io.InputStream) Field(java.lang.reflect.Field) LRUCache(com.mysql.cj.util.LRUCache) SQLException(java.sql.SQLException) ReplicationConnection(com.mysql.cj.jdbc.ha.ReplicationConnection) Connection(java.sql.Connection) XAConnection(javax.sql.XAConnection) JdbcConnection(com.mysql.cj.jdbc.JdbcConnection) MysqlConnection(com.mysql.cj.MysqlConnection) JdbcConnection(com.mysql.cj.jdbc.JdbcConnection) JdbcPreparedStatement(com.mysql.cj.jdbc.JdbcPreparedStatement) PreparedStatement(java.sql.PreparedStatement) ServerPreparedStatement(com.mysql.cj.jdbc.ServerPreparedStatement) ClientPreparedStatement(com.mysql.cj.jdbc.ClientPreparedStatement) Properties(java.util.Properties) StatementsTest(testsuite.simple.StatementsTest) Test(org.junit.jupiter.api.Test)

Example 2 with LRUCache

use of com.mysql.cj.util.LRUCache in project ABC by RuiPinto96274.

the class StatementRegressionTest method testBug87429.

/**
 * Tests fix for Bug#87429 - repeated close of ServerPreparedStatement causes memory leak.
 *
 * Original de-cache on double close() behavior modified by:
 * WL#11101 - Remove de-cache and close of SSPSs on double call to close().
 *
 * @throws Exception
 */
@Test
public void testBug87429() throws Exception {
    Field stmtsCacheField = ConnectionImpl.class.getDeclaredField("serverSideStatementCache");
    stmtsCacheField.setAccessible(true);
    ToIntFunction<Connection> getStmtsCacheSize = (c) -> {
        try {
            LRUCache<?, ?> stmtsCacheObj = (LRUCache<?, ?>) stmtsCacheField.get(c);
            return stmtsCacheObj == null ? -1 : stmtsCacheObj.size();
        } catch (IllegalArgumentException | IllegalAccessException e) {
            fail("Fail getting the statemets cache size.");
            return -1;
        }
    };
    final String sql1 = "SELECT 1, ?";
    final String sql2 = "SELECT 2, ?";
    boolean useSPS = false;
    boolean cachePS = false;
    do {
        Properties props = new Properties();
        props.setProperty(PropertyKey.useSSL.getKeyName(), "false");
        props.setProperty(PropertyKey.allowPublicKeyRetrieval.getKeyName(), "true");
        props.setProperty(PropertyKey.useServerPrepStmts.getKeyName(), Boolean.toString(useSPS));
        props.setProperty(PropertyKey.cachePrepStmts.getKeyName(), Boolean.toString(cachePS));
        props.setProperty(PropertyKey.prepStmtCacheSize.getKeyName(), "5");
        boolean cachedSPS = useSPS && cachePS;
        JdbcConnection testConn = (JdbcConnection) getConnectionWithProps(props);
        // Single PreparedStatement, closed multiple times.
        for (int i = 0; i < 100; i++) {
            this.pstmt = testConn.prepareStatement(sql1);
            assertTrue(this.pstmt.isPoolable());
            assertEquals(1, testConn.getActiveStatementCount());
            assertEquals(cachedSPS ? 0 : -1, getStmtsCacheSize.applyAsInt(testConn));
            // Close & cache.
            this.pstmt.close();
            assertEquals(cachedSPS ? 1 : 0, testConn.getActiveStatementCount());
            assertEquals(cachedSPS ? 1 : -1, getStmtsCacheSize.applyAsInt(testConn));
            // No-op.
            this.pstmt.close();
            assertEquals(cachedSPS ? 1 : 0, testConn.getActiveStatementCount());
            assertEquals(cachedSPS ? 1 : -1, getStmtsCacheSize.applyAsInt(testConn));
            // No-op.
            this.pstmt.close();
            assertEquals(cachedSPS ? 1 : 0, testConn.getActiveStatementCount());
            assertEquals(cachedSPS ? 1 : -1, getStmtsCacheSize.applyAsInt(testConn));
            try {
                // De-caches the statement or no-op if not cached.
                this.pstmt.setPoolable(false);
            } catch (SQLException e) {
                assertFalse(cachedSPS, "Exception [" + e.getMessage() + "] not expected.");
            }
            // No-op.
            this.pstmt.close();
            assertEquals(0, testConn.getActiveStatementCount());
            assertEquals(cachedSPS ? 0 : -1, getStmtsCacheSize.applyAsInt(testConn));
        }
        testConn.close();
        assertEquals(0, testConn.getActiveStatementCount());
        assertEquals(cachedSPS ? 0 : -1, getStmtsCacheSize.applyAsInt(testConn));
        testConn = (JdbcConnection) getConnectionWithProps(props);
        // Multiple PreparedStatements interchanged, two queries, closed multiple times.
        for (int i = 0; i < 100; i++) {
            for (int j = 1; j <= 4; j++) {
                PreparedStatement pstmt1 = testConn.prepareStatement(j == 1 ? sql2 : sql1);
                PreparedStatement pstmt2 = testConn.prepareStatement(j == 2 ? sql2 : sql1);
                PreparedStatement pstmt3 = testConn.prepareStatement(j == 3 ? sql2 : sql1);
                PreparedStatement pstmt4 = testConn.prepareStatement(j == 4 ? sql2 : sql1);
                assertEquals(4, testConn.getActiveStatementCount());
                // Close and cache statements successively.
                pstmt4.close();
                // No-op.
                pstmt4.close();
                assertEquals(cachedSPS ? 4 : 3, testConn.getActiveStatementCount());
                pstmt3.close();
                // No-op.
                pstmt3.close();
                assertEquals(cachedSPS ? (j >= 3 ? 4 : 3) : 2, testConn.getActiveStatementCount());
                pstmt2.close();
                // No-op.
                pstmt2.close();
                assertEquals(cachedSPS ? (j >= 2 ? 3 : 2) : 1, testConn.getActiveStatementCount());
                pstmt1.close();
                // No-op.
                pstmt1.close();
                assertEquals(cachedSPS ? 2 : 0, testConn.getActiveStatementCount());
                // No-ops.
                pstmt4.close();
                pstmt4.close();
                pstmt3.close();
                pstmt3.close();
                pstmt2.close();
                pstmt2.close();
                pstmt1.close();
                pstmt1.close();
                assertEquals(cachedSPS ? 2 : 0, testConn.getActiveStatementCount());
                // De-cache statements successively.
                try {
                    // De-caches the statement or no-op if not cached.
                    pstmt4.setPoolable(false);
                } catch (SQLException e) {
                    assertFalse(cachedSPS && j == 4, "Exception [" + e.getMessage() + "] not expected.");
                }
                // No-op.
                pstmt4.close();
                assertEquals(cachedSPS ? (j < 4 ? 2 : 1) : 0, testConn.getActiveStatementCount());
                try {
                    // De-caches the statement or no-op if not cached.
                    pstmt3.setPoolable(false);
                } catch (SQLException e) {
                    assertFalse(cachedSPS && j == 3, "Exception [" + e.getMessage() + "] not expected.");
                }
                // No-op.
                pstmt3.close();
                assertEquals(cachedSPS ? (j < 3 ? 2 : 1) : 0, testConn.getActiveStatementCount());
                try {
                    // De-caches the statement or no-op if not cached.
                    pstmt2.setPoolable(false);
                } catch (SQLException e) {
                    assertFalse(cachedSPS && j == 2, "Exception [" + e.getMessage() + "] not expected.");
                }
                // No-op.
                pstmt2.close();
                assertEquals(cachedSPS ? 1 : 0, testConn.getActiveStatementCount());
                try {
                    // De-caches the statement or no-op if not cached.
                    pstmt1.setPoolable(false);
                } catch (SQLException e) {
                    assertFalse(cachedSPS, "Exception [" + e.getMessage() + "] not expected.");
                }
                // No-op.
                pstmt1.close();
                assertEquals(0, testConn.getActiveStatementCount());
            }
        }
        testConn.close();
        assertEquals(0, testConn.getActiveStatementCount());
    } while ((useSPS = !useSPS) || (cachePS = !cachePS));
}
Also used : Arrays(java.util.Arrays) BaseTestCase(testsuite.BaseTestCase) CharArrayReader(java.io.CharArrayReader) SerialBlob(javax.sql.rowset.serial.SerialBlob) Disabled(org.junit.jupiter.api.Disabled) NativeServerSession(com.mysql.cj.protocol.a.NativeServerSession) JdbcStatement(com.mysql.cj.jdbc.JdbcStatement) BigDecimal(java.math.BigDecimal) Future(java.util.concurrent.Future) ReplicationConnection(com.mysql.cj.jdbc.ha.ReplicationConnection) MysqlXADataSource(com.mysql.cj.jdbc.MysqlXADataSource) Assumptions.assumeFalse(org.junit.jupiter.api.Assumptions.assumeFalse) ResultSet(java.sql.ResultSet) Map(java.util.Map) BigInteger(java.math.BigInteger) CharsetMappingWrapper(com.mysql.cj.CharsetMappingWrapper) NClob(java.sql.NClob) WrongArgumentException(com.mysql.cj.exceptions.WrongArgumentException) CJCommunicationsException(com.mysql.cj.exceptions.CJCommunicationsException) DataTruncation(java.sql.DataTruncation) GregorianCalendar(java.util.GregorianCalendar) ClientPreparedQuery(com.mysql.cj.ClientPreparedQuery) ParameterBindings(com.mysql.cj.jdbc.ParameterBindings) JdbcPreparedStatement(com.mysql.cj.jdbc.JdbcPreparedStatement) Reader(java.io.Reader) Assertions.assertNotSame(org.junit.jupiter.api.Assertions.assertNotSame) PreparedStatement(java.sql.PreparedStatement) ZoneId(java.time.ZoneId) Executors(java.util.concurrent.Executors) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) RowId(java.sql.RowId) Ref(java.sql.Ref) ResultSetScannerInterceptor(com.mysql.cj.jdbc.interceptors.ResultSetScannerInterceptor) Assertions.fail(org.junit.jupiter.api.Assertions.fail) MysqlErrorNumbers(com.mysql.cj.exceptions.MysqlErrorNumbers) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) ByteArrayOutputStream(java.io.ByteArrayOutputStream) UnreliableSocketFactory(testsuite.UnreliableSocketFactory) BatchUpdateException(java.sql.BatchUpdateException) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) LocalDateTime(java.time.LocalDateTime) SimpleDateFormat(java.text.SimpleDateFormat) Callable(java.util.concurrent.Callable) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) SQLException(java.sql.SQLException) Calendar(java.util.Calendar) Assumptions.assumeTrue(org.junit.jupiter.api.Assumptions.assumeTrue) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Clob(java.sql.Clob) Properties(java.util.Properties) ColumnDefinition(com.mysql.cj.protocol.ColumnDefinition) Log(com.mysql.cj.log.Log) ToIntFunction(java.util.function.ToIntFunction) ConnectionImpl(com.mysql.cj.jdbc.ConnectionImpl) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) Field(java.lang.reflect.Field) File(java.io.File) Assertions.assertSame(org.junit.jupiter.api.Assertions.assertSame) ExecutionException(java.util.concurrent.ExecutionException) StringReader(java.io.StringReader) Statement(java.sql.Statement) Connection(java.sql.Connection) Time(java.sql.Time) ExceptionFactory(com.mysql.cj.exceptions.ExceptionFactory) URL(java.net.URL) XAConnection(javax.sql.XAConnection) CachedResultSetMetaData(com.mysql.cj.jdbc.result.CachedResultSetMetaData) SQLXML(java.sql.SQLXML) TimeoutException(java.util.concurrent.TimeoutException) Array(java.sql.Array) CompletionService(java.util.concurrent.CompletionService) ResultSetInternalMethods(com.mysql.cj.jdbc.result.ResultSetInternalMethods) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) ByteArrayInputStream(java.io.ByteArrayInputStream) Locale(java.util.Locale) LocalTime(java.time.LocalTime) JdbcConnection(com.mysql.cj.jdbc.JdbcConnection) StatementsTest(testsuite.simple.StatementsTest) SQLWarning(java.sql.SQLWarning) Resultset(com.mysql.cj.protocol.Resultset) ServerSession(com.mysql.cj.protocol.ServerSession) TimeZone(java.util.TimeZone) Timestamp(java.sql.Timestamp) Query(com.mysql.cj.Query) MysqlConnectionPoolDataSource(com.mysql.cj.jdbc.MysqlConnectionPoolDataSource) Session(com.mysql.cj.Session) Test(org.junit.jupiter.api.Test) List(java.util.List) LocalDate(java.time.LocalDate) Writer(java.io.Writer) CallableStatement(java.sql.CallableStatement) MySQLTimeoutException(com.mysql.cj.jdbc.exceptions.MySQLTimeoutException) ResultSetMetaData(java.sql.ResultSetMetaData) ExecutorCompletionService(java.util.concurrent.ExecutorCompletionService) Types(java.sql.Types) ServerPreparedStatement(com.mysql.cj.jdbc.ServerPreparedStatement) SQLSyntaxErrorException(java.sql.SQLSyntaxErrorException) ServerPreparedQuery(com.mysql.cj.ServerPreparedQuery) ClientPreparedStatement(com.mysql.cj.jdbc.ClientPreparedStatement) CommunicationsException(com.mysql.cj.jdbc.exceptions.CommunicationsException) ExecutorService(java.util.concurrent.ExecutorService) PrintStream(java.io.PrintStream) FileWriter(java.io.FileWriter) LRUCache(com.mysql.cj.util.LRUCache) TimeUtil(com.mysql.cj.util.TimeUtil) Date(java.sql.Date) DatabaseTerm(com.mysql.cj.conf.PropertyDefinitions.DatabaseTerm) TimeUnit(java.util.concurrent.TimeUnit) StatementImpl(com.mysql.cj.jdbc.StatementImpl) BaseQueryInterceptor(testsuite.BaseQueryInterceptor) MysqlConnection(com.mysql.cj.MysqlConnection) Blob(java.sql.Blob) ResultsetRows(com.mysql.cj.protocol.ResultsetRows) PropertyKey(com.mysql.cj.conf.PropertyKey) QueryInterceptor(com.mysql.cj.interceptors.QueryInterceptor) InputStream(java.io.InputStream) Field(java.lang.reflect.Field) LRUCache(com.mysql.cj.util.LRUCache) SQLException(java.sql.SQLException) ReplicationConnection(com.mysql.cj.jdbc.ha.ReplicationConnection) Connection(java.sql.Connection) XAConnection(javax.sql.XAConnection) JdbcConnection(com.mysql.cj.jdbc.JdbcConnection) MysqlConnection(com.mysql.cj.MysqlConnection) JdbcConnection(com.mysql.cj.jdbc.JdbcConnection) JdbcPreparedStatement(com.mysql.cj.jdbc.JdbcPreparedStatement) PreparedStatement(java.sql.PreparedStatement) ServerPreparedStatement(com.mysql.cj.jdbc.ServerPreparedStatement) ClientPreparedStatement(com.mysql.cj.jdbc.ClientPreparedStatement) Properties(java.util.Properties) StatementsTest(testsuite.simple.StatementsTest) Test(org.junit.jupiter.api.Test)

Example 3 with LRUCache

use of com.mysql.cj.util.LRUCache in project JavaSegundasQuintas by ecteruel.

the class StatementsTest method testServerPreparedStatementsCaching.

/**
 * WL#11101 - Remove de-cache and close of SSPSs on double call to close()
 *
 * @throws Exception
 */
@Test
public void testServerPreparedStatementsCaching() throws Exception {
    // Non prepared statements must be non-poolable by default.
    assertFalse(this.stmt.isPoolable());
    Field stmtsCacheField = ConnectionImpl.class.getDeclaredField("serverSideStatementCache");
    stmtsCacheField.setAccessible(true);
    ToIntFunction<Connection> getStmtsCacheSize = (c) -> {
        try {
            LRUCache<?, ?> stmtsCacheObj = (LRUCache<?, ?>) stmtsCacheField.get(c);
            return stmtsCacheObj == null ? -1 : stmtsCacheObj.size();
        } catch (IllegalArgumentException | IllegalAccessException e) {
            fail("Fail getting the statemets cache size.");
            return -1;
        }
    };
    Function<Connection, ServerPreparedStatement> getStmtsCacheSingleElem = (c) -> {
        try {
            @SuppressWarnings("unchecked") LRUCache<?, ServerPreparedStatement> stmtsCacheObj = (LRUCache<?, ServerPreparedStatement>) stmtsCacheField.get(c);
            return stmtsCacheObj.get(stmtsCacheObj.keySet().iterator().next());
        } catch (IllegalArgumentException | IllegalAccessException e) {
            fail("Fail getting the statemets cache element.");
            return null;
        }
    };
    final String sql1 = "SELECT 1, ?";
    final String sql2 = "SELECT 2, ?";
    boolean useSPS = false;
    boolean cachePS = false;
    do {
        Properties props = new Properties();
        props.setProperty(PropertyKey.sslMode.getKeyName(), "DISABLED");
        props.setProperty(PropertyKey.allowPublicKeyRetrieval.getKeyName(), "true");
        props.setProperty(PropertyKey.useServerPrepStmts.getKeyName(), Boolean.toString(useSPS));
        props.setProperty(PropertyKey.cachePrepStmts.getKeyName(), Boolean.toString(cachePS));
        props.setProperty(PropertyKey.prepStmtCacheSize.getKeyName(), "5");
        boolean cachedSPS = useSPS && cachePS;
        /*
             * Cache the prepared statement and de-cache it later.
             * (*) if server prepared statement and caching is enabled.
             */
        {
            JdbcConnection testConn = (JdbcConnection) getConnectionWithProps(props);
            PreparedStatement testPstmt = testConn.prepareStatement(sql1);
            assertEquals(1, testConn.getActiveStatementCount());
            assertEquals(cachedSPS ? 0 : -1, getStmtsCacheSize.applyAsInt(testConn));
            assertTrue(testPstmt.isPoolable());
            // Caches this PS (*).
            testPstmt.close();
            assertEquals(cachedSPS ? 1 : 0, testConn.getActiveStatementCount());
            assertEquals(cachedSPS ? 1 : -1, getStmtsCacheSize.applyAsInt(testConn));
            // No-op.
            testPstmt.close();
            assertEquals(cachedSPS ? 1 : 0, testConn.getActiveStatementCount());
            assertEquals(cachedSPS ? 1 : -1, getStmtsCacheSize.applyAsInt(testConn));
            if (cachedSPS) {
                assertTrue(testPstmt.isPoolable());
                // De-caches this PS; it gets automatically closed (*).
                testPstmt.setPoolable(false);
                assertEquals(0, testConn.getActiveStatementCount());
                assertEquals(0, getStmtsCacheSize.applyAsInt(testConn));
            }
            // No-op.
            testPstmt.close();
            assertEquals(0, testConn.getActiveStatementCount());
            assertEquals(cachedSPS ? 0 : -1, getStmtsCacheSize.applyAsInt(testConn));
            assertThrows(SQLException.class, "No operations allowed after statement closed\\.", () -> {
                testPstmt.setPoolable(false);
                return null;
            });
            assertThrows(SQLException.class, "No operations allowed after statement closed\\.", () -> {
                testPstmt.isPoolable();
                return null;
            });
            testConn.close();
            assertEquals(0, testConn.getActiveStatementCount());
            assertEquals(cachedSPS ? 0 : -1, getStmtsCacheSize.applyAsInt(testConn));
        }
        /*
             * Set not to cache the prepared statement.
             * (*) if server prepared statement and caching is enabled.
             */
        {
            JdbcConnection testConn = (JdbcConnection) getConnectionWithProps(props);
            PreparedStatement testPstmt = testConn.prepareStatement(sql1);
            assertEquals(1, testConn.getActiveStatementCount());
            assertEquals(cachedSPS ? 0 : -1, getStmtsCacheSize.applyAsInt(testConn));
            assertTrue(testPstmt.isPoolable());
            // Don't cache this PS (*).
            testPstmt.setPoolable(false);
            assertFalse(testPstmt.isPoolable());
            // Doesn't cache this PS (*).
            testPstmt.close();
            assertEquals(0, testConn.getActiveStatementCount());
            assertEquals(cachedSPS ? 0 : -1, getStmtsCacheSize.applyAsInt(testConn));
            // No-op.
            testPstmt.close();
            assertEquals(0, testConn.getActiveStatementCount());
            assertEquals(cachedSPS ? 0 : -1, getStmtsCacheSize.applyAsInt(testConn));
            assertThrows(SQLException.class, "No operations allowed after statement closed\\.", () -> {
                testPstmt.setPoolable(true);
                return null;
            });
            assertThrows(SQLException.class, "No operations allowed after statement closed\\.", () -> {
                testPstmt.isPoolable();
                return null;
            });
            testConn.close();
            assertEquals(0, testConn.getActiveStatementCount());
            assertEquals(cachedSPS ? 0 : -1, getStmtsCacheSize.applyAsInt(testConn));
        }
        /*
             * Set not to cache the prepared statement but change mind before closing it.
             * Reuse the cached prepared statement and don't re-cache it.
             * (*) if server prepared statement and caching is enabled.
             */
        {
            JdbcConnection testConn = (JdbcConnection) getConnectionWithProps(props);
            PreparedStatement testPstmt = testConn.prepareStatement(sql1);
            assertEquals(1, testConn.getActiveStatementCount());
            assertEquals(cachedSPS ? 0 : -1, getStmtsCacheSize.applyAsInt(testConn));
            // Don't cache this PS (*).
            testPstmt.setPoolable(false);
            assertFalse(testPstmt.isPoolable());
            testPstmt.setPoolable(true);
            // Changed my mind, let it be cached (*).
            assertTrue(testPstmt.isPoolable());
            // Caches this PS (*).
            testPstmt.close();
            assertEquals(cachedSPS ? 1 : 0, testConn.getActiveStatementCount());
            assertEquals(cachedSPS ? 1 : -1, getStmtsCacheSize.applyAsInt(testConn));
            // No-op.
            testPstmt.close();
            assertEquals(cachedSPS ? 1 : 0, testConn.getActiveStatementCount());
            assertEquals(cachedSPS ? 1 : -1, getStmtsCacheSize.applyAsInt(testConn));
            PreparedStatement testPstmtOld = testPstmt;
            // Takes the cached statement (*), or creates a fresh one.
            testPstmt = testConn.prepareStatement(sql1);
            if (cachedSPS) {
                assertSame(testPstmtOld, testPstmt);
            } else {
                assertNotSame(testPstmtOld, testPstmt);
            }
            assertEquals(1, testConn.getActiveStatementCount());
            assertEquals(cachedSPS ? 0 : -1, getStmtsCacheSize.applyAsInt(testConn));
            assertTrue(testPstmt.isPoolable());
            // Don't cache this PS (*).
            testPstmt.setPoolable(false);
            assertFalse(testPstmt.isPoolable());
            // Doesn't cache this PS (*).
            testPstmt.close();
            assertEquals(0, testConn.getActiveStatementCount());
            assertEquals(cachedSPS ? 0 : -1, getStmtsCacheSize.applyAsInt(testConn));
            testPstmtOld = testPstmt;
            // Creates a fresh prepared statement.
            testPstmt = testConn.prepareStatement(sql1);
            assertNotSame(testPstmtOld, testPstmt);
            assertEquals(1, testConn.getActiveStatementCount());
            assertEquals(cachedSPS ? 0 : -1, getStmtsCacheSize.applyAsInt(testConn));
            assertTrue(testPstmt.isPoolable());
            testConn.close();
            assertEquals(0, testConn.getActiveStatementCount());
            assertEquals(cachedSPS ? 0 : -1, getStmtsCacheSize.applyAsInt(testConn));
        }
        /*
             * Caching of multiple copies of same prepared statement.
             * (*) if server prepared statement and caching is enabled.
             */
        {
            int psCount = 5;
            JdbcConnection testConn = (JdbcConnection) getConnectionWithProps(props);
            PreparedStatement[] testPstmts = new PreparedStatement[psCount];
            for (int i = 0; i < psCount; i++) {
                testPstmts[i] = testConn.prepareStatement(sql1);
            }
            assertEquals(5, testConn.getActiveStatementCount());
            assertEquals(cachedSPS ? 0 : -1, getStmtsCacheSize.applyAsInt(testConn));
            for (int i = 0; i < psCount; i++) {
                assertTrue(testPstmts[i].isPoolable());
                // Caches this PS and replaces existing if same (*).
                testPstmts[i].close();
                assertEquals(cachedSPS ? psCount - i : psCount - i - 1, testConn.getActiveStatementCount());
                assertEquals(cachedSPS ? 1 : -1, getStmtsCacheSize.applyAsInt(testConn));
                if (cachedSPS) {
                    assertSame(testPstmts[i], getStmtsCacheSingleElem.apply(testConn));
                }
            }
            PreparedStatement testPstmt = testConn.prepareStatement(sql1);
            assertEquals(1, testConn.getActiveStatementCount());
            assertEquals(cachedSPS ? 0 : -1, getStmtsCacheSize.applyAsInt(testConn));
            for (int i = 0; i < psCount; i++) {
                if (cachedSPS && i == psCount - 1) {
                    assertSame(testPstmts[i], testPstmt);
                } else {
                    assertNotSame(testPstmts[i], testPstmt);
                }
            }
            // Don't cache this PS (*).
            testPstmt.setPoolable(false);
            // Doesn't cache this PS (*).
            testPstmt.close();
            assertEquals(0, testConn.getActiveStatementCount());
            assertEquals(cachedSPS ? 0 : -1, getStmtsCacheSize.applyAsInt(testConn));
            testConn.close();
            assertEquals(0, testConn.getActiveStatementCount());
            assertEquals(cachedSPS ? 0 : -1, getStmtsCacheSize.applyAsInt(testConn));
        }
        /*
             * Combine caching different prepared statements.
             * (*) if server prepared statement and caching is enabled.
             */
        {
            int psCount = 5;
            JdbcConnection testConn = (JdbcConnection) getConnectionWithProps(props);
            PreparedStatement[] testPstmts1 = new PreparedStatement[psCount];
            for (int i = 0; i < psCount; i++) {
                testPstmts1[i] = testConn.prepareStatement(sql1);
            }
            PreparedStatement testPstmt = testConn.prepareStatement(sql2);
            assertEquals(6, testConn.getActiveStatementCount());
            assertEquals(cachedSPS ? 0 : -1, getStmtsCacheSize.applyAsInt(testConn));
            assertTrue(testPstmt.isPoolable());
            // Caches this PS (*).
            testPstmt.close();
            assertEquals(cachedSPS ? 1 : -1, getStmtsCacheSize.applyAsInt(testConn));
            for (int i = 0; i < psCount; i++) {
                assertTrue(testPstmts1[i].isPoolable());
                // Caches this PS and replaces existing if same (*).
                testPstmts1[i].close();
                assertEquals(cachedSPS ? psCount - i + 1 : psCount - i - 1, testConn.getActiveStatementCount());
                assertEquals(cachedSPS ? 2 : -1, getStmtsCacheSize.applyAsInt(testConn));
            }
            PreparedStatement testPstmt1 = testConn.prepareStatement(sql1);
            assertEquals(cachedSPS ? 2 : 1, testConn.getActiveStatementCount());
            assertEquals(cachedSPS ? 1 : -1, getStmtsCacheSize.applyAsInt(testConn));
            for (int i = 0; i < psCount; i++) {
                if (cachedSPS && i == psCount - 1) {
                    assertSame(testPstmts1[i], testPstmt1);
                } else {
                    assertNotSame(testPstmts1[i], testPstmt1);
                }
            }
            PreparedStatement testPstmt2 = testConn.prepareStatement(sql2);
            assertEquals(2, testConn.getActiveStatementCount());
            assertEquals(cachedSPS ? 0 : -1, getStmtsCacheSize.applyAsInt(testConn));
            if (cachedSPS) {
                assertSame(testPstmt, testPstmt2);
            } else {
                assertNotSame(testPstmt, testPstmt2);
            }
            // Don't cache this PS (*).
            testPstmt1.setPoolable(false);
            // Doesn't cache this PS (*).
            testPstmt1.close();
            assertEquals(1, testConn.getActiveStatementCount());
            assertEquals(cachedSPS ? 0 : -1, getStmtsCacheSize.applyAsInt(testConn));
            // Don't cache this PS (*).
            testPstmt2.setPoolable(false);
            // Doesn't cache this PS (*).
            testPstmt2.close();
            assertEquals(0, testConn.getActiveStatementCount());
            assertEquals(cachedSPS ? 0 : -1, getStmtsCacheSize.applyAsInt(testConn));
            testConn.close();
            assertEquals(0, testConn.getActiveStatementCount());
            assertEquals(cachedSPS ? 0 : -1, getStmtsCacheSize.applyAsInt(testConn));
        }
    } while ((useSPS = !useSPS) || (cachePS = !cachePS));
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) BaseTestCase(testsuite.BaseTestCase) Connection(java.sql.Connection) CharArrayReader(java.io.CharArrayReader) Time(java.sql.Time) SQLFeatureNotSupportedException(java.sql.SQLFeatureNotSupportedException) MysqlType(com.mysql.cj.MysqlType) ZonedDateTime(java.time.ZonedDateTime) Assertions.assertNotEquals(org.junit.jupiter.api.Assertions.assertNotEquals) BigDecimal(java.math.BigDecimal) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) ByteArrayInputStream(java.io.ByteArrayInputStream) ResultSet(java.sql.ResultSet) LocalTime(java.time.LocalTime) JdbcConnection(com.mysql.cj.jdbc.JdbcConnection) CharsetMappingWrapper(com.mysql.cj.CharsetMappingWrapper) NClob(java.sql.NClob) ZoneOffset(java.time.ZoneOffset) OffsetTime(java.time.OffsetTime) MySQLStatementCancelledException(com.mysql.cj.jdbc.exceptions.MySQLStatementCancelledException) Timestamp(java.sql.Timestamp) ParameterBindings(com.mysql.cj.jdbc.ParameterBindings) Reader(java.io.Reader) Assertions.assertNotSame(org.junit.jupiter.api.Assertions.assertNotSame) PreparedStatement(java.sql.PreparedStatement) Test(org.junit.jupiter.api.Test) OffsetDateTime(java.time.OffsetDateTime) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) LocalDate(java.time.LocalDate) CallableStatement(java.sql.CallableStatement) MySQLTimeoutException(com.mysql.cj.jdbc.exceptions.MySQLTimeoutException) ResultSetMetaData(java.sql.ResultSetMetaData) Types(java.sql.Types) Assertions.fail(org.junit.jupiter.api.Assertions.fail) MysqlErrorNumbers(com.mysql.cj.exceptions.MysqlErrorNumbers) ServerPreparedStatement(com.mysql.cj.jdbc.ServerPreparedStatement) CountingReBalanceStrategy(testsuite.regression.ConnectionRegressionTest.CountingReBalanceStrategy) ByteArrayOutputStream(java.io.ByteArrayOutputStream) BatchUpdateException(java.sql.BatchUpdateException) LocalDateTime(java.time.LocalDateTime) SimpleDateFormat(java.text.SimpleDateFormat) Callable(java.util.concurrent.Callable) Function(java.util.function.Function) JDBCType(java.sql.JDBCType) SQLException(java.sql.SQLException) Assumptions.assumeTrue(org.junit.jupiter.api.Assumptions.assumeTrue) ClientPreparedStatement(com.mysql.cj.jdbc.ClientPreparedStatement) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Properties(java.util.Properties) ToIntFunction(java.util.function.ToIntFunction) ConnectionImpl(com.mysql.cj.jdbc.ConnectionImpl) LRUCache(com.mysql.cj.util.LRUCache) ServerStatusDiffInterceptor(com.mysql.cj.jdbc.interceptors.ServerStatusDiffInterceptor) Field(java.lang.reflect.Field) TimeUtil(com.mysql.cj.util.TimeUtil) Assertions.assertSame(org.junit.jupiter.api.Assertions.assertSame) Date(java.sql.Date) AfterEach(org.junit.jupiter.api.AfterEach) StringReader(java.io.StringReader) DateTimeFormatter(java.time.format.DateTimeFormatter) Statement(java.sql.Statement) StringUtils(com.mysql.cj.util.StringUtils) MysqlConnection(com.mysql.cj.MysqlConnection) PropertyKey(com.mysql.cj.conf.PropertyKey) InputStream(java.io.InputStream) SQLException(java.sql.SQLException) Connection(java.sql.Connection) JdbcConnection(com.mysql.cj.jdbc.JdbcConnection) MysqlConnection(com.mysql.cj.MysqlConnection) JdbcConnection(com.mysql.cj.jdbc.JdbcConnection) PreparedStatement(java.sql.PreparedStatement) ServerPreparedStatement(com.mysql.cj.jdbc.ServerPreparedStatement) ClientPreparedStatement(com.mysql.cj.jdbc.ClientPreparedStatement) Properties(java.util.Properties) Field(java.lang.reflect.Field) LRUCache(com.mysql.cj.util.LRUCache) ServerPreparedStatement(com.mysql.cj.jdbc.ServerPreparedStatement) Test(org.junit.jupiter.api.Test)

Example 4 with LRUCache

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

the class StatementsTest method testServerPreparedStatementsCaching.

/**
 * WL#11101 - Remove de-cache and close of SSPSs on double call to close()
 *
 * @throws Exception
 */
@Test
public void testServerPreparedStatementsCaching() throws Exception {
    // Non prepared statements must be non-poolable by default.
    assertFalse(this.stmt.isPoolable());
    Field stmtsCacheField = ConnectionImpl.class.getDeclaredField("serverSideStatementCache");
    stmtsCacheField.setAccessible(true);
    ToIntFunction<Connection> getStmtsCacheSize = (c) -> {
        try {
            LRUCache<?, ?> stmtsCacheObj = (LRUCache<?, ?>) stmtsCacheField.get(c);
            return stmtsCacheObj == null ? -1 : stmtsCacheObj.size();
        } catch (IllegalArgumentException | IllegalAccessException e) {
            fail("Fail getting the statemets cache size.");
            return -1;
        }
    };
    Function<Connection, ServerPreparedStatement> getStmtsCacheSingleElem = (c) -> {
        try {
            @SuppressWarnings("unchecked") LRUCache<?, ServerPreparedStatement> stmtsCacheObj = (LRUCache<?, ServerPreparedStatement>) stmtsCacheField.get(c);
            return stmtsCacheObj.get(stmtsCacheObj.keySet().iterator().next());
        } catch (IllegalArgumentException | IllegalAccessException e) {
            fail("Fail getting the statemets cache element.");
            return null;
        }
    };
    final String sql1 = "SELECT 1, ?";
    final String sql2 = "SELECT 2, ?";
    boolean useSPS = false;
    boolean cachePS = false;
    do {
        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));
        props.setProperty(PropertyKey.cachePrepStmts.getKeyName(), Boolean.toString(cachePS));
        props.setProperty(PropertyKey.prepStmtCacheSize.getKeyName(), "5");
        boolean cachedSPS = useSPS && cachePS;
        /*
             * Cache the prepared statement and de-cache it later.
             * (*) if server prepared statement and caching is enabled.
             */
        {
            JdbcConnection testConn = (JdbcConnection) getConnectionWithProps(props);
            PreparedStatement testPstmt = testConn.prepareStatement(sql1);
            assertEquals(1, testConn.getActiveStatementCount());
            assertEquals(cachedSPS ? 0 : -1, getStmtsCacheSize.applyAsInt(testConn));
            assertTrue(testPstmt.isPoolable());
            // Caches this PS (*).
            testPstmt.close();
            assertEquals(cachedSPS ? 1 : 0, testConn.getActiveStatementCount());
            assertEquals(cachedSPS ? 1 : -1, getStmtsCacheSize.applyAsInt(testConn));
            // No-op.
            testPstmt.close();
            assertEquals(cachedSPS ? 1 : 0, testConn.getActiveStatementCount());
            assertEquals(cachedSPS ? 1 : -1, getStmtsCacheSize.applyAsInt(testConn));
            if (cachedSPS) {
                assertTrue(testPstmt.isPoolable());
                // De-caches this PS; it gets automatically closed (*).
                testPstmt.setPoolable(false);
                assertEquals(0, testConn.getActiveStatementCount());
                assertEquals(0, getStmtsCacheSize.applyAsInt(testConn));
            }
            // No-op.
            testPstmt.close();
            assertEquals(0, testConn.getActiveStatementCount());
            assertEquals(cachedSPS ? 0 : -1, getStmtsCacheSize.applyAsInt(testConn));
            assertThrows(SQLException.class, "No operations allowed after statement closed\\.", () -> {
                testPstmt.setPoolable(false);
                return null;
            });
            assertThrows(SQLException.class, "No operations allowed after statement closed\\.", () -> {
                testPstmt.isPoolable();
                return null;
            });
            testConn.close();
            assertEquals(0, testConn.getActiveStatementCount());
            assertEquals(cachedSPS ? 0 : -1, getStmtsCacheSize.applyAsInt(testConn));
        }
        /*
             * Set not to cache the prepared statement.
             * (*) if server prepared statement and caching is enabled.
             */
        {
            JdbcConnection testConn = (JdbcConnection) getConnectionWithProps(props);
            PreparedStatement testPstmt = testConn.prepareStatement(sql1);
            assertEquals(1, testConn.getActiveStatementCount());
            assertEquals(cachedSPS ? 0 : -1, getStmtsCacheSize.applyAsInt(testConn));
            assertTrue(testPstmt.isPoolable());
            // Don't cache this PS (*).
            testPstmt.setPoolable(false);
            assertFalse(testPstmt.isPoolable());
            // Doesn't cache this PS (*).
            testPstmt.close();
            assertEquals(0, testConn.getActiveStatementCount());
            assertEquals(cachedSPS ? 0 : -1, getStmtsCacheSize.applyAsInt(testConn));
            // No-op.
            testPstmt.close();
            assertEquals(0, testConn.getActiveStatementCount());
            assertEquals(cachedSPS ? 0 : -1, getStmtsCacheSize.applyAsInt(testConn));
            assertThrows(SQLException.class, "No operations allowed after statement closed\\.", () -> {
                testPstmt.setPoolable(true);
                return null;
            });
            assertThrows(SQLException.class, "No operations allowed after statement closed\\.", () -> {
                testPstmt.isPoolable();
                return null;
            });
            testConn.close();
            assertEquals(0, testConn.getActiveStatementCount());
            assertEquals(cachedSPS ? 0 : -1, getStmtsCacheSize.applyAsInt(testConn));
        }
        /*
             * Set not to cache the prepared statement but change mind before closing it.
             * Reuse the cached prepared statement and don't re-cache it.
             * (*) if server prepared statement and caching is enabled.
             */
        {
            JdbcConnection testConn = (JdbcConnection) getConnectionWithProps(props);
            PreparedStatement testPstmt = testConn.prepareStatement(sql1);
            assertEquals(1, testConn.getActiveStatementCount());
            assertEquals(cachedSPS ? 0 : -1, getStmtsCacheSize.applyAsInt(testConn));
            // Don't cache this PS (*).
            testPstmt.setPoolable(false);
            assertFalse(testPstmt.isPoolable());
            testPstmt.setPoolable(true);
            // Changed my mind, let it be cached (*).
            assertTrue(testPstmt.isPoolable());
            // Caches this PS (*).
            testPstmt.close();
            assertEquals(cachedSPS ? 1 : 0, testConn.getActiveStatementCount());
            assertEquals(cachedSPS ? 1 : -1, getStmtsCacheSize.applyAsInt(testConn));
            // No-op.
            testPstmt.close();
            assertEquals(cachedSPS ? 1 : 0, testConn.getActiveStatementCount());
            assertEquals(cachedSPS ? 1 : -1, getStmtsCacheSize.applyAsInt(testConn));
            PreparedStatement testPstmtOld = testPstmt;
            // Takes the cached statement (*), or creates a fresh one.
            testPstmt = testConn.prepareStatement(sql1);
            if (cachedSPS) {
                assertSame(testPstmtOld, testPstmt);
            } else {
                assertNotSame(testPstmtOld, testPstmt);
            }
            assertEquals(1, testConn.getActiveStatementCount());
            assertEquals(cachedSPS ? 0 : -1, getStmtsCacheSize.applyAsInt(testConn));
            assertTrue(testPstmt.isPoolable());
            // Don't cache this PS (*).
            testPstmt.setPoolable(false);
            assertFalse(testPstmt.isPoolable());
            // Doesn't cache this PS (*).
            testPstmt.close();
            assertEquals(0, testConn.getActiveStatementCount());
            assertEquals(cachedSPS ? 0 : -1, getStmtsCacheSize.applyAsInt(testConn));
            testPstmtOld = testPstmt;
            // Creates a fresh prepared statement.
            testPstmt = testConn.prepareStatement(sql1);
            assertNotSame(testPstmtOld, testPstmt);
            assertEquals(1, testConn.getActiveStatementCount());
            assertEquals(cachedSPS ? 0 : -1, getStmtsCacheSize.applyAsInt(testConn));
            assertTrue(testPstmt.isPoolable());
            testConn.close();
            assertEquals(0, testConn.getActiveStatementCount());
            assertEquals(cachedSPS ? 0 : -1, getStmtsCacheSize.applyAsInt(testConn));
        }
        /*
             * Caching of multiple copies of same prepared statement.
             * (*) if server prepared statement and caching is enabled.
             */
        {
            int psCount = 5;
            JdbcConnection testConn = (JdbcConnection) getConnectionWithProps(props);
            PreparedStatement[] testPstmts = new PreparedStatement[psCount];
            for (int i = 0; i < psCount; i++) {
                testPstmts[i] = testConn.prepareStatement(sql1);
            }
            assertEquals(5, testConn.getActiveStatementCount());
            assertEquals(cachedSPS ? 0 : -1, getStmtsCacheSize.applyAsInt(testConn));
            for (int i = 0; i < psCount; i++) {
                assertTrue(testPstmts[i].isPoolable());
                // Caches this PS and replaces existing if same (*).
                testPstmts[i].close();
                assertEquals(cachedSPS ? psCount - i : psCount - i - 1, testConn.getActiveStatementCount());
                assertEquals(cachedSPS ? 1 : -1, getStmtsCacheSize.applyAsInt(testConn));
                if (cachedSPS) {
                    assertSame(testPstmts[i], getStmtsCacheSingleElem.apply(testConn));
                }
            }
            PreparedStatement testPstmt = testConn.prepareStatement(sql1);
            assertEquals(1, testConn.getActiveStatementCount());
            assertEquals(cachedSPS ? 0 : -1, getStmtsCacheSize.applyAsInt(testConn));
            for (int i = 0; i < psCount; i++) {
                if (cachedSPS && i == psCount - 1) {
                    assertSame(testPstmts[i], testPstmt);
                } else {
                    assertNotSame(testPstmts[i], testPstmt);
                }
            }
            // Don't cache this PS (*).
            testPstmt.setPoolable(false);
            // Doesn't cache this PS (*).
            testPstmt.close();
            assertEquals(0, testConn.getActiveStatementCount());
            assertEquals(cachedSPS ? 0 : -1, getStmtsCacheSize.applyAsInt(testConn));
            testConn.close();
            assertEquals(0, testConn.getActiveStatementCount());
            assertEquals(cachedSPS ? 0 : -1, getStmtsCacheSize.applyAsInt(testConn));
        }
        /*
             * Combine caching different prepared statements.
             * (*) if server prepared statement and caching is enabled.
             */
        {
            int psCount = 5;
            JdbcConnection testConn = (JdbcConnection) getConnectionWithProps(props);
            PreparedStatement[] testPstmts1 = new PreparedStatement[psCount];
            for (int i = 0; i < psCount; i++) {
                testPstmts1[i] = testConn.prepareStatement(sql1);
            }
            PreparedStatement testPstmt = testConn.prepareStatement(sql2);
            assertEquals(6, testConn.getActiveStatementCount());
            assertEquals(cachedSPS ? 0 : -1, getStmtsCacheSize.applyAsInt(testConn));
            assertTrue(testPstmt.isPoolable());
            // Caches this PS (*).
            testPstmt.close();
            assertEquals(cachedSPS ? 1 : -1, getStmtsCacheSize.applyAsInt(testConn));
            for (int i = 0; i < psCount; i++) {
                assertTrue(testPstmts1[i].isPoolable());
                // Caches this PS and replaces existing if same (*).
                testPstmts1[i].close();
                assertEquals(cachedSPS ? psCount - i + 1 : psCount - i - 1, testConn.getActiveStatementCount());
                assertEquals(cachedSPS ? 2 : -1, getStmtsCacheSize.applyAsInt(testConn));
            }
            PreparedStatement testPstmt1 = testConn.prepareStatement(sql1);
            assertEquals(cachedSPS ? 2 : 1, testConn.getActiveStatementCount());
            assertEquals(cachedSPS ? 1 : -1, getStmtsCacheSize.applyAsInt(testConn));
            for (int i = 0; i < psCount; i++) {
                if (cachedSPS && i == psCount - 1) {
                    assertSame(testPstmts1[i], testPstmt1);
                } else {
                    assertNotSame(testPstmts1[i], testPstmt1);
                }
            }
            PreparedStatement testPstmt2 = testConn.prepareStatement(sql2);
            assertEquals(2, testConn.getActiveStatementCount());
            assertEquals(cachedSPS ? 0 : -1, getStmtsCacheSize.applyAsInt(testConn));
            if (cachedSPS) {
                assertSame(testPstmt, testPstmt2);
            } else {
                assertNotSame(testPstmt, testPstmt2);
            }
            // Don't cache this PS (*).
            testPstmt1.setPoolable(false);
            // Doesn't cache this PS (*).
            testPstmt1.close();
            assertEquals(1, testConn.getActiveStatementCount());
            assertEquals(cachedSPS ? 0 : -1, getStmtsCacheSize.applyAsInt(testConn));
            // Don't cache this PS (*).
            testPstmt2.setPoolable(false);
            // Doesn't cache this PS (*).
            testPstmt2.close();
            assertEquals(0, testConn.getActiveStatementCount());
            assertEquals(cachedSPS ? 0 : -1, getStmtsCacheSize.applyAsInt(testConn));
            testConn.close();
            assertEquals(0, testConn.getActiveStatementCount());
            assertEquals(cachedSPS ? 0 : -1, getStmtsCacheSize.applyAsInt(testConn));
        }
    } while ((useSPS = !useSPS) || (cachePS = !cachePS));
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) BaseTestCase(testsuite.BaseTestCase) Connection(java.sql.Connection) CharArrayReader(java.io.CharArrayReader) Time(java.sql.Time) SQLFeatureNotSupportedException(java.sql.SQLFeatureNotSupportedException) MysqlType(com.mysql.cj.MysqlType) ZonedDateTime(java.time.ZonedDateTime) Assertions.assertNotEquals(org.junit.jupiter.api.Assertions.assertNotEquals) BigDecimal(java.math.BigDecimal) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) ByteArrayInputStream(java.io.ByteArrayInputStream) ResultSet(java.sql.ResultSet) SslMode(com.mysql.cj.conf.PropertyDefinitions.SslMode) LocalTime(java.time.LocalTime) JdbcConnection(com.mysql.cj.jdbc.JdbcConnection) CharsetMappingWrapper(com.mysql.cj.CharsetMappingWrapper) NClob(java.sql.NClob) ZoneOffset(java.time.ZoneOffset) OffsetTime(java.time.OffsetTime) MySQLStatementCancelledException(com.mysql.cj.jdbc.exceptions.MySQLStatementCancelledException) Timestamp(java.sql.Timestamp) ParameterBindings(com.mysql.cj.jdbc.ParameterBindings) Reader(java.io.Reader) Assertions.assertNotSame(org.junit.jupiter.api.Assertions.assertNotSame) PreparedStatement(java.sql.PreparedStatement) Test(org.junit.jupiter.api.Test) OffsetDateTime(java.time.OffsetDateTime) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) LocalDate(java.time.LocalDate) CallableStatement(java.sql.CallableStatement) MySQLTimeoutException(com.mysql.cj.jdbc.exceptions.MySQLTimeoutException) ResultSetMetaData(java.sql.ResultSetMetaData) Types(java.sql.Types) Assertions.fail(org.junit.jupiter.api.Assertions.fail) MysqlErrorNumbers(com.mysql.cj.exceptions.MysqlErrorNumbers) ServerPreparedStatement(com.mysql.cj.jdbc.ServerPreparedStatement) CountingReBalanceStrategy(testsuite.regression.ConnectionRegressionTest.CountingReBalanceStrategy) ByteArrayOutputStream(java.io.ByteArrayOutputStream) BatchUpdateException(java.sql.BatchUpdateException) LocalDateTime(java.time.LocalDateTime) SimpleDateFormat(java.text.SimpleDateFormat) Callable(java.util.concurrent.Callable) Function(java.util.function.Function) JDBCType(java.sql.JDBCType) SQLException(java.sql.SQLException) Assumptions.assumeTrue(org.junit.jupiter.api.Assumptions.assumeTrue) ClientPreparedStatement(com.mysql.cj.jdbc.ClientPreparedStatement) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Properties(java.util.Properties) ToIntFunction(java.util.function.ToIntFunction) ConnectionImpl(com.mysql.cj.jdbc.ConnectionImpl) LRUCache(com.mysql.cj.util.LRUCache) ServerStatusDiffInterceptor(com.mysql.cj.jdbc.interceptors.ServerStatusDiffInterceptor) Field(java.lang.reflect.Field) TimeUtil(com.mysql.cj.util.TimeUtil) Assertions.assertSame(org.junit.jupiter.api.Assertions.assertSame) Date(java.sql.Date) AfterEach(org.junit.jupiter.api.AfterEach) StringReader(java.io.StringReader) DateTimeFormatter(java.time.format.DateTimeFormatter) Statement(java.sql.Statement) StringUtils(com.mysql.cj.util.StringUtils) MysqlConnection(com.mysql.cj.MysqlConnection) PropertyKey(com.mysql.cj.conf.PropertyKey) InputStream(java.io.InputStream) SQLException(java.sql.SQLException) Connection(java.sql.Connection) JdbcConnection(com.mysql.cj.jdbc.JdbcConnection) MysqlConnection(com.mysql.cj.MysqlConnection) JdbcConnection(com.mysql.cj.jdbc.JdbcConnection) PreparedStatement(java.sql.PreparedStatement) ServerPreparedStatement(com.mysql.cj.jdbc.ServerPreparedStatement) ClientPreparedStatement(com.mysql.cj.jdbc.ClientPreparedStatement) Properties(java.util.Properties) Field(java.lang.reflect.Field) LRUCache(com.mysql.cj.util.LRUCache) ServerPreparedStatement(com.mysql.cj.jdbc.ServerPreparedStatement) Test(org.junit.jupiter.api.Test)

Example 5 with LRUCache

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

the class StatementRegressionTest method testBug87429.

/**
 * Tests fix for Bug#87429 - repeated close of ServerPreparedStatement causes memory leak.
 *
 * Original de-cache on double close() behavior modified by:
 * WL#11101 - Remove de-cache and close of SSPSs on double call to close().
 *
 * @throws Exception
 */
@Test
public void testBug87429() throws Exception {
    Field stmtsCacheField = ConnectionImpl.class.getDeclaredField("serverSideStatementCache");
    stmtsCacheField.setAccessible(true);
    ToIntFunction<Connection> getStmtsCacheSize = (c) -> {
        try {
            LRUCache<?, ?> stmtsCacheObj = (LRUCache<?, ?>) stmtsCacheField.get(c);
            return stmtsCacheObj == null ? -1 : stmtsCacheObj.size();
        } catch (IllegalArgumentException | IllegalAccessException e) {
            fail("Fail getting the statemets cache size.");
            return -1;
        }
    };
    final String sql1 = "SELECT 1, ?";
    final String sql2 = "SELECT 2, ?";
    boolean useSPS = false;
    boolean cachePS = false;
    do {
        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));
        props.setProperty(PropertyKey.cachePrepStmts.getKeyName(), Boolean.toString(cachePS));
        props.setProperty(PropertyKey.prepStmtCacheSize.getKeyName(), "5");
        boolean cachedSPS = useSPS && cachePS;
        JdbcConnection testConn = (JdbcConnection) getConnectionWithProps(props);
        // Single PreparedStatement, closed multiple times.
        for (int i = 0; i < 100; i++) {
            this.pstmt = testConn.prepareStatement(sql1);
            assertTrue(this.pstmt.isPoolable());
            assertEquals(1, testConn.getActiveStatementCount());
            assertEquals(cachedSPS ? 0 : -1, getStmtsCacheSize.applyAsInt(testConn));
            // Close & cache.
            this.pstmt.close();
            assertEquals(cachedSPS ? 1 : 0, testConn.getActiveStatementCount());
            assertEquals(cachedSPS ? 1 : -1, getStmtsCacheSize.applyAsInt(testConn));
            // No-op.
            this.pstmt.close();
            assertEquals(cachedSPS ? 1 : 0, testConn.getActiveStatementCount());
            assertEquals(cachedSPS ? 1 : -1, getStmtsCacheSize.applyAsInt(testConn));
            // No-op.
            this.pstmt.close();
            assertEquals(cachedSPS ? 1 : 0, testConn.getActiveStatementCount());
            assertEquals(cachedSPS ? 1 : -1, getStmtsCacheSize.applyAsInt(testConn));
            try {
                // De-caches the statement or no-op if not cached.
                this.pstmt.setPoolable(false);
            } catch (SQLException e) {
                assertFalse(cachedSPS, "Exception [" + e.getMessage() + "] not expected.");
            }
            // No-op.
            this.pstmt.close();
            assertEquals(0, testConn.getActiveStatementCount());
            assertEquals(cachedSPS ? 0 : -1, getStmtsCacheSize.applyAsInt(testConn));
        }
        testConn.close();
        assertEquals(0, testConn.getActiveStatementCount());
        assertEquals(cachedSPS ? 0 : -1, getStmtsCacheSize.applyAsInt(testConn));
        testConn = (JdbcConnection) getConnectionWithProps(props);
        // Multiple PreparedStatements interchanged, two queries, closed multiple times.
        for (int i = 0; i < 100; i++) {
            for (int j = 1; j <= 4; j++) {
                PreparedStatement pstmt1 = testConn.prepareStatement(j == 1 ? sql2 : sql1);
                PreparedStatement pstmt2 = testConn.prepareStatement(j == 2 ? sql2 : sql1);
                PreparedStatement pstmt3 = testConn.prepareStatement(j == 3 ? sql2 : sql1);
                PreparedStatement pstmt4 = testConn.prepareStatement(j == 4 ? sql2 : sql1);
                assertEquals(4, testConn.getActiveStatementCount());
                // Close and cache statements successively.
                pstmt4.close();
                // No-op.
                pstmt4.close();
                assertEquals(cachedSPS ? 4 : 3, testConn.getActiveStatementCount());
                pstmt3.close();
                // No-op.
                pstmt3.close();
                assertEquals(cachedSPS ? (j >= 3 ? 4 : 3) : 2, testConn.getActiveStatementCount());
                pstmt2.close();
                // No-op.
                pstmt2.close();
                assertEquals(cachedSPS ? (j >= 2 ? 3 : 2) : 1, testConn.getActiveStatementCount());
                pstmt1.close();
                // No-op.
                pstmt1.close();
                assertEquals(cachedSPS ? 2 : 0, testConn.getActiveStatementCount());
                // No-ops.
                pstmt4.close();
                pstmt4.close();
                pstmt3.close();
                pstmt3.close();
                pstmt2.close();
                pstmt2.close();
                pstmt1.close();
                pstmt1.close();
                assertEquals(cachedSPS ? 2 : 0, testConn.getActiveStatementCount());
                // De-cache statements successively.
                try {
                    // De-caches the statement or no-op if not cached.
                    pstmt4.setPoolable(false);
                } catch (SQLException e) {
                    assertFalse(cachedSPS && j == 4, "Exception [" + e.getMessage() + "] not expected.");
                }
                // No-op.
                pstmt4.close();
                assertEquals(cachedSPS ? (j < 4 ? 2 : 1) : 0, testConn.getActiveStatementCount());
                try {
                    // De-caches the statement or no-op if not cached.
                    pstmt3.setPoolable(false);
                } catch (SQLException e) {
                    assertFalse(cachedSPS && j == 3, "Exception [" + e.getMessage() + "] not expected.");
                }
                // No-op.
                pstmt3.close();
                assertEquals(cachedSPS ? (j < 3 ? 2 : 1) : 0, testConn.getActiveStatementCount());
                try {
                    // De-caches the statement or no-op if not cached.
                    pstmt2.setPoolable(false);
                } catch (SQLException e) {
                    assertFalse(cachedSPS && j == 2, "Exception [" + e.getMessage() + "] not expected.");
                }
                // No-op.
                pstmt2.close();
                assertEquals(cachedSPS ? 1 : 0, testConn.getActiveStatementCount());
                try {
                    // De-caches the statement or no-op if not cached.
                    pstmt1.setPoolable(false);
                } catch (SQLException e) {
                    assertFalse(cachedSPS, "Exception [" + e.getMessage() + "] not expected.");
                }
                // No-op.
                pstmt1.close();
                assertEquals(0, testConn.getActiveStatementCount());
            }
        }
        testConn.close();
        assertEquals(0, testConn.getActiveStatementCount());
    } while ((useSPS = !useSPS) || (cachePS = !cachePS));
}
Also used : Arrays(java.util.Arrays) BaseTestCase(testsuite.BaseTestCase) CharArrayReader(java.io.CharArrayReader) SerialBlob(javax.sql.rowset.serial.SerialBlob) Disabled(org.junit.jupiter.api.Disabled) NativeServerSession(com.mysql.cj.protocol.a.NativeServerSession) JdbcStatement(com.mysql.cj.jdbc.JdbcStatement) BigDecimal(java.math.BigDecimal) Future(java.util.concurrent.Future) ReplicationConnection(com.mysql.cj.jdbc.ha.ReplicationConnection) MysqlXADataSource(com.mysql.cj.jdbc.MysqlXADataSource) Assumptions.assumeFalse(org.junit.jupiter.api.Assumptions.assumeFalse) ResultSet(java.sql.ResultSet) Map(java.util.Map) SslMode(com.mysql.cj.conf.PropertyDefinitions.SslMode) BigInteger(java.math.BigInteger) CharsetMappingWrapper(com.mysql.cj.CharsetMappingWrapper) NClob(java.sql.NClob) WrongArgumentException(com.mysql.cj.exceptions.WrongArgumentException) CJCommunicationsException(com.mysql.cj.exceptions.CJCommunicationsException) DataTruncation(java.sql.DataTruncation) GregorianCalendar(java.util.GregorianCalendar) ClientPreparedQuery(com.mysql.cj.ClientPreparedQuery) ParameterBindings(com.mysql.cj.jdbc.ParameterBindings) JdbcPreparedStatement(com.mysql.cj.jdbc.JdbcPreparedStatement) Reader(java.io.Reader) Assertions.assertNotSame(org.junit.jupiter.api.Assertions.assertNotSame) PreparedStatement(java.sql.PreparedStatement) ZoneId(java.time.ZoneId) Executors(java.util.concurrent.Executors) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) RowId(java.sql.RowId) Ref(java.sql.Ref) ResultSetScannerInterceptor(com.mysql.cj.jdbc.interceptors.ResultSetScannerInterceptor) Assertions.fail(org.junit.jupiter.api.Assertions.fail) MysqlErrorNumbers(com.mysql.cj.exceptions.MysqlErrorNumbers) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) ByteArrayOutputStream(java.io.ByteArrayOutputStream) UnreliableSocketFactory(testsuite.UnreliableSocketFactory) Message(com.mysql.cj.protocol.Message) BatchUpdateException(java.sql.BatchUpdateException) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) LocalDateTime(java.time.LocalDateTime) SimpleDateFormat(java.text.SimpleDateFormat) Callable(java.util.concurrent.Callable) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) SQLException(java.sql.SQLException) Calendar(java.util.Calendar) Assumptions.assumeTrue(org.junit.jupiter.api.Assumptions.assumeTrue) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Clob(java.sql.Clob) Properties(java.util.Properties) ColumnDefinition(com.mysql.cj.protocol.ColumnDefinition) Log(com.mysql.cj.log.Log) ToIntFunction(java.util.function.ToIntFunction) ConnectionImpl(com.mysql.cj.jdbc.ConnectionImpl) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) Field(java.lang.reflect.Field) File(java.io.File) Assertions.assertSame(org.junit.jupiter.api.Assertions.assertSame) ExecutionException(java.util.concurrent.ExecutionException) StringReader(java.io.StringReader) Statement(java.sql.Statement) StringUtils(com.mysql.cj.util.StringUtils) Connection(java.sql.Connection) Time(java.sql.Time) ExceptionFactory(com.mysql.cj.exceptions.ExceptionFactory) URL(java.net.URL) XAConnection(javax.sql.XAConnection) CachedResultSetMetaData(com.mysql.cj.jdbc.result.CachedResultSetMetaData) SQLXML(java.sql.SQLXML) TimeoutException(java.util.concurrent.TimeoutException) Array(java.sql.Array) CompletionService(java.util.concurrent.CompletionService) ResultSetInternalMethods(com.mysql.cj.jdbc.result.ResultSetInternalMethods) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) ByteArrayInputStream(java.io.ByteArrayInputStream) Locale(java.util.Locale) LocalTime(java.time.LocalTime) JdbcConnection(com.mysql.cj.jdbc.JdbcConnection) StatementsTest(testsuite.simple.StatementsTest) SQLWarning(java.sql.SQLWarning) Resultset(com.mysql.cj.protocol.Resultset) ServerSession(com.mysql.cj.protocol.ServerSession) TimeZone(java.util.TimeZone) Timestamp(java.sql.Timestamp) Query(com.mysql.cj.Query) MysqlConnectionPoolDataSource(com.mysql.cj.jdbc.MysqlConnectionPoolDataSource) Session(com.mysql.cj.Session) Test(org.junit.jupiter.api.Test) List(java.util.List) LocalDate(java.time.LocalDate) Writer(java.io.Writer) CallableStatement(java.sql.CallableStatement) MySQLTimeoutException(com.mysql.cj.jdbc.exceptions.MySQLTimeoutException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ResultSetMetaData(java.sql.ResultSetMetaData) ExecutorCompletionService(java.util.concurrent.ExecutorCompletionService) Types(java.sql.Types) ServerPreparedStatement(com.mysql.cj.jdbc.ServerPreparedStatement) SQLSyntaxErrorException(java.sql.SQLSyntaxErrorException) ServerPreparedQuery(com.mysql.cj.ServerPreparedQuery) ClientPreparedStatement(com.mysql.cj.jdbc.ClientPreparedStatement) CommunicationsException(com.mysql.cj.jdbc.exceptions.CommunicationsException) ExecutorService(java.util.concurrent.ExecutorService) PrintStream(java.io.PrintStream) FileWriter(java.io.FileWriter) LRUCache(com.mysql.cj.util.LRUCache) TimeUtil(com.mysql.cj.util.TimeUtil) Date(java.sql.Date) DatabaseTerm(com.mysql.cj.conf.PropertyDefinitions.DatabaseTerm) TimeUnit(java.util.concurrent.TimeUnit) StatementImpl(com.mysql.cj.jdbc.StatementImpl) BaseQueryInterceptor(testsuite.BaseQueryInterceptor) MysqlConnection(com.mysql.cj.MysqlConnection) Blob(java.sql.Blob) ResultsetRows(com.mysql.cj.protocol.ResultsetRows) PropertyKey(com.mysql.cj.conf.PropertyKey) QueryInterceptor(com.mysql.cj.interceptors.QueryInterceptor) InputStream(java.io.InputStream) Field(java.lang.reflect.Field) LRUCache(com.mysql.cj.util.LRUCache) SQLException(java.sql.SQLException) ReplicationConnection(com.mysql.cj.jdbc.ha.ReplicationConnection) Connection(java.sql.Connection) XAConnection(javax.sql.XAConnection) JdbcConnection(com.mysql.cj.jdbc.JdbcConnection) MysqlConnection(com.mysql.cj.MysqlConnection) JdbcConnection(com.mysql.cj.jdbc.JdbcConnection) JdbcPreparedStatement(com.mysql.cj.jdbc.JdbcPreparedStatement) PreparedStatement(java.sql.PreparedStatement) ServerPreparedStatement(com.mysql.cj.jdbc.ServerPreparedStatement) ClientPreparedStatement(com.mysql.cj.jdbc.ClientPreparedStatement) Properties(java.util.Properties) StatementsTest(testsuite.simple.StatementsTest) Test(org.junit.jupiter.api.Test)

Aggregations

CharsetMappingWrapper (com.mysql.cj.CharsetMappingWrapper)6 MysqlConnection (com.mysql.cj.MysqlConnection)6 PropertyKey (com.mysql.cj.conf.PropertyKey)6 MysqlErrorNumbers (com.mysql.cj.exceptions.MysqlErrorNumbers)6 ClientPreparedStatement (com.mysql.cj.jdbc.ClientPreparedStatement)6 ConnectionImpl (com.mysql.cj.jdbc.ConnectionImpl)6 JdbcConnection (com.mysql.cj.jdbc.JdbcConnection)6 ParameterBindings (com.mysql.cj.jdbc.ParameterBindings)6 ServerPreparedStatement (com.mysql.cj.jdbc.ServerPreparedStatement)6 MySQLTimeoutException (com.mysql.cj.jdbc.exceptions.MySQLTimeoutException)6 LRUCache (com.mysql.cj.util.LRUCache)6 TimeUtil (com.mysql.cj.util.TimeUtil)6 ByteArrayInputStream (java.io.ByteArrayInputStream)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6 CharArrayReader (java.io.CharArrayReader)6 InputStream (java.io.InputStream)6 Reader (java.io.Reader)6 StringReader (java.io.StringReader)6 Field (java.lang.reflect.Field)6 BigDecimal (java.math.BigDecimal)6