Connections { static void checkConnectionState(PoolItem<Connection> connection, SQLException e) { String state = e.getSQLState(); if (state != null && (state.startsWith("08") || "S1009".equals(state))) { connection.broken = true; } if (e instanceof SQLTimeoutException) { connection.broken = true; } }    }
@Test void withSQLConnectionError() { PoolItem<Connection> connection = new PoolItem<>(null); Connections.checkConnectionState(connection, new SQLException("ER_HANDSHAKE_ERROR", "08S01")); assertThat(connection.broken).isTrue(); }
@Test void withQueryTimeout() { PoolItem<Connection> connection = new PoolItem<>(null); Connections.checkConnectionState(connection, new SQLTimeoutException("Statement cancelled due to timeout or client request")); assertThat(connection.broken).isTrue(); }
@Test void withStatementIsClosed() { PoolItem<Connection> connection = new PoolItem<>(null); Connections.checkConnectionState(connection, new SQLException("No operations allowed after statement closed", "S1009")); assertThat(connection.broken).isTrue(); }