Search in sources :

Example 1 with NativePacketHeader

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

the class ConnectionRegressionTest method testBug25642021.

/**
 * Tests fix for BUG#25642021, CHANGEUSER() FAILS WHEN ENABLEPACKETDEBUG=TRUE.
 *
 * @throws Exception
 */
@Test
public void testBug25642021() throws Exception {
    Properties props = getPropertiesFromTestsuiteUrl();
    props.setProperty(PropertyKey.sslMode.getKeyName(), SslMode.DISABLED.name());
    props.setProperty(PropertyKey.allowPublicKeyRetrieval.getKeyName(), "true");
    props.setProperty(PropertyKey.enablePacketDebug.getKeyName(), "true");
    props.setProperty(PropertyKey.maintainTimeStats.getKeyName(), "true");
    Connection newConn = getConnectionWithProps(props);
    ((JdbcConnection) newConn).changeUser(props.getProperty(PropertyKey.USER.getKeyName()), props.getProperty(PropertyKey.PASSWORD.getKeyName()));
    // check that decorators are still in place
    NativeProtocol p = ((NativeSession) ((JdbcConnection) newConn).getSession()).getProtocol();
    MessageSender<NativePacketPayload> sender = p.getPacketSender();
    MessageReader<NativePacketHeader, NativePacketPayload> reader = p.getPacketReader();
    assertEquals(DebugBufferingPacketSender.class, sender.getClass());
    assertEquals(TimeTrackingPacketSender.class, sender.undecorate().getClass());
    assertEquals(SimplePacketSender.class, sender.undecorate().undecorate().getClass());
    assertEquals(SimplePacketSender.class, sender.undecorate().undecorate().undecorate().getClass());
    assertEquals(MultiPacketReader.class, reader.getClass());
    assertEquals(DebugBufferingPacketReader.class, reader.undecorate().getClass());
    assertEquals(TimeTrackingPacketReader.class, reader.undecorate().undecorate().getClass());
    assertEquals(SimplePacketReader.class, reader.undecorate().undecorate().undecorate().getClass());
    assertEquals(SimplePacketReader.class, reader.undecorate().undecorate().undecorate().undecorate().getClass());
}
Also used : ReplicationConnection(com.mysql.cj.jdbc.ha.ReplicationConnection) MysqlPooledConnection(com.mysql.cj.jdbc.MysqlPooledConnection) SuspendableXAConnection(com.mysql.cj.jdbc.SuspendableXAConnection) Connection(java.sql.Connection) XAConnection(javax.sql.XAConnection) PooledConnection(javax.sql.PooledConnection) MysqlXAConnection(com.mysql.cj.jdbc.MysqlXAConnection) JdbcConnection(com.mysql.cj.jdbc.JdbcConnection) MysqlConnection(com.mysql.cj.MysqlConnection) NativeSession(com.mysql.cj.NativeSession) JdbcConnection(com.mysql.cj.jdbc.JdbcConnection) NativeProtocol(com.mysql.cj.protocol.a.NativeProtocol) Properties(java.util.Properties) NativePacketPayload(com.mysql.cj.protocol.a.NativePacketPayload) NativePacketHeader(com.mysql.cj.protocol.a.NativePacketHeader) Test(org.junit.jupiter.api.Test)

Example 2 with NativePacketHeader

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

the class ConnectionTest method testDecoratorsChain.

@Test
public void testDecoratorsChain() throws Exception {
    Connection c = null;
    try {
        Properties props = new Properties();
        props.setProperty(PropertyKey.sslMode.getKeyName(), SslMode.DISABLED.name());
        props.setProperty(PropertyKey.allowPublicKeyRetrieval.getKeyName(), "true");
        props.setProperty(PropertyKey.useCompression.getKeyName(), "false");
        props.setProperty(PropertyKey.maintainTimeStats.getKeyName(), "true");
        props.setProperty(PropertyKey.traceProtocol.getKeyName(), "true");
        props.setProperty(PropertyKey.enablePacketDebug.getKeyName(), "true");
        c = getConnectionWithProps(props);
        NativeProtocol p = ((NativeSession) ((JdbcConnection) c).getSession()).getProtocol();
        MessageSender<NativePacketPayload> sender = p.getPacketSender();
        MessageReader<NativePacketHeader, NativePacketPayload> reader = p.getPacketReader();
        assertEquals(DebugBufferingPacketSender.class, sender.getClass());
        assertEquals(TracingPacketSender.class, sender.undecorate().getClass());
        assertEquals(TimeTrackingPacketSender.class, sender.undecorate().undecorate().getClass());
        assertEquals(SimplePacketSender.class, sender.undecorate().undecorate().undecorate().getClass());
        assertEquals(MultiPacketReader.class, reader.getClass());
        assertEquals(DebugBufferingPacketReader.class, reader.undecorate().getClass());
        assertEquals(TracingPacketReader.class, reader.undecorate().undecorate().getClass());
        assertEquals(TimeTrackingPacketReader.class, reader.undecorate().undecorate().undecorate().getClass());
        assertEquals(SimplePacketReader.class, reader.undecorate().undecorate().undecorate().undecorate().getClass());
        // remove traceProtocol
        p.getPropertySet().getProperty(PropertyKey.traceProtocol).setValue(false);
        sender = p.getPacketSender();
        reader = p.getPacketReader();
        assertEquals(DebugBufferingPacketSender.class, sender.getClass());
        assertEquals(TimeTrackingPacketSender.class, sender.undecorate().getClass());
        assertEquals(SimplePacketSender.class, sender.undecorate().undecorate().getClass());
        assertEquals(MultiPacketReader.class, reader.getClass());
        assertEquals(DebugBufferingPacketReader.class, reader.undecorate().getClass());
        assertEquals(TimeTrackingPacketReader.class, reader.undecorate().undecorate().getClass());
        assertEquals(SimplePacketReader.class, reader.undecorate().undecorate().undecorate().getClass());
        // remove maintainTimeStats
        p.getPropertySet().getProperty(PropertyKey.maintainTimeStats).setValue(false);
        sender = p.getPacketSender();
        reader = p.getPacketReader();
        assertEquals(DebugBufferingPacketSender.class, sender.getClass());
        assertEquals(SimplePacketSender.class, sender.undecorate().getClass());
        assertEquals(MultiPacketReader.class, reader.getClass());
        assertEquals(DebugBufferingPacketReader.class, reader.undecorate().getClass());
        assertEquals(SimplePacketReader.class, reader.undecorate().undecorate().getClass());
        assertNotEquals(TimeTrackingPacketSender.class, p.getPacketSentTimeHolder().getClass());
        assertNotEquals(TimeTrackingPacketReader.class, p.getPacketReceivedTimeHolder().getClass());
        // remove enablePacketDebug
        p.getPropertySet().getProperty(PropertyKey.enablePacketDebug).setValue(false);
        sender = p.getPacketSender();
        reader = p.getPacketReader();
        assertEquals(SimplePacketSender.class, sender.getClass());
        assertEquals(MultiPacketReader.class, reader.getClass());
        assertEquals(SimplePacketReader.class, reader.undecorate().getClass());
        // add maintainTimeStats
        p.getPropertySet().getProperty(PropertyKey.maintainTimeStats).setValue(true);
        sender = p.getPacketSender();
        reader = p.getPacketReader();
        assertEquals(TimeTrackingPacketSender.class, sender.getClass());
        assertEquals(SimplePacketSender.class, sender.undecorate().getClass());
        assertEquals(MultiPacketReader.class, reader.getClass());
        assertEquals(TimeTrackingPacketReader.class, reader.undecorate().getClass());
        assertEquals(SimplePacketReader.class, reader.undecorate().undecorate().getClass());
        assertEquals(TimeTrackingPacketSender.class, p.getPacketSentTimeHolder().getClass());
        assertEquals(TimeTrackingPacketReader.class, p.getPacketReceivedTimeHolder().getClass());
        // remove listener and try to enable traceProtocol, it should be missed in this case
        p.getPropertySet().getBooleanProperty(PropertyKey.traceProtocol).removeListener(p);
        // please note that the property is changed anyways, see the next step
        p.getPropertySet().getProperty(PropertyKey.traceProtocol).setValue(true);
        sender = p.getPacketSender();
        reader = p.getPacketReader();
        assertEquals(TimeTrackingPacketSender.class, sender.getClass());
        assertEquals(SimplePacketSender.class, sender.undecorate().getClass());
        assertEquals(MultiPacketReader.class, reader.getClass());
        assertEquals(TimeTrackingPacketReader.class, reader.undecorate().getClass());
        assertEquals(SimplePacketReader.class, reader.undecorate().undecorate().getClass());
        // ensure that other listeners are still working
        p.getPropertySet().getProperty(PropertyKey.enablePacketDebug).setValue(true);
        sender = p.getPacketSender();
        reader = p.getPacketReader();
        assertEquals(DebugBufferingPacketSender.class, sender.getClass());
        // it's here because we changed the traceProtocol previously
        assertEquals(TracingPacketSender.class, sender.undecorate().getClass());
        assertEquals(TimeTrackingPacketSender.class, sender.undecorate().undecorate().getClass());
        assertEquals(SimplePacketSender.class, sender.undecorate().undecorate().undecorate().getClass());
        assertEquals(MultiPacketReader.class, reader.getClass());
        assertEquals(DebugBufferingPacketReader.class, reader.undecorate().getClass());
        assertEquals(TracingPacketReader.class, reader.undecorate().undecorate().getClass());
        assertEquals(TimeTrackingPacketReader.class, reader.undecorate().undecorate().undecorate().getClass());
        assertEquals(SimplePacketReader.class, reader.undecorate().undecorate().undecorate().undecorate().getClass());
    } finally {
        if (c != null) {
            c.close();
        }
    }
}
Also used : Connection(java.sql.Connection) JdbcConnection(com.mysql.cj.jdbc.JdbcConnection) MysqlConnection(com.mysql.cj.MysqlConnection) NativeSession(com.mysql.cj.NativeSession) NativeProtocol(com.mysql.cj.protocol.a.NativeProtocol) Properties(java.util.Properties) NativePacketPayload(com.mysql.cj.protocol.a.NativePacketPayload) NativePacketHeader(com.mysql.cj.protocol.a.NativePacketHeader) Test(org.junit.jupiter.api.Test)

Aggregations

MysqlConnection (com.mysql.cj.MysqlConnection)2 NativeSession (com.mysql.cj.NativeSession)2 JdbcConnection (com.mysql.cj.jdbc.JdbcConnection)2 NativePacketHeader (com.mysql.cj.protocol.a.NativePacketHeader)2 NativePacketPayload (com.mysql.cj.protocol.a.NativePacketPayload)2 NativeProtocol (com.mysql.cj.protocol.a.NativeProtocol)2 Connection (java.sql.Connection)2 Properties (java.util.Properties)2 Test (org.junit.jupiter.api.Test)2 MysqlPooledConnection (com.mysql.cj.jdbc.MysqlPooledConnection)1 MysqlXAConnection (com.mysql.cj.jdbc.MysqlXAConnection)1 SuspendableXAConnection (com.mysql.cj.jdbc.SuspendableXAConnection)1 ReplicationConnection (com.mysql.cj.jdbc.ha.ReplicationConnection)1 PooledConnection (javax.sql.PooledConnection)1 XAConnection (javax.sql.XAConnection)1