Search in sources :

Example 6 with PacketSentTimeHolder

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

the class ExceptionsTest method testConstructors.

@Test
public void testConstructors() {
    new CommunicationsException(TEST_MESSAGE, new Throwable());
    new CommunicationsException((JdbcConnection) this.conn, new PacketSentTimeHolder() {
    }, new PacketReceivedTimeHolder() {
    }, new Exception());
    new ConnectionFeatureNotAvailableException(TEST_MESSAGE, new Throwable());
    new ConnectionFeatureNotAvailableException((JdbcConnection) this.conn, new PacketSentTimeHolder() {
    }, new Exception());
    new MysqlDataTruncation(TEST_MESSAGE, 0, false, false, 0, 0, 0);
    new MySQLQueryInterruptedException();
    new MySQLQueryInterruptedException(TEST_MESSAGE);
    new MySQLQueryInterruptedException(TEST_MESSAGE, TEST_SQL_STATE);
    new MySQLQueryInterruptedException(TEST_MESSAGE, TEST_SQL_STATE, 0);
    new MySQLStatementCancelledException();
    new MySQLStatementCancelledException(TEST_MESSAGE);
    new MySQLStatementCancelledException(TEST_MESSAGE, TEST_SQL_STATE);
    new MySQLStatementCancelledException(TEST_MESSAGE, TEST_SQL_STATE, 0);
    new MySQLTimeoutException();
    new MySQLTimeoutException(TEST_MESSAGE);
    new MySQLTimeoutException(TEST_MESSAGE, TEST_SQL_STATE);
    new MySQLTimeoutException(TEST_MESSAGE, TEST_SQL_STATE, 0);
    new MySQLTransactionRollbackException();
    new MySQLTransactionRollbackException(TEST_MESSAGE);
    new MySQLTransactionRollbackException(TEST_MESSAGE, TEST_SQL_STATE);
    new MySQLTransactionRollbackException(TEST_MESSAGE, TEST_SQL_STATE, 0);
    new NotUpdatable(TEST_MESSAGE);
    new OperationNotSupportedException();
    new OperationNotSupportedException(TEST_MESSAGE);
    new PacketTooBigException(TEST_MESSAGE);
    new PacketTooBigException(0, 100);
    new SQLError();
}
Also used : OperationNotSupportedException(com.mysql.cj.jdbc.exceptions.OperationNotSupportedException) PacketTooBigException(com.mysql.cj.jdbc.exceptions.PacketTooBigException) ConnectionFeatureNotAvailableException(com.mysql.cj.jdbc.exceptions.ConnectionFeatureNotAvailableException) MysqlDataTruncation(com.mysql.cj.jdbc.exceptions.MysqlDataTruncation) MySQLTransactionRollbackException(com.mysql.cj.jdbc.exceptions.MySQLTransactionRollbackException) PacketReceivedTimeHolder(com.mysql.cj.protocol.PacketReceivedTimeHolder) MySQLStatementCancelledException(com.mysql.cj.jdbc.exceptions.MySQLStatementCancelledException) MySQLQueryInterruptedException(com.mysql.cj.jdbc.exceptions.MySQLQueryInterruptedException) OperationNotSupportedException(com.mysql.cj.jdbc.exceptions.OperationNotSupportedException) ConnectionFeatureNotAvailableException(com.mysql.cj.jdbc.exceptions.ConnectionFeatureNotAvailableException) MySQLTransactionRollbackException(com.mysql.cj.jdbc.exceptions.MySQLTransactionRollbackException) SQLException(java.sql.SQLException) PacketTooBigException(com.mysql.cj.jdbc.exceptions.PacketTooBigException) MySQLTimeoutException(com.mysql.cj.jdbc.exceptions.MySQLTimeoutException) CommunicationsException(com.mysql.cj.jdbc.exceptions.CommunicationsException) NotUpdatable(com.mysql.cj.jdbc.exceptions.NotUpdatable) MySQLTimeoutException(com.mysql.cj.jdbc.exceptions.MySQLTimeoutException) SQLError(com.mysql.cj.jdbc.exceptions.SQLError) PacketSentTimeHolder(com.mysql.cj.protocol.PacketSentTimeHolder) MySQLStatementCancelledException(com.mysql.cj.jdbc.exceptions.MySQLStatementCancelledException) CommunicationsException(com.mysql.cj.jdbc.exceptions.CommunicationsException) MySQLQueryInterruptedException(com.mysql.cj.jdbc.exceptions.MySQLQueryInterruptedException) Test(org.junit.jupiter.api.Test)

Example 7 with PacketSentTimeHolder

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

the class ConnectionRegressionTest method testBug45419.

/**
 * Tests fix for BUG#45419, ensure that time is not converted to seconds before being reported as milliseconds.
 *
 * @throws Exception
 */
@Test
public void testBug45419() throws Exception {
    Exception e = null;
    String msg = ExceptionFactory.createLinkFailureMessageBasedOnHeuristics(((MysqlConnection) this.conn).getPropertySet(), ((MysqlConnection) this.conn).getSession().getServerSession(), new PacketSentTimeHolder() {

        @Override
        public long getPreviousPacketSentTime() {
            return System.currentTimeMillis() - 1000;
        }

        @Override
        public long getLastPacketSentTime() {
            return System.currentTimeMillis() - 1000;
        }
    }, new PacketReceivedTimeHolder() {

        @Override
        public long getLastPacketReceivedTime() {
            return System.currentTimeMillis() - 2000;
        }
    }, e);
    Matcher m = Pattern.compile("\\d.?\\d{3}", Pattern.MULTILINE).matcher(msg);
    assertTrue(m.find());
    assertTrue(Long.parseLong(m.group().replaceAll("[^\\d]", "")) >= 2000);
    assertTrue(m.find());
    assertTrue(Long.parseLong(m.group().replaceAll("[^\\d]", "")) >= 1000);
}
Also used : Matcher(java.util.regex.Matcher) PacketSentTimeHolder(com.mysql.cj.protocol.PacketSentTimeHolder) MysqlConnection(com.mysql.cj.MysqlConnection) PacketReceivedTimeHolder(com.mysql.cj.protocol.PacketReceivedTimeHolder) SQLFeatureNotSupportedException(java.sql.SQLFeatureNotSupportedException) SQLTransientException(java.sql.SQLTransientException) InvocationTargetException(java.lang.reflect.InvocationTargetException) XAException(javax.transaction.xa.XAException) SocketException(java.net.SocketException) SQLClientInfoException(java.sql.SQLClientInfoException) SQLException(java.sql.SQLException) SocketTimeoutException(java.net.SocketTimeoutException) IOException(java.io.IOException) PasswordExpiredException(com.mysql.cj.exceptions.PasswordExpiredException) ExecutionException(java.util.concurrent.ExecutionException) TimeoutException(java.util.concurrent.TimeoutException) SQLNonTransientConnectionException(java.sql.SQLNonTransientConnectionException) CommunicationsException(com.mysql.cj.jdbc.exceptions.CommunicationsException) CertificateException(java.security.cert.CertificateException) ClosedOnExpiredPasswordException(com.mysql.cj.exceptions.ClosedOnExpiredPasswordException) PropertyNotModifiableException(com.mysql.cj.exceptions.PropertyNotModifiableException) Test(org.junit.jupiter.api.Test)

Example 8 with PacketSentTimeHolder

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

the class NativeSocketConnection method connect.

@Override
public void connect(String hostName, int portNumber, PropertySet propSet, ExceptionInterceptor excInterceptor, Log log, int loginTimeout) {
    try {
        this.port = portNumber;
        this.host = hostName;
        this.propertySet = propSet;
        this.exceptionInterceptor = excInterceptor;
        this.socketFactory = createSocketFactory(propSet.getStringProperty(PropertyKey.socketFactory).getStringValue());
        this.mysqlSocket = this.socketFactory.connect(this.host, this.port, propSet, loginTimeout);
        int socketTimeout = propSet.getIntegerProperty(PropertyKey.socketTimeout).getValue();
        if (socketTimeout != 0) {
            try {
                this.mysqlSocket.setSoTimeout(socketTimeout);
            } catch (Exception ex) {
            /* Ignore if the platform does not support it */
            }
        }
        this.socketFactory.beforeHandshake();
        InputStream rawInputStream;
        if (propSet.getBooleanProperty(PropertyKey.useReadAheadInput).getValue()) {
            rawInputStream = new ReadAheadInputStream(this.mysqlSocket.getInputStream(), 16384, propSet.getBooleanProperty(PropertyKey.traceProtocol).getValue(), log);
        } else if (propSet.getBooleanProperty(PropertyKey.useUnbufferedInput).getValue()) {
            rawInputStream = this.mysqlSocket.getInputStream();
        } else {
            rawInputStream = new BufferedInputStream(this.mysqlSocket.getInputStream(), 16384);
        }
        this.mysqlInput = new FullReadInputStream(rawInputStream);
        this.mysqlOutput = new BufferedOutputStream(this.mysqlSocket.getOutputStream(), 16384);
    } catch (IOException ioEx) {
        throw ExceptionFactory.createCommunicationsException(propSet, null, new PacketSentTimeHolder() {
        }, null, ioEx, getExceptionInterceptor());
    }
}
Also used : FullReadInputStream(com.mysql.cj.protocol.FullReadInputStream) BufferedInputStream(java.io.BufferedInputStream) BufferedInputStream(java.io.BufferedInputStream) ReadAheadInputStream(com.mysql.cj.protocol.ReadAheadInputStream) FullReadInputStream(com.mysql.cj.protocol.FullReadInputStream) InputStream(java.io.InputStream) PacketSentTimeHolder(com.mysql.cj.protocol.PacketSentTimeHolder) ReadAheadInputStream(com.mysql.cj.protocol.ReadAheadInputStream) IOException(java.io.IOException) BufferedOutputStream(java.io.BufferedOutputStream) IOException(java.io.IOException) SSLParamsException(com.mysql.cj.exceptions.SSLParamsException) FeatureNotAvailableException(com.mysql.cj.exceptions.FeatureNotAvailableException)

Example 9 with PacketSentTimeHolder

use of com.mysql.cj.protocol.PacketSentTimeHolder in project ABC by RuiPinto96274.

the class ExceptionsTest method testConstructors.

@Test
public void testConstructors() {
    new CommunicationsException(TEST_MESSAGE, new Throwable());
    new CommunicationsException((JdbcConnection) this.conn, new PacketSentTimeHolder() {
    }, new PacketReceivedTimeHolder() {
    }, new Exception());
    new ConnectionFeatureNotAvailableException(TEST_MESSAGE, new Throwable());
    new ConnectionFeatureNotAvailableException((JdbcConnection) this.conn, new PacketSentTimeHolder() {
    }, new Exception());
    new MysqlDataTruncation(TEST_MESSAGE, 0, false, false, 0, 0, 0);
    new MySQLQueryInterruptedException();
    new MySQLQueryInterruptedException(TEST_MESSAGE);
    new MySQLQueryInterruptedException(TEST_MESSAGE, TEST_SQL_STATE);
    new MySQLQueryInterruptedException(TEST_MESSAGE, TEST_SQL_STATE, 0);
    new MySQLStatementCancelledException();
    new MySQLStatementCancelledException(TEST_MESSAGE);
    new MySQLStatementCancelledException(TEST_MESSAGE, TEST_SQL_STATE);
    new MySQLStatementCancelledException(TEST_MESSAGE, TEST_SQL_STATE, 0);
    new MySQLTimeoutException();
    new MySQLTimeoutException(TEST_MESSAGE);
    new MySQLTimeoutException(TEST_MESSAGE, TEST_SQL_STATE);
    new MySQLTimeoutException(TEST_MESSAGE, TEST_SQL_STATE, 0);
    new MySQLTransactionRollbackException();
    new MySQLTransactionRollbackException(TEST_MESSAGE);
    new MySQLTransactionRollbackException(TEST_MESSAGE, TEST_SQL_STATE);
    new MySQLTransactionRollbackException(TEST_MESSAGE, TEST_SQL_STATE, 0);
    new NotUpdatable(TEST_MESSAGE);
    new OperationNotSupportedException();
    new OperationNotSupportedException(TEST_MESSAGE);
    new PacketTooBigException(TEST_MESSAGE);
    new PacketTooBigException(0, 100);
    new SQLError();
}
Also used : OperationNotSupportedException(com.mysql.cj.jdbc.exceptions.OperationNotSupportedException) PacketTooBigException(com.mysql.cj.jdbc.exceptions.PacketTooBigException) ConnectionFeatureNotAvailableException(com.mysql.cj.jdbc.exceptions.ConnectionFeatureNotAvailableException) MysqlDataTruncation(com.mysql.cj.jdbc.exceptions.MysqlDataTruncation) MySQLTransactionRollbackException(com.mysql.cj.jdbc.exceptions.MySQLTransactionRollbackException) PacketReceivedTimeHolder(com.mysql.cj.protocol.PacketReceivedTimeHolder) MySQLStatementCancelledException(com.mysql.cj.jdbc.exceptions.MySQLStatementCancelledException) MySQLQueryInterruptedException(com.mysql.cj.jdbc.exceptions.MySQLQueryInterruptedException) OperationNotSupportedException(com.mysql.cj.jdbc.exceptions.OperationNotSupportedException) ConnectionFeatureNotAvailableException(com.mysql.cj.jdbc.exceptions.ConnectionFeatureNotAvailableException) MySQLTransactionRollbackException(com.mysql.cj.jdbc.exceptions.MySQLTransactionRollbackException) SQLException(java.sql.SQLException) PacketTooBigException(com.mysql.cj.jdbc.exceptions.PacketTooBigException) MySQLTimeoutException(com.mysql.cj.jdbc.exceptions.MySQLTimeoutException) CommunicationsException(com.mysql.cj.jdbc.exceptions.CommunicationsException) NotUpdatable(com.mysql.cj.jdbc.exceptions.NotUpdatable) MySQLTimeoutException(com.mysql.cj.jdbc.exceptions.MySQLTimeoutException) SQLError(com.mysql.cj.jdbc.exceptions.SQLError) PacketSentTimeHolder(com.mysql.cj.protocol.PacketSentTimeHolder) MySQLStatementCancelledException(com.mysql.cj.jdbc.exceptions.MySQLStatementCancelledException) CommunicationsException(com.mysql.cj.jdbc.exceptions.CommunicationsException) MySQLQueryInterruptedException(com.mysql.cj.jdbc.exceptions.MySQLQueryInterruptedException) Test(org.junit.jupiter.api.Test)

Example 10 with PacketSentTimeHolder

use of com.mysql.cj.protocol.PacketSentTimeHolder in project JavaSegundasQuintas by ecteruel.

the class ExceptionsTest method testConstructors.

@Test
public void testConstructors() {
    new CommunicationsException(TEST_MESSAGE, new Throwable());
    new CommunicationsException((JdbcConnection) this.conn, new PacketSentTimeHolder() {
    }, new PacketReceivedTimeHolder() {
    }, new Exception());
    new ConnectionFeatureNotAvailableException(TEST_MESSAGE, new Throwable());
    new ConnectionFeatureNotAvailableException((JdbcConnection) this.conn, new PacketSentTimeHolder() {
    }, new Exception());
    new MysqlDataTruncation(TEST_MESSAGE, 0, false, false, 0, 0, 0);
    new MySQLQueryInterruptedException();
    new MySQLQueryInterruptedException(TEST_MESSAGE);
    new MySQLQueryInterruptedException(TEST_MESSAGE, TEST_SQL_STATE);
    new MySQLQueryInterruptedException(TEST_MESSAGE, TEST_SQL_STATE, 0);
    new MySQLStatementCancelledException();
    new MySQLStatementCancelledException(TEST_MESSAGE);
    new MySQLStatementCancelledException(TEST_MESSAGE, TEST_SQL_STATE);
    new MySQLStatementCancelledException(TEST_MESSAGE, TEST_SQL_STATE, 0);
    new MySQLTimeoutException();
    new MySQLTimeoutException(TEST_MESSAGE);
    new MySQLTimeoutException(TEST_MESSAGE, TEST_SQL_STATE);
    new MySQLTimeoutException(TEST_MESSAGE, TEST_SQL_STATE, 0);
    new MySQLTransactionRollbackException();
    new MySQLTransactionRollbackException(TEST_MESSAGE);
    new MySQLTransactionRollbackException(TEST_MESSAGE, TEST_SQL_STATE);
    new MySQLTransactionRollbackException(TEST_MESSAGE, TEST_SQL_STATE, 0);
    new NotUpdatable(TEST_MESSAGE);
    new OperationNotSupportedException();
    new OperationNotSupportedException(TEST_MESSAGE);
    new PacketTooBigException(TEST_MESSAGE);
    new PacketTooBigException(0, 100);
    new SQLError();
}
Also used : OperationNotSupportedException(com.mysql.cj.jdbc.exceptions.OperationNotSupportedException) PacketTooBigException(com.mysql.cj.jdbc.exceptions.PacketTooBigException) ConnectionFeatureNotAvailableException(com.mysql.cj.jdbc.exceptions.ConnectionFeatureNotAvailableException) MysqlDataTruncation(com.mysql.cj.jdbc.exceptions.MysqlDataTruncation) MySQLTransactionRollbackException(com.mysql.cj.jdbc.exceptions.MySQLTransactionRollbackException) PacketReceivedTimeHolder(com.mysql.cj.protocol.PacketReceivedTimeHolder) MySQLStatementCancelledException(com.mysql.cj.jdbc.exceptions.MySQLStatementCancelledException) MySQLQueryInterruptedException(com.mysql.cj.jdbc.exceptions.MySQLQueryInterruptedException) OperationNotSupportedException(com.mysql.cj.jdbc.exceptions.OperationNotSupportedException) ConnectionFeatureNotAvailableException(com.mysql.cj.jdbc.exceptions.ConnectionFeatureNotAvailableException) MySQLTransactionRollbackException(com.mysql.cj.jdbc.exceptions.MySQLTransactionRollbackException) SQLException(java.sql.SQLException) PacketTooBigException(com.mysql.cj.jdbc.exceptions.PacketTooBigException) MySQLTimeoutException(com.mysql.cj.jdbc.exceptions.MySQLTimeoutException) CommunicationsException(com.mysql.cj.jdbc.exceptions.CommunicationsException) NotUpdatable(com.mysql.cj.jdbc.exceptions.NotUpdatable) MySQLTimeoutException(com.mysql.cj.jdbc.exceptions.MySQLTimeoutException) SQLError(com.mysql.cj.jdbc.exceptions.SQLError) PacketSentTimeHolder(com.mysql.cj.protocol.PacketSentTimeHolder) MySQLStatementCancelledException(com.mysql.cj.jdbc.exceptions.MySQLStatementCancelledException) CommunicationsException(com.mysql.cj.jdbc.exceptions.CommunicationsException) MySQLQueryInterruptedException(com.mysql.cj.jdbc.exceptions.MySQLQueryInterruptedException) Test(org.junit.jupiter.api.Test)

Aggregations

PacketSentTimeHolder (com.mysql.cj.protocol.PacketSentTimeHolder)12 CommunicationsException (com.mysql.cj.jdbc.exceptions.CommunicationsException)9 PacketReceivedTimeHolder (com.mysql.cj.protocol.PacketReceivedTimeHolder)9 IOException (java.io.IOException)9 SQLException (java.sql.SQLException)9 Test (org.junit.jupiter.api.Test)9 MysqlConnection (com.mysql.cj.MysqlConnection)6 ClosedOnExpiredPasswordException (com.mysql.cj.exceptions.ClosedOnExpiredPasswordException)6 PasswordExpiredException (com.mysql.cj.exceptions.PasswordExpiredException)6 PropertyNotModifiableException (com.mysql.cj.exceptions.PropertyNotModifiableException)6 InvocationTargetException (java.lang.reflect.InvocationTargetException)6 SocketException (java.net.SocketException)6 SocketTimeoutException (java.net.SocketTimeoutException)6 CertificateException (java.security.cert.CertificateException)6 SQLClientInfoException (java.sql.SQLClientInfoException)6 SQLFeatureNotSupportedException (java.sql.SQLFeatureNotSupportedException)6 SQLNonTransientConnectionException (java.sql.SQLNonTransientConnectionException)6 SQLTransientException (java.sql.SQLTransientException)6 ExecutionException (java.util.concurrent.ExecutionException)6 TimeoutException (java.util.concurrent.TimeoutException)6