|
20 | 20 |
|
21 | 21 | import java.sql.Connection; |
22 | 22 | import java.sql.SQLException; |
| 23 | +import java.util.concurrent.TimeUnit; |
23 | 24 |
|
24 | 25 | import javax.sql.ConnectionEvent; |
25 | 26 | import javax.sql.ConnectionEventListener; |
26 | 27 |
|
27 | 28 | import org.junit.jupiter.api.Test; |
| 29 | +import org.junit.jupiter.api.Timeout; |
28 | 30 | import org.junit.jupiter.api.extension.ExtendWith; |
29 | 31 | import org.mockito.InjectMocks; |
30 | 32 | import org.mockito.Mock; |
@@ -189,4 +191,24 @@ void testGetConnectionRestoresAutoCommit() throws SQLException { |
189 | 191 |
|
190 | 192 | verify(physical).setAutoCommit(true); |
191 | 193 | } |
| 194 | + |
| 195 | + /** |
| 196 | + * See also <a href="https://github.com/FirebirdSQL/jaybird/issues/927">#927</a>. |
| 197 | + */ |
| 198 | + @Test |
| 199 | + @Timeout(value = 200, unit = TimeUnit.MILLISECONDS, threadMode = Timeout.ThreadMode.SEPARATE_THREAD) |
| 200 | + void noInfiniteLoopWithNonFatalChainedExceptions(@Mock ConnectionEventListener cel) throws Exception { |
| 201 | + pooled.addConnectionEventListener(cel); |
| 202 | + Connection connection = pooled.getConnection(); |
| 203 | + |
| 204 | + var nonFatalChainedException = new SQLException("Not fatal"); |
| 205 | + nonFatalChainedException.setNextException(new SQLException("Not fatal either")); |
| 206 | + doThrow(nonFatalChainedException).when(physical).setAutoCommit(false); |
| 207 | + |
| 208 | + var exception = assertThrows(SQLException.class, () -> connection.setAutoCommit(false)); |
| 209 | + assertSame(nonFatalChainedException, exception); |
| 210 | + |
| 211 | + verify(cel, never()).connectionErrorOccurred(any(ConnectionEvent.class)); |
| 212 | + } |
| 213 | + |
192 | 214 | } |
0 commit comments