|
22 | 22 |
|
23 | 23 | import javax.sql.DataSource;
|
24 | 24 |
|
| 25 | +import com.zaxxer.hikari.HikariDataSource; |
| 26 | +import com.zaxxer.hikari.HikariPoolMXBean; |
25 | 27 | import org.apache.derby.jdbc.EmbeddedDriver;
|
26 | 28 | import org.junit.After;
|
27 | 29 | import org.junit.Before;
|
@@ -122,8 +124,23 @@ public void inMemoryDerbyIsShutdown() throws SQLException {
|
122 | 124 | ConfigurableApplicationContext context = createContext("org.apache.derby.jdbc.EmbeddedDriver",
|
123 | 125 | "jdbc:derby:memory:test;create=true", DataSourceAutoConfiguration.class,
|
124 | 126 | DataSourceSpyConfiguration.class);
|
125 |
| - JdbcTemplate jdbc = new JdbcTemplate(context.getBean(DataSource.class)); |
| 127 | + HikariDataSource dataSource = context.getBean(HikariDataSource.class); |
| 128 | + JdbcTemplate jdbc = new JdbcTemplate(dataSource); |
126 | 129 | jdbc.execute("SELECT 1 FROM SYSIBM.SYSDUMMY1");
|
| 130 | + HikariPoolMXBean pool = dataSource.getHikariPoolMXBean(); |
| 131 | + // Prevent a race between Hikari's initialization and Derby shutdown |
| 132 | + long end = System.currentTimeMillis() + 30000; |
| 133 | + while (pool.getIdleConnections() != dataSource.getMinimumIdle()) { |
| 134 | + if (System.currentTimeMillis() >= end) { |
| 135 | + throw new IllegalStateException("DataSource did not become idle within 30 seconds"); |
| 136 | + } |
| 137 | + try { |
| 138 | + Thread.sleep(100); |
| 139 | + } |
| 140 | + catch (InterruptedException ex) { |
| 141 | + Thread.currentThread().interrupt(); |
| 142 | + } |
| 143 | + } |
127 | 144 | context.close();
|
128 | 145 | // Connect should fail as DB no longer exists
|
129 | 146 | assertThatExceptionOfType(SQLException.class)
|
|
0 commit comments