|
1 | | -// SPDX-FileCopyrightText: Copyright 2011-2024 Mark Rotteveel |
| 1 | +// SPDX-FileCopyrightText: Copyright 2011-2026 Mark Rotteveel |
2 | 2 | // SPDX-License-Identifier: LGPL-2.1-or-later |
3 | 3 | package org.firebirdsql.ds; |
4 | 4 |
|
5 | 5 | import java.sql.Connection; |
6 | 6 | import java.sql.SQLException; |
| 7 | +import java.util.concurrent.TimeUnit; |
7 | 8 |
|
8 | 9 | import javax.sql.ConnectionEvent; |
9 | 10 | import javax.sql.ConnectionEventListener; |
10 | 11 |
|
11 | 12 | import org.junit.jupiter.api.Test; |
| 13 | +import org.junit.jupiter.api.Timeout; |
12 | 14 | import org.junit.jupiter.api.extension.ExtendWith; |
13 | 15 | import org.mockito.InjectMocks; |
14 | 16 | import org.mockito.Mock; |
@@ -173,4 +175,24 @@ void testGetConnectionRestoresAutoCommit() throws SQLException { |
173 | 175 |
|
174 | 176 | verify(physical).setAutoCommit(true); |
175 | 177 | } |
| 178 | + |
| 179 | + /** |
| 180 | + * See also <a href="https://github.com/FirebirdSQL/jaybird/issues/927">#927</a>. |
| 181 | + */ |
| 182 | + @Test |
| 183 | + @Timeout(value = 200, unit = TimeUnit.MILLISECONDS, threadMode = Timeout.ThreadMode.SEPARATE_THREAD) |
| 184 | + void noInfiniteLoopWithNonFatalChainedExceptions(@Mock ConnectionEventListener cel) throws Exception { |
| 185 | + pooled.addConnectionEventListener(cel); |
| 186 | + Connection connection = pooled.getConnection(); |
| 187 | + |
| 188 | + var nonFatalChainedException = new SQLException("Not fatal"); |
| 189 | + nonFatalChainedException.setNextException(new SQLException("Not fatal either")); |
| 190 | + doThrow(nonFatalChainedException).when(physical).setAutoCommit(false); |
| 191 | + |
| 192 | + var exception = assertThrows(SQLException.class, () -> connection.setAutoCommit(false)); |
| 193 | + assertSame(nonFatalChainedException, exception); |
| 194 | + |
| 195 | + verify(cel, never()).connectionErrorOccurred(any(ConnectionEvent.class)); |
| 196 | + } |
| 197 | + |
176 | 198 | } |
0 commit comments