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());
}
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();
}
}
}
Aggregations