|
47 | 47 | import io.opentelemetry.sdk.testing.assertj.TraceAssert; |
48 | 48 | import java.beans.PropertyVetoException; |
49 | 49 | import java.io.Closeable; |
50 | | -import java.io.IOException; |
51 | 50 | import java.sql.CallableStatement; |
52 | 51 | import java.sql.Connection; |
53 | 52 | import java.sql.Driver; |
|
69 | 68 | import org.assertj.core.api.ThrowingConsumer; |
70 | 69 | import org.h2.jdbcx.JdbcDataSource; |
71 | 70 | import org.hsqldb.jdbc.JDBCDriver; |
72 | | -import org.junit.jupiter.api.AfterAll; |
73 | 71 | import org.junit.jupiter.api.BeforeAll; |
74 | 72 | import org.junit.jupiter.api.DisplayName; |
75 | 73 | import org.junit.jupiter.api.Test; |
@@ -129,32 +127,19 @@ static void setUp() { |
129 | 127 | prepareConnectionPoolDatasources(); |
130 | 128 | } |
131 | 129 |
|
132 | | - @AfterAll |
133 | | - static void tearDown() { |
134 | | - cpDatasources |
135 | | - .values() |
136 | | - .forEach( |
137 | | - k -> |
138 | | - k.values() |
139 | | - .forEach( |
140 | | - dataSource -> { |
141 | | - if (dataSource instanceof Closeable) { |
142 | | - try { |
143 | | - ((Closeable) dataSource).close(); |
144 | | - } catch (IOException ignored) { |
145 | | - // ignore exceptions during close |
146 | | - } |
147 | | - } |
148 | | - })); |
149 | | - } |
150 | | - |
151 | 130 | static void prepareConnectionPoolDatasources() { |
152 | 131 | List<String> connectionPoolNames = asList("tomcat", "hikari", "c3p0"); |
153 | 132 | connectionPoolNames.forEach( |
154 | 133 | cpName -> { |
155 | 134 | Map<String, DataSource> dbDsMapping = new HashMap<>(); |
156 | 135 | jdbcUrls.forEach( |
157 | | - (dbType, jdbcUrl) -> dbDsMapping.put(dbType, createDs(cpName, dbType, jdbcUrl))); |
| 136 | + (dbType, jdbcUrl) -> { |
| 137 | + DataSource dataSource = createDs(cpName, dbType, jdbcUrl); |
| 138 | + if (dataSource instanceof Closeable) { |
| 139 | + cleanup.deferAfterAll((Closeable) dataSource); |
| 140 | + } |
| 141 | + dbDsMapping.put(dbType, dataSource); |
| 142 | + }); |
158 | 143 | cpDatasources.put(cpName, dbDsMapping); |
159 | 144 | }); |
160 | 145 | } |
|
0 commit comments