use of com.mysql.cj.protocol.SocketConnection in project aws-mysql-jdbc by awslabs.
the class SimplePacketReaderTest method basicHeaderRead.
// the basic operation: make sure header bytes are interpreted properly
@Test
public void basicHeaderRead() throws IOException {
RuntimeProperty<Integer> maxAllowedPacket = new JdbcPropertySetImpl().getProperty(PropertyKey.maxAllowedPacket);
maxAllowedPacket.setValue(100000);
// mix up the bits so we know they're interpreted correctly
SocketConnection connection = new FixedBufferSocketConnection(new byte[] { 3, 2, 1, 42 });
MessageReader<NativePacketHeader, NativePacketPayload> reader = new SimplePacketReader(connection, maxAllowedPacket);
assertEquals(-1, reader.getMessageSequence());
NativePacketHeader hdr = reader.readHeader();
assertEquals(65536 + 512 + 3, hdr.getMessageSize());
assertEquals(42, hdr.getMessageSequence());
assertEquals(42, reader.getMessageSequence());
reader.resetMessageSequence();
assertEquals(0, reader.getMessageSequence());
}
use of com.mysql.cj.protocol.SocketConnection in project aws-mysql-jdbc by awslabs.
the class SimplePacketReaderTest method readBasicPayload.
// trivial payload test
@Test
public void readBasicPayload() throws IOException {
RuntimeProperty<Integer> maxAllowedPacket = new JdbcPropertySetImpl().getProperty(PropertyKey.maxAllowedPacket);
SocketConnection connection = new FixedBufferSocketConnection(new byte[] { 3, 2, 1, 6, 5, 4 });
MessageReader<NativePacketHeader, NativePacketPayload> reader = new SimplePacketReader(connection, maxAllowedPacket);
NativePacketPayload b = reader.readMessage(Optional.empty(), new NativePacketHeader(new byte[] { 3, 0, 0, 0 }));
assertEquals(3, b.getByteBuffer()[0]);
assertEquals(2, b.getByteBuffer()[1]);
assertEquals(1, b.getByteBuffer()[2]);
// make sure the first only consumed the requested 3 bytes
b = reader.readMessage(Optional.empty(), new NativePacketHeader(new byte[] { 3, 0, 0, 0 }));
assertEquals(6, b.getByteBuffer()[0]);
assertEquals(5, b.getByteBuffer()[1]);
assertEquals(4, b.getByteBuffer()[2]);
}
use of com.mysql.cj.protocol.SocketConnection in project aws-mysql-jdbc by awslabs.
the class NativeSession method connect.
public void connect(HostInfo hi, String user, String password, String database, int loginTimeout, TransactionEventHandler transactionManager) throws IOException {
this.hostInfo = hi;
// reset max-rows to default value
this.setSessionMaxRows(-1);
// TODO do we need different types of physical connections?
SocketConnection socketConnection = new NativeSocketConnection();
socketConnection.connect(this.hostInfo.getHost(), this.hostInfo.getPort(), this.propertySet, getExceptionInterceptor(), this.log, loginTimeout);
// physical connection is responsible *only* for I/O streams
if (this.protocol == null) {
this.protocol = NativeProtocol.getInstance(this, socketConnection, this.propertySet, this.log, transactionManager);
} else {
this.protocol.init(this, socketConnection, this.propertySet, transactionManager);
}
// use protocol to create a -> session
// protocol is responsible for building a session and authenticating (using AuthenticationProvider) internally
this.protocol.connect(user, password, database);
this.isClosed = false;
this.commandBuilder = new NativeMessageBuilder(this.getServerSession().supportsQueryAttributes());
}
Aggregations