use of com.mysql.cj.protocol.PacketSentTimeHolder in project JavaSegundasQuintas by ecteruel.
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);
}
use of com.mysql.cj.protocol.PacketSentTimeHolder in project JavaSegundasQuintas by ecteruel.
the class ConnectionRegressionTest method testBug44587.
/**
* Tests fix for BUG#44587, provide last packet sent/received timing in all connection failure errors.
*
* @throws Exception
*/
@Test
public void testBug44587() 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);
assertTrue(containsMessage(msg, "CommunicationsException.ServerPacketTimingInfo"));
}
use of com.mysql.cj.protocol.PacketSentTimeHolder in project ABC by RuiPinto96274.
the class ConnectionRegressionTest method testBug44587.
/**
* Tests fix for BUG#44587, provide last packet sent/received timing in all connection failure errors.
*
* @throws Exception
*/
@Test
public void testBug44587() 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);
assertTrue(containsMessage(msg, "CommunicationsException.ServerPacketTimingInfo"));
}
use of com.mysql.cj.protocol.PacketSentTimeHolder in project JavaSegundasQuintas by ecteruel.
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());
}
}
use of com.mysql.cj.protocol.PacketSentTimeHolder in project aws-mysql-jdbc by awslabs.
the class ConnectionRegressionTest method testBug44587.
/**
* Tests fix for BUG#44587, provide last packet sent/received timing in all connection failure errors.
*
* @throws Exception
*/
@Test
public void testBug44587() 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);
assertTrue(containsMessage(msg, "CommunicationsException.ServerPacketTimingInfo"));
}
Aggregations