From f546e2e88b2f67db77422fd22169d01a49b898e1 Mon Sep 17 00:00:00 2001 From: Mark Crisp Date: Thu, 23 Jul 2020 19:50:12 -0400 Subject: [PATCH 1/2] propagate all exceptions that occur in binary log client --- .../com/github/shyiko/mysql/binlog/BinaryLogClient.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/github/shyiko/mysql/binlog/BinaryLogClient.java b/src/main/java/com/github/shyiko/mysql/binlog/BinaryLogClient.java index 2fe57f53..e4b8b4df 100644 --- a/src/main/java/com/github/shyiko/mysql/binlog/BinaryLogClient.java +++ b/src/main/java/com/github/shyiko/mysql/binlog/BinaryLogClient.java @@ -495,8 +495,9 @@ public void setThreadFactory(ThreadFactory threadFactory) { * @throws AuthenticationException if authentication fails * @throws ServerException if MySQL server responds with an error * @throws IOException if anything goes wrong while trying to connect + * @throws IllegalStateException if binary log client is already connected */ - public void connect() throws IOException { + public void connect() throws IOException, IllegalStateException { if (!connectLock.tryLock()) { throw new IllegalStateException("BinaryLogClient is already connected"); } @@ -836,8 +837,8 @@ public void run() { try { setConnectTimeout(timeout); connect(); - } catch (IOException e) { - exceptionReference.set(e); + } catch (Exception e) { + exceptionReference.set(new IOException(e)); // method is asynchronous, catch all exceptions so that they are not lost countDownLatch.countDown(); // making sure we don't end up waiting whole "timeout" } } From d3c019e77546e1813dfd98266d98a56a24e0fbf0 Mon Sep 17 00:00:00 2001 From: Mark Crisp Date: Thu, 23 Jul 2020 20:03:58 -0400 Subject: [PATCH 2/2] added integration test --- .../shyiko/mysql/binlog/BinaryLogClientIntegrationTest.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/test/java/com/github/shyiko/mysql/binlog/BinaryLogClientIntegrationTest.java b/src/test/java/com/github/shyiko/mysql/binlog/BinaryLogClientIntegrationTest.java index 7b7efa31..aa81b588 100644 --- a/src/test/java/com/github/shyiko/mysql/binlog/BinaryLogClientIntegrationTest.java +++ b/src/test/java/com/github/shyiko/mysql/binlog/BinaryLogClientIntegrationTest.java @@ -833,6 +833,12 @@ public void testExceptionIsThrownWhenTryingToConnectAlreadyConnectedClient() thr client.connect(); } + @Test(expectedExceptions = IOException.class) + public void testExceptionIsThrownWhenTryingToConnectAlreadyConnectedClientWithTimeout() throws Exception { + assertTrue(client.isConnected()); + client.connect(1000); + } + @Test public void testExceptionIsThrownWhenProvidedWithWrongCredentials() throws Exception { BinaryLogClient binaryLogClient =