Skip to content

Commit bec58ee

Browse files
committed
Improved on pull request #55
1 parent cdf85f7 commit bec58ee

File tree

2 files changed

+13
-15
lines changed

2 files changed

+13
-15
lines changed

src/main/java/com/github/shyiko/mysql/binlog/BinaryLogClient.java

+10-5
Original file line numberDiff line numberDiff line change
@@ -670,11 +670,16 @@ private void updateGtidSet(Event event) {
670670

671671
private ResultSetRowPacket[] readResultSet() throws IOException {
672672
List<ResultSetRowPacket> resultSet = new LinkedList<ResultSetRowPacket>();
673-
if ((channel.read())[0] != (byte) 0xFF /* error */) {
674-
while ((channel.read())[0] != (byte) 0xFE /* eof */) { /* skip */ }
675-
for (byte[] bytes; (bytes = channel.read())[0] != (byte) 0xFE /* eof */; ) {
676-
resultSet.add(new ResultSetRowPacket(bytes));
677-
}
673+
byte[] statementResult = channel.read();
674+
if (statementResult[0] == (byte) 0xFF /* error */) {
675+
byte[] bytes = Arrays.copyOfRange(statementResult, 1, statementResult.length);
676+
ErrorPacket errorPacket = new ErrorPacket(bytes);
677+
throw new ServerException(errorPacket.getErrorMessage(), errorPacket.getErrorCode(),
678+
errorPacket.getSqlState());
679+
}
680+
while ((channel.read())[0] != (byte) 0xFE /* eof */) { /* skip */ }
681+
for (byte[] bytes; (bytes = channel.read())[0] != (byte) 0xFE /* eof */; ) {
682+
resultSet.add(new ResultSetRowPacket(bytes));
678683
}
679684
return resultSet.toArray(new ResultSetRowPacket[resultSet.size()]);
680685
}

src/test/java/com/github/shyiko/mysql/binlog/BinaryLogClientIntegrationTest.java

+3-10
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import com.github.shyiko.mysql.binlog.event.deserialization.QueryEventDataDeserializer;
3232
import com.github.shyiko.mysql.binlog.io.ByteArrayInputStream;
3333
import com.github.shyiko.mysql.binlog.network.AuthenticationException;
34+
import com.github.shyiko.mysql.binlog.network.ServerException;
3435
import org.mockito.InOrder;
3536
import org.testng.annotations.AfterClass;
3637
import org.testng.annotations.AfterMethod;
@@ -603,21 +604,13 @@ public void testExceptionIsThrownWhenProvidedWithWrongCredentials() throws Excep
603604
}
604605
}
605606

606-
@Test
607+
@Test(expectedExceptions = ServerException.class)
607608
public void testExceptionIsThrownWhenInsufficientPermissionsToDetectPosition() throws Exception {
608609
ResourceBundle bundle = ResourceBundle.getBundle("jdbc");
609610
String prefix = "jdbc.mysql.replication.";
610611
String slaveUsername = bundle.getString(prefix + "slave.slaveUsername");
611612
String slavePassword = bundle.getString(prefix + "slave.slavePassword");
612-
BinaryLogClient binaryLogClient =
613-
new BinaryLogClient(slave.hostname, slave.port, slaveUsername, slavePassword);
614-
615-
try {
616-
binaryLogClient.connect();
617-
fail("No REPLICATION CLIENT privilege should have resulted in IOException being thrown");
618-
} catch (IOException e) {
619-
assertFalse(binaryLogClient.isConnected());
620-
}
613+
new BinaryLogClient(slave.hostname, slave.port, slaveUsername, slavePassword).connect();
621614
}
622615

623616
private void bindInSeparateThread(final TCPReverseProxy tcpReverseProxy) throws InterruptedException {

0 commit comments

Comments
 (0)